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
16tests:
17  - file-name: lda.obj
18    isa:
19      title: Load accumulator from register
20      description: Moves register content into an accumulator.
21      exceptions:
22        - x_none
23    commands:
24      - file-name: op_p
25        isa:
26          instructions:
27            - sig: lda.obj v:in:ref
28              acc: out:ref
29              format: [op_v_8]
30        check-type: none
31        code-template: |
32          %s
33          # header
34          .function i32 main() {
35          # Check lda.obj for different type of arguments (empty object, with fields, statics, etc).
36              newobj v0, Object
37              lda.obj v0
38              jne.obj v0, return_ne_num
39              ldai 0
40              return
41          return_ne_num:
42              ldai 1
43              return
44        header-template: []
45        description: Check lda.obj moves register content into accumulator (references to various type of objects) in PandaAssembly context.
46        cases:
47          - values:
48              - |
49                .record Object {
50                }
51          - values:
52              - |
53                .record Object {
54                    i32 fld2
55                }
56          - values:
57              - |
58                .record Object {
59                    i64 fld2
60                }
61          - values:
62              - |
63                .record Object {
64                    u64 fld2
65                }
66          - values:
67              - |
68                .record Object {
69                    i32 fld2 <static>
70                }
71          - values:
72              - |
73                .record Object {
74                    i32 fld1
75                    i32 fld2 <static>
76                }
77          - values:
78              - |
79                .record Object {
80                    i64 fld1
81                    i64 fld2 <static>
82                }
83          - values:
84              - |
85                .record Object {
86                    f64 fld1
87                    f64 fld2 <static>
88                }
89          - values:
90              - |
91                .record Object {
92                    f32 fld1
93                    f32 fld2 <static>
94                    f64 fld3
95                    f64 fld4 <static>
96                    i32 fld5
97                    i32 fld6 <static>
98                    i64 fld7
99                    i64 fld8 <static>
100                }
101          - case-template: |
102              #
103              .function i32 main() {
104              # Check lda.obj for string
105                  lda.str ""
106                  sta.obj v0
107                  lda.obj v0
108                  jne.obj v0, return_ne_num
109                  ldai 0
110                  return
111              return_ne_num:
112                  ldai 1
113                  return
114          - case-template: |
115              #
116              .record Object {}
117              .function i32 main() {
118              # Check lda.obj for type
119                  lda.type Object
120                  sta.obj v0
121                  lda.obj v0
122                  jne.obj v0, return_ne_num
123                  ldai 0
124                  return
125              return_ne_num:
126                  ldai 1
127                  return
128
129      - file-name: op_j
130        runner-options: [use-pa]
131        isa:
132          instructions:
133            - sig: lda.obj v:in:ref
134              acc: out:ref
135              format: [op_v_8]
136        check-type: none
137        code-template: |
138          .language PandaAssembly
139          %s
140          # header
141          .function i32 main() {
142          # Check lda.obj for different type of arguments (empty object, with fields, statics, etc).
143              %s
144              lda.obj v0
145              jne.obj v0, return_ne_num
146              ldai 0
147              return
148          return_ne_num:
149              ldai 1
150              return
151        header-template: []
152        description: Check lda.obj moves register content into accumulator (references to various type of objects) in PandaAssembly context.
153        cases:
154          - values:
155              - |
156                .record Obj {
157                }
158              - newobj v0, Obj
159          - values:
160              - |
161                .record Obj {
162                    i32 fld2
163                }
164              - newobj v0, Obj
165          - values:
166              - ''
167              - |
168                lda.str "test string"
169                sta.obj v0
170          - values:
171              - .record panda.Object <external>
172              - |
173                lda.type panda.Object
174                sta.obj v0
175          - values:
176              - .record panda.NullPointerException <external>
177              - newobj v0, panda.NullPointerException
178
179      - file-name: 'null'
180        isa:
181          instructions:
182            - sig: lda.obj v:in:ref
183              acc: out:ref
184              format: [op_v_8]
185        description: Check lda.obj moves register content into accumulator (null reference).
186        check-type: none
187        code-template: |
188          # header
189          .function i32 main() {
190          # Check lda.obj for null
191              lda.null
192              sta.obj v0
193              lda.obj v0
194              jne.obj v0, return_ne_num
195              ldai 0
196              return
197          return_ne_num:
198              ldai 1
199              return
200        header-template: []
201
202      - file-name: op_8
203        description: Check lda.obj with various register numbers.
204        isa:
205          instructions:
206            - sig: lda.obj v:in:ref
207              acc: out:ref
208              format: [op_v_8]
209        tags: ['tsan']
210        check-type: none
211        code-template: |
212          .record Object {}
213          # header
214          .function i32 main() {
215          # Check lda.obj with different registers number
216              newobj v0, Object
217              mov.obj %s, v0
218              lda.obj %s
219              jne.obj v0, return_ne_num
220              ldai 0
221              return
222          return_ne_num:
223              ldai 1
224              return
225        header-template: []
226        cases:
227          - values: [v0, v0]
228          - values: [v7, v7]
229          - values: [v8, v8]
230          - values: [v15, v15]
231          - values: [v16, v16]
232          - values: [v127, v127]
233          - values: [v128, v128]
234          - values: [v255, v255]
235          - values: [v256, v256]
236            runner-options: [compile-failure]
237            description: Check lda.obj with incorrect register number.
238
239      - file-name: op_8_null
240        isa:
241          instructions:
242            - sig: lda.obj v:in:ref
243              acc: out:ref
244              format: [op_v_8]
245        description: Check lda.obj with various register numbers and null.
246        check-type: none
247        code-template: |
248          #
249              lda.null
250              sta.obj v0
251              mov.obj %s, v0
252              lda.obj %s
253              jne.obj v0, return_ne_num
254              ldai 0
255              return
256          return_ne_num:
257              ldai 1
258              return
259        cases:
260          - values: [v0, v0]
261          - values: [v7, v7]
262          - values: [v8, v8]
263          - values: [v15, v15]
264          - values: [v16, v16]
265          - values: [v127, v127]
266          - values: [v128, v128]
267          - values: [v255, v255]
268          - values: [v256, v256]
269            runner-options: [compile-failure]
270            description: Check lda.obj with incorrect register number and null.
271
272      - file-name: op_type
273        tags: ['verifier']
274        bugid: ['966', '964']
275        isa:
276          instructions:
277            - sig: lda.obj v:in:ref
278              acc: out:ref
279              format: [op_v_8]
280          verification:
281            - v1_type
282        check-type: none
283        code-template: |
284          # Check lda.obj with wrong type
285              %s
286              lda.obj v0
287              jne.obj v0, return_ne_num
288              ldai 0
289              return
290          return_ne_num:
291              ldai 1
292              return
293        runner-options: ['verifier-failure', 'verifier-config']
294        description: Check lda.obj with incorrect register type (i32, i64, f32, f64).
295        cases:
296          - values:
297              - movi v0, 0
298          - values:
299              - movi v0, 123
300          - values:
301              - movi.64 v0, 0
302          - values:
303              - movi.64 v0, 123
304          - values:
305              - fmovi v0, 0
306          - values:
307              - fmovi v0, 123
308          - values:
309              - fmovi.64 v0, 0
310          - values:
311              - fmovi.64 v0, 123
312
313      - file-name: err
314        isa:
315          instructions:
316            - sig: lda.obj v:in:ref
317              acc: out:ref
318              format: [op_v_8]
319        code-template: |
320          # Check lda.obj with wrong arguments
321              %s
322              ldai 0
323              return
324        check-type: none
325        runner-options: [compile-failure]
326        description: Check lda.obj with incorrect values.
327        cases:
328          - values:
329              - lda.obj 1
330          - values:
331              - lda.obj 1.1
332          - values:
333              - lda.obj a0
334          - values:
335              - lda.obj ""
336
337      - file-name: type_p
338        isa:
339          instructions:
340            - sig: lda.obj v:in:ref
341              acc: out:ref
342              format: [op_v_8]
343          verification:
344            - v1_type
345        description: Check lda.obj with incorrect source register type in PandaAssembly context. Accumulator type is not checked.
346        runner-options: ['verifier-failure', 'verifier-config']
347        tags: ['verifier']
348        header-template: []
349        code-template: |
350          #
351          .record B {}
352          .record panda.String <external>
353          .record panda.Object <external>
354          .function i32 main() {
355              *s
356              %s
357              lda.obj v1
358              ldai 0
359        check-type: no-check
360        template-cases:
361          - values:
362              - |
363                #
364                    lda.type B
365          - values:
366              - |
367                #
368                    lda.type B[]
369          - values:
370              - |
371                #
372                    lda.type panda.String
373          - values:
374              - |
375                #
376                    lda.str "string"
377          - values:
378              - |
379                #
380                    lda.type panda.Object
381          - values:
382              - |
383                #
384                    movi v0, 10
385                    newarr v0, v0, i32[]
386                    lda.obj v0
387          - values:
388              - lda.null
389          - values:
390              - ldai 0
391          - values:
392              - ldai.64 0
393          - values:
394              - fldai.64 0
395        cases:
396          - values:
397              - movi v1, 0
398          - values:
399              - fmovi v1, 0
400          - values:
401              - movi.64 v1, 0
402          - values:
403              - fmovi.64 v1, 0
404
405      - file-name: type_j
406        isa:
407          instructions:
408            - sig: lda.obj v:in:ref
409              acc: out:ref
410              format: [op_v_8]
411          verification:
412            - v1_type
413        description: Check lda.obj with incorrect source register type in PandaAssembly context. Accumulator type is not checked.
414        runner-options: ['verifier-failure', 'verifier-config', 'use-pa']
415        tags: [verifier, pa-verifier]
416        header-template: []
417        code-template: |
418          .language PandaAssembly
419          #
420          .record B {}
421          .record panda.String <external>
422          .record panda.Object <external>
423          .function i32 main() {
424              *s
425              %s
426              lda.obj v1
427              ldai 0
428        check-type: no-check
429        template-cases:
430          - values:
431              - |
432                #
433                    lda.type B
434          - values:
435              - |
436                #
437                    lda.type B[]
438          - values:
439              - |
440                #
441                    lda.type panda.String
442          - values:
443              - |
444                #
445                    lda.str "string"
446          - values:
447              - |
448                #
449                    lda.type panda.Object
450          - values:
451              - |
452                #
453                    movi v0, 10
454                    newarr v0, v0, i32[]
455                    lda.obj v0
456          - values:
457              - lda.null
458          - values:
459              - ldai 0
460          - values:
461              - ldai.64 0
462          - values:
463              - fldai.64 0
464        cases:
465          - values:
466              - movi v1, 0
467          - values:
468              - fmovi v1, 0
469          - values:
470              - movi.64 v1, 0
471          - values:
472              - fmovi.64 v1, 0
473
474      - file-name: uninitialized_regs
475        isa:
476          instructions:
477            - sig: lda.obj v:in:ref
478              acc: out:ref
479              format: [op_v_8]
480        description: Check lda.obj with uninitialized registers.
481        tags: ['verifier']
482        runner-options: ['verifier-failure', 'verifier-config']
483        header-template: []
484        code-template: |
485          #
486          .function i32 main() {
487              lda.obj %s
488              ldai 0
489        check-type: no-check
490        cases:
491          - values:
492              - v0
493          - values:
494              - v8
495          - values:
496              - v15
497          - values:
498              - v255
499