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.32"
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.32 v:in:f32[]
41              acc: inout:i32->f32
42              format: [op_v_8]
43              properties: [acc_read, acc_write, float]
44        description: Check fldarr.32 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, f32[]
50              ldai 0
51              fldarr.32 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.32 v:in:f32[]
63              acc: inout:i32->f32
64              format: [op_v_8]
65              properties: [acc_read, acc_write, float]
66        description: Check fldarr.32 reads items from array of different size and type in PandaAssembly context.
67        header-template: [PandaAssembly, main]
68        tags: ['irtoc_ignore']
69        code-template: |
70          #
71              movi v0, %s
72              newarr v0, v0, f32[]
73              ldai 0
74              fldarr.32 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.32 v:in:f32[]
87              acc: inout:i32->f32
88              format: [op_v_8]
89        tags: ['tsan', 'verifier']
90        bugid: ['3052']
91        description: Check array of primitive types for 'fldarr.32' 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.32 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            runner-options: [verifier-only, verifier-config]
133          - values: [f64]
134
135      - file-name: "primitive_types_j"
136        isa:
137          instructions:
138            - sig: fldarr.32 v:in:f32[]
139              acc: inout:i32->f32
140              format: [op_v_8]
141        tags: ['tsan', 'verifier', 'pa-verifier']
142        bugid: ['3052']
143        description: Check array of primitive types for 'fldarr.32' 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.32 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            runner-options: [verifier-only, verifier-config, use-pa]
179          - values: [f64]
180
181      - file-name: "read_values"
182        isa:
183          instructions:
184            - sig: fldarr.32 v:in:f32[]
185              acc: inout:i32->f32
186              format: [op_v_8]
187              properties: [acc_read, acc_write, float]
188        description: Check fldarr.32 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, f32[]       # 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              andi 0xFFFFFF    # Limit amount of digit in number to fit in f32 primitive without loss of precision
205              i32tof32
206              sta v5
207              fstarr.32 v1, v2 # save random number v1[v2] = acc
208              lda v2
209              fldarr.32 v1     # acc = v1[v2]
210              fcmpl v5      # Compare random number and stored value from array
211              jeqz passed
212              ldai 1
213              return
214          passed:
215              inci v3, -1
216              lda v3
217              jnez loop
218        check-type: exit-positive
219        cases:
220          - values: ['0', '1']
221          - values: ['254', '255']
222          - values: ['65535', '65536']
223          - values: ['7', '16']
224          - values: ['123', '255']
225          - values: ['49151', '65536']
226
227      - file-name: "read_all_values"
228        isa:
229          instructions:
230            - sig: fldarr.32 v:in:f32[]
231              acc: inout:i32->f32
232              format: [op_v_8]
233              properties: [acc_read, acc_write, float]
234        description: Check fldarr.32 reads correct items from array of primitives. Inspect different indexes and values.
235        tags: ['irtoc_ignore']
236        code-template: |
237          #
238              movi v1, 0       # v1 - index
239              movi v0, %s
240                               # v0 is array size
241              mov v2, v0       # v2 is size too
242              newarr v0, v0, f32[]       # v0 - testable array
243          fill_array:
244              lda v1
245              i32tof32         # acc = (f32)v1
246              fstarr.32 v0, v1 # v0[v1] = acc
247              inci v1, 1       # v1 = v1 + 1
248              lda v1
249              jne v2, fill_array
250
251              movi v1, 0       # index
252          check_array:
253              lda v1
254              fldarr.32 v0
255              sta v3
256              lda v1
257              i32tof32
258              fcmpl v3
259              jeqz ok
260              ldai 1
261              return
262          ok:
263              inci v1, 1
264              lda v1
265              jne v2, check_array
266        check-type: exit-positive
267        cases:
268          - values: ['100']
269          - values: ['255']
270            tags: ['tsan']
271          - values: ['65535']
272            tags: ['tsan']
273
274      - file-name: "reg_number"
275        isa:
276          instructions:
277            - sig: fldarr.32 v:in:f32[]
278              acc: inout:i32->f32
279              format: [op_v_8]
280              properties: [acc_read, acc_write, float]
281        check-type: empty
282        runner-options: [compile-only]
283        description: Check 'fldarr.32' instruction with different registers numbers.
284        header-template: []
285        code-template: |
286          #
287          .function i32 main() {
288              fldarr.32 %s
289          }
290        cases:
291          - values: [v0]
292          - values: [v16]
293          - values: [v128]
294          - values: [v255]
295          - values: [v256]
296            runner-options: [compile-failure]
297          - values: [v65535]
298            runner-options: [compile-failure]
299          - case-template: |
300              #
301              .function void f1(i32 a0) {
302                  fldarr.32 a0 # valid name of register
303              }
304
305              .function i32 main() {
306                  movi v0, 0
307                  call.short f1, v0
308              }
309          - case-template: |
310              #
311              .function void f1(i32 a0) {
312                  fldarr.32 a1 # invalid name of register
313              }
314
315              .function i32 main() {
316                  movi v0, 0
317                  call.short f1, v0
318              }
319            runner-options: [compile-failure]
320          - values: [a0]
321            runner-options: [compile-failure]
322          - values: [a255]
323            runner-options: [compile-failure]
324          - values: ['null']
325            runner-options: [compile-failure]
326          - values: [0]
327            runner-options: [compile-failure]
328          - values: [1.1]
329            runner-options: [compile-failure]
330          - values: ['2.2']
331            runner-options: [compile-failure]
332
333      - file-name: "arr_type"
334        isa:
335          instructions:
336            - sig: fldarr.32 v:in:f32[]
337              acc: inout:i32->f32
338              format: [op_v_8]
339              properties: [acc_read, acc_write, float]
340          verification:
341            - v1_array_type
342        tags: ['verifier']
343        runner-options: ['verifier-failure', 'verifier-config']
344        header-template: []
345        code-template: |
346          #
347          .record A {}
348          .record panda.String <external>
349          .record panda.Object <external>
350          .function i32 main() {
351              %s
352              ldai 0
353              fldarr.32 v0
354        check-type: exit-positive
355        description: Check 'fldarr.32' with incorrect array type. See also "rejectable_primitive_types" tests.
356        cases:
357          - values:
358              - movi v0, 0
359          - values:
360              - movi.64 v0, 0
361          - values:
362              - fmovi v0, 0
363          - values:
364              - fmovi.64 v0, 0
365          - values:
366              - |
367                #
368                    lda.type A
369                    sta.obj v0
370          - values:
371              - |
372                #
373                    lda.type A[]
374                    sta.obj v0
375          - values:
376              - |
377                #
378                    lda.type panda.String
379                    sta.obj v0
380          - values:
381              - |
382                #
383                    lda.type panda.String[]
384                    sta.obj v0
385          - values:
386              - |
387                #
388                    lda.type panda.Object
389                    sta.obj v0
390          - values:
391              - |
392                #
393                    lda.type panda.Object[]
394                    sta.obj v0
395          - values:
396              - |
397                #
398                    movi v0, 1
399                    newarr v0, v0, panda.Object[]
400          - values:
401              - |
402                #
403                    movi v0, 1
404                    newarr v0, v0, panda.String[]
405          - values:
406              - |
407                #
408                    lda.str "string"
409                    sta.obj v0
410
411      - file-name: "acc_type"
412        isa:
413          instructions:
414            - sig: fldarr.32 v:in:f32[]
415              acc: inout:i32->f32
416              format: [op_v_8]
417              properties: [acc_read, acc_write, float]
418          verification:
419            - acc_i32
420        tags: ['verifier']
421        runner-options: ['verifier-failure', 'verifier-config']
422        header-template: []
423        code-template: |
424          #
425          .record A {}
426          .record panda.String <external>
427          .record panda.Object <external>
428          .function i32 main() {
429              movi v0, 0
430              newarr v0, v0, f32[]
431              %s
432              fldarr.32 v0
433        check-type: exit-positive
434        description: Check 'fldarr.32' with incorrect index type.
435        cases:
436          - values:
437              - ldai.64 0
438          - values:
439              - fldai 0
440          - values:
441              - fldai.64 0
442          - values:
443              - lda.null
444          - values:
445              - |
446                #
447                    lda.type A
448          - values:
449              - |
450                #
451                    lda.type A[]
452          - values:
453              - |
454                #
455                    lda.type panda.String
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.32 v:in:f32[]
489              acc: inout:i32->f32
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.32 v0
506        check-type: exit-positive
507        description: Check 'fldarr.32' 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.32 v:in:f32[]
618              acc: inout:i32->f32
619              format: [op_v_8]
620              properties: [acc_read, acc_write, float]
621        description: Check 'fldarr.32' with uninitialized register and accumulator.
622        tags: ['verifier']
623        runner-options: ['verifier-failure', 'verifier-config']
624        code-template: |
625            #
626                %s
627                fldarr.32 v0
628        check-type: exit-positive
629        cases:
630          - values: ['ldai 0']
631          - values:
632            - |
633              #
634                  movi v0, 1
635                  newarr v0, v0, f32[]
636          - values: ['']
637
638      - file-name: array_out_of_bound_exception_p
639        isa:
640          instructions:
641            - sig: fldarr.32 v:in:f32[]
642              acc: inout:i32->f32
643              format: [op_v_8]
644              properties: [acc_read, acc_write, float]
645          exceptions:
646            - x_bounds
647        tags: ['irtoc_ignore']
648        description: Check 'fldarr.32' behavior when index is out of array bounds.
649        header-template: [aoobe_p, main]
650        code-template: |
651          #
652              movi v0, %s
653              newarr v0, v0, f32[]
654              ldai %s
655          begin:
656              fldarr.32 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.32 v:in:f32[]
698              acc: inout:i32->f32
699              format: [op_v_8]
700              properties: [acc_read, acc_write, float]
701          exceptions:
702            - x_bounds
703        description: Check 'fldarr.32' 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, f32[]
711              ldai %s
712          begin:
713              fldarr.32 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.32 v:in:f32[]
755              acc: inout:i32->f32
756              format: [op_v_8]
757              properties: [acc_read, acc_write, float]
758          exceptions:
759            - x_null
760        tags: ['irtoc_ignore']
761        description: Check 'fldarr.32' behavior when array is null reference.
762        header-template: [npe_p]
763        code-template: |
764          .function f32[] 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.32 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.32 v:in:f32[]
807              acc: inout:i32->f32
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.32' behavior when array is null reference.
814        header-template: [PandaAssembly, npe_j]
815        runner-options: [use-pa]
816        bugid: ['3293']
817        code-template: |
818          .function f32[] 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.32 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