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