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 14tests: 15 - file-name: lda.const 16 isa: 17 title: Create and initialize new constant array 18 description: > 19 Create a new single-dimensional constant literal array and put a reference to it into register. 20 21 commands: 22 - file-name: array_def_err 23 description: > 24 Check that compiler and/or verifier produce meaningful 25 diagnostics on constant array definition error. 26 isa: 27 instructions: 28 - sig: lda.const v:out:ref, literalarray_id 29 acc: none 30 format: [op_v_8_id_32] 31 verification: 32 - constant_literalarray_id 33 runner-options: [compile-failure] 34 header-template: [] 35 code-template: | 36 .record panda.String <external> 37 .record panda.Object <external> 38 .record panda.Class <external> 39 .record E {} 40 %s 41 .function i32 main() { 42 lda.const v0, arr1 43 check-type: exit-positive 44 cases: 45 - values: ['.array arr1'] 46 - values: ['.array arr1 i32'] 47 - values: ['.array arr1 i32 4'] 48 bugid: ['5698'] 49 ignore: true 50 - values: ['.array arr1 i32 4 { }'] 51 - values: ['.array arr1 i32 4 { 1 }'] 52 - values: ['.array arr1 i32 4 { 1 2 3 4 5 }'] 53 - values: ['.array arr1 i32 0 { }'] 54 - values: ['.array arr1 i32[] 1 { 1 }'] 55 - values: ['.array arr1 panda.String 1 { }'] 56 - values: ['.array arr1 panda.String 1 { "" }'] 57 runner-options: ['compile-only'] 58 - values: ['.array arr1 E 1 { "" }'] 59 - values: ['.array arr1 xyz 1 { 0 }'] 60 - values: ['.array arr1 panda.String 1 { 0 }'] 61 - values: ['.array arr1 panda.String 1 { null }'] 62 - values: ['.array arr1 panda.Object 1 { "" }'] 63 - values: ['.array arr1 panda.Class 1 { panda.Object }'] 64 - values: ['.array arr1 i32 { 1 2 3 4 5 }'] 65 - values: ['.array arr1 i32 2 { "1" "2" }'] 66 - values: ['.array arr1 main 2 { 1 2 }'] 67 - values: ['.array 123 i32 2 { 1 2 }'] 68 69 70 - file-name: instr_err 71 description: > 72 Check that compiler and/or verifier produce meaningful diagnostics 73 on lda.const syntax errors. 74 isa: 75 instructions: 76 - sig: lda.const v:out:ref, literalarray_id 77 acc: none 78 format: [op_v_8_id_32] 79 verification: 80 - constant_literalarray_id 81 header-template: [] 82 runner-options: [compile-failure] 83 code-template: | 84 .record E {} 85 .array arr1 i32 4 { 1 2 3 4 } 86 87 .function i32 main() { 88 lda.const %s 89 check-type: exit-positive 90 cases: 91 - values: ['v0'] 92 - values: ['v0, E'] 93 - values: ['v0, E[]'] 94 - values: ['v256, arr1'] 95 - values: ['v32767, arr1'] 96 - values: ['v32768, arr1'] 97 - values: ['v65535, arr1'] 98 - values: ['v65536, arr1'] 99 - values: ['a0, arr1'] 100 - values: ['arr1'] 101 102 103 - file-name: big_size_primitives 104 description: > 105 Check that big size literal arrays of primitives work as expected. 106 isa: 107 instructions: 108 - sig: lda.const v:out:ref, literalarray_id 109 acc: none 110 format: [op_v_8_id_32] 111 verification: 112 - constant_literalarray_id 113 header-template: [] 114 tags: ['irtoc_ignore'] 115 bugid: ['5693'] 116 code-template: | 117 .array arr1 %s 118 119 .function i32 main() { 120 lda.const v0, arr1 121 movi v1, %s 122 lda v1 123 %s 124 inci v1, 1 125 jeq v1, ok 126 ldai 1 127 return 128 ok: 129 check-type: exit-positive 130 cases: 131 - values: 132 - "#{'i64 255 { ' + [*1..255].map do |i| \"#{i} \" end .join + '}' }" 133 - 254 134 - | 135 # 136 ldarr.64 v0 137 i64toi32 138 - values: 139 - "#{'u32 511 { ' + [*1..511].map do |i| \"#{i} \" end .join + '}' }" 140 - 510 141 - ldarr v0 142 - values: 143 - "#{'i16 1024 { ' + [*1..1024].map do |i| \"#{i} \" end .join + '}' }" 144 - 1023 145 - ldarr.16 v0 146 - values: 147 - "#{'u16 4096 { ' + [*1..4096].map do |i| \"#{i} \" end .join + '}' }" 148 - 4095 149 - ldarru.16 v0 150 151 152 - file-name: big_size_str 153 description: > 154 Check that big size literal arrays of strings work as expected. 155 isa: 156 instructions: 157 - sig: lda.const v:out:ref, literalarray_id 158 acc: none 159 format: [op_v_8_id_32] 160 verification: 161 - constant_literalarray_id 162 header-template: [] 163 tags: ['irtoc_ignore'] 164 code-template: | 165 .record panda.String <external> 166 .array arr1 %s 167 168 .function i32 main() { 169 lda.const v0, arr1 170 lda.str "%s" 171 sta.obj v1 172 ldai %s 173 %s 174 jeq.obj v1, ok 175 ldai 1 176 return 177 ok: 178 check-type: exit-positive 179 cases: 180 - values: 181 - "#{'panda.String 1024 { ' + [*1..1024].map do |i| \"\\\"#{i}\\\" \" end .join + '}' }" 182 - 1024 183 - 1023 184 - ldarr.obj v0 185 bugid: ['5693'] 186 - values: 187 - "#{'panda.String 4096 { ' + [*1..4096].map do |i| \"\\\"#{i}\\\" \" end .join + '}' }" 188 - 4001 189 - 4000 190 - ldarr.obj v0 191 bugid: ['5696'] 192 193 194 - file-name: values_u1 195 description: > 196 Check values in literal array. 197 isa: 198 instructions: 199 - sig: lda.const v:out:ref, literalarray_id 200 acc: none 201 format: [op_v_8_id_32] 202 header-template: [] 203 tags: ['irtoc_ignore'] 204 bugid: ['5693'] 205 code-template: | 206 .array v1 %s 207 208 .function i32 main() { 209 lda.const v0, v1 210 movi v1, %s # index 211 movi v15, %s # value at index 212 loop: 213 lda v1 214 jltz ok 215 %s 216 jne v15, err 217 inci v1, -1 218 lda v15 219 xori 1 220 sta v15 221 jmp loop 222 err: 223 ldai 1 224 return 225 ok: 226 check-type: exit-positive 227 cases: 228 - values: 229 - "#{'u1 2560 { ' + [*0..2559].map do |i| \"#{i%2} \" end .join + '}' }" 230 - 2559 231 - 1 232 - ldarru.8 v0 233 234 235 - file-name: values_i32 236 description: > 237 Check values in literal array. 238 isa: 239 instructions: 240 - sig: lda.const v:out:ref, literalarray_id 241 acc: none 242 format: [op_v_8_id_32] 243 header-template: [] 244 tags: ['irtoc_ignore'] 245 bugid: ['5693'] 246 code-template: | 247 .array v1 %s 248 249 .function i32 main() { 250 lda.const v0, v1 251 movi v1, %s # index 252 movi v15, %s # value at index 253 loop: 254 lda v1 255 jltz ok 256 %s 257 jne v15, err 258 inci v1, -1 259 inci v15, -1 260 jmp loop 261 err: 262 ldai 1 263 return 264 ok: 265 check-type: exit-positive 266 cases: 267 - values: 268 - "#{'i8 256 { ' + [*-128..127].map do |i| \"#{i} \" end .join + '}' }" 269 - 255 270 - 127 271 - ldarr.8 v0 272 - values: 273 - "#{'u8 256 { ' + [*0..255].map do |i| \"#{i} \" end .join + '}' }" 274 - 255 275 - 255 276 - ldarru.8 v0 277 - values: 278 - "#{'i16 512 { ' + [*-206..305].map do |i| \"#{i} \" end .join + '}' }" 279 - 511 280 - 305 281 - ldarr.16 v0 282 - values: 283 - "#{'u16 512 { ' + [*65024..65535].map do |i| \"#{i} \" end .join + '}' }" 284 - 511 285 - 0xffff 286 - ldarru.16 v0 287 - values: 288 - "#{'i32 100 { ' + [*-2147483648..-2147483549].map do |i| \"#{i} \" end .join + '}' }" 289 - 99 290 - -2147483549 291 - ldarr v0 292 tags: [sanitizer-fail] 293 294 295 - file-name: values_i64 296 description: > 297 Check values in literal array. 298 isa: 299 instructions: 300 - sig: lda.const v:out:ref, literalarray_id 301 acc: none 302 format: [op_v_8_id_32] 303 header-template: [] 304 tags: ['irtoc_ignore'] 305 bugid: ['5693'] 306 code-template: | 307 .array v1 %s 308 309 .function i32 main() { 310 movi.64 v2, 1 311 lda.const v0, v1 312 movi v1, %s # index 313 movi.64 v15, %s # value at index 314 loop: 315 lda v1 316 jltz ok 317 %s 318 cmp.64 v15 319 jnez err 320 inci v1, -1 321 lda.64 v15 322 sub2.64 v2 323 sta.64 v15 324 jmp loop 325 err: 326 ldai 1 327 return 328 ok: 329 check-type: exit-positive 330 cases: 331 - values: 332 - "#{'i64 45 { ' + [*9223372036854775763..9223372036854775807].map do |i| \"#{i} \" end .join + '}' }" 333 - 44 334 - 0x7fffffffffffffff 335 - ldarr.64 v0 336 337 338 - file-name: values_f32 339 description: > 340 Check values in literal array of f32. 341 isa: 342 instructions: 343 - sig: lda.const v:out:ref, literalarray_id 344 acc: none 345 format: [op_v_8_id_32] 346 header-template: [] 347 tags: ['irtoc_ignore'] 348 bugid: ['5693'] 349 code-template: | 350 .array v1 %s 351 352 .function i32 main() { 353 fmovi v2, 10.0 354 lda.const v0, v1 355 movi v1, %s # index 356 fmovi v15, %s # value at index 357 loop: 358 lda v1 359 jltz ok 360 fldarr.32 v0 361 fcmpg v15 362 jnez err 363 inci v1, -1 364 lda v15 365 fdiv2 v2 366 sta v15 367 jmp loop 368 err: 369 ldai 1 370 return 371 ok: 372 check-type: exit-positive 373 cases: 374 - values: 375 - f32 10 { 1.0 10.0 100.0 1000.0 10000 100000 1000000 10000000 1e8 1e9 } 376 - 9 377 - 1000000000 378 379 380 - file-name: values_f64 381 description: > 382 Check values in literal array of f64. 383 isa: 384 instructions: 385 - sig: lda.const v:out:ref, literalarray_id 386 acc: none 387 format: [op_v_8_id_32] 388 header-template: [] 389 tags: ['irtoc_ignore'] 390 bugid: ['5693'] 391 code-template: | 392 .array v1 %s 393 394 .function i32 main() { 395 fmovi.64 v2, 10.0 396 lda.const v0, v1 397 movi v1, %s # index 398 fmovi.64 v15, %s # value at index 399 loop: 400 lda v1 401 jltz ok 402 fldarr.64 v0 403 fcmpg.64 v15 404 jnez err 405 inci v1, -1 406 lda.64 v15 407 fdiv2.64 v2 408 sta.64 v15 409 jmp loop 410 err: 411 ldai 1 412 return 413 ok: 414 check-type: exit-positive 415 cases: 416 - values: 417 - "#{'f64 10 { ' + [*-4..5].map do |i| \"1e#{i} \" end .join + '}' }" 418 - 9 419 - 1e5 420 421 422 - file-name: values_str 423 description: > 424 Check values in literal array. 425 isa: 426 instructions: 427 - sig: lda.const v:out:ref, literalarray_id 428 acc: none 429 format: [op_v_8_id_32] 430 header-template: [] 431 tags: ['irtoc_ignore'] 432 bugid: ['5693'] 433 code-template: | 434 .record panda.String <external> 435 .array v1 %s 436 437 .function i32 main() { 438 lda.const v0, v1 439 movi v1, %s # size, then index 440 %s 441 jmp ok 442 err: 443 ldai 1 444 return 445 ok: 446 check-type: exit-positive 447 cases: 448 - values: 449 - "#{'panda.String 300 { ' + [*0..299].map do |i| \"\\\"#{i}\\\" \" end .join + '}' }" 450 - 300 451 - "#{[*0..299].map do |i| \" inci v1, -1\\n lda v1\\n ldarr.obj v0\\n sta.obj v2\\n lda.str \\\"#{299-i}\\\"\\n jne.obj v2, err\\n\" end .join }" 452 453 454 - file-name: primitive_types_p 455 description: Check acceptable array of primitive types in Panda Assembly context. 456 isa: 457 instructions: 458 - sig: lda.const v:out:ref, literalarray_id 459 acc: none 460 format: [op_v_8_id_32] 461 tags: ['verifier'] 462 header-template: [] 463 runner-options: ['verifier-only', 'verifier-config'] 464 code-template: | 465 .array v0 %s 466 .function i32 main() { 467 lda.const v0, v0 468 check-type: exit-positive 469 cases: 470 - values: ['u1 1 { 1 }'] 471 - values: ['u8 1 { 1 }'] 472 - values: ['i8 1 { 1 }'] 473 - values: ['u16 1 { 1 }'] 474 - values: ['i16 1 { 1 }'] 475 - values: ['u32 1 { 1 }'] 476 - values: ['i32 1 { 1 }'] 477 - values: ['u64 1 { 1 }'] 478 - values: ['i64 1 { 1 }'] 479 - values: ['f32 1 { 1 }'] 480 - values: ['f64 1 { 1 }'] 481 482 483 - file-name: primitive_types_j 484 description: Check acceptable array of primitive types in PandaAssembly context. 485 isa: 486 instructions: 487 - sig: lda.const v:out:ref, literalarray_id 488 acc: none 489 format: [op_v_8_id_32] 490 tags: [verifier, pa-verifier] 491 header-template: [] 492 runner-options: ['verifier-only', 'verifier-config', 'use-pa'] 493 code-template: | 494 .language PandaAssembly 495 .array v0 %s 496 .function i32 main() { 497 lda.const v0, v0 498 check-type: exit-positive 499 cases: 500 - values: ['u1 1 { 1 }'] 501 - values: ['u8 1 { 1 }'] 502 runner-options: ['verifier-failure', 'verifier-config', 'use-pa'] 503 bugid: ['5694'] 504 - values: ['i8 1 { 1 }'] 505 - values: ['u16 1 { 1 }'] 506 - values: ['i16 1 { 1 }'] 507 - values: ['u32 1 { 1 }'] 508 runner-options: ['verifier-failure', 'verifier-config', 'use-pa'] 509 bugid: ['5694'] 510 - values: ['i32 1 { 1 }'] 511 - values: ['u64 1 { 1 }'] 512 runner-options: ['verifier-failure', 'verifier-config', 'use-pa'] 513 bugid: ['5694'] 514 - values: ['i64 1 { 1 }'] 515 - values: ['f32 1 { 1 }'] 516 - values: ['f64 1 { 1 }'] 517 518 519 - file-name: array_out_of_bounds_p 520 isa: 521 instructions: 522 - sig: lda.const v:out:ref, literalarray_id 523 acc: none 524 format: [op_v_8_id_32] 525 description: Check that ArrayIndexOutOfBoundsException is thrown for literal array. 526 header-template: [] 527 tags: ['irtoc_ignore'] 528 bugid: ['5693'] 529 code-template: | 530 .record panda.ArrayIndexOutOfBoundsException <external> 531 .array arr1 %s 532 533 .function i32 main() { 534 lda.const v0, arr1 535 begin: 536 ldai %s 537 %s 538 end: 539 ldai 1 # Should not reach this line 540 return 541 542 catch_AOOBE: 543 ldai 0 # Expected panda.ArrayIndexOutOfBoundsException 544 return 545 546 catch_all: 547 ldai 2 # Unexpected exception, test failed 548 return 549 550 .catch panda.ArrayIndexOutOfBoundsException, begin, end, catch_AOOBE 551 .catchall begin, end, catch_all 552 check-type: none 553 cases: 554 - values: 555 - i32 4 { 1 2 3 4 } 556 - 4 557 - ldarr v0 558 - values: 559 - u8 1 { 0xff } 560 - 65536 561 - ldarru.8 v0 562 563 564 - file-name: array_out_of_bounds_j 565 isa: 566 instructions: 567 - sig: lda.const v:out:ref, literalarray_id 568 acc: none 569 format: [op_v_8_id_32] 570 description: Check that ArrayIndexOutOfBoundsException is thrown for literal array. 571 runner-options: [use-pa] 572 header-template: [] 573 tags: ['irtoc_ignore'] 574 bugid: ['5693'] 575 code-template: | 576 .language PandaAssembly 577 .record panda.Object <external> 578 .record panda.String <external> 579 .record panda.ArrayIndexOutOfBoundsException <external> 580 .array arr1 %s 581 582 .function panda.Object load_array() { 583 lda.const v0, arr1 584 ldai %s 585 %s 586 lda.obj v0 587 return.obj 588 } 589 590 .function i32 main() { 591 begin: 592 call.short load_array 593 end: 594 ldai 1 # Should not reach this line 595 return 596 597 catch_AOOBE: 598 ldai 0 # Expected panda.ArrayIndexOutOfBoundsException 599 return 600 601 catch_all: 602 ldai 2 # Unexpected exception, test failed 603 return 604 605 .catch panda.ArrayIndexOutOfBoundsException, begin, end, catch_AOOBE 606 .catchall begin, end, catch_all 607 check-type: none 608 cases: 609 - values: 610 - f64 3 { 0 1.1 2.2 } 611 - -3 612 - fldarr.64 v0 613 - values: 614 - panda.String 10 { "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" } 615 - 10 616 - ldarr.obj v0 617 618