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