• 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: "jgez"
17    isa:
18      title: Conditional compared to zero jump
19      description: >
20        Transfer execution to an instruction at offset bytes
21        from the beginning of the current instruction
22        if signed 32-bit integer in accumulator compares with 0 as specified.
23        Offset is sign extended to the size of instruction address.
24      exceptions:
25        - x_none
26    commands:
27
28      - file-name: "op"
29        isa:
30          instructions:
31            - sig: jgez imm:i32
32              acc: in:i32
33              format: [op_imm_8, op_imm_16]
34        description: >
35          Check jump occurs or not occurs, depending on `acc < 0` condition
36          for forward, backward, or current cases.
37        code-template: |
38          #
39              %s
40        check-type: exit-positive
41        cases:
42          - values:
43            - |
44              # Check forward jump
45                  ldai 0
46                  jgez label
47                  ldai 255 ##*65536
48                  return  # should be jumped over
49              label:
50          - values:
51            - |
52              # Check backward jump
53                  jmp label2
54              label1:
55                  jmp label3
56                  ldai 255 ##*65536
57              label2:
58                  ldai 1
59                  jgez label1
60                  ldai 255
61                  return  # should be jummped over
62              label3:
63          - values:
64              - |
65                # Check jump to itself
66                    ldai -1
67                loop:
68                    jgez loop
69            bugid: ['3468']
70          - values:
71              - |
72                # Check jump to itself
73                    ldai 1
74                loop:
75                    jgez loop
76            runner-options: [compile-only]
77
78      - file-name: "op_bounds_1"
79        isa:
80          instructions:
81            - sig: jgez imm:i32
82              acc: in:i32
83              format: [op_imm_8, op_imm_16]
84        description: >
85          Check jump occurs or not occurs, depending on `acc > 0` condition
86          for forward and backward cases.
87        code-template: |
88          #
89              %s
90        check-type: none
91        cases:
92          - values:
93            - |
94              # Max forward jump for imm8, 2 + 124 + 1 = 127 bytes
95                  ldai 1
96                  jgez label    # 2-byte instruction
97                  ldai 1 ##*62
98                  return
99              label:
100                  ldai 0
101                  return
102          - values:
103            - |
104              # Max backward jump for imm8, 2 + 61*2 + 1 + 1 + 2 = 128 bytes
105                  jmp label2
106              label:
107                  ldai 61
108                  subi 1 ##*61
109                  return
110                  return
111              label2:
112                  ldai 1
113                  jgez label
114                  return
115          - values:
116            - |
117              # Max forward jump for imm16, 3 + 32760 + 4 = 32767 bytes
118                  ldai 1
119                  jgez label    # 3-byte instruction
120                  movi.64 v0, 0 ##*3276
121                  addi 3
122                  return
123                  return
124              label:
125                  ldai 0
126                  return
127          - values:
128            - |
129              # Max backward jump for imm16, 1 + 4 + 32760 + 1 + 2 = 32768 bytes
130                  jmp label2
131              label:
132                  ldai 0
133                  return
134                  ldai 1
135                  movi.64 v0, 0 ##*3276
136                  return
137              label2:
138                  ldai 1
139                  jgez label
140                  return
141
142      - file-name: "op_bounds_2"
143        isa:
144          instructions:
145            - sig: jgez imm:i32
146              acc: in:i32
147              format: [op_imm_8, op_imm_16]
148        description: >
149          Check jump occurs or not occurs, depending on `acc == 0` condition
150          for forward and backward cases.
151        code-template: |
152          #
153              %s
154        check-type: none
155        cases:
156          - values:
157            - |
158              # Max forward jump for imm8, 2 + 124 + 1 = 127 bytes
159                  ldai 0
160                  jgez label    # 2-byte instruction
161                  neg
162                  ldai 2 ##*62
163              label:
164                  return
165          - values:
166            - |
167              # Max backward jump for imm8, 1 + 2 + 61*2 + 1 + 2 = 128 bytes
168                  jmp label2
169              label:
170                  neg
171                  ldai 61
172                  subi 1 ##*61
173                  return
174              label2:
175                  ldai 0
176                  jgez label
177                  ldai 1
178                  return
179          - values:
180            - |
181              # Max forward jump for imm16, 3 + 32760 + 4 = 32767 bytes
182                  ldai 0
183                  jgez label    # 3-byte instruction
184                  movi.64 v0, 0 ##*3276
185                  ldai 1
186                  ldai 1
187              label:
188                  return
189          - values:
190            - |
191              # Max backward jump for imm16, 1 + 4 + 32760 + 1 + 2 = 32768 bytes
192                  jmp label2
193              label:
194                  return
195                  ldai 2
196                  ldai 2
197                  movi.64 v0, 0 ##*3276
198                  return
199              label2:
200                  ldai 0
201                  jgez label
202                  ldai 1
203                  return
204
205      - file-name: "vals"
206        isa:
207          instructions:
208            - sig: jgez imm:i32
209              acc: in:i32
210              format: [op_imm_8, op_imm_16]
211        description: >
212          Check jump not occurs if `acc < 0`
213          for different values in acc.
214        code-template: |
215          #
216              ldai %s
217              jgez label_bad
218              ldai *s
219              jgez label_good
220          label_bad:
221              ldai 255
222              return  # should be jumped over
223          label_good:
224        check-type: exit-positive
225        template-cases:
226          - values:
227              - "-1"
228            exclude: [one]
229          - values:
230              - "0x80000000"
231            exclude: [max]
232          - values:
233              - "0xFFFFFFFF"
234            exclude: [one]
235        cases:
236          - values:
237              - "1"
238            id: one
239          - values:
240              - "0x7FFFFFFF"
241            id: max
242
243      - file-name: "type"
244        isa:
245          instructions:
246            - sig: jgez imm:i32
247              acc: in:i32
248              format: [op_imm_8, op_imm_16]
249          verification:
250              - acc_type
251        description: >
252          Check `jgez` with invalid types in acc.
253        tags: ['verifier']
254        runner-options: ['verifier-failure', 'verifier-debug-config']
255        header-template: []
256        code-template: |
257          #
258          .record A {}
259          .record panda.String <external>
260          .record panda.Object <external>
261          .function i32 main() {
262              %s
263              jgez label
264              ldai 255
265          label:
266        check-type: exit-positive
267        cases:
268          - values:
269              - lda.null
270          - values:
271              - ldai.64 0
272          - values:
273              - fldai.64 0
274          - values:
275              - lda.type A
276          - values:
277              - lda.type A[]
278          - values:
279              - lda.type panda.String
280          - values:
281              - |
282                newobj v0, A
283                lda.obj v0
284          - values:
285              - |
286                newobj v0, panda.Object
287                lda.obj v0
288          - values:
289              - lda.str "0"
290          - values:
291              - |
292                #
293                    movi v0, 10
294                    newarr v0, v0, i32[]
295                    lda.obj v0
296
297      - file-name: "outside_function"
298        isa:
299          instructions:
300            - sig: jgez imm:i32
301              acc: in:i32
302              format: [op_imm_8, op_imm_16]
303          verification:
304            - branch_target
305        description: >
306          Branch target should point to a beginning
307          of an instruction of the same method.
308        runner-options: ['compile-failure']
309        header-template: []
310        code-template: |
311          #
312          .function i32 f() {
313          label:
314              ldai 255
315              return
316          }
317          .function i32 main() {
318              ldai 1
319              jgez label
320        check-type: exit-positive
321
322      - file-name: "outside_try_catch_p"
323        isa:
324          instructions:
325            - sig: jgez imm:i32
326              acc: in:i32
327              format: [op_imm_8, op_imm_16]
328        description: Jump outside try/catch block.
329        bugid: ['3425']
330        header-template: []
331        code-template: |
332          .record panda.ArithmeticException <external>
333          .function i32 main() {
334          begin:
335              ldai 1
336              jgez outside
337              newobj v0, panda.ArithmeticException
338              throw v0
339          end:
340              ldai 1
341              return
342          catch_ae:
343              ldai 2
344              return
345          .catch panda.ArithmeticException, begin, end, catch_ae
346              ldai 3
347              return
348          outside:
349        check-type: exit-positive
350
351      - file-name: uninitialized_regs
352        isa:
353          instructions:
354            - sig: jgez imm:i32
355              acc: in:i32
356              format: [op_imm_8, op_imm_16]
357        description: Check `jgez` with uninitialized acc.
358        tags: ['verifier']
359        runner-options: ['verifier-failure', 'verifier-debug-config']
360        code-template: |
361          #
362          label:
363              jgez label
364        check-type: exit-positive
365
366      - file-name: "invalid_branch_target"
367        isa:
368          verification:
369            - branch_target
370        runner-options: [compile-failure]
371        description: Check 'jgez' instruction with invalid branch target.
372        header-template: []
373        code-template: |
374            .record R {}
375
376            .function void R.ctor(R a0) <ctor> {
377            lbl_ctor:
378                return.void
379            }
380
381            .function void R.cctor() <cctor> {
382            lbl_cctor:
383                return.void
384            }
385
386            .function i32 foo(i32 a0, i32 a1) <static> {
387                lda a0
388                jgez %s
389                return
390            }
391
392            .function i32 bar() <static> {
393            lbl_bar:
394                ldai 1
395                return
396            }
397
398            .function i32 main() {
399                movi v0, 0
400                movi v1, 1
401                call.short foo, v0, v1
402            lbl_main:
403        check-type: exit-positive
404        cases:
405          - values: ["main"]
406          - values: ["foo"]
407          - values: ["bar"]
408          - values: ["baz"]
409          - values: ["R"]
410          - values: ["lbl_main"]
411          - values: ["lbl_bar"]
412          - values: ["lbl_ctor"]
413          - values: ["lbl_cctor"]
414
415
416      - file-name: "prohibited_branch_target"
417        isa:
418          verification:
419            - branch_target
420        runner-options: ['verifier-failure', 'verifier-debug-config']
421        tags: [verifier]
422        description: Check 'jgez' instruction with prohibited branch target.
423        header-template: []
424        code-template: |
425            .record E1 {}
426            .record E2 {}
427
428            .function i32 main() {
429                ldai 0
430                jgez %s
431
432            begin:
433                ldai 0
434                return
435            mid:
436                ldai 1
437                return
438            end:
439                ldai 2
440                return
441
442            catch_E1_begin:
443                ldai 3
444                return
445            catch_E1_mid:
446                ldai 4
447                return
448            catch_E1_end:
449                ldai 5
450                return
451
452            catch_E2_begin:
453                ldai 6
454                return
455            catch_E2_mid:
456                ldai 7
457                return
458            catch_E2_end:
459
460            quit:
461                ldai 8
462                return
463
464            .catch E1, begin, end, catch_E1_begin, catch_E1_end
465            .catch E2, catch_E1_begin, catch_E1_end, catch_E2_begin, catch_E2_end
466            outside:
467        check-type: none
468        cases:
469          - values: ["begin"]
470            runner-options: ['verifier-only', 'verifier-debug-config']
471          - values: ["mid"]
472            runner-options: ['verifier-only', 'verifier-debug-config']
473          - values: ["end"]
474            runner-options: ['verifier-only', 'verifier-debug-config']
475          - values: ["quit"]
476            runner-options: ['verifier-only', 'verifier-debug-config']
477          - values: ["catch_E1_begin"]
478          - values: ["catch_E1_mid"]
479          - values: ["catch_E1_end"]
480            runner-options: ['verifier-only', 'verifier-debug-config']
481          - values: ["catch_E2_begin"]
482          - values: ["catch_E2_mid"]
483          - values: ["catch_E2_end"]
484            runner-options: ['verifier-only', 'verifier-debug-config']
485          - values: ["outside"]
486