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: "f64toi32"
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: f64toi32
28              acc: inout:f64->i32
29              prefix: cast
30              format: [pref_op_none]
31        code-template: |
32          #
33              fldai.64 %s
34              f64toi32
35              movi v0, %s
36              jne v0, set_failure
37              ldai 0
38              jmp fall_through
39          set_failure:
40              ldai 1
41          fall_through:
42        description: Check f64toi32 with various values.
43        cases:
44          - values:
45              - "0.0"
46              - "0"
47          - values:
48              - "1.0"
49              - "1"
50          - values:
51              - "2.147483647e9"
52              - "0x7fffffff"
53          - values:
54              - "-0.0"
55              - "0"
56          - values:
57              - "-1.0"
58              - "-1"
59          - values:
60              - "-2.147483647e9"
61              - "-2147483647"
62      - file-name: "op_none_round"
63        isa:
64          instructions:
65            - sig: f64toi32
66              acc: inout:f64->i32
67              prefix: cast
68              format: [pref_op_none]
69          description: It is rounding toward zero.
70        code-template: |
71          #
72              fldai.64 %s
73              f64toi32
74              movi v0, %s
75              jne v0, set_failure
76              ldai 0
77              jmp fall_through
78          set_failure:
79              ldai 1
80          fall_through:
81        description: Check f64toi32 rounding with various values.
82        tags: ['tsan']
83        cases:
84          - values:
85              - "0.1"
86              - "0"
87          - values:
88              - "0.9"
89              - "0"
90          - values:
91              - "0.9999999999"
92              - "0"
93          - values:
94              - "1.1"
95              - "1"
96          - values:
97              - "2.14748364699999e9"
98              - "0x7ffffffe"
99          - values:
100              - "2.14748364799999e9"
101              - "0x7fffffff"
102          - values:
103              - "-0.1"
104              - "0"
105          - values:
106              - "-0.9"
107              - "0"
108          - values:
109              - "-0.9999999999"
110              - "0"
111          - values:
112              - "-1.1"
113              - "-1"
114          - values:
115              - "-2.14748364699999e9"
116              - "-2147483646"
117          - values:
118              - "-2.14748364799999e9"
119              - "-2147483647"
120
121      - file-name: "op_none_min"
122        isa:
123          instructions:
124            - sig: f64toi32
125              acc: inout:f64->i32
126              prefix: cast
127              format: [pref_op_none]
128          description: If converted integer is less than minimal value for destination type, the result is minimal value for that type.
129        code-template: |
130          #
131              fldai.64 %s
132              f64toi32
133              movi v0, %s
134              jne v0, set_failure
135              ldai 0
136              jmp fall_through
137          set_failure:
138              ldai 1
139          fall_through:
140        description: Check f64toi32 conversion to minimal value.
141        cases:
142          - values:
143              - "-2.147483648e9"
144              - "-2147483648"
145          - values:
146              - "-6e100"
147              - "-2147483648"
148
149      - file-name: "op_none_max"
150        isa:
151          instructions:
152            - sig: f64toi32
153              acc: inout:f64->i32
154              prefix: cast
155              format: [pref_op_none]
156          description: If converted integer is greater than maximum value for destination type, the result is maximum value for that type.
157        code-template: |
158          #
159              fldai.64 %s
160              f64toi32
161              movi v0, %s
162              jne v0, set_failure
163              ldai 0
164              jmp fall_through
165          set_failure:
166              ldai 1
167          fall_through:
168        description: Check f64toi32 conversion to maximal value.
169        cases:
170          - values:
171              - "+2.147483647e9"
172              - "2147483647"
173          - values:
174              - "+2.147483648e9"
175              - "2147483647"
176          - values:
177              - "6e100"
178              - "2147483647"
179
180      - file-name: "op_none_pinf"
181        isa:
182          instructions:
183            - sig: f64toi32
184              acc: inout:f64->i32
185              prefix: cast
186              format: [pref_op_none]
187          description: If source is positive infinity, the result is maximum value for destination type.
188        description: Check f64toi32 conversion +inf to maximal value.
189        code-template: |
190          #
191              fldai.64 0x7ff0000000000000 # +Inf
192              f64toi32
193              movi v0, 0x7fffffff
194              jne v0, set_failure
195              ldai 0
196              jmp fall_through
197          set_failure:
198              ldai 1
199          fall_through:
200
201      - file-name: "op_none_ninf"
202        isa:
203          instructions:
204            - sig: f64toi32
205              acc: inout:f64->i32
206              prefix: cast
207              format: [pref_op_none]
208          description: If source is negative infinity, the result is minimal value for destination type.
209        description: Check f64toi32 conversion -inf to minimal value.
210        code-template: |
211          #
212              fldai.64 0xfff0000000000000 # -Inf
213              f64toi32
214              movi v0, 0x80000000
215              jne v0, set_failure
216              ldai 0
217              jmp fall_through
218          set_failure:
219              ldai 1
220          fall_through:
221
222      - file-name: "op_none_nan"
223        isa:
224          instructions:
225            - sig: f64toi32
226              acc: inout:f64->i32
227              prefix: cast
228              format: [pref_op_none]
229          description: If source is NaN, the result is equal to 0.
230        description: Check f64toi32 conversion of NaN to 0.
231        code-template: |
232          #
233              fldai.64 %s
234              f64toi32
235              movi v0, 0
236              jne v0, set_failure
237              ldai 0
238              jmp fall_through
239          set_failure:
240              ldai 1
241          fall_through:
242        cases:
243          - values:
244              # NaN
245              - "0x7ff8000000000000"
246          - values:
247              # Other NaN representation
248              - "0xFFFFFFFFFFFFFFFF"
249
250      - file-name: "type"
251        isa:
252          instructions:
253            - sig: f64toi32
254              acc: inout:f64->i32
255              prefix: cast
256              format: [pref_op_none]
257          verification:
258              - acc_type
259        description: |
260          Check f64toi32 with incorrect accumulator type.
261          Load different values (objects, strings, types, 32-bit values, 64-bit integer values) and invokes `f64toi32`.
262          Return 0 to indicate that negative test failed, because this line is unreachable and code will not be executed after verification error.
263        runner-options: ['verifier-failure', 'verifier-config']
264        bugid: ["964", "1653"]
265        tags: ["verifier"]
266        header-template: []
267        code-template: |
268            #
269            .record B {}
270            .record panda.String <external>
271            .record panda.Object <external>
272            .function i32 main() {
273                %s
274                f64toi32
275        check-type: exit-positive
276        cases:
277            - values:
278                - ldai 0
279            - values:
280                - ldai.64 0
281            - values:
282                - fldai 0
283              bugid: ['6094']
284            - values:
285                - lda.type B
286            - values:
287                - lda.type B[]
288            - values:
289                - lda.type panda.String
290            - values:
291                - lda.str "string"
292            - values:
293                - lda.type panda.Object
294            - values:
295                - |
296                  #
297                      movi v0, 10
298                      newarr v0, v0, i32[]
299                      lda.obj v0
300            - values:
301                - lda.null
302
303      - file-name: uninitialized_regs
304        isa:
305          instructions:
306            - sig: f64toi32
307              acc: inout:f64->i32
308              prefix: cast
309              format: [pref_op_none]
310        description: Check 'i32tof64' with uninitialized accumulator.
311        tags: ['verifier']
312        runner-options: ['verifier-failure', 'verifier-config']
313        code-template: |
314            #
315                f64toi32
316        check-type: exit-positive
317
318