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: "fsub2"
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: fsub2 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              fsub2 v0
39        description: >
40          Check fsub2 results in NaN when acc or v0 is NaN
41        template-cases:
42          - values:
43              # NaN
44              - "0x7ff80000"
45          - values:
46              # NaN representation
47              - "0xFFFFFFFF"
48          - values:
49              - "0"
50            exclude: [hasval]
51          - values:
52              - "-0.0"
53            exclude: [hasval]
54          - values:
55              - "1"
56            exclude: [hasval]
57          - values:
58              - "-1"
59            exclude: [hasval]
60          - values:
61              # +Inf
62              - "0x7ff00000"
63            exclude: [hasval]
64          - values:
65              # -Inf
66              - "0xfff00000"
67            exclude: [hasval]
68          - values:
69              # +max
70              - "0x7fefffff"
71            exclude: [hasval]
72          - values:
73              # -max
74              - "0xffefffff"
75            exclude: [hasval]
76          - values:
77              # +min
78              - "0x00000001"
79            exclude: [hasval]
80          - values:
81              # -min
82              - "0x80000001"
83            exclude: [hasval]
84          - values:
85              - "3.1415927"
86            exclude: [hasval]
87          - values:
88              - "1234567890"
89            exclude: [hasval]
90        cases:
91          - values:
92              # NaN
93              - "0x7ff80000"
94          - values:
95              # NaN
96              - "0xFFFFFFFF"
97          - values:
98              - "0"
99            id: hasval
100          - values:
101              - "-0.0"
102            id: hasval
103          - values:
104              - "1"
105            id: hasval
106          - values:
107              - "-1"
108            id: hasval
109          - values:
110              # +Inf
111              - "0x7ff00000"
112            id: hasval
113          - values:
114              # -Inf
115              - "0xfff00000"
116            id: hasval
117          - values:
118              # +max
119              - "0x7fefffff"
120            id: hasval
121          - values:
122              # -max
123              - "0xffefffff"
124            id: hasval
125          - values:
126              # +min
127              - "0x00000001"
128            id: hasval
129          - values:
130              # -min
131              - "0x80000001"
132            id: hasval
133          - values:
134              - "3.1415927"
135            id: hasval
136          - values:
137              - "1234567890"
138            id: hasval
139
140      - file-name: "op_vs_8_pinf"
141        isa:
142          instructions:
143            - sig: fsub2 v:in:f32
144              acc: inout:f32
145              format: [op_v_8]
146          description: >
147            The sum of two infinities of the same sign or the difference of two infinities of opposite sign is infinity.
148            The sign of result matches the sign of accumulator value.
149            The sum or the difference of infinity and any finite value is infinity.
150            The sign of result matches the sign of infinity.
151        check-type: check-positive
152        tags: ['irtoc_ignore']
153        code-template: |
154            #
155                fldai 0x7f800000 # +Inf
156                fmovi v0, %s
157            # Sub of +Inf and value
158                fsub2 v0
159                fmovi v1, %s
160                fcmpg v1
161        description: Check fsub2 with positive Inf and various values (NaN, Inf, min, max, numbers).
162        cases:
163          - values:
164              # -Inf
165              - "0xff800000"
166              - "0x7f800000"
167          - values:
168              - "0"
169              - "0x7f800000"
170          - values:
171              - "-0.0"
172              - "0x7f800000"
173          - values:
174              - "1"
175              - "0x7f800000"
176          - values:
177              - "-1"
178              - "0x7f800000"
179          - values:
180              # +max
181              - "0x7f7fffff"
182              - "0x7f800000"
183          - values:
184              # -max
185              - "0xff7fffff"
186              - "0x7f800000"
187          - values:
188              # +min
189              - "0x00000001"
190              - "0x7f800000"
191          - values:
192              # -min
193              - "0x80000001"
194              - "0x7f800000"
195          - values:
196              - "3.1415927"
197              - "0x7f800000"
198          - values:
199              - "1234567890"
200              - "0x7f800000"
201
202      - file-name: "op_vs_8_ninf"
203        isa:
204          instructions:
205            - sig: fsub2 v:in:f32
206              acc: inout:f32
207              format: [op_v_8]
208          description: >
209            The sum of two infinities of the same sign or the difference of two infinities of opposite sign is infinity.
210            The sign of result matches the sign of accumulator value.
211            The sum or the difference of infinity and any finite value is infinity.
212            The sign of result matches the sign of infinity.
213        check-type: check-positive
214        tags: ['irtoc_ignore']
215        code-template: |
216            #
217                fldai 0xff800000 # -Inf
218                fmovi v0, %s
219            # Sub of -Inf and value
220                fsub2 v0
221                fmovi v1, %s
222                fcmpg v1
223        description: Check fsub2 with negative Inf and various values (NaN, Inf, min, max, numbers).
224        cases:
225            - values:
226                # +Inf
227                - "0x7f800000"
228                # -Inf
229                - "0xff800000"
230            - values:
231                - "0"
232                # -Inf
233                - "0xff800000"
234            - values:
235                - "-0.0"
236                # -Inf
237                - "0xff800000"
238            - values:
239                - "1"
240                # -Inf
241                - "0xff800000"
242            - values:
243                - "-1"
244                # -Inf
245                - "0xff800000"
246            - values:
247                # +max
248                - "0x7f7fffff"
249                # -Inf
250                - "0xff800000"
251            - values:
252                # -max
253                - "0xff7fffff"
254                # -Inf
255                - "0xff800000"
256            - values:
257                # +min
258                - "0x00000001"
259                # -Inf
260                - "0xff800000"
261            - values:
262                # -min
263                - "0x80000001"
264                # -Inf
265                - "0xff800000"
266            - values:
267                - "3.1415927"
268                # -Inf
269                - "0xff800000"
270            - values:
271                - "1234567890"
272                # -Inf
273                - "0xff800000"
274
275      - file-name: "op_vs_8_inf_nan"
276        isa:
277          instructions:
278            - sig: fsub2 v:in:f32
279              acc: inout:f32
280              format: [op_v_8]
281          description: >
282            The sum of opposite infinities or the difference of the same sign infinities is NaN.
283        check-type: check-acc-nan-f32
284        tags: ['irtoc_ignore']
285        code-template: |
286            #
287                fldai %s
288                fmovi v0, %s
289            # Sub of same sign Inf-s
290                fsub2 v0
291        description: >
292          Check fsub2 with (-Inf, -Inf) and (+Inf, +Inf) is NaN.
293        cases:
294          - values:
295              - "0x7ff00000"
296              - "0x7ff00000"
297          - values:
298              - "0xfff00000"
299              - "0xfff00000"
300
301      - file-name: "op_vs_8_pzero"
302        isa:
303          instructions:
304            - sig: fsub2 v:in:f32
305              acc: inout:f32
306              format: [op_v_8]
307          description: >
308              The sum or the difference of infinity and any finite value is infinity.
309              The sign of result matches the sign of infinity.
310              The sum or the difference of zeros is zero.
311              Exceptions are the sum of two negative zeros and the difference of negative and positive zero - the result is negative zero.
312        check-type: check-positive
313        tags: ['irtoc_ignore']
314        code-template: |
315            #
316                fldai 0.0 #
317                fmovi v0, %s
318            # Sub of +0.0 and value
319                fsub2 v0
320                fmovi v1, %s
321                fcmpg v1
322        description: Check fsub2 with positive zero and various values (NaN, Inf, min, max, numbers).
323        cases:
324            - values:
325                - "0"
326                - "0"
327            - values:
328                - "-0.0"
329                - "0"
330            - values:
331                - "1"
332                - "-1"
333            - values:
334                - "-1"
335                - "1"
336            - values:
337                # +Inf
338                - "0x7f800000"
339                - "0xff800000"
340            - values:
341                # -Inf
342                - "0xff800000"
343                # +Inf
344                - "0x7f800000"
345            - values:
346                # +max
347                - "0x7f7fffff"
348                # -max
349                - "0xff7fffff"
350            - values:
351                # -max
352                - "0xff7fffff"
353                # +max
354                - "0x7f7fffff"
355            - values:
356                # +min
357                - "0x00000001"
358                - "0x80000001"
359            - values:
360                # -min
361                - "0x80000001"
362                - "0x00000001"
363            - values:
364                - "3.1415927"
365                - "-3.1415927"
366            - values:
367                - "-3.1415927"
368                - "3.1415927"
369
370      - file-name: "op_vs_8_nzero"
371        isa:
372          instructions:
373            - sig: fsub2 v:in:f32
374              acc: inout:f32
375              format: [op_v_8]
376          description: >
377              The sum or the difference of infinity and any finite value is infinity.
378              The sign of result matches the sign of infinity.
379              The sum or the difference of zeros is zero.
380              Exceptions are the sum of two negative zeros and the difference of negative and positive zero - the result is negative zero.
381        check-type: check-positive
382        tags: ['irtoc_ignore']
383        code-template: |
384            #
385                fldai -0.0 #
386                fmovi v0, %s
387            # Sub of -0.0 and value
388                fsub2 v0
389                fmovi v1, %s
390                fcmpg v1
391        description: Check fsub2 with negative zero and various values (NaN, Inf, min, max, numbers).
392        cases:
393          # Commented because there is no direct way to compare 0.0 and -0.0
394          # - case-template: |
395          #    #
396          #        fldai -0.0 #
397          #        fmovi v0, +0.0
398          #    # Sub of -0.0 and +0.0 should be -0.0
399          #        fsub2 v0
400          #        fmovi v1, -0.0
401          #        fcmpg v1 # compare as binary values, due to +0.0 == -0.0, but 0x8000000000000000 != 0x0000000000000000
402            - values:
403                - "0"
404                - "0"
405            - values:
406                - "-0.0"
407                - "0"
408            - values:
409                - "1"
410                - "-1"
411            - values:
412                - "-1"
413                - "1"
414            - values:
415                # +Inf
416                - "0x7f800000"
417                - "0xff800000"
418            - values:
419                # -Inf
420                - "0xff800000"
421                # +Inf
422                - "0x7f800000"
423            - values:
424                # +max
425                - "0x7f7fffff"
426                # -max
427                - "0xff7fffff"
428            - values:
429                # -max
430                - "0xff7fffff"
431                # +max
432                - "0x7f7fffff"
433            - values:
434                # +min
435                - "0x00000001"
436                - "0x80000001"
437            - values:
438                # -min
439                - "0x80000001"
440                - "0x00000001"
441            - values:
442                - "3.1415927"
443                - "-3.1415927"
444            - values:
445                - "-3.1415927"
446                - "3.1415927"
447
448      - file-name: "op_vs_8_pone"
449        isa:
450          instructions:
451            - sig: fsub2 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        check-type: check-positive
458        tags: ['irtoc_ignore']
459        code-template: |
460            #
461                fldai 1.0 #
462                fmovi v0, %s
463            # Sub of 1.0 and value
464                fsub2 v0
465                fmovi v1, %s
466                fcmpg v1
467        description: Check fsub2 with +1 and various values (NaN, Inf, min, max, numbers).
468        cases:
469          - values:
470              - "0"
471              - "1"
472          - values:
473              - "-0.0"
474              - "1"
475          - values:
476              - "1"
477              - "0"
478          - values:
479              - "-1"
480              - "2"
481          - values:
482              # +Inf
483              - "0x7f800000"
484              - "0xFF800000"
485          - values:
486              # -Inf
487              - "0xff800000"
488              # +Inf
489              - "0x7F800000"
490          - values:
491              # +max
492              - "0x7f7fffff"
493              - "0xFF7FFFFF"
494          - values:
495              # -max
496              - "0xFF7FFFFF"
497              # +max
498              - "0x7F7FFFFF"
499          - values:
500              # +min
501              - "0x00000001"
502              - "1"
503          - values:
504              # -min
505              - "0x80000001"
506              - "1"
507          - values:
508              - "3.1415927"
509              - "-2.1415927"
510          - values:
511              - "-3.1415927"
512              - "4.141593"
513          - values:
514              - "1234.9876"
515              - "-1233.9875"
516
517      - file-name: "op_vs_8_none"
518        isa:
519          instructions:
520            - sig: fsub2 v:in:f32
521              acc: inout:f32
522              format: [op_v_8]
523          description: >
524              The sum or the difference of infinity and any finite value is infinity.
525              The sign of result matches the sign of infinity.
526        check-type: check-positive
527        tags: ['irtoc_ignore']
528        code-template: |
529            #
530                fldai -1.0 #
531                fmovi v0, %s
532            # Sub of -1.0 and value
533                fsub2 v0
534                fmovi v1, %s
535                fcmpg v1
536        description: Check fsub2 with -1 and various values (NaN, Inf, min, max, numbers).
537        cases:
538          - values:
539              - "0"
540              - "-1"
541          - values:
542              - "-0.0"
543              - "-1"
544          - values:
545              - "1"
546              - "-2"
547          - values:
548              - "-1"
549              - "0"
550          - values:
551              # +Inf
552              - "0x7f800000"
553              - "0xff800000"
554          - values:
555              # -Inf
556              - "0xff800000"
557              # -Inf
558              - "0x7F800000"
559          - values:
560              # +max
561              - "0x7f7fffff"
562              - "0xFF7FFFFF"
563          - values:
564              # -max
565              - "0xFF7FFFFF"
566              - "0x7F7FFFFF"
567          - values:
568              # +min
569              - "0x00000001"
570              - "-1"
571          - values:
572              # -min
573              - "0x80000001"
574              - "-1"
575          - values:
576              - "3.1415927"
577              - "-4.141593"
578          - values:
579              - "-3.1415927"
580              - "2.1415927"
581          - values:
582              - "1234.9876"
583              - "-1235.9875"
584      - file-name: "op_vs_8"
585        isa:
586          instructions:
587            - sig: fsub2 v:in:f32
588              acc: inout:f32
589              format: [op_v_8]
590          description: >
591              The sum or the difference of zeros is zero.
592              Exceptions are the sum of two negative zeros and the difference of negative and positive zero - the result is negative zero.
593        check-type: check-positive
594        tags: ['irtoc_ignore']
595        code-template: |
596            #
597                fldai %s #
598                fmovi v0, %s
599            # Sub of -1.0 and value
600                fsub2 v0
601                fmovi v1, %s
602                fcmpg v1
603        description: Check fsub2 with various values.
604        cases:
605            - values:
606                - "0.0"
607                - "0.0"
608                - "0.0"
609            - values:
610                - "0.0"
611                - "-0.0"
612                - "0.0"
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                - "1.0"
623                - "-1.0"
624                - "2.0"
625            - values:
626                - "1.0"
627                - "1.0"
628                - "0.0"
629            - values:
630                - "-1.0"
631                - "1.0"
632                - "-2.0"
633            - values:
634                - "1.0e10"
635                - "1.0e10"
636                - "0.0"
637            - values:
638                - "1.0e10"
639                - "-1.0e10"
640                - "2.0e10"
641            - values:
642                - "1.0e+10"
643                - "1.0e-10"
644                - "1.0e+10"
645            - values:
646                - "-1.0e10"
647                - "1.0e10"
648                - "-2.0e10"
649            - values:
650                - "-1.0e-10"
651                - "1.0e-10"
652                - "-2.0e-10"
653            - values:
654                - "-1.0e+10"
655                - "-1.0e-10"
656                - "-1.0e+10"
657            - values:
658                - "3.1415927"
659                - "-3.1415927"
660                - "6.2831854"
661            - values:
662                - "3.1415927e20"
663                - "-3.1415927e20"
664                - "6.2831854e20"
665#            - values:
666#              # TODO add test cases for maximal and minimal FP value in decimal scientific literal
667      - file-name: "op_vs_8_max"
668        isa:
669          instructions:
670            - sig: fsub2 v:in:f32
671              acc: inout:f32
672              format: [op_v_8]
673        check-type: check-positive
674        tags: ['irtoc_ignore']
675        code-template: |
676            #
677                fldai %s
678                fmovi v0, %s
679            # Sub of two values
680                fsub2 v0
681                fmovi v1, %s
682                fcmpg v1
683        description: Check fsub2 with various max values.
684        cases:
685          - values:
686              # +max
687              - "0x7f7fffff"
688              # +max
689              - "0x7f7fffff"
690              - "0"
691          - values:
692              # -max
693              - "0xFF7FFFFF"
694              # -max
695              - "0xFF7FFFFF"
696              - "0"
697          - values:
698              # +max
699              - "0x7f7fffff"
700              # -max
701              - "0xFF7FFFFF"
702              # +Inf
703              - "0x7f800000"
704
705          - values:
706              # +max
707              - "0x7f7fffff"
708              - "1"
709              # +max
710              - "0x7f7fffff"
711
712          - values:
713              # +max
714              - "0x7f7fffff"
715              - "-1"
716              # +max
717              - "0x7f7fffff"
718          - values:
719              # -max
720              - "0xFF7FFFFF"
721              - "1"
722              # -max
723              - "0xFF7FFFFF"
724          - values:
725              # -max
726              - "0xFF7FFFFF"
727              - "-1"
728              # -max
729              - "0xFF7FFFFF"
730
731      - file-name: "incorrect_reg"
732        isa:
733          instructions:
734            - sig: fsub2 v:in:f32
735              acc: inout:f32
736              format: [op_v_8]
737        check-type: none
738        runner-options: [compile-failure]
739        description: Check fsub2 with incorrect register numbers.
740        code-template: |
741          #
742              fsub2 %s
743        cases:
744          - values: [v256]
745          - values: [v65535]
746          - values: [a0]
747          - values: [a255]
748          - values: ['null']
749          - values: [0]
750          - values: [1.1]
751          - values: ['2.2']
752
753      - file-name: "reg_number"
754        isa:
755          instructions:
756            - sig: fsub2 v:in:f32
757              acc: inout:f32
758              format: [op_v_8]
759        check-type: none
760        runner-options: [compile-only]
761        description: Check fsub2 with correct register numbers.
762        code-template: |
763          #
764              fsub2 %s
765        cases:
766          - values: [v0]
767          - values: [v16]
768          - values: [v128]
769          - values: [v255]
770
771
772      - file-name: "calc"
773        isa:
774          instructions:
775            - sig: fsub2 v:in:f32
776              acc: inout:f32
777              format: [op_v_8]
778        check-type: check-positive
779        code-template: |
780            #
781                fldai %s #
782                fmovi v0, %s
783                fsub2 v0
784                fmovi v1, %s
785                fcmpg v1
786        description: Check fsub2 with various values.
787        tags: ['tsan', 'irtoc_ignore']
788        cases:
789          - values:
790              - "-0.0567335"
791              - "0.4165127"
792              - "-0.4732462"
793          - values:
794              - "-0.2607618"
795              - "0.0750908"
796              - "-0.3358526"
797          - values:
798              - "-0.1367484"
799              - "-0.3743675"
800              - "0.2376191"
801          - values:
802              - "0.1286609"
803              - "0.4168653"
804              - "-0.28820437"
805          - values:
806              - "0.3796686"
807              - "0.499001"
808              - "-0.1193324"
809          - values:
810              - "0.1856411"
811              - "0.2197109"
812              - "-0.034069806"
813          - values:
814              - "0.40653"
815              - "0.11364"
816              - "0.29288998"
817          - values:
818              - "-0.1010416"
819              - "-0.1119799"
820              - "0.010938302"
821          - values:
822              - "0.3251595"
823              - "-0.0959657"
824              - "0.42112517"
825          - values:
826              - "0.2310778"
827              - "-0.2677659"
828              - "0.49884373"
829          - values:
830              - "2.2049776e-20"
831              - "-8.691135e-21"
832              - "3.074091e-20"
833          - values:
834              - "2.4603309e10"
835              - "-3.5318111e9"
836              - "2.81351188e10"
837
838      - file-name: "type"
839        isa:
840            instructions:
841              - sig: fsub2 v:in:f32
842                acc: inout:f32
843                format: [op_v_8]
844            verification:
845              - acc_type
846              - v1_type
847        tags: ['verifier']
848        runner-options: ['verifier-failure', 'verifier-config']
849        header-template: []
850        code-template: |
851          #
852          .record A {}
853          .record B {}
854          .record panda.String <external>
855          .record panda.Object <external>
856          .function i32 main() {
857              %s
858              *s
859              fsub2 v0
860        check-type: exit-positive
861        description: Check 'fsub2' with incorrect register and accumulator type.
862        template-cases:
863          - values:
864              - movi v0, 0
865          - values:
866              - movi.64 v0, 0
867          - values:
868              - fmovi v0, 0
869            exclude: [val]
870          - values:
871              - fmovi.64 v0, 0
872          - values:
873              - |
874                #
875                    lda.type B
876                    sta.obj v0
877          - values:
878              - |
879                #
880                    lda.type B[]
881                    sta.obj v0
882          - values:
883              - |
884                #
885                    lda.type panda.String
886                    sta.obj v0
887          - values:
888              - |
889                #
890                    lda.str "string"
891                    sta.obj v0
892          - values:
893              - |
894                #
895                    movi v0, 10
896                    newarr v0, v0, i32[]
897          - values:
898              - mov.null v0
899
900        cases:
901          - values:
902              - ldai 0
903          - values:
904              - ldai.64 0
905          - values:
906              - fldai 0
907            id: val
908          - values:
909              - fldai.64 0
910          - values:
911              - |
912                #
913                    lda.type A
914          - values:
915              - |
916                #
917                    lda.type A[]
918          - values:
919              - |
920                #
921                    lda.type panda.String
922          - values:
923              - |
924                #
925                    lda.str "string"
926          - values:
927              - |
928                #
929                    movi v1, 10
930                    newarr v1, v1, f64[]
931                    lda.obj v1
932          - values:
933              - lda.null
934
935      - file-name: uninitialized_regs
936        isa:
937          instructions:
938            - sig: fsub2 v:in:f32
939              acc: inout:f32
940              format: [op_v_8]
941        description: Check 'fsub2' with uninitialized register and accumulator.
942        tags: ['verifier']
943        runner-options: ['verifier-failure', 'verifier-config']
944        code-template: |
945            #
946                %s
947                *s
948                fsub2 %s
949        check-type: exit-positive
950        template-cases:
951          - values:
952              - ''
953              - v0
954          - values:
955              - fmovi v0, 0
956              - v0
957            exclude: [init]
958          - values:
959              - ''
960              - v7
961          - values:
962              - ''
963              - v15
964          - values:
965              - fmovi v15, 0
966              - v15
967            exclude: [init]
968          - values:
969              - ''
970              - v128
971          - values:
972              - fmovi v128, 0
973              - v128
974            exclude: [init]
975          - values:
976              - ''
977              - v255
978          - values:
979              - fmovi v255, 0
980              - v255
981            exclude: [init]
982        cases:
983          - values:
984              - ''
985          - values:
986              - fldai 0
987            id: init
988