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:
15  - name: PandaAssembly
16    template: |
17      .language PandaAssembly
18  - name: aoobe_p
19    template: |
20      .record panda.ArrayIndexOutOfBoundsException<external>
21  - name: aoobe_j
22    template: |
23      .record panda.ArrayIndexOutOfBoundsException<external>
24  - name: npe_p
25    template: |
26      .record panda.NullPointerException <external>
27  - name: npe_j
28    template: |
29      .record panda.NullPointerException <external>
30tests:
31  - file-name: "fldarr.64"
32    isa:
33      title: Load from array
34      description: >
35        Load an element from array using accumulator as an index and puts it into accumulator.
36    commands:
37      - file-name: "read_arr_p"
38        isa:
39          instructions:
40            - sig: fldarr.64 v:in:f64[]
41              acc: inout:i32->f64
42              format: [op_v_8]
43              properties: [acc_read, acc_write, float]
44        description: Check fldarr.64 reads items from array of different size and type in Panda Assembly context.
45        tags: ['irtoc_ignore']
46        code-template: |
47          #
48              movi v0, %s
49              newarr v0, v0, f64[]
50              ldai 0
51              fldarr.64 v0
52        check-type: exit-positive
53        cases:
54          - values: ['1']
55          - values: ['255']
56            tags: ['tsan']
57          - values: ['65536']
58
59      - file-name: "read_arr_j"
60        isa:
61          instructions:
62            - sig: fldarr.64 v:in:f64[]
63              acc: inout:i32->f64
64              format: [op_v_8]
65              properties: [acc_read, acc_write, float]
66        description: Check fldarr.64 reads items from array of different size and type in PandaAssembly context.
67        tags: ['irtoc_ignore']
68        header-template: [PandaAssembly, main]
69        code-template: |
70          #
71              movi v0, %s
72              newarr v0, v0, f64[]
73              ldai 0
74              fldarr.64 v0
75        check-type: exit-positive
76        runner-options: ['use-pa']
77        cases:
78          - values: ['1']
79          - values: ['255']
80            tags: ['tsan']
81          - values: ['65536']
82
83      - file-name: "primitive_types_p"
84        isa:
85          instructions:
86            - sig: fldarr.64 v:in:f64[]
87              acc: inout:i32->f64
88              format: [op_v_8]
89        tags: ['tsan', 'verifier']
90        bugid: ['3052']
91        description: Check array of primitive types for 'fldarr.64' instruction in Panda Assembly context.
92        header-template: []
93        code-template: |
94          .array arr_u1 u1 1 { 1 }
95          .array arr_i8 i8 1 { 1 }
96          .array arr_u8 u8 1 { 1 }
97          .array arr_i16 i16 1 { 1 }
98          .array arr_u16 u16 1 { 1 }
99          .array arr_i32 i32 1 { 1 }
100          .array arr_u32 u32 1 { 1 }
101          .array arr_i64 i64 1 { 1 }
102          .array arr_u64 u64 1 { 1 }
103          .array arr_f32 f32 1 { 1 }
104          .array arr_f64 f64 1 { 1 }
105          .function i32 main() {
106              %s
107              ldai 0
108              fldarr.64 v0
109        check-type: exit-positive
110        runner-options: [verifier-failure, verifier-config]
111        template-cases:
112          - values:
113            - |
114              #
115                  movi v0, 1
116                  newarr v0, v0, %s[]
117          - values:
118            - |
119              #
120                  lda.const v0, arr_%s
121        cases:
122          - values: [u1]
123          - values: [i8]
124          - values: [u8]
125          - values: [i16]
126          - values: [u16]
127          - values: [i32]
128          - values: [u32]
129          - values: [i64]
130          - values: [u64]
131          - values: [f32]
132          - values: [f64]
133            runner-options: [verifier-only, verifier-config]
134
135      - file-name: "primitive_types_j"
136        isa:
137          instructions:
138            - sig: fldarr.64 v:in:f64[]
139              acc: inout:i32->f64
140              format: [op_v_8]
141        tags: ['tsan', 'verifier', 'pa-verifier']
142        bugid: ['3052']
143        description: Check array of primitive types for 'fldarr.64' instruction in PandaAssembly context.
144        header-template: [PandaAssembly]
145        code-template: |
146          .array arr_u1 u1 1 { 1 }
147          .array arr_i8 i8 1 { 1 }
148          .array arr_i16 i16 1 { 1 }
149          .array arr_u16 u16 1 { 1 }
150          .array arr_i32 i32 1 { 1 }
151          .array arr_i64 i64 1 { 1 }
152          .array arr_f32 f32 1 { 1 }
153          .array arr_f64 f64 1 { 1 }
154          .function i32 main() {
155              %s
156              ldai 0
157              fldarr.64 v0
158        check-type: exit-positive
159        runner-options: [verifier-failure, verifier-config, use-pa]
160        template-cases:
161          - values:
162            - |
163              #
164                  movi v0, 1
165                  newarr v0, v0, %s[]
166          - values:
167            - |
168              #
169                  lda.const v0, arr_%s
170        cases:
171          - values: [u1]
172          - values: [i8]
173          - values: [i16]
174          - values: [u16]
175          - values: [i32]
176          - values: [i64]
177          - values: [f32]
178          - values: [f64]
179            runner-options: [verifier-only, verifier-config, use-pa]
180
181      - file-name: "read_values"
182        isa:
183          instructions:
184            - sig: fldarr.64 v:in:f64[]
185              acc: inout:i32->f64
186              format: [op_v_8]
187              properties: [acc_read, acc_write, float]
188        description: Check fldarr.64 reads correct items from array of primitives.
189        header-template: [xorshift32, main]
190        tags: ['irtoc_ignore']
191        code-template: |
192          #
193              movi v3, 10000   # iterations
194              movi v2, %s
195                               # index
196              movi v0, %s
197                               # array size
198              newarr v1, v0, f64[]       # v1 - testable array
199
200              movi v0, 1       # initial random number
201          loop:
202              call.short nextRand, v0
203              sta v0           # v0 - next random number
204              i32tof64
205              sta.64 v5
206              fstarr.64 v1, v2 # save random number v1[v2] = acc
207              lda v2
208              fldarr.64 v1     # acc = v1[v2]
209              fcmpl.64 v5      # Compare random number and stored value from array
210              jeqz passed
211              ldai 1
212              return
213          passed:
214              inci v3, -1
215              lda v3
216              jnez loop
217        check-type: exit-positive
218        cases:
219          - values: ['0', '1']
220          - values: ['254', '255']
221          - values: ['65535', '65536']
222          - values: ['7', '16']
223          - values: ['123', '255']
224          - values: ['49151', '65536']
225
226      - file-name: "read_all_values"
227        isa:
228          instructions:
229            - sig: fldarr.64 v:in:f64[]
230              acc: inout:i32->f64
231              format: [op_v_8]
232              properties: [acc_read, acc_write, float]
233        description: Check fldarr.64 reads correct items from array of primitives. Inspect different indexes and values.
234        tags: ['irtoc_ignore']
235        code-template: |
236          #
237              movi v1, 0       # v1 - index
238              movi v0, %s
239                               # v0 is array size
240              mov v2, v0       # v2 is size too
241              newarr v0, v0, f64[]       # v0 - testable array
242          fill_array:
243              lda v1
244              i32tof64         # acc = (f64)v1
245              fstarr.64 v0, v1 # v0[v1] = acc
246              inci v1, 1
247              lda v1
248              jne v2, fill_array
249
250              movi v1, 0       # index
251          check_array:
252              lda v1
253              fldarr.64 v0
254              sta.64 v3
255              lda v1
256              i32tof64
257              fcmpl.64 v3
258              jeqz ok
259              ldai 1
260              return
261          ok:
262              inci v1, 1
263              lda v1
264              jne v2, check_array
265        check-type: exit-positive
266        cases:
267          - values: ['100']
268          - values: ['255']
269            tags: ['tsan']
270          - values: ['65535']
271            tags: ['tsan']
272
273      - file-name: "reg_number"
274        isa:
275          instructions:
276            - sig: fldarr.64 v:in:f64[]
277              acc: inout:i32->f64
278              format: [op_v_8]
279              properties: [acc_read, acc_write, float]
280        check-type: empty
281        runner-options: [compile-only]
282        description: Check 'fldarr.64' instruction with different registers numbers.
283        header-template: []
284        code-template: |
285          #
286          .function i32 main() {
287              fldarr.64 %s
288          }
289        cases:
290          - values: [v0]
291          - values: [v16]
292          - values: [v128]
293          - values: [v255]
294          - values: [v256]
295            runner-options: [compile-failure]
296          - values: [v65535]
297            runner-options: [compile-failure]
298          - case-template: |
299              #
300              .function void f1(i32 a0) {
301                  fldarr.64 a0 # valid name of register
302              }
303
304              .function i32 main() {
305                  movi v0, 0
306                  call.short f1, v0
307              }
308          - case-template: |
309              #
310              .function void f1(i32 a0) {
311                  fldarr.64 a1 # invalid name of register
312              }
313
314              .function i32 main() {
315                  movi v0, 0
316                  call.short f1, v0
317              }
318            runner-options: [compile-failure]
319          - values: [a0]
320            runner-options: [compile-failure]
321          - values: [a255]
322            runner-options: [compile-failure]
323          - values: ['null']
324            runner-options: [compile-failure]
325          - values: [0]
326            runner-options: [compile-failure]
327          - values: [1.1]
328            runner-options: [compile-failure]
329          - values: ['2.2']
330            runner-options: [compile-failure]
331
332      - file-name: "arr_type"
333        isa:
334          instructions:
335            - sig: fldarr.64 v:in:f64[]
336              acc: inout:i32->f64
337              format: [op_v_8]
338              properties: [acc_read, acc_write, float]
339          verification:
340            - v1_array_type
341        tags: ['verifier']
342        runner-options: ['verifier-failure', 'verifier-config']
343        header-template: []
344        code-template: |
345          #
346          .record A {}
347          .record panda.String <external>
348          .record panda.Object <external>
349          .function i32 main() {
350              %s
351              ldai 0
352              fldarr.64 v0
353        check-type: exit-positive
354        description: Check 'fldarr.64' with incorrect array type. See also "rejectable_primitive_types" tests.
355        cases:
356          - values:
357              - movi v0, 0
358          - values:
359              - movi.64 v0, 0
360          - values:
361              - fmovi v0, 0
362          - values:
363              - fmovi.64 v0, 0
364          - values:
365              - |
366                #
367                    lda.type A
368                    sta.obj v0
369          - values:
370              - |
371                #
372                    lda.type A[]
373                    sta.obj v0
374          - values:
375              - |
376                #
377                    lda.type panda.String
378                    sta.obj v0
379          - values:
380              - |
381                #
382                    lda.type panda.String[]
383                    sta.obj v0
384          - values:
385              - |
386                #
387                    lda.type panda.Object
388                    sta.obj v0
389          - values:
390              - |
391                #
392                    lda.type panda.Object[]
393                    sta.obj v0
394          - values:
395              - |
396                #
397                    movi v0, 1
398                    newarr v0, v0, panda.Object[]
399          - values:
400              - |
401                #
402                    movi v0, 1
403                    newarr v0, v0, panda.String[]
404          - values:
405              - |
406                #
407                    lda.str "string"
408                    sta.obj v0
409
410      - file-name: "acc_type"
411        isa:
412          instructions:
413            - sig: fldarr.64 v:in:f64[]
414              acc: inout:i32->f64
415              format: [op_v_8]
416              properties: [acc_read, acc_write, float]
417          verification:
418            - acc_i32
419        tags: ['verifier']
420        runner-options: ['verifier-failure', 'verifier-config']
421        header-template: []
422        code-template: |
423          #
424          .record A {}
425          .record panda.String <external>
426          .record panda.Object <external>
427          .function i32 main() {
428              movi v0, 0
429              newarr v0, v0, f64[]
430              %s
431              fldarr.64 v0
432        check-type: exit-positive
433        description: Check 'fldarr.64' with incorrect index type.
434        cases:
435          - values:
436              - ldai.64 0
437          - values:
438              - fldai 0
439          - values:
440              - fldai.64 0
441          - values:
442              - lda.null
443          - values:
444              - |
445                #
446                    lda.type A
447          - values:
448              - |
449                #
450                    lda.type A[]
451          - values:
452              - |
453                #
454                    lda.type panda.String
455
456          - values:
457              - |
458                #
459                    lda.type panda.String[]
460          - values:
461              - |
462                #
463                    lda.type panda.Object
464          - values:
465              - |
466                #
467                    lda.type panda.Object[]
468          - values:
469              - |
470                #
471                    lda.str "string"
472          - values:
473              - |
474                #
475                    movi v1, 1
476                    newarr v1, v1, panda.Object[]
477                    lda.obj v1
478          - values:
479              - |
480                #
481                    movi v1, 1
482                    newarr v1, v1, panda.String[]
483                    lda.obj v1
484
485      - file-name: "arr_acc_type"
486        isa:
487          instructions:
488            - sig: fldarr.64 v:in:f64[]
489              acc: inout:i32->f64
490              format: [op_v_8]
491              properties: [acc_read, acc_write, float]
492          verification:
493            - v1_array_type
494        tags: ['verifier']
495        runner-options: ['verifier-failure', 'verifier-config']
496        header-template: []
497        code-template: |
498          #
499          .record A {}
500          .record panda.String <external>
501          .record panda.Object <external>
502          .function i32 main() {
503              %s
504              *s
505              fldarr.64 v0
506        check-type: exit-positive
507        description: Check 'fldarr.64' with incorrect register and accumulator types.
508        template-cases:
509          - values:
510              - movi v0, 0
511          - values:
512              - movi.64 v0, 0
513          - values:
514              - fmovi v0, 0
515          - values:
516              - fmovi.64 v0, 0
517          - values:
518              - |
519                #
520                    lda.type A
521                    sta.obj v0
522          - values:
523              - |
524                #
525                    lda.type A[]
526                    sta.obj v0
527          - values:
528              - |
529                #
530                    lda.type panda.String
531                    sta.obj v0
532          - values:
533              - |
534                #
535                    lda.type panda.String[]
536                    sta.obj v0
537          - values:
538              - |
539                #
540                    lda.type panda.Object
541                    sta.obj v0
542          - values:
543              - |
544                #
545                    lda.type panda.Object[]
546                    sta.obj v0
547          - values:
548              - |
549                #
550                    lda.str "string"
551                    sta.obj v0
552          - values:
553              - |
554                #
555                    movi v1, 1
556                    newarr v0, v1, panda.Object[]
557          - values:
558              - |
559                #
560                    movi v1, 1
561                    newarr v0, v1, panda.String[]
562        cases:
563          - values:
564              - ldai 0
565          - values:
566              - ldai.64 0
567          - values:
568              - fldai 0
569          - values:
570              - fldai.64 0
571          - values:
572              - lda.null
573          - values:
574              - |
575                #
576                    lda.type A
577          - values:
578              - |
579                #
580                    lda.type A[]
581          - values:
582              - |
583                #
584                    lda.type panda.String
585          - values:
586              - |
587                #
588                    lda.type panda.String[]
589          - values:
590              - |
591                #
592                    lda.type panda.Object
593          - values:
594              - |
595                #
596                    lda.type panda.Object[]
597          - values:
598              - |
599                #
600                    lda.str "string"
601          - values:
602              - |
603                #
604                    movi v1, 1
605                    newarr v1, v1, panda.Object[]
606                    lda.obj v1
607          - values:
608              - |
609                #
610                    movi v1, 1
611                    newarr v1, v1, panda.String[]
612                    lda.obj v1
613
614      - file-name: uninitialized_acc_regs
615        isa:
616          instructions:
617            - sig: fldarr.64 v:in:f64[]
618              acc: inout:i32->f64
619              format: [op_v_8]
620              properties: [acc_read, acc_write, float]
621        description: Check 'fldarr.64' with uninitialized register and accumulator.
622        tags: ['verifier']
623        runner-options: ['verifier-failure', 'verifier-config']
624        code-template: |
625            #
626                %s
627                fldarr.64 v0
628        check-type: exit-positive
629        cases:
630          - values: ['ldai 0']
631          - values:
632            - |
633              #
634                  movi v0, 1
635                  newarr v0, v0, f64[]
636          - values: ['']
637
638      - file-name: array_out_of_bound_exception_p
639        isa:
640          instructions:
641            - sig: fldarr.64 v:in:f64[]
642              acc: inout:i32->f64
643              format: [op_v_8]
644              properties: [acc_read, acc_write, float]
645          exceptions:
646            - x_bounds
647        description: Check 'fldarr.64' behavior when index is out of array bounds.
648        tags: ['irtoc_ignore']
649        header-template: [aoobe_p, main]
650        code-template: |
651          #
652              movi v0, %s
653              newarr v0, v0, f64[]
654              ldai %s
655          begin:
656              fldarr.64 v0
657          end:
658              ldai 1 # Should not reach this line
659              return
660
661          catch_AOOBE:
662              ldai 0 # Expected panda.ArrayIndexOutOfBoundsException
663              return
664
665          catch_all:
666              ldai 2 # Unexpected exception, test failed
667              return
668
669          .catch panda.ArrayIndexOutOfBoundsException, begin, end, catch_AOOBE
670          .catchall begin, end, catch_all
671        check-type: none
672        cases:
673          - values: [0, 0]
674            tags: ['tsan']
675          - values: [0, 1]
676          - values: [10, 10]
677          - values: [10, 128]
678          - values: [255, 255]
679          - values: [254, 255]
680          - values: [65535, 65535]
681            tags: ['tsan']
682          - values: [65535, 65536]
683          - values: [10, 0xFFFFFFFF]
684          - values: [256, 0xFFFFFFFE]
685          - values: [65536, 0xFFFFFFFD]
686            tags: ['tsan']
687          - values: [0x100000, 0xFFFFFFFC]
688          - values: [10, 0x80000000]
689          - values: [256, 0x80000001]
690          - values: [65536, 0x80000002]
691            tags: ['tsan']
692          - values: [0x100000, 0x80000003]
693
694      - file-name: array_out_of_bound_exception_j
695        isa:
696          instructions:
697            - sig: fldarr.64 v:in:f64[]
698              acc: inout:i32->f64
699              format: [op_v_8]
700              properties: [acc_read, acc_write, float]
701          exceptions:
702            - x_bounds
703        description: Check 'fldarr.64' behavior when index is out of array bounds.
704        tags: ['irtoc_ignore']
705        runner-options: [use-pa]
706        header-template: [PandaAssembly, aoobe_j, main]
707        code-template: |
708          #
709              movi v0, %s
710              newarr v0, v0, f64[]
711              ldai %s
712          begin:
713              fldarr.64 v0
714          end:
715              ldai 1 # Should not reach this line
716              return
717
718          catch_AOOBE:
719              ldai 0 # Expected panda.ArrayIndexOutOfBoundsException
720              return
721
722          catch_all:
723              ldai 2 # Unexpected exception, test failed
724              return
725
726          .catch panda.ArrayIndexOutOfBoundsException, begin, end, catch_AOOBE
727          .catchall begin, end, catch_all
728        check-type: none
729        cases:
730          - values: [0, 0]
731            tags: ['tsan']
732          - values: [0, 1]
733          - values: [10, 10]
734          - values: [10, 128]
735          - values: [255, 255]
736          - values: [254, 255]
737          - values: [65535, 65535]
738            tags: ['tsan']
739          - values: [65535, 65536]
740          - values: [10, 0xFFFFFFFF]
741          - values: [256, 0xFFFFFFFE]
742          - values: [65536, 0xFFFFFFFD]
743            tags: ['tsan']
744          - values: [0x100000, 0xFFFFFFFC]
745          - values: [10, 0x80000000]
746          - values: [256, 0x80000001]
747          - values: [65536, 0x80000002]
748            tags: ['tsan']
749          - values: [0x100000, 0x80000003]
750
751      - file-name: null_pointer_p
752        isa:
753          instructions:
754            - sig: fldarr.64 v:in:f64[]
755              acc: inout:i32->f64
756              format: [op_v_8]
757              properties: [acc_read, acc_write, float]
758          exceptions:
759            - x_null
760        description: Check 'fldarr.64' behavior when array is null reference.
761        tags: ['irtoc_ignore']
762        header-template: [npe_p]
763        code-template: |
764          .function f64[] get_null() {
765              lda.null
766              return.obj
767          }
768
769          .function i32 main() {
770              call.short get_null
771              sta.obj v0
772              ldai %s
773          begin:
774              fldarr.64 v0
775          end:
776              ldai 1 # Should not reach this line
777              return
778
779          catch_NPE:
780              ldai 0 # Expected panda.NullPointerException
781              return
782
783          catch_all:
784              ldai 2 # Unexpected exception, test failed
785              return
786
787          .catch panda.NullPointerException, begin, end, catch_NPE
788          .catchall begin, end, catch_all
789        check-type: none
790        cases:
791          - values: [0]
792            tags: ['tsan']
793          - values: [1]
794          - values: [10]
795          - values: [128]
796          - values: [255]
797          - values: [65535]
798            tags: ['tsan']
799          - values: [0x7FFFFFFF]
800          - values: [0xFFFFFFFF]
801          - values: [0x80000000]
802
803      - file-name: null_pointer_j
804        isa:
805          instructions:
806            - sig: fldarr.64 v:in:f64[]
807              acc: inout:i32->f64
808              format: [op_v_8]
809              properties: [acc_read, acc_write, float]
810          exceptions:
811            - x_null
812        tags: ['irtoc_ignore']
813        description: Check 'fldarr.64' behavior when array is null reference.
814        header-template: [PandaAssembly, npe_j]
815        runner-options: [use-pa]
816        bugid: ['3047']
817        code-template: |
818          .function f64[] get_null() {
819              lda.null
820              return.obj
821          }
822
823          .function i32 main() {
824              call.short get_null
825              sta.obj v0
826              ldai %s
827          begin:
828              fldarr.64 v0
829          end:
830              ldai 1 # Should not reach this line
831              return
832
833          catch_NPE:
834              ldai 0 # Expected panda.NullPointerException
835              return
836
837          catch_all:
838              ldai 2 # Unexpected exception, test failed
839              return
840
841          .catch panda.NullPointerException, begin, end, catch_NPE
842          .catchall begin, end, catch_all
843        check-type: none
844        cases:
845          - values: [0]
846            tags: ['tsan']
847          - values: [1]
848          - values: [10]
849          - values: [128]
850          - values: [255]
851          - values: [65535]
852            tags: ['tsan']
853          - values: [0x7FFFFFFF]
854          - values: [0xFFFFFFFF]
855          - values: [0x80000000]
856