1# Copyright (c) 2021-2022 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14definitions: [] 15tests: 16 - file-name: "fadd2" 17 isa: 18 title: Two address floating-point binary operation on accumulator 19 description: > 20 Perform specified floating-point binary operation on accumulator and register and store result into accumulator. 21 The results of instructions correspond IEEE-754 arithmetic rules. 22 exceptions: 23 - x_none 24 commands: 25 - file-name: "op_vs_8_nan" 26 isa: 27 instructions: 28 - sig: fadd2 v:in:f32 29 acc: inout:f32 30 format: [op_v_8] 31 description: Any operation with NaN results to NaN value. 32 check-type: check-acc-nan-f32 33 tags: ['irtoc_ignore'] 34 code-template: | 35 # 36 fldai %s 37 fmovi v0, *s 38 # Sum of any value and NaN is NaN 39 fadd2 v0 40 description: > 41 Check fadd2 results in NaN when acc or v0 is NaN 42 template-cases: 43 - values: 44 # NaN 45 - "0x7FC00000" 46 - values: 47 # NaN representation 48 - "0xFFFFFFFF" 49 - values: 50 # Positive zero 51 # +0.0d 52 - "0" 53 exclude: [hasval] 54 - values: 55 # Negative zero 56 # -0.0d 57 - "0x80000000" 58 exclude: [hasval] 59 - values: 60 # 1d 61 - "0x3ff00000" 62 exclude: [hasval] 63 - values: 64 # -1d 65 - "0xbff00000" 66 exclude: [hasval] 67 - values: 68 # +Inf 69 - "0x7f800000" 70 exclude: [hasval] 71 - values: 72 # -Inf 73 - "0xff800000" 74 exclude: [hasval] 75 - values: 76 # +max 77 - "0x7fefffff" 78 exclude: [hasval] 79 - values: 80 # -max 81 - "0xffefffff" 82 exclude: [hasval] 83 - values: 84 # +min 85 - "0x00000001" 86 exclude: [hasval] 87 - values: 88 # -min 89 - "0x80000001" 90 exclude: [hasval] 91 - values: 92 # Some FP value 93 - "9.9e-30" 94 exclude: [hasval] 95 - values: 96 # Some FP value 97 - "-0.000000001" 98 exclude: [hasval] 99 cases: 100 - values: 101 # NaN 102 - "0x7fc00000" 103 - values: 104 # NaN representation 105 - "0xFFFFFFFF" 106 - values: 107 # Positive zero 108 # +0.0d 109 - "0" 110 id: hasval 111 - values: 112 # Negative zero 113 # -0.0d 114 - "0x80000000" 115 id: hasval 116 - values: 117 # 1d 118 - "0x3ff00000" 119 id: hasval 120 - values: 121 # -1d 122 - "0xbff00000" 123 id: hasval 124 - values: 125 # +Inf 126 - "0x7f800000" 127 id: hasval 128 - values: 129 # -Inf 130 - "0xff800000" 131 id: hasval 132 - values: 133 # +max 134 - "0x7f7fffff" 135 id: hasval 136 - values: 137 # -max 138 - "0xff7fffff" 139 id: hasval 140 - values: 141 # +min 142 - "0x00000001" 143 id: hasval 144 - values: 145 # -min 146 - "0x80000001" 147 id: hasval 148 - values: 149 # Some FP value 150 - "9.9e-30" 151 id: hasval 152 - values: 153 # Some FP value 154 - "-0.000000001" 155 id: hasval 156 157 - file-name: "op_vs_8_pinf" 158 isa: 159 instructions: 160 - sig: fadd2 v:in:f32 161 acc: inout:f32 162 format: [op_v_8] 163 description: > 164 The sum of two infinities of the same sign or the difference of two infinities of opposite sign is infinity. 165 The sign of result matches the sign of accumulator value. 166 The sum or the difference of infinity and any finite value is infinity. 167 The sign of result matches the sign of infinity. 168 check-type: check-positive 169 tags: ['irtoc_ignore'] 170 code-template: | 171 # 172 fldai 0x7f800000 # +Inf 173 fmovi v0, %s 174 # Sum of +Inf and value 175 fadd2 v0 176 fmovi v1, %s 177 fcmpg v1 178 description: Check fadd2 with positive Inf and various values (Inf, min, max, numbers). 179 cases: 180 - values: 181 # +0.0d 182 - "0" 183 - "0x7f800000" 184 - values: 185 # -0.0d 186 - "0x80000000" 187 - "0x7f800000" 188 - values: 189 # 1d 190 - "0x3ff00000" 191 - "0x7f800000" 192 - values: 193 # -1d 194 - "0xbff00000" 195 - "0x7f800000" 196 - values: 197 # +Inf 198 - "0x7f800000" 199 - "0x7f800000" 200 - values: 201 # +max 202 - "0x7f7fffff" 203 - "0x7f800000" 204 - values: 205 # -max 206 - "0xff7fffff" 207 - "0x7f800000" 208 - values: 209 # +min 210 - "0x00000001" 211 - "0x7f800000" 212 - values: 213 # -min 214 - "0x80000001" 215 - "0x7f800000" 216 - values: 217 # Some FP value, 3.1415927 218 - "0x40490fdb" 219 - "0x7f800000" 220 - values: 221 - "123456780" 222 - "0x7f800000" 223 224 - file-name: "op_vs_8_ninf" 225 isa: 226 instructions: 227 - sig: fadd2 v:in:f32 228 acc: inout:f32 229 format: [op_v_8] 230 description: > 231 The sum of two infinities of the same sign or the difference of two infinities of opposite sign is infinity. 232 The sign of result matches the sign of accumulator value. 233 The sum or the difference of infinity and any finite value is infinity. 234 The sign of result matches the sign of infinity. 235 check-type: check-positive 236 tags: ['irtoc_ignore'] 237 # TODO update template to use Hexadecimal value for -Inf 238 code-template: | 239 # 240 fldai 0xff800000 # -Inf 241 fmovi v0, %s 242 # Sum of -Inf and value 243 fadd2 v0 244 fmovi v1, %s 245 fcmpg v1 246 description: Check fadd2 with negative Inf and various values (Inf, min, max, numbers). 247 cases: 248 - values: 249 # +0.0d 250 - "0" 251 # -Inf 252 - "0xff800000" 253 - values: 254 # -0.0d 255 - "0x80000000" 256 # -Inf 257 - "0xff800000" 258 - values: 259 # 1d 260 - "0x3ff00000" 261 # -Inf 262 - "0xff800000" 263 - values: 264 # -1d 265 - "0xbff00000" 266 # -Inf 267 - "0xff800000" 268 - values: 269 # -Inf 270 - "0xff800000" 271 # -Inf 272 - "0xff800000" 273 - values: 274 # +max 275 - "0x7f7fffff" 276 # -Inf 277 - "0xff800000" 278 - values: 279 # -max 280 - "0xff7fffff" 281 # -Inf 282 - "0xff800000" 283 - values: 284 # +min 285 - "0x00000001" 286 # -Inf 287 - "0xff800000" 288 - values: 289 # -min 290 - "0x80000001" 291 # -Inf 292 - "0xff800000" 293 - values: 294 # Some FP value, 3.1415927 295 - "0x40490fdb" 296 # -Inf 297 - "0xff800000" 298 - values: 299 - "1234567890" 300 # -Inf 301 - "0xff800000" 302 303 - file-name: "op_vs_8_inf_nan" 304 isa: 305 instructions: 306 - sig: fadd2 v:in:f32 307 acc: inout:f32 308 format: [op_v_8] 309 description: > 310 The sum of opposite infinities or the difference of the same sign infinities is NaN. 311 check-type: check-acc-nan-f32 312 tags: ['irtoc_ignore'] 313 code-template: | 314 # 315 fldai %s 316 fmovi v0, %s 317 # Sum of opposite Inf-s 318 fadd2 v0 319 description: Check fadd2 with +Inf and -Inf is NaN. 320 cases: 321 - values: 322 - "0x7f700000" 323 - "0x7fc00000" 324 - values: 325 - "0xff800000" 326 - "0x7fc00000" 327 328 - file-name: "op_vs_8_pzero" 329 isa: 330 instructions: 331 - sig: fadd2 v:in:f32 332 acc: inout:f32 333 format: [op_v_8] 334 description: > 335 The sum or the difference of infinity and any finite value is infinity. 336 The sign of result matches the sign of infinity. 337 The sum or the difference of zeros is zero. 338 Exceptions are the sum of two negative zeros and the difference of negative and positive zero - the result is negative zero. 339 check-type: check-positive 340 tags: ['irtoc_ignore'] 341 description: Check fadd2 with positive zero and various values (Inf, min, max, numbers). 342 code-template: | 343 # 344 fldai 0.0 # 345 fmovi v0, %s 346 mov v1, v0 347 # Sum of +0.0 and value 348 fadd2 v0 349 fcmpg v1 350 cases: 351 - values: 352 # +0.0d 353 - "0" 354 - values: 355 # -0.0d 356 - "0x80000000" 357 - values: 358 # 1d 359 - "1" 360 - values: 361 # -1d 362 - "-1" 363 - values: 364 # +Inf 365 - "0x7f800000" 366 - values: 367 # -Inf 368 - "0xff800000" 369 - values: 370 # +max 371 - "0x7f7fffff" 372 - values: 373 # -max 374 - "0xff7fffff" 375 - values: 376 # +min 377 - "0x00000001" 378 379 - values: 380 # -min 381 - "0x80000001" 382 - values: 383 - "3.1415927" 384 - values: 385 - "1234567890" 386 387 - file-name: "op_vs_8_nzero" 388 isa: 389 instructions: 390 - sig: fadd2 v:in:f32 391 acc: inout:f32 392 format: [op_v_8] 393 description: > 394 The sum or the difference of infinity and any finite value is infinity. 395 The sign of result matches the sign of infinity. 396 The sum or the difference of zeros is zero. 397 Exceptions are the sum of two negative zeros and the difference of negative and positive zero - the result is negative zero. 398 check-type: check-positive 399 tags: ['irtoc_ignore'] 400 description: Check fadd2 with negative zero and various values (Inf, min, max, numbers). 401 code-template: | 402 # 403 fldai -0.0 # 404 fmovi v0, %s 405 mov v1, v0 406 # Sum of -0.0 and value 407 fadd2 v0 408 fcmpg v1 409 cases: 410 # Comment this case, since it is incorrect. 411 # It seems the better way to compare -0.0 and -0.0 is to convert it to -Inf 412 # - case-template: | 413 # # 414 # fldai -0.0 # 415 # fmovi v0, -0.0 416 # # Sum of -0.0 and -0.0 should be -0.0 417 # fadd2 v0 418 # fmovi v1, -0.0 419 # cmp v1 # compare as binary values, due to +0.0 == -0.0, but 0x80000000 != 0x00000000 420 - values: 421 # 1d 422 - "1" 423 - values: 424 - "-1" 425 - values: 426 # +Inf 427 - "0x7f800000" 428 - values: 429 # -Inf 430 - "0xff800000" 431 - values: 432 # +max 433 - "0x7f7fffff" 434 - values: 435 # -max 436 - "0xff7fffff" 437 - values: 438 # +min 439 - "0x00000001" 440 - values: 441 # -min 442 - "0x80000001" 443 - values: 444 - "3.1415927" 445 - values: 446 - "1234567890" 447 448 - file-name: "op_vs_8_pone" 449 isa: 450 instructions: 451 - sig: fadd2 v:in:f32 452 acc: inout:f32 453 format: [op_v_8] 454 description: > 455 The sum or the difference of infinity and any finite value is infinity. 456 The sign of result matches the sign of infinity. 457 tags: ['irtoc_ignore'] 458 check-type: check-positive 459 description: Check fadd2 with +1 and various values (Inf, min, max, numbers). 460 code-template: | 461 # 462 fldai 1.0 # 463 fmovi v0, %s 464 # Sum of 1.0 and value 465 fadd2 v0 466 fmovi v1, %s 467 fcmpg v1 468 cases: 469 - values: 470 # +0.0d 471 - "0" 472 - "1.0" 473 - values: 474 # -0.0d 475 - "0x80000000" 476 - "1.0" 477 - values: 478 - "1.0" 479 - "2.0" 480 - values: 481 - "-1.0" 482 - "0" 483 - values: 484 # +Inf 485 - "0x7f800000" 486 - "0x7f800000" 487 - values: 488 # -Inf 489 - "0xff800000" 490 # -Inf 491 - "0xff800000" 492 - values: 493 # +max 494 - "0x7f7fffff" 495 - "0x7f7fffff" 496 - values: 497 # -max 498 - "0xff7fffff" 499 # -max 500 - "0xff7fffff" 501 - values: 502 # +min 503 - "0x00000001" 504 - "1.0" 505 - values: 506 # -min 507 - "0x80000001" 508 - "1.0" 509 - values: 510 # Some FP value, 3.1415927 511 - "3.1415927" 512 - "4.141593" 513 - values: 514 # Some FP value 515 - "1234.4321" 516 - "1235.4321" 517 518 - file-name: "op_vs_8_none" 519 isa: 520 instructions: 521 - sig: fadd2 v:in:f32 522 acc: inout:f32 523 format: [op_v_8] 524 description: > 525 The sum or the difference of infinity and any finite value is infinity. 526 The sign of result matches the sign of infinity. 527 check-type: check-positive 528 tags: ['irtoc_ignore'] 529 description: Check fadd2 with -1 and various values (Inf, min, max, numbers). 530 code-template: | 531 # 532 fldai -1.0 # 533 fmovi v0, %s 534 # Sum of -1.0 and value 535 fadd2 v0 536 fmovi v1, %s 537 fcmpg v1 538 cases: 539 - values: 540 # +0.0d 541 - "0" 542 - "-1" 543 - values: 544 # -0.0d 545 - "0x80000000" 546 - "-1" 547 - values: 548 # 1d 549 - "1" 550 - "0" 551 - values: 552 # -1d 553 - "-1" 554 - "-2" 555 - values: 556 # +Inf 557 - "0x7f800000" 558 - "0x7f800000" 559 - values: 560 # -Inf 561 - "0xff800000" 562 # -Inf 563 - "0xff800000" 564 - values: 565 # +max 566 - "0x7f7fffff" 567 - "0x7f7fffff" 568 - values: 569 # -max 570 - "0xff7fffff" 571 # -max 572 - "0xff7fffff" 573 - values: 574 # +min 575 - "0x00000001" 576 # -1d 577 - "-1" 578 - values: 579 # -min 580 - "0x80000001" 581 # -1d 582 - "-1" 583 - values: 584 # Some FP value, 3.1415927 585 - "3.1415927" 586 - "2.1415927" 587 - values: 588 # Some FP value 589 - "1234.4321" 590 - "1233.4321" 591 592 - file-name: "op_vs_8" 593 isa: 594 instructions: 595 - sig: fadd2 v:in:f32 596 acc: inout:f32 597 format: [op_v_8] 598 description: > 599 The sum or the difference of zeros is zero. 600 Exceptions are the sum of two negative zeros and the difference of negative and positive zero - the result is negative zero. 601 check-type: check-positive 602 tags: ['irtoc_ignore'] 603 description: Check fadd2 with various values. 604 code-template: | 605 # 606 fldai %s # 607 fmovi v0, %s 608 # Sum of -1.0 and value 609 fadd2 v0 610 fmovi v1, %s 611 fcmpg v1 612 cases: 613 - values: 614 - "0.0" 615 - "0.0" 616 - "0.0" 617 - values: 618 - "0.0" 619 - "-0.0" 620 - "0.0" 621 - values: 622 - "-0.0" 623 - "0.0" 624 - "0.0" 625 - values: 626 - "-0.0" 627 - "-0.0" 628 - "0.0" 629 - values: 630 - "1.0" 631 - "-1.0" 632 - "0.0" 633 - values: 634 - "-1.0" 635 - "1.0" 636 - "0.0" 637 - values: 638 - "1.0e30" 639 - "1.0e30" 640 - "2.0e30" 641 - values: 642 - "1.0e-30" 643 - "1.0e-30" 644 - "2.0e-30" 645 - values: 646 - "1.0e+30" 647 - "1.0e-30" 648 - "1.0e+30" 649 - values: 650 - "-1.0e30" 651 - "-1.0e30" 652 - "-2.0e30" 653 - values: 654 - "-1.0e-30" 655 - "-1.0e-30" 656 - "-2.0e-30" 657 - values: 658 - "-1.0e+30" 659 - "-1.0e-30" 660 - "-1.0e+30" 661 - values: 662 - "3.1415927" 663 - "3.1415927" 664 - "6.2831854" 665 - values: 666 - "3.1415927e20" 667 - "3.1415927e20" 668 - "6.2831854e20" 669# - values: 670# # TODO add test cases for maximal and minimal FP value in decimal scientific literal 671 672 - file-name: "op_vs_8_max" 673 isa: 674 instructions: 675 - sig: fadd2 v:in:f32 676 acc: inout:f32 677 format: [op_v_8] 678 check-type: check-positive 679 tags: ['irtoc_ignore'] 680 code-template: | 681 # 682 fldai %s 683 fmovi v0, %s 684 # Sum of two values 685 fadd2 v0 686 fmovi v1, %s 687 fcmpg v1 688 description: Check fadd2 with various max values. 689 cases: 690 - values: 691 # +max 692 - "0x7f7fffff" 693 # +max 694 - "0x7f7fffff" 695 # +Inf 696 - "0x7f800000" 697 - values: 698 # -max 699 - "0xff7fffff" 700 # -max 701 - "0xff7fffff" 702 # -Inf 703 - "0xff800000" 704 - values: 705 # +max 706 - "0x7f7fffff" 707 # -max 708 - "0xff7fffff" 709 - "0" 710 - values: 711 # +max 712 - "0x7f7fffff" 713 # 1d 714 - "0x3ff00000" 715 # +max 716 - "0x7f7fffff" 717 - values: 718 # +max 719 - "0x7f7fffff" 720 - "-1.0" 721 # +max 722 - "0x7f7fffff" 723 - values: 724 # -max 725 - "0xff7fffff" 726 - "1" 727 # -max 728 - "0xff7fffff" 729 - values: 730 # -max 731 - "0xff7fffff" 732 - "-1.0" 733 # -max 734 - "0xff7fffff" 735 736 - file-name: "incorrect_reg" 737 isa: 738 instructions: 739 - sig: fadd2 v:in:f32 740 acc: inout:f32 741 format: [op_v_8] 742 check-type: none 743 runner-options: [compile-failure] 744 description: Check fadd2 with incorrect register numbers. 745 code-template: | 746 # 747 fadd2 %s 748 cases: 749 - values: [v256] 750 - values: [v65535] 751 - values: [a0] 752 - values: [a255] 753 - values: ['null'] 754 - values: [0] 755 - values: [1.1] 756 - values: ['2.2'] 757 758 - file-name: "reg_number" 759 isa: 760 instructions: 761 - sig: fadd2 v:in:f32 762 acc: inout:f32 763 format: [op_v_8] 764 check-type: none 765 runner-options: [compile-only] 766 description: Check fadd2 with correct register numbers. 767 code-template: | 768 # 769 fadd2 %s 770 cases: 771 - values: [v0] 772 - values: [v16] 773 - values: [v128] 774 - values: [v255] 775 776 - file-name: "calc" 777 isa: 778 instructions: 779 - sig: fadd2 v:in:f32 780 acc: inout:f32 781 format: [op_v_8] 782 check-type: check-positive 783 description: Check fadd2 with various values. 784 tags: ['tsan', 'irtoc_ignore'] 785 code-template: | 786 # 787 fldai %s 788 fmovi v0, %s 789 fadd2 v0 790 fmovi v1, %s 791 fcmpg v1 792 cases: 793 - values: 794 - "-0.150508" 795 - "0.189967" 796 - "0.039459005" 797 - values: 798 - "0.099515" 799 - "0.037194" 800 - "0.136709" 801 - values: 802 - "0.038831" 803 - "-0.466269" 804 - "-0.427438" 805 - values: 806 - "-0.117858" 807 - "-0.410644" 808 - "-0.528502" 809 - values: 810 - "0.233251" 811 - "0.093035" 812 - "0.32628602" 813 - values: 814 - "-0.363069" 815 - "-0.188132" 816 - "-0.551201" 817 - values: 818 - "0.100352" 819 - "0.235968" 820 - "0.33631998" 821 - values: 822 - "-0.223127" 823 - "-0.218416" 824 - "-0.44154298" 825 - values: 826 - "0.185290" 827 - "0.484167" 828 - "0.669457" 829 - values: 830 - "-0.475417" 831 - "0.082336" 832 - "-0.39308098" 833 - values: 834 - "2.75991e-36" 835 - "-1.94471e-36" 836 - "8.151998e-37" 837 - values: 838 - "2.514854e14" 839 - "1.918314e15" 840 - "2.16979936e15" 841 - values: 842 - "-9.871449e19" 843 - "4.913647e20" 844 - "3.926502e20" 845 - values: 846 - "4.636161e-8" 847 - "-6.780937e-9" 848 - "3.9580673e-8" 849 - values: 850 - "-2.55497e19" 851 - "4.064694e19" 852 - "1.509724e19" 853 854 - file-name: "type" 855 isa: 856 instructions: 857 - sig: fadd2 v:in:f32 858 acc: inout:f32 859 format: [op_v_8] 860 verification: 861 - acc_type 862 - v1_type 863 tags: ['verifier'] 864 runner-options: ['verifier-failure', 'verifier-config'] 865 header-template: [] 866 code-template: | 867 # 868 .record A {} 869 .record B {} 870 .record panda.String <external> 871 .record panda.Object <external> 872 .function i32 main() { 873 %s 874 *s 875 fadd2 v0 876 check-type: exit-positive 877 description: Check 'fadd2' with incorrect register and accumulator type. 878 template-cases: 879 - values: 880 - movi v0, 0 881 - values: 882 - movi.64 v0, 0 883 - values: 884 - fmovi v0, 0 885 exclude: [val] 886 - values: 887 - fmovi.64 v0, 0 888 - values: 889 - | 890 # 891 lda.type B 892 sta.obj v0 893 - values: 894 - | 895 # 896 lda.type B[] 897 sta.obj v0 898 - values: 899 - | 900 # 901 lda.type panda.String 902 sta.obj v0 903 - values: 904 - | 905 # 906 lda.str "string" 907 sta.obj v0 908 - values: 909 - | 910 # 911 movi v0, 10 912 newarr v0, v0, i32[] 913 - values: 914 - mov.null v0 915 916 cases: 917 - values: 918 - ldai 0 919 - values: 920 - ldai.64 0 921 - values: 922 - fldai 0 923 id: val 924 - values: 925 - fldai.64 0 926 - values: 927 - | 928 # 929 lda.type A 930 - values: 931 - | 932 # 933 lda.type A[] 934 - values: 935 - | 936 # 937 lda.type panda.String 938 - values: 939 - | 940 # 941 lda.str "string" 942 - values: 943 - | 944 # 945 movi v1, 10 946 newarr v1, v1, f32[] 947 lda.obj v1 948 - values: 949 - lda.null 950 951 - file-name: uninitialized_regs 952 isa: 953 instructions: 954 - sig: fadd2 v:in:f32 955 acc: inout:f32 956 format: [op_v_8] 957 description: Check 'fadd2' with uninitialized register and accumulator. 958 tags: ['verifier'] 959 runner-options: ['verifier-failure', 'verifier-config'] 960 code-template: | 961 # 962 %s 963 *s 964 fadd2 %s 965 check-type: exit-positive 966 template-cases: 967 - values: 968 - '' 969 - v0 970 - values: 971 - fmovi v0, 0 972 - v0 973 exclude: [init] 974 - values: 975 - '' 976 - v7 977 - values: 978 - '' 979 - v15 980 - values: 981 - fmovi v15, 0 982 - v15 983 exclude: [init] 984 - values: 985 - '' 986 - v128 987 - values: 988 - fmovi v128, 0 989 - v128 990 exclude: [init] 991 - values: 992 - '' 993 - v255 994 - values: 995 - fmovi v255, 0 996 - v255 997 exclude: [init] 998 cases: 999 - values: 1000 - '' 1001 - values: 1002 - fldai 0 1003 id: init 1004