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: []
15tests:
16  - file-name: 'sta'
17    isa:
18      title: Store accumulator
19      description: Moves accumulator content into a register.
20      exceptions:
21        - x_none
22    commands:
23      - file-name: 'op_vd_8'
24        description: Check sta moves accumulator content into a register.
25        isa:
26          instructions:
27            - sig: sta v:out:b32
28              acc: in:b32
29              format: [op_v_8]
30        code-template: |
31          #
32          %s
33              ldai 0
34              return
35          err:
36              ldai 1
37              return
38        check-type: none
39        tags: ['tsan']
40        cases:
41          - values:
42              - "#{[
43                '0',
44                '1',
45                '0xF',
46                '0xFF',
47                '0xFFF',
48                '0xFFFF',
49                '0xFFFFF',
50                '0xFFFFFF',
51                '0xFFFFFFF',
52                '0xFFFFFFFF',
53                '0x7F',
54                '0x7FF',
55                '0x7FFF',
56                '0x7FFFF',
57                '0x7FFFFF',
58                '0x7FFFFFF',
59                '0x7FFFFFFF',
60                '-1',
61                '-0xF',
62                '-0xFF',
63                '-0xFFF',
64                '-0xFFFF',
65                '-0xFFFFF',
66                '-0xFFFFFF',
67                '-0xFFFFFFF',
68                '-0xFFFFFFFF',
69                '-0x7F',
70                '-0x7FF',
71                '-0x7FFF',
72                '-0x7FFFF',
73                '-0x7FFFFF',
74                '-0x7FFFFFF',
75                '-0x7FFFFFFF'
76                ].map do |s| \"    ldai #{s}\\n    sta v0\\n    jne v0, err\\n\" end .join}"
77
78      - file-name: 'reg'
79        description: Check sta with various register numbers.
80        isa:
81          instructions:
82            - sig: sta v:out:b32
83              acc: in:b32
84              format: [op_v_8]
85        code-template: |
86          #
87              ldai 0xDEADBEEF
88              sta %s
89              jne %s, set_failure
90              ldai 0
91              return
92          set_failure:
93              ldai 1
94              return
95        check-type: none
96        cases:
97          - values: [v0, v0]
98          - values: [v1, v1]
99          - values: [v7, v7]
100          - values: [v8, v8]
101          - values: [v15, v15]
102          - values: [v16, v16]
103          - values: [v127, v127]
104          - values: [v128, v128]
105          - values: [v255, v255]
106          - values: [v256, v255]
107            runner-options: [compile-failure]
108            description: Check sta with incorrect register numbers.
109          - values: [a0, v255]
110            runner-options: [compile-failure]
111            description: Check sta with incorrect register numbers.
112          - values: [0, v255]
113            runner-options: [compile-failure]
114            description: Check sta with incorrect register numbers.
115
116      - file-name: 'type'
117        description: Check 'sta' with incorrect accumulator type. Register type is not checked.
118        isa:
119          verification:
120            - acc_type
121        tags: ['verifier']
122        runner-options: ['verifier-failure', 'verifier-config']
123        header-template: []
124        code-template: |
125          #
126          .record A {}
127          .record B {}
128          .record panda.String <external>
129          .record panda.Object <external>
130          .function i32 main() {
131              ##- v1 initialization with different types
132              *s
133              ##- Accumulator initialization with incorrect types
134              %s
135              sta v1
136        check-type: exit-positive
137        template-cases:
138          - values:
139              - ldai.64 0
140          - values:
141              - fldai.64 0
142          - values:
143              - |
144                #
145                    lda.type B
146          - values:
147              - |
148                #
149                    lda.type B[]
150          - values:
151              - |
152                #
153                    lda.type panda.String
154          - values:
155              - |
156                #
157                    lda.str "string"
158          - values:
159              - |
160                #
161                    movi v0, 10
162                    newarr v0, v0, i32[]
163                    lda.obj v0
164          - values:
165              - lda.null
166        cases:
167          - values:
168              - movi v1, 0
169          - values:
170              - movi.64 v1, 0
171          - values:
172              - fmovi.64 v1, 0
173          - values:
174              - |
175                #
176                    lda.type A
177                    sta.obj v1
178          - values:
179              - |
180                #
181                    lda.type A[]
182                    sta.obj v1
183
184          - values:
185              - |
186                #
187                    lda.type panda.String
188                    sta.obj v1
189          - values:
190              - |
191                #
192                    lda.type panda.Object
193                    sta.obj v1
194          - values:
195              - |
196                #
197                    movi v1, 10
198                    newarr v1, v1, f64[]
199          - values:
200              - mov.null v1
201
202      - file-name: uninitialized_regs
203        description: Check 'sta' with uninitialized accumulator. Destination register is not checked.
204        isa:
205          instructions:
206            - sig: sta v:out:b32
207              acc: in:b32
208              format: [op_v_8]
209        tags: ['verifier']
210        runner-options: ['verifier-failure', 'verifier-config']
211        header-template: []
212        code-template: |
213          #
214          .function i32 main() {
215              %s
216              sta %s
217        check-type: exit-positive
218        cases:
219          - values:
220              - ''
221              - v0
222          - values:
223              - movi v0, 0
224              - v0
225          - values:
226              - ''
227              - v15
228          - values:
229              - 'movi.64 v15, 0'
230              - v15
231          - values:
232              - ''
233              - v128
234          - values:
235              - 'fmovi.64 v128, 0'
236              - v128
237          - values:
238              - ''
239              - v255
240          - values:
241              - 'mov.null v255'
242              - v255
243
244      - file-name: 'err'
245        description: Check sta.64 with incorrect value.
246        isa:
247          instructions:
248            - sig: sta v:out:b32
249              acc: in:b32
250              format: [op_v_8]
251        runner-options: [compile-failure]
252        code-template: |
253          # Check sta with wrong arguments
254              %s
255        check-type: exit-positive
256        cases:
257          - values:
258              - sta 1
259          - values:
260              - sta 1.1
261          - values:
262              - sta a0
263          - values:
264              - sta ""
265