1# Copyright (c) 2021 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: "jltz" 17 isa: 18 title: Conditional compared to zero jump 19 description: > 20 Transfer execution to an instruction at offset bytes 21 from the beginning of the current instruction 22 if signed 32-bit integer in accumulator compares with 0 as specified. 23 Offset is sign extended to the size of instruction address. 24 exceptions: 25 - x_none 26 commands: 27 28 - file-name: "op" 29 isa: 30 instructions: 31 - sig: jltz imm:i32 32 acc: in:i32 33 format: [op_imm_8, op_imm_16] 34 description: > 35 Check jump occurs or not occurs, depending on `acc < 0` condition 36 for forward, backward, or current cases. 37 code-template: | 38 # 39 %s 40 check-type: exit-positive 41 cases: 42 - values: 43 - | 44 # Check forward jump 45 ldai 0xFFFFFFFF 46 jltz label 47 ldai 255 ##*65536 48 return # should be jumped over 49 label: 50 - values: 51 - | 52 # Check backward jump 53 jmp label2 54 label1: 55 jmp label3 56 ldai 255 ##*65536 57 label2: 58 ldai -1 59 jltz label1 60 ldai 255 61 return # should be jumped over 62 label3: 63 - values: 64 - | 65 # Check jump to itself 66 ldai 0 67 loop: 68 jltz loop 69 bugid: ['3468'] 70 - values: 71 - | 72 # Check jump to itself 73 ldai -1 74 loop: 75 jltz loop 76 runner-options: [compile-only] 77 78 - file-name: "op_bounds" 79 isa: 80 instructions: 81 - sig: jltz imm:i32 82 acc: in:i32 83 format: [op_imm_8, op_imm_16] 84 description: > 85 Check jump occurs or not occurs, depending on `acc < 0` condition 86 for forward and backward cases. 87 code-template: | 88 # 89 %s 90 check-type: none 91 cases: 92 - values: 93 - | 94 # Max forward jump for imm8, 2 + 124 + 1 = 127 bytes 95 ldai -1 96 jltz label # 2-byte instruction 97 ldai 1 ##*62 98 return 99 label: 100 ldai 0 101 return 102 - values: 103 - | 104 # Max backward jump for imm8, 1 + 2 + 61*2 + 1 + 2 = 128 bytes 105 jmp label2 106 label: 107 neg 108 ldai 61 109 subi 1 ##*61 110 return 111 label2: 112 ldai -1 113 jltz label 114 ldai 1 115 return 116 - values: 117 - | 118 # Max forward jump for imm16, 3 + 32760 + 4 = 32767 bytes 119 ldai -1 120 jltz label # 3-byte instruction 121 movi.64 v0, 0 ##*3276 122 neg 123 ldai 2 124 return 125 label: 126 ldai 0 127 return 128 - values: 129 - | 130 # Max backward jump for imm16, 1 + 4 + 32760 + 1 + 2 = 32768 bytes 131 jmp label2 132 label: 133 ldai 0 134 return 135 ldai 1 136 movi.64 v0, 0 ##*3276 137 return 138 label2: 139 ldai -1 140 jltz label 141 ldai 1 142 return 143 144 - file-name: "vals" 145 isa: 146 instructions: 147 - sig: jltz imm:i32 148 acc: in:i32 149 format: [op_imm_8, op_imm_16] 150 description: > 151 Check jump not occurs if `acc >= 0` 152 for different values in acc. 153 code-template: | 154 # 155 ldai *s 156 jltz label_bad 157 ldai %s 158 jltz label_good 159 label_bad: 160 ldai 255 161 return # should be jumped over 162 label_good: 163 check-type: exit-positive 164 template-cases: 165 - values: 166 - "-1" 167 exclude: [zero, max] 168 - values: 169 - "0x80000000" 170 exclude: [zero, one] 171 - values: 172 - "0xFFFFFFFF" 173 exclude: [one, max] 174 cases: 175 - values: 176 - "0" 177 id: zero 178 - values: 179 - "1" 180 id: one 181 - values: 182 - "0x7FFFFFFF" 183 id: max 184 185 - file-name: "type" 186 isa: 187 instructions: 188 - sig: jltz imm:i32 189 acc: in:i32 190 format: [op_imm_8, op_imm_16] 191 verification: 192 - acc_type 193 description: > 194 Check `jltz` with invalid types in acc. 195 tags: ['verifier'] 196 runner-options: ['verifier-failure', 'verifier-debug-config'] 197 header-template: [] 198 code-template: | 199 # 200 .record A {} 201 .record panda.String <external> 202 .record panda.Object <external> 203 .function i32 main() { 204 %s 205 jltz label 206 ldai 255 207 label: 208 check-type: exit-positive 209 cases: 210 - values: 211 - lda.null 212 - values: 213 - ldai.64 0 214 - values: 215 - fldai.64 0 216 - values: 217 - lda.type A 218 - values: 219 - lda.type A[] 220 - values: 221 - lda.type panda.String 222 - values: 223 - | 224 newobj v0, A 225 lda.obj v0 226 - values: 227 - | 228 newobj v0, panda.Object 229 lda.obj v0 230 - values: 231 - lda.str "0" 232 - values: 233 - | 234 # 235 movi v0, 10 236 newarr v0, v0, i32[] 237 lda.obj v0 238 239 - file-name: "outside_function" 240 isa: 241 instructions: 242 - sig: jltz imm:i32 243 acc: in:i32 244 format: [op_imm_8, op_imm_16] 245 verification: 246 - branch_target 247 description: > 248 Branch target should point to a beginning 249 of an instruction of the same method. 250 runner-options: ['compile-failure'] 251 header-template: [] 252 code-template: | 253 # 254 .function i32 f() { 255 label: 256 ldai 255 257 return 258 } 259 .function i32 main() { 260 ldai -1 261 jltz label 262 check-type: exit-positive 263 264 - file-name: "outside_try_catch_p" 265 isa: 266 instructions: 267 - sig: jltz imm:i32 268 acc: in:i32 269 format: [op_imm_8, op_imm_16] 270 description: Jump outside try/catch block. 271 bugid: ['3425'] 272 header-template: [] 273 code-template: | 274 .record panda.ArithmeticException <external> 275 .function i32 main() { 276 begin: 277 ldai -1 278 jltz outside 279 newobj v0, panda.ArithmeticException 280 throw v0 281 end: 282 ldai 1 283 return 284 catch_ae: 285 ldai 2 286 return 287 .catch panda.ArithmeticException, begin, end, catch_ae 288 ldai 3 289 return 290 outside: 291 check-type: exit-positive 292 293 - file-name: uninitialized_regs 294 isa: 295 instructions: 296 - sig: jltz imm:i32 297 acc: in:i32 298 format: [op_imm_8, op_imm_16] 299 description: Check `jltz` with uninitialized acc. 300 tags: ['verifier'] 301 runner-options: ['verifier-failure', 'verifier-debug-config'] 302 code-template: | 303 # 304 label: 305 jltz label 306 check-type: exit-positive 307 308 - file-name: "invalid_branch_target" 309 isa: 310 verification: 311 - branch_target 312 runner-options: [compile-failure] 313 description: Check 'jltz' instruction with invalid branch target. 314 header-template: [] 315 code-template: | 316 .record R {} 317 318 .function void R.ctor(R a0) <ctor> { 319 lbl_ctor: 320 return.void 321 } 322 323 .function void R.cctor() <cctor> { 324 lbl_cctor: 325 return.void 326 } 327 328 .function i32 foo(i32 a0, i32 a1) <static> { 329 lda a0 330 jltz %s 331 return 332 } 333 334 .function i32 bar() <static> { 335 lbl_bar: 336 ldai 1 337 return 338 } 339 340 .function i32 main() { 341 movi v0, 0 342 movi v1, 1 343 call.short foo, v0, v1 344 lbl_main: 345 check-type: exit-positive 346 cases: 347 - values: ["main"] 348 - values: ["foo"] 349 - values: ["bar"] 350 - values: ["baz"] 351 - values: ["R"] 352 - values: ["lbl_main"] 353 - values: ["lbl_bar"] 354 - values: ["lbl_ctor"] 355 - values: ["lbl_cctor"] 356 357 358 - file-name: "prohibited_branch_target" 359 isa: 360 verification: 361 - branch_target 362 runner-options: ['verifier-failure', 'verifier-debug-config'] 363 tags: [verifier] 364 description: Check 'jltz' instruction with prohibited branch target. 365 header-template: [] 366 code-template: | 367 .record E1 {} 368 .record E2 {} 369 370 .function i32 main() { 371 ldai -1 372 jltz %s 373 374 begin: 375 ldai 0 376 return 377 mid: 378 ldai 1 379 return 380 end: 381 ldai 2 382 return 383 384 catch_E1_begin: 385 ldai 3 386 return 387 catch_E1_mid: 388 ldai 4 389 return 390 catch_E1_end: 391 ldai 5 392 return 393 394 catch_E2_begin: 395 ldai 6 396 return 397 catch_E2_mid: 398 ldai 7 399 return 400 catch_E2_end: 401 402 quit: 403 ldai 8 404 return 405 406 .catch E1, begin, end, catch_E1_begin, catch_E1_end 407 .catch E2, catch_E1_begin, catch_E1_end, catch_E2_begin, catch_E2_end 408 outside: 409 check-type: none 410 cases: 411 - values: ["begin"] 412 runner-options: ['verifier-only', 'verifier-debug-config'] 413 - values: ["mid"] 414 runner-options: ['verifier-only', 'verifier-debug-config'] 415 - values: ["end"] 416 runner-options: ['verifier-only', 'verifier-debug-config'] 417 - values: ["quit"] 418 runner-options: ['verifier-only', 'verifier-debug-config'] 419 - values: ["catch_E1_begin"] 420 - values: ["catch_E1_mid"] 421 - values: ["catch_E1_end"] 422 runner-options: ['verifier-only', 'verifier-debug-config'] 423 - values: ["catch_E2_begin"] 424 - values: ["catch_E2_mid"] 425 - values: ["catch_E2_end"] 426 runner-options: ['verifier-only', 'verifier-debug-config'] 427 - values: ["outside"] 428