• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 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: "mod"
17    isa:
18      title: Three address integer division or modulo
19      description: Perform integer division or modulo on two registers and store result into accumulator
20    commands:
21      - file-name: "op_v1_4_v2_4_zero"
22        isa:
23          instructions:
24            - sig: mod v1:in:i32, v2:in:i32
25              acc: out:i32
26              format: [op_v1_4_v2_4]
27        code-template: |
28          #
29              movi v0, 0
30              movi v1, %s
31              mod v0, v1
32              movi v0, 0
33              jne v0, set_failure
34              ldai 0
35              jmp fall_through
36          set_failure:
37              ldai 1
38          fall_through:
39        description: Check mod with zero and various values.
40        cases:
41          - values: ["1"]
42          - values: ["-1"]
43          - values: ["0x7FFFFFFF"]
44          - values: ["0x80000000"]
45          - values: ["-0x7FFFFFFF"]
46          - values: ["-0x80000000"]
47          - values: ["0xFFFFFFFF"]
48          - values: ["-0xFFFFFFFF"]
49
50      - file-name: "op_vs_8_pone"
51        isa:
52          instructions:
53            - sig: mod v1:in:i32, v2:in:i32
54              acc: out:i32
55              format: [op_v1_4_v2_4]
56        code-template: |
57          #
58              movi v0, 1
59              movi v1, %s
60              mod v0, v1
61              movi v0, %s
62              jne v0, set_failure
63              ldai 0
64              jmp fall_through
65          set_failure:
66              ldai 1
67          fall_through:
68        description: Check mod with +1 and various values.
69        cases:
70          - values: ["1", "0x0"]
71          - values: ["-1", "0x0"]
72          - values: ["0x7FFFFFFF", "0x1"]
73          - values: ["-0x7FFFFFFF", "0x1"]
74          - values: ["0x80000000", "0x1"]
75          - values: ["-0x80000000", "0x1"]
76          - values: ["0xFFFFFFFF", "0x0"]
77          - values: ["-0xFFFFFFFF", "0x0"]
78
79      - file-name: "op_vs_8_none"
80        isa:
81          instructions:
82            - sig: mod v1:in:i32, v2:in:i32
83              acc: out:i32
84              format: [op_v1_4_v2_4]
85        code-template: |
86          #
87              movi v0, -1
88              movi v1, %s
89              mod v0, v1
90              movi v0, %s
91              jne v0, set_failure
92              ldai 0
93              jmp fall_through
94          set_failure:
95              ldai 1
96          fall_through:
97        description: Check mod with -1 and various values.
98        cases:
99          - values: ["1", "0x0"]
100          - values: ["-1", "0x0"]
101          - values: ["0x7FFFFFFF", "0xFFFFFFFF"]
102          - values: ["-0x7FFFFFFF", "0xFFFFFFFF"]
103          - values: ["0x80000000", "0xFFFFFFFF"]
104          - values: ["-0x80000000", "0xFFFFFFFF"]
105          - values: ["0xFFFFFFFF", "0x0"]
106          - values: ["-0xFFFFFFFF", "0x0"]
107
108      - file-name: "op_vs_8_pmax"
109        isa:
110          instructions:
111            - sig: mod v1:in:i32, v2:in:i32
112              acc: out:i32
113              format: [op_v1_4_v2_4]
114        code-template: |
115          #
116              movi v0, 0x7FFFFFFF
117              movi v1, %s
118              mod v0, v1
119              movi v0, %s
120              jne v0, set_failure
121              ldai 0
122              jmp fall_through
123          set_failure:
124              ldai 1
125          fall_through:
126        description: Check mod with +max and various values.
127        cases:
128          - values: ["1", "0x0"]
129          - values: ["-1", "0x0"]
130          - values: ["0x7FFFFFFF", "0x0"]
131          - values: ["-0x7FFFFFFF", "0x0"]
132          - values: ["0x80000000", "0x7FFFFFFF"]
133          - values: ["-0x80000000", "0x7FFFFFFF"]
134          - values: ["0xFFFFFFFF", "0x0"]
135          - values: ["-0xFFFFFFFF", "0x0"]
136
137      - file-name: "op_vs_8_nmax"
138        isa:
139          instructions:
140            - sig: mod v1:in:i32, v2:in:i32
141              acc: out:i32
142              format: [op_v1_4_v2_4]
143        code-template: |
144          #
145              movi v0, -0x80000000
146              movi v1, %s
147              mod v0, v1
148              movi v0, %s
149              jne v0, set_failure
150              ldai 0
151              jmp fall_through
152          set_failure:
153              ldai 1
154          fall_through:
155        description: Check mod with -max and various values.
156        cases:
157          - values: ["1", "0x0"]
158          - values: ["-1", "0x0"]
159          - values: ["0x7FFFFFFF", "0xFFFFFFFF"]
160          - values: ["-0x7FFFFFFF", "0xFFFFFFFF"]
161          - values: ["0x80000000", "0x0"]
162          - values: ["-0x80000000", "0x0"]
163          - values: ["0xFFFFFFFF", "0x0"]
164          - values: ["-0xFFFFFFFF", "0x0"]
165
166      - file-name: "vals"
167        isa:
168          instructions:
169            - sig: mod v1:in:i32, v2:in:i32
170              acc: out:i32
171              format: [op_v1_4_v2_4]
172        code-template: |
173          #
174              movi v0, %s
175              movi v1, %s
176              mod v0, v1
177              movi v0, %s
178              jne v0, set_failure
179              ldai 0
180              jmp fall_through
181          set_failure:
182              ldai 1
183          fall_through:
184        description: Check mod with various values.
185        tags: ['tsan']
186        cases:
187          - values: ["0x87A8E1D9", "0x6D8935CF", "0xF53217A8"]
188          - values: ["0x6AFB709C", "0xD7328FDF", "0x1960905A"]
189          - values: ["0x91AD1CA9", "0x330B9F8D", "0xF7C45BC3"]
190          - values: ["0xC5EA3D60", "0x40FCDDC1", "0xC5EA3D60"]
191          - values: ["0x63F6803C", "0x616041E0", "0x2963E5C"]
192          - values: ["0x1E0384B", "0x7C662C8", "0x1E0384B"]
193          - values: ["0x3CFC06FC", "0x54EF2076", "0x3CFC06FC"]
194          - values: ["0x47CB3788", "0x35782ACF", "0x12530CB9"]
195          - values: ["0x2680767A", "0x4E618FD7", "0x2680767A"]
196          - values: ["0x817E8C9D", "0xB92B1E1B", "0xC8536E82"]
197          - values: ["0x80000000", "-1", "0"]
198          - values: ["-2147483648", "-1", "0"]
199
200      - file-name: "op_v1_4_v2_4_exception"
201        isa:
202          instructions:
203            - sig: mod v1:in:i32, v2:in:i32
204              acc: out:i32
205              format: [op_v1_4_v2_4]
206          exceptions:
207            - x_arith
208        header-template: [ArithmeticException, main]
209        code-template: |
210            #
211                movi v0, %s
212                movi v1, 0
213            begin:
214                mod v0, v1
215            end:
216                ldai 1 # Should not reach this line
217                return
218
219            catch_AE:
220                ldai 0 # Expected panda.ArithmeticException
221                return
222
223            catch_all:
224                ldai 1 # Unexpected exception, test failed
225                return
226
227            .catch panda.ArithmeticException, begin, end, catch_AE
228            .catchall begin, end, catch_all
229        check-type: none
230        description: Check `mod` throws ArithmeticException when divides by zero.
231        cases:
232          - values: ["0"]
233          - values: ["1"]
234          - values: ["0x7FFFFFFF"]
235          - values: ["0x80000000"]
236          - values: ["0xFFFFFFFF"]
237          - values: ["-1"]
238          - values: ["-0x7FFFFFFF"]
239          - values: ["-0x80000000"]
240          - values: ["-0xFFFFFFFF"]
241
242      - file-name: "regs"
243        isa:
244          instructions:
245            - sig: mod v1:in:i32, v2:in:i32
246              acc: out:i32
247              format: [op_v1_4_v2_4]
248        runner-options: ['compile-only']
249        code-template: |
250          #
251              mod %s, %s
252        check-type: none
253        description: Check mod with various register numbers.
254        cases:
255          - values: ["v15", "v15"]
256          - values: ["v0", "v15"]
257          - values: ["v15", "v0"]
258          - values: ["v15", "v16"]
259            runner-options: ['compile-failure']
260          - values: ["v16", "v15"]
261            runner-options: ['compile-failure']
262          - values: ["v16", "v16"]
263            runner-options: ['compile-failure']
264
265      - file-name: type_v2
266        # These tests will be removed due to verifier tests cover these cases.
267        bugid: ["964", "966"]
268        tags: ["verifier"]
269        isa:
270          instructions:
271            - sig: mod v1:in:i32, v2:in:i32
272              acc: out:i32
273              format: [op_v1_4_v2_4]
274          verification:
275            - v2_type
276        runner-options: ['verifier-failure', 'verifier-debug-config']
277        code-template: |
278          #
279              movi v0, 1
280              %s
281              sta v1
282              mod v0, v1
283              ldai 0
284              return
285        check-type: no-check
286        description: Check mod with incorrect second register type.
287        cases:
288          - values: [lda.str ""]
289          - values: [lda.str "some string"]
290          - values: [lda.null]
291          - values: [fldai.64 0.0]
292          - values: [fldai.64 -0.0]
293          - values: [fldai.64 1.0]
294          - values: [fldai.64 -1.0]
295          - values: [fldai.64 0x7FF8000000000000]
296          - values: [fldai.64 0xFFFFFFFFFFFFFFFF]
297          - values: [fldai.64 0x7FF0000000000000]
298          - values: [fldai.64 0xFFF0000000000000]
299          - values: [fldai.64 0xFFEFFFFFFFFFFFFF]
300          - values: [fldai.64 0x7FEFFFFFFFFFFFFF]
301          - values: [fldai.64 0x0000000000000001]
302          - values: [fldai.64 0x8000000000000001]
303          - values: [fldai.64 3.14159265358979323846]
304          - values: [ldai.64 0]
305          - values: [ldai.64 1]
306          - values: [ldai.64 -1]
307          - values: [ldai.64 0x0000000100000000]
308          - values: [ldai.64 0x0000000080000000]
309          - values: [ldai.64 0x8000000000000000]
310          - values: [ldai.64 0xFFFFFFFF00000000]
311          - values: [ldai.64 0xFFFFFFFFFFFFFFFF]
312
313      - file-name: type_v1
314        # These tests will be removed due to verifier tests cover these cases.
315        bugid: ["964", "966"]
316        tags: ["verifier"]
317        isa:
318          instructions:
319            - sig: mod v1:in:i32, v2:in:i32
320              acc: out:i32
321              format: [op_v1_4_v2_4]
322          verification:
323            - v1_type
324        runner-options: ['verifier-failure', 'verifier-debug-config']
325        code-template: |
326          #
327              %s
328              sta v0
329              movi v1, 1
330              mod v0, v1
331              ldai 0
332              return
333        check-type: no-check
334        description: Check mod with incorrect first register type.
335        cases:
336          - values: [lda.str ""]
337          - values: [lda.str "some string"]
338          - values: [lda.null]
339          - values: [fldai.64 0.0]
340          - values: [fldai.64 -0.0]
341          - values: [fldai.64 1.0]
342          - values: [fldai.64 -1.0]
343          - values: [fldai.64 0x7FF8000000000000]
344          - values: [fldai.64 0xFFFFFFFFFFFFFFFF]
345          - values: [fldai.64 0x7FF0000000000000]
346          - values: [fldai.64 0xFFF0000000000000]
347          - values: [fldai.64 0xFFEFFFFFFFFFFFFF]
348          - values: [fldai.64 0x7FEFFFFFFFFFFFFF]
349          - values: [fldai.64 0x0000000000000001]
350          - values: [fldai.64 0x8000000000000001]
351          - values: [fldai.64 3.14159265358979323846]
352          - values: [ldai.64 0]
353          - values: [ldai.64 1]
354          - values: [ldai.64 -1]
355          - values: [ldai.64 0x0000000100000000]
356          - values: [ldai.64 0x0000000080000000]
357          - values: [ldai.64 0x8000000000000000]
358          - values: [ldai.64 0xFFFFFFFF00000000]
359          - values: [ldai.64 0xFFFFFFFFFFFFFFFF]
360
361      - file-name: type_obj_v1
362        bugid: ["964", "966"]
363        tags: ["verifier"]
364        isa:
365          instructions:
366            - sig: mod v1:in:i32, v2:in:i32
367              acc: out:i32
368              format: [op_v1_4_v2_4]
369          verification:
370            - v1_type
371        runner-options: ['verifier-failure', 'verifier-debug-config']
372        description: Check mod with incorrect first register type.
373        code-template: |
374          #
375          .record Object {}
376          .function i32 main() {
377              %s
378
379              movi v1, 1
380              mod v0, v1
381              ldai 0
382              return
383        check-type: none
384        header-template: []
385        cases:
386          - values:
387            - |
388              lda.type Object
389              sta.obj v0
390          - values:
391            - newobj v0, Object
392
393      - file-name: type_obj_v2
394        bugid: ["964", "966"]
395        tags: ["verifier"]
396        isa:
397          instructions:
398            - sig: mod v1:in:i32, v2:in:i32
399              acc: out:i32
400              format: [op_v1_4_v2_4]
401          verification:
402            - v2_type
403        runner-options: ['verifier-failure', 'verifier-debug-config']
404        description: Check mod with incorrect second register type.
405        code-template: |
406          #
407          .record Object {}
408          .function i32 main() {
409              movi v0, 1
410              %s
411              mod v0, v1
412              ldai 0
413              return
414        check-type: none
415        header-template: []
416        cases:
417          - values:
418            - |
419              lda.type Object
420              sta.obj v1
421          - values:
422            - newobj v1, Object
423