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: "mod" 17 isa: 18 title: Three address integer division or modulo 19 description: Perform integer division or modulo on two registers and store result into accumulator 20 commands: 21 - file-name: "op_v1_4_v2_4_zero" 22 isa: 23 instructions: 24 - sig: mod v1:in:i32, v2:in:i32 25 acc: out:i32 26 format: [op_v1_4_v2_4] 27 code-template: | 28 # 29 movi v0, 0 30 movi v1, %s 31 mod v0, v1 32 movi v0, 0 33 jne v0, set_failure 34 ldai 0 35 jmp fall_through 36 set_failure: 37 ldai 1 38 fall_through: 39 description: Check mod with zero and various values. 40 cases: 41 - values: ["1"] 42 - values: ["-1"] 43 - values: ["0x7FFFFFFF"] 44 - values: ["0x80000000"] 45 - values: ["-0x7FFFFFFF"] 46 - values: ["-0x80000000"] 47 - values: ["0xFFFFFFFF"] 48 - values: ["-0xFFFFFFFF"] 49 50 - file-name: "op_vs_8_pone" 51 isa: 52 instructions: 53 - sig: mod v1:in:i32, v2:in:i32 54 acc: out:i32 55 format: [op_v1_4_v2_4] 56 code-template: | 57 # 58 movi v0, 1 59 movi v1, %s 60 mod v0, v1 61 movi v0, %s 62 jne v0, set_failure 63 ldai 0 64 jmp fall_through 65 set_failure: 66 ldai 1 67 fall_through: 68 description: Check mod with +1 and various values. 69 cases: 70 - values: ["1", "0x0"] 71 - values: ["-1", "0x0"] 72 - values: ["0x7FFFFFFF", "0x1"] 73 - values: ["-0x7FFFFFFF", "0x1"] 74 - values: ["0x80000000", "0x1"] 75 - values: ["-0x80000000", "0x1"] 76 - values: ["0xFFFFFFFF", "0x0"] 77 - values: ["-0xFFFFFFFF", "0x0"] 78 79 - file-name: "op_vs_8_none" 80 isa: 81 instructions: 82 - sig: mod v1:in:i32, v2:in:i32 83 acc: out:i32 84 format: [op_v1_4_v2_4] 85 code-template: | 86 # 87 movi v0, -1 88 movi v1, %s 89 mod v0, v1 90 movi v0, %s 91 jne v0, set_failure 92 ldai 0 93 jmp fall_through 94 set_failure: 95 ldai 1 96 fall_through: 97 description: Check mod with -1 and various values. 98 cases: 99 - values: ["1", "0x0"] 100 - values: ["-1", "0x0"] 101 - values: ["0x7FFFFFFF", "0xFFFFFFFF"] 102 - values: ["-0x7FFFFFFF", "0xFFFFFFFF"] 103 - values: ["0x80000000", "0xFFFFFFFF"] 104 - values: ["-0x80000000", "0xFFFFFFFF"] 105 - values: ["0xFFFFFFFF", "0x0"] 106 - values: ["-0xFFFFFFFF", "0x0"] 107 108 - file-name: "op_vs_8_pmax" 109 isa: 110 instructions: 111 - sig: mod v1:in:i32, v2:in:i32 112 acc: out:i32 113 format: [op_v1_4_v2_4] 114 code-template: | 115 # 116 movi v0, 0x7FFFFFFF 117 movi v1, %s 118 mod v0, v1 119 movi v0, %s 120 jne v0, set_failure 121 ldai 0 122 jmp fall_through 123 set_failure: 124 ldai 1 125 fall_through: 126 description: Check mod with +max and various values. 127 cases: 128 - values: ["1", "0x0"] 129 - values: ["-1", "0x0"] 130 - values: ["0x7FFFFFFF", "0x0"] 131 - values: ["-0x7FFFFFFF", "0x0"] 132 - values: ["0x80000000", "0x7FFFFFFF"] 133 - values: ["-0x80000000", "0x7FFFFFFF"] 134 - values: ["0xFFFFFFFF", "0x0"] 135 - values: ["-0xFFFFFFFF", "0x0"] 136 137 - file-name: "op_vs_8_nmax" 138 isa: 139 instructions: 140 - sig: mod v1:in:i32, v2:in:i32 141 acc: out:i32 142 format: [op_v1_4_v2_4] 143 code-template: | 144 # 145 movi v0, -0x80000000 146 movi v1, %s 147 mod v0, v1 148 movi v0, %s 149 jne v0, set_failure 150 ldai 0 151 jmp fall_through 152 set_failure: 153 ldai 1 154 fall_through: 155 description: Check mod with -max and various values. 156 cases: 157 - values: ["1", "0x0"] 158 - values: ["-1", "0x0"] 159 - values: ["0x7FFFFFFF", "0xFFFFFFFF"] 160 - values: ["-0x7FFFFFFF", "0xFFFFFFFF"] 161 - values: ["0x80000000", "0x0"] 162 - values: ["-0x80000000", "0x0"] 163 - values: ["0xFFFFFFFF", "0x0"] 164 - values: ["-0xFFFFFFFF", "0x0"] 165 166 - file-name: "vals" 167 isa: 168 instructions: 169 - sig: mod v1:in:i32, v2:in:i32 170 acc: out:i32 171 format: [op_v1_4_v2_4] 172 code-template: | 173 # 174 movi v0, %s 175 movi v1, %s 176 mod v0, v1 177 movi v0, %s 178 jne v0, set_failure 179 ldai 0 180 jmp fall_through 181 set_failure: 182 ldai 1 183 fall_through: 184 description: Check mod with various values. 185 tags: ['tsan'] 186 cases: 187 - values: ["0x87A8E1D9", "0x6D8935CF", "0xF53217A8"] 188 - values: ["0x6AFB709C", "0xD7328FDF", "0x1960905A"] 189 - values: ["0x91AD1CA9", "0x330B9F8D", "0xF7C45BC3"] 190 - values: ["0xC5EA3D60", "0x40FCDDC1", "0xC5EA3D60"] 191 - values: ["0x63F6803C", "0x616041E0", "0x2963E5C"] 192 - values: ["0x1E0384B", "0x7C662C8", "0x1E0384B"] 193 - values: ["0x3CFC06FC", "0x54EF2076", "0x3CFC06FC"] 194 - values: ["0x47CB3788", "0x35782ACF", "0x12530CB9"] 195 - values: ["0x2680767A", "0x4E618FD7", "0x2680767A"] 196 - values: ["0x817E8C9D", "0xB92B1E1B", "0xC8536E82"] 197 - values: ["0x80000000", "-1", "0"] 198 - values: ["-2147483648", "-1", "0"] 199 200 - file-name: "op_v1_4_v2_4_exception" 201 isa: 202 instructions: 203 - sig: mod v1:in:i32, v2:in:i32 204 acc: out:i32 205 format: [op_v1_4_v2_4] 206 exceptions: 207 - x_arith 208 tags: ['irtoc_ignore'] 209 header-template: [ArithmeticException, main] 210 code-template: | 211 # 212 movi v0, %s 213 movi v1, 0 214 begin: 215 mod v0, v1 216 end: 217 ldai 1 # Should not reach this line 218 return 219 220 catch_AE: 221 ldai 0 # Expected panda.ArithmeticException 222 return 223 224 catch_all: 225 ldai 1 # Unexpected exception, test failed 226 return 227 228 .catch panda.ArithmeticException, begin, end, catch_AE 229 .catchall begin, end, catch_all 230 check-type: none 231 description: Check `mod` throws ArithmeticException when divides by zero. 232 cases: 233 - values: ["0"] 234 - values: ["1"] 235 - values: ["0x7FFFFFFF"] 236 - values: ["0x80000000"] 237 - values: ["0xFFFFFFFF"] 238 - values: ["-1"] 239 - values: ["-0x7FFFFFFF"] 240 - values: ["-0x80000000"] 241 - values: ["-0xFFFFFFFF"] 242 243 - file-name: "regs" 244 isa: 245 instructions: 246 - sig: mod v1:in:i32, v2:in:i32 247 acc: out:i32 248 format: [op_v1_4_v2_4] 249 runner-options: ['compile-only'] 250 code-template: | 251 # 252 mod %s, %s 253 check-type: none 254 description: Check mod with various register numbers. 255 cases: 256 - values: ["v15", "v15"] 257 - values: ["v0", "v15"] 258 - values: ["v15", "v0"] 259 - values: ["v15", "v16"] 260 runner-options: ['compile-failure'] 261 - values: ["v16", "v15"] 262 runner-options: ['compile-failure'] 263 - values: ["v16", "v16"] 264 runner-options: ['compile-failure'] 265 266 - file-name: type 267 isa: 268 verification: 269 - v1_type 270 - v2_type 271 tags: ['verifier'] 272 runner-options: ['verifier-failure', 'verifier-config'] 273 header-template: [] 274 code-template: | 275 # 276 .record A {} 277 .record B {} 278 .record panda.String <external> 279 .record panda.Object <external> 280 .function i32 main() { 281 %s 282 *s 283 mod v0, v1 284 check-type: exit-positive 285 description: Check 'mod' with incorrect register types. 286 template-cases: 287 - values: 288 - movi v0, 0 289 exclude: [val] 290 - values: 291 - movi.64 v0, 0 292 - values: 293 - fmovi v0, 0 294 - values: 295 - fmovi.64 v0, 0 296 - values: 297 - | 298 # 299 lda.type B 300 sta.obj v0 301 - values: 302 - | 303 # 304 lda.type B[] 305 sta.obj v0 306 - values: 307 - | 308 # 309 lda.type panda.String 310 sta.obj v0 311 - values: 312 - | 313 # 314 lda.type panda.Object 315 sta.obj v0 316 - values: 317 - | 318 # 319 movi v0, 10 320 newarr v0, v0, i32[] 321 - values: 322 - mov.null v0 323 cases: 324 - values: 325 - movi v1, 0 326 id: val 327 - values: 328 - movi.64 v1, 0 329 - values: 330 - fmovi v1, 0 331 - values: 332 - fmovi.64 v1, 0 333 - values: 334 - | 335 # 336 lda.type A 337 sta.obj v1 338 - values: 339 - | 340 # 341 lda.type A[] 342 sta.obj v1 343 - values: 344 - | 345 # 346 lda.type panda.String 347 sta.obj v1 348 - values: 349 - | 350 # 351 lda.type panda.Object 352 sta.obj v1 353 - values: 354 - | 355 # 356 movi v1, 10 357 newarr v1, v1, i32[] 358 - values: 359 - mov.null v1 360 361 362 - file-name: uninitialized_regs 363 isa: 364 instructions: 365 - sig: mod v1:in:i32, v2:in:i32 366 acc: out:i32 367 format: [op_v1_4_v2_4] 368 description: Check 'mod' with uninitialized registers. 369 tags: ['verifier'] 370 runner-options: ['verifier-failure', 'verifier-config'] 371 code-template: | 372 # 373 %s 374 *s 375 mod %s, *s 376 check-type: exit-positive 377 template-cases: 378 - values: 379 - '' 380 - v0 381 - values: 382 - movi v0, 0 383 - v0 384 exclude: [init] 385 - values: 386 - '' 387 - v7 388 - values: 389 - '' 390 - v15 391 - values: 392 - 'movi v15, 0' 393 - v15 394 exclude: [init] 395 cases: 396 - values: 397 - '' 398 - v1 399 - values: 400 - movi v1, 0 401 - v1 402 id: init 403 - values: 404 - '' 405 - v8 406 - values: 407 - '' 408 - v14 409