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: "f32tou32"
17    isa:
18      title: Conversions between integer and floating point types
19      description: >
20        Perform specified primitive type conversion of accumulator.
21      exceptions:
22        - x_none
23    commands:
24      - file-name: "op_none_vals"
25        isa:
26          instructions:
27            - sig: f32tou32
28              acc: inout:f32->u32
29              prefix: cast
30              format: [pref_op_none]
31        code-template: |
32          #
33              fldai %s
34              f32tou32
35              movi v0, %s
36              ucmp v0
37        description: Check f32tou32 with various values.
38        tags: ['tsan']
39        cases:
40          - values:
41              - "0.0"
42              - "0"
43          - values:
44              - "1.0"
45              - "1"
46          - values:
47              - "2.14748365e9"
48              - "2147483648"
49          - values:
50              - "-0.0"
51              - "0"
52          - values:
53              - "-1.0"
54              - "0"
55          - values:
56              - "-2.14748365e9"
57              - "0"
58      - file-name: "op_none_round"
59        isa:
60          instructions:
61            - sig: f32tou32
62              acc: inout:f32->u32
63              prefix: cast
64              format: [pref_op_none]
65          description: It is rounding toward zero.
66        code-template: |
67          #
68              fldai %s
69              f32tou32
70              movi v0, %s
71              ucmp v0
72        description: Check f32tou32 rounding with various values.
73        cases:
74          - values:
75              - "0.1"
76              - "0"
77          - values:
78              - "0.9"
79              - "0"
80          - values:
81              - "0.9999999"
82              - "0"
83          - values:
84              - "1.1"
85              - "1"
86          - values:
87              - "-0.1"
88              - "0"
89          - values:
90              - "-0.9"
91              - "0"
92
93      - file-name: "op_none_min"
94        isa:
95          instructions:
96            - sig: f32tou32
97              acc: inout:f32->u32
98              prefix: cast
99              format: [pref_op_none]
100          description: If converted integer is less than minimal value for destination type, the result is minimal value for that type.
101        code-template: |
102          #
103              fldai %s
104              f32tou32
105              movi v0, %s
106              ucmp v0
107        description: Check f32tou32 conversion to 0.
108        cases:
109          - values:
110              - "-2.14748365e9"
111              - "0"
112          - values:
113              - "-6e44"
114              - "0"
115
116      - file-name: "op_none_max"
117        isa:
118          instructions:
119            - sig: f32tou32
120              acc: inout:f32->u32
121              prefix: cast
122              format: [pref_op_none]
123          description: If converted integer is greater than maximum value for destination type, the result is maximum value for that type.
124        code-template: |
125          #
126              fldai %s
127              f32tou32
128              movi v0, -1 # 0xFFFFFFFF - max unsigned value
129              ucmp v0
130        description: Check f32tou32 conversion to 0xFFFFFFFF.
131        cases:
132          - values:
133              - "4294967295.0"
134          - values:
135              - "4294967296.0"
136          - values:
137              - "6e37"
138
139      - file-name: "op_none_pinf"
140        isa:
141          instructions:
142            - sig: f32tou32
143              acc: inout:f32->u32
144              prefix: cast
145              format: [pref_op_none]
146          description: If source is positive infinity, the result is maximum value for destination type.
147        description: Check f32tou32 conversion +inf to 0xFFFFFFFF.
148        code-template: |
149          #
150              fldai 0x7f800000 # +Inf
151              f32tou32
152              movi v0, -1 # Max positive value, i.e. 0xFFFFFFFF
153              ucmp v0
154
155      - file-name: "op_none_ninf"
156        isa:
157          instructions:
158            - sig: f32tou32
159              acc: inout:f32->u32
160              prefix: cast
161              format: [pref_op_none]
162          description: If source is negative infinity, the result is minimal value for destination type.
163        description: Check f32tou32 conversion -inf to 0.
164        code-template: |
165          #
166              fldai 0xff800000 # -Inf
167              f32tou32
168              movi v0, 0
169              ucmp v0
170
171      - file-name: "op_none_nan"
172        isa:
173          instructions:
174            - sig: f32tou32
175              acc: inout:f32->u32
176              prefix: cast
177              format: [pref_op_none]
178          description: If source is NaN, the result is equal to 0.
179        description: Check f32tou32 conversion of NaN to 0.
180        code-template: |
181          #
182              fldai %s
183              f32tou32
184              movi v0, 0
185              ucmp v0
186
187        cases:
188          - values:
189              # NaN
190              - "0x7ff80000"
191          - values:
192              # Other NaN representation
193              - "0xFFFFFFFF"
194
195      - file-name: "type"
196        isa:
197          instructions:
198            - sig: f32tou32
199              acc: inout:f32->u32
200              prefix: cast
201              format: [pref_op_none]
202          verification:
203              - acc_type
204        description: |
205          Check `f32tou32` with incorrect accumulator type.
206          Load different values (objects, strings, types, 32-bit values, 64-bit integer values) and invokes `f64tou32`.
207          Return 0 to indicate that negative test failed, because this line is unreachable and code will not be executed after verification error.
208        runner-options: ['verifier-failure', 'verifier-config']
209        bugid: ["964", "1653"]
210        tags: ["verifier"]
211        header-template: []
212        code-template: |
213            #
214            .record B {}
215            .record panda.String <external>
216            .record panda.Object <external>
217            .function i32 main() {
218                %s
219                f32tou32
220        check-type: exit-positive
221        cases:
222            - values:
223                - ldai 0
224            - values:
225                - ldai.64 0
226            - values:
227                - fldai.64 0
228            - values:
229                - lda.type B
230            - values:
231                - lda.type B[]
232            - values:
233                - lda.type panda.String
234            - values:
235                - lda.str "string"
236            - values:
237                - lda.type panda.Object
238            - values:
239                - |
240                  #
241                      movi v0, 10
242                      newarr v0, v0, i32[]
243                      lda.obj v0
244            - values:
245                - lda.null
246
247      - file-name: uninitialized_regs
248        isa:
249          instructions:
250            - sig: f32tou32
251              acc: inout:f32->u32
252              prefix: cast
253              format: [pref_op_none]
254        description: Check 'f32tou32' with uninitialized accumulator.
255        tags: ['verifier']
256        runner-options: ['verifier-failure', 'verifier-config']
257        code-template: |
258            #
259                f32tou32
260        check-type: exit-positive
261