OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdint.h> | 5 #include <stdint.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "src/base/platform/elapsed-timer.h" | 9 #include "src/base/platform/elapsed-timer.h" |
10 #include "src/utils.h" | 10 #include "src/utils.h" |
11 #include "src/wasm/wasm-macro-gen.h" | 11 #include "src/wasm/wasm-macro-gen.h" |
12 | 12 |
13 #include "test/cctest/cctest.h" | 13 #include "test/cctest/cctest.h" |
14 #include "test/cctest/compiler/value-helper.h" | 14 #include "test/cctest/compiler/value-helper.h" |
15 #include "test/cctest/wasm/wasm-run-utils.h" | 15 #include "test/cctest/wasm/wasm-run-utils.h" |
16 #include "test/common/wasm/test-signatures.h" | 16 #include "test/common/wasm/test-signatures.h" |
17 | 17 |
18 using namespace v8::base; | 18 using namespace v8::base; |
19 using namespace v8::internal; | 19 using namespace v8::internal; |
20 using namespace v8::internal::compiler; | 20 using namespace v8::internal::compiler; |
21 using namespace v8::internal::wasm; | 21 using namespace v8::internal::wasm; |
22 | 22 |
23 // for even shorter tests. | 23 // for even shorter tests. |
24 #define B1(a) WASM_BLOCK(a) | 24 #define B1(a) WASM_BLOCK(a) |
25 #define B2(a, b) WASM_BLOCK(a, b) | 25 #define B2(a, b) WASM_BLOCK(a, b) |
26 #define B3(a, b, c) WASM_BLOCK(a, b, c) | 26 #define B3(a, b, c) WASM_BLOCK(a, b, c) |
27 #define RET(x) x, kExprReturn | 27 #define RET(x) x, kExprReturn |
28 #define RET_I8(x) kExprI8Const, x, kExprReturn | 28 #define RET_I8(x) WASM_I32V_2(x), kExprReturn |
29 | |
30 WASM_EXEC_TEST(Int8Const) { | |
31 WasmRunner<int32_t> r(execution_mode); | |
32 const byte kExpectedValue = 121; | |
33 // return(kExpectedValue) | |
34 BUILD(r, WASM_I8(kExpectedValue)); | |
35 CHECK_EQ(kExpectedValue, r.Call()); | |
36 } | |
37 | |
38 WASM_EXEC_TEST(Int8Const_end) { | |
39 WasmRunner<int32_t> r(execution_mode); | |
40 const byte kExpectedValue = 121; | |
41 // return(kExpectedValue) | |
42 BUILD(r, WASM_I8(kExpectedValue), kExprEnd); | |
43 CHECK_EQ(kExpectedValue, r.Call()); | |
44 } | |
45 | |
46 WASM_EXEC_TEST(Int8Const_fallthru2) { | |
47 WasmRunner<int32_t> r(execution_mode); | |
48 const byte kExpectedValue = 123; | |
49 // -99 kExpectedValue | |
50 BUILD(r, WASM_I8(-99), WASM_DROP, WASM_I8(kExpectedValue)); | |
51 CHECK_EQ(kExpectedValue, r.Call()); | |
52 } | |
53 | |
54 WASM_EXEC_TEST(Int8Const_all) { | |
55 for (int value = -128; value <= 127; ++value) { | |
56 WasmRunner<int32_t> r(execution_mode); | |
57 // return(value) | |
58 BUILD(r, WASM_I8(value)); | |
59 int32_t result = r.Call(); | |
60 CHECK_EQ(value, result); | |
61 } | |
62 } | |
63 | 29 |
64 WASM_EXEC_TEST(Int32Const) { | 30 WASM_EXEC_TEST(Int32Const) { |
65 WasmRunner<int32_t> r(execution_mode); | 31 WasmRunner<int32_t> r(execution_mode); |
66 const int32_t kExpectedValue = 0x11223344; | 32 const int32_t kExpectedValue = 0x11223344; |
67 // return(kExpectedValue) | 33 // return(kExpectedValue) |
68 BUILD(r, WASM_I32V_5(kExpectedValue)); | 34 BUILD(r, WASM_I32V_5(kExpectedValue)); |
69 CHECK_EQ(kExpectedValue, r.Call()); | 35 CHECK_EQ(kExpectedValue, r.Call()); |
70 } | 36 } |
71 | 37 |
72 WASM_EXEC_TEST(Int32Const_many) { | 38 WASM_EXEC_TEST(Int32Const_many) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 WASM_EXEC_TEST(Int32Param1) { | 70 WASM_EXEC_TEST(Int32Param1) { |
105 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); | 71 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); |
106 // local[1] | 72 // local[1] |
107 BUILD(r, WASM_GET_LOCAL(1)); | 73 BUILD(r, WASM_GET_LOCAL(1)); |
108 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(-111, *i)); } | 74 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(-111, *i)); } |
109 } | 75 } |
110 | 76 |
111 WASM_EXEC_TEST(Int32Add) { | 77 WASM_EXEC_TEST(Int32Add) { |
112 WasmRunner<int32_t> r(execution_mode); | 78 WasmRunner<int32_t> r(execution_mode); |
113 // 11 + 44 | 79 // 11 + 44 |
114 BUILD(r, WASM_I32_ADD(WASM_I8(11), WASM_I8(44))); | 80 BUILD(r, WASM_I32_ADD(WASM_I32V_1(11), WASM_I32V_1(44))); |
115 CHECK_EQ(55, r.Call()); | 81 CHECK_EQ(55, r.Call()); |
116 } | 82 } |
117 | 83 |
118 WASM_EXEC_TEST(Int32Add_P) { | 84 WASM_EXEC_TEST(Int32Add_P) { |
119 WasmRunner<int32_t, int32_t> r(execution_mode); | 85 WasmRunner<int32_t, int32_t> r(execution_mode); |
120 // p0 + 13 | 86 // p0 + 13 |
121 BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0))); | 87 BUILD(r, WASM_I32_ADD(WASM_I32V_1(13), WASM_GET_LOCAL(0))); |
122 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } | 88 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } |
123 } | 89 } |
124 | 90 |
125 WASM_EXEC_TEST(Int32Add_P_fallthru) { | 91 WASM_EXEC_TEST(Int32Add_P_fallthru) { |
126 WasmRunner<int32_t, int32_t> r(execution_mode); | 92 WasmRunner<int32_t, int32_t> r(execution_mode); |
127 // p0 + 13 | 93 // p0 + 13 |
128 BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0))); | 94 BUILD(r, WASM_I32_ADD(WASM_I32V_1(13), WASM_GET_LOCAL(0))); |
129 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } | 95 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } |
130 } | 96 } |
131 | 97 |
132 static void RunInt32AddTest(WasmExecutionMode execution_mode, const byte* code, | 98 static void RunInt32AddTest(WasmExecutionMode execution_mode, const byte* code, |
133 size_t size) { | 99 size_t size) { |
134 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); | 100 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); |
135 r.Build(code, code + size); | 101 r.Build(code, code + size); |
136 FOR_INT32_INPUTS(i) { | 102 FOR_INT32_INPUTS(i) { |
137 FOR_INT32_INPUTS(j) { | 103 FOR_INT32_INPUTS(j) { |
138 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) + | 104 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) + |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 386 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
421 CHECK_TRAP(r.Call(100, 0)); | 387 CHECK_TRAP(r.Call(100, 0)); |
422 CHECK_TRAP(r.Call(-1001, 0)); | 388 CHECK_TRAP(r.Call(-1001, 0)); |
423 CHECK_TRAP(r.Call(kMin, 0)); | 389 CHECK_TRAP(r.Call(kMin, 0)); |
424 CHECK_EQ(kMin, r.Call(kMin, -1)); | 390 CHECK_EQ(kMin, r.Call(kMin, -1)); |
425 } | 391 } |
426 | 392 |
427 WASM_EXEC_TEST_WITH_TRAP(Int32DivS_byzero_const) { | 393 WASM_EXEC_TEST_WITH_TRAP(Int32DivS_byzero_const) { |
428 for (int8_t denom = -2; denom < 8; ++denom) { | 394 for (int8_t denom = -2; denom < 8; ++denom) { |
429 WasmRunner<int32_t, int32_t> r(execution_mode); | 395 WasmRunner<int32_t, int32_t> r(execution_mode); |
430 BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom))); | 396 BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I32V_1(denom))); |
431 for (int32_t val = -7; val < 8; ++val) { | 397 for (int32_t val = -7; val < 8; ++val) { |
432 if (denom == 0) { | 398 if (denom == 0) { |
433 CHECK_TRAP(r.Call(val)); | 399 CHECK_TRAP(r.Call(val)); |
434 } else { | 400 } else { |
435 CHECK_EQ(val / denom, r.Call(val)); | 401 CHECK_EQ(val / denom, r.Call(val)); |
436 } | 402 } |
437 } | 403 } |
438 } | 404 } |
439 } | 405 } |
440 | 406 |
441 WASM_EXEC_TEST(Int32AsmjsDivS_byzero_const) { | 407 WASM_EXEC_TEST(Int32AsmjsDivS_byzero_const) { |
442 for (int8_t denom = -2; denom < 8; ++denom) { | 408 for (int8_t denom = -2; denom < 8; ++denom) { |
443 WasmRunner<int32_t, int32_t> r(execution_mode); | 409 WasmRunner<int32_t, int32_t> r(execution_mode); |
444 r.module().ChangeOriginToAsmjs(); | 410 r.module().ChangeOriginToAsmjs(); |
445 BUILD(r, WASM_I32_ASMJS_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom))); | 411 BUILD(r, WASM_I32_ASMJS_DIVS(WASM_GET_LOCAL(0), WASM_I32V_1(denom))); |
446 FOR_INT32_INPUTS(i) { | 412 FOR_INT32_INPUTS(i) { |
447 if (denom == 0) { | 413 if (denom == 0) { |
448 CHECK_EQ(0, r.Call(*i)); | 414 CHECK_EQ(0, r.Call(*i)); |
449 } else if (denom == -1 && *i == std::numeric_limits<int32_t>::min()) { | 415 } else if (denom == -1 && *i == std::numeric_limits<int32_t>::min()) { |
450 CHECK_EQ(std::numeric_limits<int32_t>::min(), r.Call(*i)); | 416 CHECK_EQ(std::numeric_limits<int32_t>::min(), r.Call(*i)); |
451 } else { | 417 } else { |
452 CHECK_EQ(*i / denom, r.Call(*i)); | 418 CHECK_EQ(*i / denom, r.Call(*i)); |
453 } | 419 } |
454 } | 420 } |
455 } | 421 } |
456 } | 422 } |
457 | 423 |
458 WASM_EXEC_TEST(Int32AsmjsRemS_byzero_const) { | 424 WASM_EXEC_TEST(Int32AsmjsRemS_byzero_const) { |
459 for (int8_t denom = -2; denom < 8; ++denom) { | 425 for (int8_t denom = -2; denom < 8; ++denom) { |
460 WasmRunner<int32_t, int32_t> r(execution_mode); | 426 WasmRunner<int32_t, int32_t> r(execution_mode); |
461 r.module().ChangeOriginToAsmjs(); | 427 r.module().ChangeOriginToAsmjs(); |
462 BUILD(r, WASM_I32_ASMJS_REMS(WASM_GET_LOCAL(0), WASM_I8(denom))); | 428 BUILD(r, WASM_I32_ASMJS_REMS(WASM_GET_LOCAL(0), WASM_I32V_1(denom))); |
463 FOR_INT32_INPUTS(i) { | 429 FOR_INT32_INPUTS(i) { |
464 if (denom == 0) { | 430 if (denom == 0) { |
465 CHECK_EQ(0, r.Call(*i)); | 431 CHECK_EQ(0, r.Call(*i)); |
466 } else if (denom == -1 && *i == std::numeric_limits<int32_t>::min()) { | 432 } else if (denom == -1 && *i == std::numeric_limits<int32_t>::min()) { |
467 CHECK_EQ(0, r.Call(*i)); | 433 CHECK_EQ(0, r.Call(*i)); |
468 } else { | 434 } else { |
469 CHECK_EQ(*i % denom, r.Call(*i)); | 435 CHECK_EQ(*i % denom, r.Call(*i)); |
470 } | 436 } |
471 } | 437 } |
472 } | 438 } |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 FOR_FLOAT64_INPUTS(i) { | 636 FOR_FLOAT64_INPUTS(i) { |
671 CHECK_EQ(0x8000000000000000, | 637 CHECK_EQ(0x8000000000000000, |
672 bit_cast<uint64_t>(*i) ^ bit_cast<uint64_t>(r.Call(*i))); | 638 bit_cast<uint64_t>(*i) ^ bit_cast<uint64_t>(r.Call(*i))); |
673 } | 639 } |
674 } | 640 } |
675 | 641 |
676 WASM_EXEC_TEST(IfElse_P) { | 642 WASM_EXEC_TEST(IfElse_P) { |
677 WasmRunner<int32_t, int32_t> r(execution_mode); | 643 WasmRunner<int32_t, int32_t> r(execution_mode); |
678 // if (p0) return 11; else return 22; | 644 // if (p0) return 11; else return 22; |
679 BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), // -- | 645 BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), // -- |
680 WASM_I8(11), // -- | 646 WASM_I32V_1(11), // -- |
681 WASM_I8(22))); // -- | 647 WASM_I32V_1(22))); // -- |
682 FOR_INT32_INPUTS(i) { | 648 FOR_INT32_INPUTS(i) { |
683 int32_t expected = *i ? 11 : 22; | 649 int32_t expected = *i ? 11 : 22; |
684 CHECK_EQ(expected, r.Call(*i)); | 650 CHECK_EQ(expected, r.Call(*i)); |
685 } | 651 } |
686 } | 652 } |
687 #define EMPTY | 653 #define EMPTY |
688 | 654 |
689 WASM_EXEC_TEST(If_empty1) { | 655 WASM_EXEC_TEST(If_empty1) { |
690 WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode); | 656 WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode); |
691 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kLocalVoid, kExprEnd, WASM_GET_LOCAL(1)); | 657 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kLocalVoid, kExprEnd, WASM_GET_LOCAL(1)); |
(...skipping 18 matching lines...) Expand all Loading... |
710 WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode); | 676 WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode); |
711 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kLocalVoid, kExprElse, WASM_NOP, | 677 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kLocalVoid, kExprElse, WASM_NOP, |
712 kExprEnd, WASM_GET_LOCAL(1)); | 678 kExprEnd, WASM_GET_LOCAL(1)); |
713 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 6, *i)); } | 679 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 6, *i)); } |
714 } | 680 } |
715 | 681 |
716 WASM_EXEC_TEST(If_chain1) { | 682 WASM_EXEC_TEST(If_chain1) { |
717 WasmRunner<int32_t, int32_t> r(execution_mode); | 683 WasmRunner<int32_t, int32_t> r(execution_mode); |
718 // if (p0) 13; if (p0) 14; 15 | 684 // if (p0) 13; if (p0) 14; 15 |
719 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP), | 685 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP), |
720 WASM_IF(WASM_GET_LOCAL(0), WASM_NOP), WASM_I8(15)); | 686 WASM_IF(WASM_GET_LOCAL(0), WASM_NOP), WASM_I32V_1(15)); |
721 FOR_INT32_INPUTS(i) { CHECK_EQ(15, r.Call(*i)); } | 687 FOR_INT32_INPUTS(i) { CHECK_EQ(15, r.Call(*i)); } |
722 } | 688 } |
723 | 689 |
724 WASM_EXEC_TEST(If_chain_set) { | 690 WASM_EXEC_TEST(If_chain_set) { |
725 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); | 691 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); |
726 // if (p0) p1 = 73; if (p0) p1 = 74; p1 | 692 // if (p0) p1 = 73; if (p0) p1 = 74; p1 |
727 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(73))), | 693 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I32V_2(73))), |
728 WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(74))), | 694 WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I32V_2(74))), |
729 WASM_GET_LOCAL(1)); | 695 WASM_GET_LOCAL(1)); |
730 FOR_INT32_INPUTS(i) { | 696 FOR_INT32_INPUTS(i) { |
731 int32_t expected = *i ? 74 : *i; | 697 int32_t expected = *i ? 74 : *i; |
732 CHECK_EQ(expected, r.Call(*i, *i)); | 698 CHECK_EQ(expected, r.Call(*i, *i)); |
733 } | 699 } |
734 } | 700 } |
735 | 701 |
736 WASM_EXEC_TEST(IfElse_Unreachable1) { | 702 WASM_EXEC_TEST(IfElse_Unreachable1) { |
737 WasmRunner<int32_t> r(execution_mode); | 703 WasmRunner<int32_t> r(execution_mode); |
738 // 0 ? unreachable : 27 | 704 // 0 ? unreachable : 27 |
739 BUILD(r, WASM_IF_ELSE_I(WASM_ZERO, // -- | 705 BUILD(r, WASM_IF_ELSE_I(WASM_ZERO, // -- |
740 WASM_UNREACHABLE, // -- | 706 WASM_UNREACHABLE, // -- |
741 WASM_I8(27))); // -- | 707 WASM_I32V_1(27))); // -- |
742 CHECK_EQ(27, r.Call()); | 708 CHECK_EQ(27, r.Call()); |
743 } | 709 } |
744 | 710 |
745 WASM_EXEC_TEST(IfElse_Unreachable2) { | 711 WASM_EXEC_TEST(IfElse_Unreachable2) { |
746 WasmRunner<int32_t> r(execution_mode); | 712 WasmRunner<int32_t> r(execution_mode); |
747 // 1 ? 28 : unreachable | 713 // 1 ? 28 : unreachable |
748 BUILD(r, WASM_IF_ELSE_I(WASM_I8(1), // -- | 714 BUILD(r, WASM_IF_ELSE_I(WASM_I32V_1(1), // -- |
749 WASM_I8(28), // -- | 715 WASM_I32V_1(28), // -- |
750 WASM_UNREACHABLE)); // -- | 716 WASM_UNREACHABLE)); // -- |
751 CHECK_EQ(28, r.Call()); | 717 CHECK_EQ(28, r.Call()); |
752 } | 718 } |
753 | 719 |
754 WASM_EXEC_TEST(Return12) { | 720 WASM_EXEC_TEST(Return12) { |
755 WasmRunner<int32_t> r(execution_mode); | 721 WasmRunner<int32_t> r(execution_mode); |
756 | 722 |
757 BUILD(r, RET_I8(12)); | 723 BUILD(r, RET_I8(12)); |
758 CHECK_EQ(12, r.Call()); | 724 CHECK_EQ(12, r.Call()); |
759 } | 725 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 WasmRunner<float, float, float, int32_t> r(execution_mode); | 775 WasmRunner<float, float, float, int32_t> r(execution_mode); |
810 // return select(11, 22, a); | 776 // return select(11, 22, a); |
811 BUILD(r, | 777 BUILD(r, |
812 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), WASM_GET_LOCAL(2))); | 778 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), WASM_GET_LOCAL(2))); |
813 CHECK_FLOAT_EQ(2.0f, r.Call(2.0f, 1.0f, 1)); | 779 CHECK_FLOAT_EQ(2.0f, r.Call(2.0f, 1.0f, 1)); |
814 } | 780 } |
815 | 781 |
816 WASM_EXEC_TEST(Select) { | 782 WASM_EXEC_TEST(Select) { |
817 WasmRunner<int32_t, int32_t> r(execution_mode); | 783 WasmRunner<int32_t, int32_t> r(execution_mode); |
818 // return select(11, 22, a); | 784 // return select(11, 22, a); |
819 BUILD(r, WASM_SELECT(WASM_I8(11), WASM_I8(22), WASM_GET_LOCAL(0))); | 785 BUILD(r, WASM_SELECT(WASM_I32V_1(11), WASM_I32V_1(22), WASM_GET_LOCAL(0))); |
820 FOR_INT32_INPUTS(i) { | 786 FOR_INT32_INPUTS(i) { |
821 int32_t expected = *i ? 11 : 22; | 787 int32_t expected = *i ? 11 : 22; |
822 CHECK_EQ(expected, r.Call(*i)); | 788 CHECK_EQ(expected, r.Call(*i)); |
823 } | 789 } |
824 } | 790 } |
825 | 791 |
826 WASM_EXEC_TEST(Select_strict1) { | 792 WASM_EXEC_TEST(Select_strict1) { |
827 WasmRunner<int32_t, int32_t> r(execution_mode); | 793 WasmRunner<int32_t, int32_t> r(execution_mode); |
828 // select(a=0, a=1, a=2); return a | 794 // select(a=0, a=1, a=2); return a |
829 BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(0, WASM_I8(0)), | 795 BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(0, WASM_ZERO), |
830 WASM_TEE_LOCAL(0, WASM_I8(1)), | 796 WASM_TEE_LOCAL(0, WASM_I32V_1(1)), |
831 WASM_TEE_LOCAL(0, WASM_I8(2))), | 797 WASM_TEE_LOCAL(0, WASM_I32V_1(2))), |
832 WASM_DROP, WASM_GET_LOCAL(0)); | 798 WASM_DROP, WASM_GET_LOCAL(0)); |
833 FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); } | 799 FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); } |
834 } | 800 } |
835 | 801 |
836 WASM_EXEC_TEST(Select_strict2) { | 802 WASM_EXEC_TEST(Select_strict2) { |
837 WasmRunner<int32_t, int32_t> r(execution_mode); | 803 WasmRunner<int32_t, int32_t> r(execution_mode); |
838 r.AllocateLocal(kWasmI32); | 804 r.AllocateLocal(kWasmI32); |
839 r.AllocateLocal(kWasmI32); | 805 r.AllocateLocal(kWasmI32); |
840 // select(b=5, c=6, a) | 806 // select(b=5, c=6, a) |
841 BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I8(5)), | 807 BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I32V_1(5)), |
842 WASM_TEE_LOCAL(2, WASM_I8(6)), WASM_GET_LOCAL(0))); | 808 WASM_TEE_LOCAL(2, WASM_I32V_1(6)), WASM_GET_LOCAL(0))); |
843 FOR_INT32_INPUTS(i) { | 809 FOR_INT32_INPUTS(i) { |
844 int32_t expected = *i ? 5 : 6; | 810 int32_t expected = *i ? 5 : 6; |
845 CHECK_EQ(expected, r.Call(*i)); | 811 CHECK_EQ(expected, r.Call(*i)); |
846 } | 812 } |
847 } | 813 } |
848 | 814 |
849 WASM_EXEC_TEST(Select_strict3) { | 815 WASM_EXEC_TEST(Select_strict3) { |
850 WasmRunner<int32_t, int32_t> r(execution_mode); | 816 WasmRunner<int32_t, int32_t> r(execution_mode); |
851 r.AllocateLocal(kWasmI32); | 817 r.AllocateLocal(kWasmI32); |
852 r.AllocateLocal(kWasmI32); | 818 r.AllocateLocal(kWasmI32); |
853 // select(b=5, c=6, a=b) | 819 // select(b=5, c=6, a=b) |
854 BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I8(5)), | 820 BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I32V_1(5)), |
855 WASM_TEE_LOCAL(2, WASM_I8(6)), | 821 WASM_TEE_LOCAL(2, WASM_I32V_1(6)), |
856 WASM_TEE_LOCAL(0, WASM_GET_LOCAL(1)))); | 822 WASM_TEE_LOCAL(0, WASM_GET_LOCAL(1)))); |
857 FOR_INT32_INPUTS(i) { | 823 FOR_INT32_INPUTS(i) { |
858 int32_t expected = 5; | 824 int32_t expected = 5; |
859 CHECK_EQ(expected, r.Call(*i)); | 825 CHECK_EQ(expected, r.Call(*i)); |
860 } | 826 } |
861 } | 827 } |
862 | 828 |
863 WASM_EXEC_TEST(BrIf_strict) { | 829 WASM_EXEC_TEST(BrIf_strict) { |
864 WasmRunner<int32_t, int32_t> r(execution_mode); | 830 WasmRunner<int32_t, int32_t> r(execution_mode); |
865 BUILD(r, WASM_BLOCK_I(WASM_BRV_IF(0, WASM_GET_LOCAL(0), | 831 BUILD(r, WASM_BLOCK_I(WASM_BRV_IF(0, WASM_GET_LOCAL(0), |
866 WASM_TEE_LOCAL(0, WASM_I8(99))))); | 832 WASM_TEE_LOCAL(0, WASM_I32V_2(99))))); |
867 | 833 |
868 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 834 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
869 } | 835 } |
870 | 836 |
871 WASM_EXEC_TEST(Br_height) { | 837 WASM_EXEC_TEST(Br_height) { |
872 WasmRunner<int32_t, int32_t> r(execution_mode); | 838 WasmRunner<int32_t, int32_t> r(execution_mode); |
873 BUILD(r, | 839 BUILD(r, WASM_BLOCK_I(WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_GET_LOCAL(0), |
874 WASM_BLOCK_I( | 840 WASM_GET_LOCAL(0)), |
875 WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)), | 841 WASM_RETURN1(WASM_I32V_1(9)), |
876 WASM_RETURN1(WASM_I8(9)), WASM_I8(7), WASM_I8(7)), | 842 WASM_I32V_1(7), WASM_I32V_1(7)), |
877 WASM_BRV(0, WASM_I8(8)))); | 843 WASM_BRV(0, WASM_I32V_1(8)))); |
878 | 844 |
879 for (int32_t i = 0; i < 5; i++) { | 845 for (int32_t i = 0; i < 5; i++) { |
880 int32_t expected = i != 0 ? 8 : 9; | 846 int32_t expected = i != 0 ? 8 : 9; |
881 CHECK_EQ(expected, r.Call(i)); | 847 CHECK_EQ(expected, r.Call(i)); |
882 } | 848 } |
883 } | 849 } |
884 | 850 |
885 WASM_EXEC_TEST(Regression_660262) { | 851 WASM_EXEC_TEST(Regression_660262) { |
886 WasmRunner<int32_t> r(execution_mode); | 852 WasmRunner<int32_t> r(execution_mode); |
887 r.module().AddMemoryElems<int32_t>(8); | 853 r.module().AddMemoryElems<int32_t>(8); |
888 BUILD(r, kExprI8Const, 0x00, kExprI8Const, 0x00, kExprI32LoadMem, 0x00, 0x0f, | 854 BUILD(r, kExprI32Const, 0x00, kExprI32Const, 0x00, kExprI32LoadMem, 0x00, |
889 kExprBrTable, 0x00, 0x80, 0x00); // entries=0 | 855 0x0f, kExprBrTable, 0x00, 0x80, 0x00); // entries=0 |
890 r.Call(); | 856 r.Call(); |
891 } | 857 } |
892 | 858 |
893 WASM_EXEC_TEST(BrTable0a) { | 859 WASM_EXEC_TEST(BrTable0a) { |
894 WasmRunner<int32_t, int32_t> r(execution_mode); | 860 WasmRunner<int32_t, int32_t> r(execution_mode); |
895 BUILD(r, B1(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))), | 861 BUILD(r, B1(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))), |
896 WASM_I8(91)); | 862 WASM_I32V_2(91)); |
897 FOR_INT32_INPUTS(i) { CHECK_EQ(91, r.Call(*i)); } | 863 FOR_INT32_INPUTS(i) { CHECK_EQ(91, r.Call(*i)); } |
898 } | 864 } |
899 | 865 |
900 WASM_EXEC_TEST(BrTable0b) { | 866 WASM_EXEC_TEST(BrTable0b) { |
901 WasmRunner<int32_t, int32_t> r(execution_mode); | 867 WasmRunner<int32_t, int32_t> r(execution_mode); |
902 BUILD(r, | 868 BUILD(r, |
903 B1(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(0)))), | 869 B1(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(0)))), |
904 WASM_I8(92)); | 870 WASM_I32V_2(92)); |
905 FOR_INT32_INPUTS(i) { CHECK_EQ(92, r.Call(*i)); } | 871 FOR_INT32_INPUTS(i) { CHECK_EQ(92, r.Call(*i)); } |
906 } | 872 } |
907 | 873 |
908 WASM_EXEC_TEST(BrTable0c) { | 874 WASM_EXEC_TEST(BrTable0c) { |
909 WasmRunner<int32_t, int32_t> r(execution_mode); | 875 WasmRunner<int32_t, int32_t> r(execution_mode); |
910 BUILD( | 876 BUILD( |
911 r, | 877 r, |
912 B1(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(1))), | 878 B1(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(1))), |
913 RET_I8(76))), | 879 RET_I8(76))), |
914 WASM_I8(77)); | 880 WASM_I32V_2(77)); |
915 FOR_INT32_INPUTS(i) { | 881 FOR_INT32_INPUTS(i) { |
916 int32_t expected = *i == 0 ? 76 : 77; | 882 int32_t expected = *i == 0 ? 76 : 77; |
917 CHECK_EQ(expected, r.Call(*i)); | 883 CHECK_EQ(expected, r.Call(*i)); |
918 } | 884 } |
919 } | 885 } |
920 | 886 |
921 WASM_EXEC_TEST(BrTable1) { | 887 WASM_EXEC_TEST(BrTable1) { |
922 WasmRunner<int32_t, int32_t> r(execution_mode); | 888 WasmRunner<int32_t, int32_t> r(execution_mode); |
923 BUILD(r, B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), RET_I8(93)); | 889 BUILD(r, B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), RET_I8(93)); |
924 FOR_INT32_INPUTS(i) { CHECK_EQ(93, r.Call(*i)); } | 890 FOR_INT32_INPUTS(i) { CHECK_EQ(93, r.Call(*i)); } |
925 } | 891 } |
926 | 892 |
927 WASM_EXEC_TEST(BrTable_loop) { | 893 WASM_EXEC_TEST(BrTable_loop) { |
928 WasmRunner<int32_t, int32_t> r(execution_mode); | 894 WasmRunner<int32_t, int32_t> r(execution_mode); |
929 BUILD(r, | 895 BUILD(r, |
930 B2(B1(WASM_LOOP(WASM_BR_TABLE(WASM_INC_LOCAL_BYV(0, 1), 2, BR_TARGET(2), | 896 B2(B1(WASM_LOOP(WASM_BR_TABLE(WASM_INC_LOCAL_BYV(0, 1), 2, BR_TARGET(2), |
931 BR_TARGET(1), BR_TARGET(0)))), | 897 BR_TARGET(1), BR_TARGET(0)))), |
932 RET_I8(99)), | 898 RET_I8(99)), |
933 WASM_I8(98)); | 899 WASM_I32V_2(98)); |
934 CHECK_EQ(99, r.Call(0)); | 900 CHECK_EQ(99, r.Call(0)); |
935 CHECK_EQ(98, r.Call(-1)); | 901 CHECK_EQ(98, r.Call(-1)); |
936 CHECK_EQ(98, r.Call(-2)); | 902 CHECK_EQ(98, r.Call(-2)); |
937 CHECK_EQ(98, r.Call(-3)); | 903 CHECK_EQ(98, r.Call(-3)); |
938 CHECK_EQ(98, r.Call(-100)); | 904 CHECK_EQ(98, r.Call(-100)); |
939 } | 905 } |
940 | 906 |
941 WASM_EXEC_TEST(BrTable_br) { | 907 WASM_EXEC_TEST(BrTable_br) { |
942 WasmRunner<int32_t, int32_t> r(execution_mode); | 908 WasmRunner<int32_t, int32_t> r(execution_mode); |
943 BUILD(r, | 909 BUILD(r, |
944 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(1), BR_TARGET(0))), | 910 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(1), BR_TARGET(0))), |
945 RET_I8(91)), | 911 RET_I8(91)), |
946 WASM_I8(99)); | 912 WASM_I32V_2(99)); |
947 CHECK_EQ(99, r.Call(0)); | 913 CHECK_EQ(99, r.Call(0)); |
948 CHECK_EQ(91, r.Call(1)); | 914 CHECK_EQ(91, r.Call(1)); |
949 CHECK_EQ(91, r.Call(2)); | 915 CHECK_EQ(91, r.Call(2)); |
950 CHECK_EQ(91, r.Call(3)); | 916 CHECK_EQ(91, r.Call(3)); |
951 } | 917 } |
952 | 918 |
953 WASM_EXEC_TEST(BrTable_br2) { | 919 WASM_EXEC_TEST(BrTable_br2) { |
954 WasmRunner<int32_t, int32_t> r(execution_mode); | 920 WasmRunner<int32_t, int32_t> r(execution_mode); |
955 | 921 |
956 BUILD(r, B2(B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 3, BR_TARGET(1), | 922 BUILD(r, B2(B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 3, BR_TARGET(1), |
957 BR_TARGET(2), BR_TARGET(3), BR_TARGET(0))), | 923 BR_TARGET(2), BR_TARGET(3), BR_TARGET(0))), |
958 RET_I8(85)), | 924 RET_I8(85)), |
959 RET_I8(86)), | 925 RET_I8(86)), |
960 RET_I8(87)), | 926 RET_I8(87)), |
961 WASM_I8(88)); | 927 WASM_I32V_2(88)); |
962 CHECK_EQ(86, r.Call(0)); | 928 CHECK_EQ(86, r.Call(0)); |
963 CHECK_EQ(87, r.Call(1)); | 929 CHECK_EQ(87, r.Call(1)); |
964 CHECK_EQ(88, r.Call(2)); | 930 CHECK_EQ(88, r.Call(2)); |
965 CHECK_EQ(85, r.Call(3)); | 931 CHECK_EQ(85, r.Call(3)); |
966 CHECK_EQ(85, r.Call(4)); | 932 CHECK_EQ(85, r.Call(4)); |
967 CHECK_EQ(85, r.Call(5)); | 933 CHECK_EQ(85, r.Call(5)); |
968 } | 934 } |
969 | 935 |
970 WASM_EXEC_TEST(BrTable4) { | 936 WASM_EXEC_TEST(BrTable4) { |
971 for (int i = 0; i < 4; ++i) { | 937 for (int i = 0; i < 4; ++i) { |
972 for (int t = 0; t < 4; ++t) { | 938 for (int t = 0; t < 4; ++t) { |
973 uint32_t cases[] = {0, 1, 2, 3}; | 939 uint32_t cases[] = {0, 1, 2, 3}; |
974 cases[i] = t; | 940 cases[i] = t; |
975 byte code[] = {B2(B2(B2(B2(B1(WASM_BR_TABLE( | 941 byte code[] = {B2(B2(B2(B2(B1(WASM_BR_TABLE( |
976 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]), | 942 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]), |
977 BR_TARGET(cases[1]), BR_TARGET(cases[2]), | 943 BR_TARGET(cases[1]), BR_TARGET(cases[2]), |
978 BR_TARGET(cases[3]))), | 944 BR_TARGET(cases[3]))), |
979 RET_I8(70)), | 945 RET_I8(70)), |
980 RET_I8(71)), | 946 RET_I8(71)), |
981 RET_I8(72)), | 947 RET_I8(72)), |
982 RET_I8(73)), | 948 RET_I8(73)), |
983 WASM_I8(75)}; | 949 WASM_I32V_2(75)}; |
984 | 950 |
985 WasmRunner<int32_t, int32_t> r(execution_mode); | 951 WasmRunner<int32_t, int32_t> r(execution_mode); |
986 r.Build(code, code + arraysize(code)); | 952 r.Build(code, code + arraysize(code)); |
987 | 953 |
988 for (int x = -3; x < 50; ++x) { | 954 for (int x = -3; x < 50; ++x) { |
989 int index = (x > 3 || x < 0) ? 3 : x; | 955 int index = (x > 3 || x < 0) ? 3 : x; |
990 int32_t expected = 70 + cases[index]; | 956 int32_t expected = 70 + cases[index]; |
991 CHECK_EQ(expected, r.Call(x)); | 957 CHECK_EQ(expected, r.Call(x)); |
992 } | 958 } |
993 } | 959 } |
994 } | 960 } |
995 } | 961 } |
996 | 962 |
997 WASM_EXEC_TEST(BrTable4x4) { | 963 WASM_EXEC_TEST(BrTable4x4) { |
998 for (byte a = 0; a < 4; ++a) { | 964 for (byte a = 0; a < 4; ++a) { |
999 for (byte b = 0; b < 4; ++b) { | 965 for (byte b = 0; b < 4; ++b) { |
1000 for (byte c = 0; c < 4; ++c) { | 966 for (byte c = 0; c < 4; ++c) { |
1001 for (byte d = 0; d < 4; ++d) { | 967 for (byte d = 0; d < 4; ++d) { |
1002 for (int i = 0; i < 4; ++i) { | 968 for (int i = 0; i < 4; ++i) { |
1003 uint32_t cases[] = {a, b, c, d}; | 969 uint32_t cases[] = {a, b, c, d}; |
1004 byte code[] = { | 970 byte code[] = { |
1005 B2(B2(B2(B2(B1(WASM_BR_TABLE( | 971 B2(B2(B2(B2(B1(WASM_BR_TABLE( |
1006 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]), | 972 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]), |
1007 BR_TARGET(cases[1]), BR_TARGET(cases[2]), | 973 BR_TARGET(cases[1]), BR_TARGET(cases[2]), |
1008 BR_TARGET(cases[3]))), | 974 BR_TARGET(cases[3]))), |
1009 RET_I8(50)), | 975 RET_I8(50)), |
1010 RET_I8(51)), | 976 RET_I8(51)), |
1011 RET_I8(52)), | 977 RET_I8(52)), |
1012 RET_I8(53)), | 978 RET_I8(53)), |
1013 WASM_I8(55)}; | 979 WASM_I32V_2(55)}; |
1014 | 980 |
1015 WasmRunner<int32_t, int32_t> r(execution_mode); | 981 WasmRunner<int32_t, int32_t> r(execution_mode); |
1016 r.Build(code, code + arraysize(code)); | 982 r.Build(code, code + arraysize(code)); |
1017 | 983 |
1018 for (int x = -6; x < 47; ++x) { | 984 for (int x = -6; x < 47; ++x) { |
1019 int index = (x > 3 || x < 0) ? 3 : x; | 985 int index = (x > 3 || x < 0) ? 3 : x; |
1020 int32_t expected = 50 + cases[index]; | 986 int32_t expected = 50 + cases[index]; |
1021 CHECK_EQ(expected, r.Call(x)); | 987 CHECK_EQ(expected, r.Call(x)); |
1022 } | 988 } |
1023 } | 989 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 CHECK_EQ(expected, r.Call()); | 1032 CHECK_EQ(expected, r.Call()); |
1067 } | 1033 } |
1068 } | 1034 } |
1069 | 1035 |
1070 WASM_EXEC_TEST(I32ReinterpretF32) { | 1036 WASM_EXEC_TEST(I32ReinterpretF32) { |
1071 WasmRunner<int32_t, int32_t> r(execution_mode); | 1037 WasmRunner<int32_t, int32_t> r(execution_mode); |
1072 int32_t* memory = r.module().AddMemoryElems<int32_t>(8); | 1038 int32_t* memory = r.module().AddMemoryElems<int32_t>(8); |
1073 | 1039 |
1074 BUILD(r, WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, | 1040 BUILD(r, WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, |
1075 WASM_F32_REINTERPRET_I32(WASM_GET_LOCAL(0))), | 1041 WASM_F32_REINTERPRET_I32(WASM_GET_LOCAL(0))), |
1076 WASM_I8(107)); | 1042 WASM_I32V_2(107)); |
1077 | 1043 |
1078 FOR_INT32_INPUTS(i) { | 1044 FOR_INT32_INPUTS(i) { |
1079 int32_t expected = *i; | 1045 int32_t expected = *i; |
1080 CHECK_EQ(107, r.Call(expected)); | 1046 CHECK_EQ(107, r.Call(expected)); |
1081 CHECK_EQ(expected, r.module().ReadMemory(&memory[0])); | 1047 CHECK_EQ(expected, r.module().ReadMemory(&memory[0])); |
1082 } | 1048 } |
1083 } | 1049 } |
1084 | 1050 |
1085 WASM_EXEC_TEST_WITH_TRAP(LoadMaxUint32Offset) { | 1051 WASM_EXEC_TEST_WITH_TRAP(LoadMaxUint32Offset) { |
1086 WasmRunner<int32_t> r(execution_mode); | 1052 WasmRunner<int32_t> r(execution_mode); |
1087 r.module().AddMemoryElems<int32_t>(8); | 1053 r.module().AddMemoryElems<int32_t>(8); |
1088 | 1054 |
1089 BUILD(r, kExprI8Const, 0, // index | 1055 BUILD(r, kExprI32Const, 0, // index |
1090 static_cast<byte>(v8::internal::wasm::WasmOpcodes::LoadStoreOpcodeOf( | 1056 static_cast<byte>(v8::internal::wasm::WasmOpcodes::LoadStoreOpcodeOf( |
1091 MachineType::Int32(), false)), // -- | 1057 MachineType::Int32(), false)), // -- |
1092 0, // alignment | 1058 0, // alignment |
1093 U32V_5(0xffffffff)); // offset | 1059 U32V_5(0xffffffff)); // offset |
1094 | 1060 |
1095 CHECK_TRAP32(r.Call()); | 1061 CHECK_TRAP32(r.Call()); |
1096 } | 1062 } |
1097 | 1063 |
1098 WASM_EXEC_TEST(LoadStoreLoad) { | 1064 WASM_EXEC_TEST(LoadStoreLoad) { |
1099 WasmRunner<int32_t> r(execution_mode); | 1065 WasmRunner<int32_t> r(execution_mode); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 | 1166 |
1201 WASM_EXEC_TEST(Block_br2) { | 1167 WASM_EXEC_TEST(Block_br2) { |
1202 WasmRunner<int32_t, int32_t> r(execution_mode); | 1168 WasmRunner<int32_t, int32_t> r(execution_mode); |
1203 BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); | 1169 BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
1204 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, static_cast<uint32_t>(r.Call(*i))); } | 1170 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, static_cast<uint32_t>(r.Call(*i))); } |
1205 } | 1171 } |
1206 | 1172 |
1207 WASM_EXEC_TEST(Block_If_P) { | 1173 WASM_EXEC_TEST(Block_If_P) { |
1208 WasmRunner<int32_t, int32_t> r(execution_mode); | 1174 WasmRunner<int32_t, int32_t> r(execution_mode); |
1209 // block { if (p0) break 51; 52; } | 1175 // block { if (p0) break 51; 52; } |
1210 BUILD(r, WASM_BLOCK_I( // -- | 1176 BUILD(r, WASM_BLOCK_I( // -- |
1211 WASM_IF(WASM_GET_LOCAL(0), // -- | 1177 WASM_IF(WASM_GET_LOCAL(0), // -- |
1212 WASM_BRV(1, WASM_I8(51))), // -- | 1178 WASM_BRV(1, WASM_I32V_1(51))), // -- |
1213 WASM_I8(52))); // -- | 1179 WASM_I32V_1(52))); // -- |
1214 FOR_INT32_INPUTS(i) { | 1180 FOR_INT32_INPUTS(i) { |
1215 int32_t expected = *i ? 51 : 52; | 1181 int32_t expected = *i ? 51 : 52; |
1216 CHECK_EQ(expected, r.Call(*i)); | 1182 CHECK_EQ(expected, r.Call(*i)); |
1217 } | 1183 } |
1218 } | 1184 } |
1219 | 1185 |
1220 WASM_EXEC_TEST(Loop_empty) { | 1186 WASM_EXEC_TEST(Loop_empty) { |
1221 WasmRunner<int32_t, int32_t> r(execution_mode); | 1187 WasmRunner<int32_t, int32_t> r(execution_mode); |
1222 BUILD(r, kExprLoop, kLocalVoid, kExprEnd, WASM_GET_LOCAL(0)); | 1188 BUILD(r, kExprLoop, kLocalVoid, kExprEnd, WASM_GET_LOCAL(0)); |
1223 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1189 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1266 FOR_UINT32_INPUTS(i) { | 1232 FOR_UINT32_INPUTS(i) { |
1267 FOR_UINT32_INPUTS(j) { | 1233 FOR_UINT32_INPUTS(j) { |
1268 CHECK_EQ(*i, r.Call(0, *i, *j)); | 1234 CHECK_EQ(*i, r.Call(0, *i, *j)); |
1269 CHECK_EQ(*j, r.Call(1, *i, *j)); | 1235 CHECK_EQ(*j, r.Call(1, *i, *j)); |
1270 } | 1236 } |
1271 } | 1237 } |
1272 } | 1238 } |
1273 | 1239 |
1274 WASM_EXEC_TEST(Block_BrIf_P) { | 1240 WASM_EXEC_TEST(Block_BrIf_P) { |
1275 WasmRunner<int32_t, int32_t> r(execution_mode); | 1241 WasmRunner<int32_t, int32_t> r(execution_mode); |
1276 BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(51), WASM_GET_LOCAL(0)), | 1242 BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I32V_1(51), WASM_GET_LOCAL(0)), |
1277 WASM_I8(52))); | 1243 WASM_I32V_1(52))); |
1278 FOR_INT32_INPUTS(i) { | 1244 FOR_INT32_INPUTS(i) { |
1279 int32_t expected = *i ? 51 : 52; | 1245 int32_t expected = *i ? 51 : 52; |
1280 CHECK_EQ(expected, r.Call(*i)); | 1246 CHECK_EQ(expected, r.Call(*i)); |
1281 } | 1247 } |
1282 } | 1248 } |
1283 | 1249 |
1284 WASM_EXEC_TEST(Block_IfElse_P_assign) { | 1250 WASM_EXEC_TEST(Block_IfElse_P_assign) { |
1285 WasmRunner<int32_t, int32_t> r(execution_mode); | 1251 WasmRunner<int32_t, int32_t> r(execution_mode); |
1286 // { if (p0) p0 = 71; else p0 = 72; return p0; } | 1252 // { if (p0) p0 = 71; else p0 = 72; return p0; } |
1287 BUILD(r, // -- | 1253 BUILD(r, // -- |
1288 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- | 1254 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- |
1289 WASM_SET_LOCAL(0, WASM_I8(71)), // -- | 1255 WASM_SET_LOCAL(0, WASM_I32V_2(71)), // -- |
1290 WASM_SET_LOCAL(0, WASM_I8(72))), // -- | 1256 WASM_SET_LOCAL(0, WASM_I32V_2(72))), // -- |
1291 WASM_GET_LOCAL(0)); | 1257 WASM_GET_LOCAL(0)); |
1292 FOR_INT32_INPUTS(i) { | 1258 FOR_INT32_INPUTS(i) { |
1293 int32_t expected = *i ? 71 : 72; | 1259 int32_t expected = *i ? 71 : 72; |
1294 CHECK_EQ(expected, r.Call(*i)); | 1260 CHECK_EQ(expected, r.Call(*i)); |
1295 } | 1261 } |
1296 } | 1262 } |
1297 | 1263 |
1298 WASM_EXEC_TEST(Block_IfElse_P_return) { | 1264 WASM_EXEC_TEST(Block_IfElse_P_return) { |
1299 WasmRunner<int32_t, int32_t> r(execution_mode); | 1265 WasmRunner<int32_t, int32_t> r(execution_mode); |
1300 // if (p0) return 81; else return 82; | 1266 // if (p0) return 81; else return 82; |
1301 BUILD(r, // -- | 1267 BUILD(r, // -- |
1302 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- | 1268 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- |
1303 RET_I8(81), // -- | 1269 RET_I8(81), // -- |
1304 RET_I8(82))); // -- | 1270 RET_I8(82))); // -- |
1305 FOR_INT32_INPUTS(i) { | 1271 FOR_INT32_INPUTS(i) { |
1306 int32_t expected = *i ? 81 : 82; | 1272 int32_t expected = *i ? 81 : 82; |
1307 CHECK_EQ(expected, r.Call(*i)); | 1273 CHECK_EQ(expected, r.Call(*i)); |
1308 } | 1274 } |
1309 } | 1275 } |
1310 | 1276 |
1311 WASM_EXEC_TEST(Block_If_P_assign) { | 1277 WASM_EXEC_TEST(Block_If_P_assign) { |
1312 WasmRunner<int32_t, int32_t> r(execution_mode); | 1278 WasmRunner<int32_t, int32_t> r(execution_mode); |
1313 // { if (p0) p0 = 61; p0; } | 1279 // { if (p0) p0 = 61; p0; } |
1314 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(61))), | 1280 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I32V_1(61))), |
1315 WASM_GET_LOCAL(0)); | 1281 WASM_GET_LOCAL(0)); |
1316 FOR_INT32_INPUTS(i) { | 1282 FOR_INT32_INPUTS(i) { |
1317 int32_t expected = *i ? 61 : *i; | 1283 int32_t expected = *i ? 61 : *i; |
1318 CHECK_EQ(expected, r.Call(*i)); | 1284 CHECK_EQ(expected, r.Call(*i)); |
1319 } | 1285 } |
1320 } | 1286 } |
1321 | 1287 |
1322 WASM_EXEC_TEST(DanglingAssign) { | 1288 WASM_EXEC_TEST(DanglingAssign) { |
1323 WasmRunner<int32_t, int32_t> r(execution_mode); | 1289 WasmRunner<int32_t, int32_t> r(execution_mode); |
1324 // { return 0; p0 = 0; } | 1290 // { return 0; p0 = 0; } |
1325 BUILD(r, B2(RET_I8(99), WASM_SET_LOCAL(0, WASM_ZERO))); | 1291 BUILD(r, B2(RET_I8(99), WASM_SET_LOCAL(0, WASM_ZERO))); |
1326 CHECK_EQ(99, r.Call(1)); | 1292 CHECK_EQ(99, r.Call(1)); |
1327 } | 1293 } |
1328 | 1294 |
1329 WASM_EXEC_TEST(ExprIf_P) { | 1295 WASM_EXEC_TEST(ExprIf_P) { |
1330 WasmRunner<int32_t, int32_t> r(execution_mode); | 1296 WasmRunner<int32_t, int32_t> r(execution_mode); |
1331 // p0 ? 11 : 22; | 1297 // p0 ? 11 : 22; |
1332 BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), // -- | 1298 BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), // -- |
1333 WASM_I8(11), // -- | 1299 WASM_I32V_1(11), // -- |
1334 WASM_I8(22))); // -- | 1300 WASM_I32V_1(22))); // -- |
1335 FOR_INT32_INPUTS(i) { | 1301 FOR_INT32_INPUTS(i) { |
1336 int32_t expected = *i ? 11 : 22; | 1302 int32_t expected = *i ? 11 : 22; |
1337 CHECK_EQ(expected, r.Call(*i)); | 1303 CHECK_EQ(expected, r.Call(*i)); |
1338 } | 1304 } |
1339 } | 1305 } |
1340 | 1306 |
1341 WASM_EXEC_TEST(CountDown) { | 1307 WASM_EXEC_TEST(CountDown) { |
1342 WasmRunner<int32_t, int32_t> r(execution_mode); | 1308 WasmRunner<int32_t, int32_t> r(execution_mode); |
1343 BUILD(r, WASM_LOOP(WASM_IFB( | 1309 BUILD(r, WASM_LOOP(WASM_IFB(WASM_GET_LOCAL(0), |
1344 WASM_GET_LOCAL(0), | 1310 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), |
1345 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), | 1311 WASM_I32V_1(1))), |
1346 WASM_BR(1))), | 1312 WASM_BR(1))), |
1347 WASM_GET_LOCAL(0)); | 1313 WASM_GET_LOCAL(0)); |
1348 CHECK_EQ(0, r.Call(1)); | 1314 CHECK_EQ(0, r.Call(1)); |
1349 CHECK_EQ(0, r.Call(10)); | 1315 CHECK_EQ(0, r.Call(10)); |
1350 CHECK_EQ(0, r.Call(100)); | 1316 CHECK_EQ(0, r.Call(100)); |
1351 } | 1317 } |
1352 | 1318 |
1353 WASM_EXEC_TEST(CountDown_fallthru) { | 1319 WASM_EXEC_TEST(CountDown_fallthru) { |
1354 WasmRunner<int32_t, int32_t> r(execution_mode); | 1320 WasmRunner<int32_t, int32_t> r(execution_mode); |
1355 BUILD(r, WASM_LOOP( | 1321 BUILD( |
1356 WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), | 1322 r, |
1357 WASM_BRV(2, WASM_GET_LOCAL(0))), | 1323 WASM_LOOP( |
1358 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), | 1324 WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), WASM_BRV(2, WASM_GET_LOCAL(0))), |
1359 WASM_CONTINUE(0)), | 1325 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(1))), |
1360 WASM_GET_LOCAL(0)); | 1326 WASM_CONTINUE(0)), |
| 1327 WASM_GET_LOCAL(0)); |
1361 CHECK_EQ(0, r.Call(1)); | 1328 CHECK_EQ(0, r.Call(1)); |
1362 CHECK_EQ(0, r.Call(10)); | 1329 CHECK_EQ(0, r.Call(10)); |
1363 CHECK_EQ(0, r.Call(100)); | 1330 CHECK_EQ(0, r.Call(100)); |
1364 } | 1331 } |
1365 | 1332 |
1366 WASM_EXEC_TEST(WhileCountDown) { | 1333 WASM_EXEC_TEST(WhileCountDown) { |
1367 WasmRunner<int32_t, int32_t> r(execution_mode); | 1334 WasmRunner<int32_t, int32_t> r(execution_mode); |
1368 BUILD(r, WASM_WHILE( | 1335 BUILD(r, WASM_WHILE(WASM_GET_LOCAL(0), |
1369 WASM_GET_LOCAL(0), | 1336 WASM_SET_LOCAL( |
1370 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1)))), | 1337 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(1)))), |
1371 WASM_GET_LOCAL(0)); | 1338 WASM_GET_LOCAL(0)); |
1372 CHECK_EQ(0, r.Call(1)); | 1339 CHECK_EQ(0, r.Call(1)); |
1373 CHECK_EQ(0, r.Call(10)); | 1340 CHECK_EQ(0, r.Call(10)); |
1374 CHECK_EQ(0, r.Call(100)); | 1341 CHECK_EQ(0, r.Call(100)); |
1375 } | 1342 } |
1376 | 1343 |
1377 WASM_EXEC_TEST(Loop_if_break1) { | 1344 WASM_EXEC_TEST(Loop_if_break1) { |
1378 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); | 1345 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); |
1379 BUILD(r, WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(2, WASM_GET_LOCAL(1))), | 1346 BUILD(r, WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(2, WASM_GET_LOCAL(1))), |
1380 WASM_SET_LOCAL(0, WASM_I8(99))), | 1347 WASM_SET_LOCAL(0, WASM_I32V_2(99))), |
1381 WASM_GET_LOCAL(0)); | 1348 WASM_GET_LOCAL(0)); |
1382 CHECK_EQ(99, r.Call(0, 11)); | 1349 CHECK_EQ(99, r.Call(0, 11)); |
1383 CHECK_EQ(65, r.Call(3, 65)); | 1350 CHECK_EQ(65, r.Call(3, 65)); |
1384 CHECK_EQ(10001, r.Call(10000, 10001)); | 1351 CHECK_EQ(10001, r.Call(10000, 10001)); |
1385 CHECK_EQ(-29, r.Call(-28, -29)); | 1352 CHECK_EQ(-29, r.Call(-28, -29)); |
1386 } | 1353 } |
1387 | 1354 |
1388 WASM_EXEC_TEST(Loop_if_break2) { | 1355 WASM_EXEC_TEST(Loop_if_break2) { |
1389 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); | 1356 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); |
1390 BUILD(r, WASM_LOOP(WASM_BRV_IF(1, WASM_GET_LOCAL(1), WASM_GET_LOCAL(0)), | 1357 BUILD(r, WASM_LOOP(WASM_BRV_IF(1, WASM_GET_LOCAL(1), WASM_GET_LOCAL(0)), |
1391 WASM_DROP, WASM_SET_LOCAL(0, WASM_I8(99))), | 1358 WASM_DROP, WASM_SET_LOCAL(0, WASM_I32V_2(99))), |
1392 WASM_GET_LOCAL(0)); | 1359 WASM_GET_LOCAL(0)); |
1393 CHECK_EQ(99, r.Call(0, 33)); | 1360 CHECK_EQ(99, r.Call(0, 33)); |
1394 CHECK_EQ(3, r.Call(1, 3)); | 1361 CHECK_EQ(3, r.Call(1, 3)); |
1395 CHECK_EQ(10000, r.Call(99, 10000)); | 1362 CHECK_EQ(10000, r.Call(99, 10000)); |
1396 CHECK_EQ(-29, r.Call(-11, -29)); | 1363 CHECK_EQ(-29, r.Call(-11, -29)); |
1397 } | 1364 } |
1398 | 1365 |
1399 WASM_EXEC_TEST(Loop_if_break_fallthru) { | 1366 WASM_EXEC_TEST(Loop_if_break_fallthru) { |
1400 WasmRunner<int32_t, int32_t> r(execution_mode); | 1367 WasmRunner<int32_t, int32_t> r(execution_mode); |
1401 BUILD(r, B1(WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2)), | 1368 BUILD(r, B1(WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2)), |
1402 WASM_SET_LOCAL(0, WASM_I8(93)))), | 1369 WASM_SET_LOCAL(0, WASM_I32V_2(93)))), |
1403 WASM_GET_LOCAL(0)); | 1370 WASM_GET_LOCAL(0)); |
1404 CHECK_EQ(93, r.Call(0)); | 1371 CHECK_EQ(93, r.Call(0)); |
1405 CHECK_EQ(3, r.Call(3)); | 1372 CHECK_EQ(3, r.Call(3)); |
1406 CHECK_EQ(10001, r.Call(10001)); | 1373 CHECK_EQ(10001, r.Call(10001)); |
1407 CHECK_EQ(-22, r.Call(-22)); | 1374 CHECK_EQ(-22, r.Call(-22)); |
1408 } | 1375 } |
1409 | 1376 |
1410 WASM_EXEC_TEST(Loop_if_break_fallthru2) { | 1377 WASM_EXEC_TEST(Loop_if_break_fallthru2) { |
1411 WasmRunner<int32_t, int32_t> r(execution_mode); | 1378 WasmRunner<int32_t, int32_t> r(execution_mode); |
1412 BUILD(r, B1(B1(WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2)), | 1379 BUILD(r, B1(B1(WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2)), |
1413 WASM_SET_LOCAL(0, WASM_I8(93))))), | 1380 WASM_SET_LOCAL(0, WASM_I32V_2(93))))), |
1414 WASM_GET_LOCAL(0)); | 1381 WASM_GET_LOCAL(0)); |
1415 CHECK_EQ(93, r.Call(0)); | 1382 CHECK_EQ(93, r.Call(0)); |
1416 CHECK_EQ(3, r.Call(3)); | 1383 CHECK_EQ(3, r.Call(3)); |
1417 CHECK_EQ(10001, r.Call(10001)); | 1384 CHECK_EQ(10001, r.Call(10001)); |
1418 CHECK_EQ(-22, r.Call(-22)); | 1385 CHECK_EQ(-22, r.Call(-22)); |
1419 } | 1386 } |
1420 | 1387 |
1421 WASM_EXEC_TEST(IfBreak1) { | 1388 WASM_EXEC_TEST(IfBreak1) { |
1422 WasmRunner<int32_t, int32_t> r(execution_mode); | 1389 WasmRunner<int32_t, int32_t> r(execution_mode); |
1423 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), WASM_UNREACHABLE)), | 1390 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), WASM_UNREACHABLE)), |
1424 WASM_I8(91)); | 1391 WASM_I32V_2(91)); |
1425 CHECK_EQ(91, r.Call(0)); | 1392 CHECK_EQ(91, r.Call(0)); |
1426 CHECK_EQ(91, r.Call(1)); | 1393 CHECK_EQ(91, r.Call(1)); |
1427 CHECK_EQ(91, r.Call(-8734)); | 1394 CHECK_EQ(91, r.Call(-8734)); |
1428 } | 1395 } |
1429 | 1396 |
1430 WASM_EXEC_TEST(IfBreak2) { | 1397 WASM_EXEC_TEST(IfBreak2) { |
1431 WasmRunner<int32_t, int32_t> r(execution_mode); | 1398 WasmRunner<int32_t, int32_t> r(execution_mode); |
1432 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), RET_I8(77))), | 1399 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), RET_I8(77))), |
1433 WASM_I8(81)); | 1400 WASM_I32V_2(81)); |
1434 CHECK_EQ(81, r.Call(0)); | 1401 CHECK_EQ(81, r.Call(0)); |
1435 CHECK_EQ(81, r.Call(1)); | 1402 CHECK_EQ(81, r.Call(1)); |
1436 CHECK_EQ(81, r.Call(-8734)); | 1403 CHECK_EQ(81, r.Call(-8734)); |
1437 } | 1404 } |
1438 | 1405 |
1439 WASM_EXEC_TEST(LoadMemI32) { | 1406 WASM_EXEC_TEST(LoadMemI32) { |
1440 WasmRunner<int32_t, int32_t> r(execution_mode); | 1407 WasmRunner<int32_t, int32_t> r(execution_mode); |
1441 int32_t* memory = r.module().AddMemoryElems<int32_t>(8); | 1408 int32_t* memory = r.module().AddMemoryElems<int32_t>(8); |
1442 r.module().RandomizeMemory(1111); | 1409 r.module().RandomizeMemory(1111); |
1443 | 1410 |
1444 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(0))); | 1411 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)); |
1445 | 1412 |
1446 r.module().WriteMemory(&memory[0], 99999999); | 1413 r.module().WriteMemory(&memory[0], 99999999); |
1447 CHECK_EQ(99999999, r.Call(0)); | 1414 CHECK_EQ(99999999, r.Call(0)); |
1448 | 1415 |
1449 r.module().WriteMemory(&memory[0], 88888888); | 1416 r.module().WriteMemory(&memory[0], 88888888); |
1450 CHECK_EQ(88888888, r.Call(0)); | 1417 CHECK_EQ(88888888, r.Call(0)); |
1451 | 1418 |
1452 r.module().WriteMemory(&memory[0], 77777777); | 1419 r.module().WriteMemory(&memory[0], 77777777); |
1453 CHECK_EQ(77777777, r.Call(0)); | 1420 CHECK_EQ(77777777, r.Call(0)); |
1454 } | 1421 } |
1455 | 1422 |
1456 WASM_EXEC_TEST(LoadMemI32_alignment) { | 1423 WASM_EXEC_TEST(LoadMemI32_alignment) { |
1457 for (byte alignment = 0; alignment <= 2; ++alignment) { | 1424 for (byte alignment = 0; alignment <= 2; ++alignment) { |
1458 WasmRunner<int32_t, int32_t> r(execution_mode); | 1425 WasmRunner<int32_t, int32_t> r(execution_mode); |
1459 int32_t* memory = r.module().AddMemoryElems<int32_t>(8); | 1426 int32_t* memory = r.module().AddMemoryElems<int32_t>(8); |
1460 r.module().RandomizeMemory(1111); | 1427 r.module().RandomizeMemory(1111); |
1461 | 1428 |
1462 BUILD(r, | 1429 BUILD(r, |
1463 WASM_LOAD_MEM_ALIGNMENT(MachineType::Int32(), WASM_I8(0), alignment)); | 1430 WASM_LOAD_MEM_ALIGNMENT(MachineType::Int32(), WASM_ZERO, alignment)); |
1464 | 1431 |
1465 r.module().WriteMemory(&memory[0], 0x1a2b3c4d); | 1432 r.module().WriteMemory(&memory[0], 0x1a2b3c4d); |
1466 CHECK_EQ(0x1a2b3c4d, r.Call(0)); | 1433 CHECK_EQ(0x1a2b3c4d, r.Call(0)); |
1467 | 1434 |
1468 r.module().WriteMemory(&memory[0], 0x5e6f7a8b); | 1435 r.module().WriteMemory(&memory[0], 0x5e6f7a8b); |
1469 CHECK_EQ(0x5e6f7a8b, r.Call(0)); | 1436 CHECK_EQ(0x5e6f7a8b, r.Call(0)); |
1470 | 1437 |
1471 r.module().WriteMemory(&memory[0], 0x7ca0b1c2); | 1438 r.module().WriteMemory(&memory[0], 0x7ca0b1c2); |
1472 CHECK_EQ(0x7ca0b1c2, r.Call(0)); | 1439 CHECK_EQ(0x7ca0b1c2, r.Call(0)); |
1473 } | 1440 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1542 | 1509 |
1543 WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob_misaligned) { | 1510 WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob_misaligned) { |
1544 const int kMemSize = 12; | 1511 const int kMemSize = 12; |
1545 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable. | 1512 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable. |
1546 for (int offset = 0; offset < kMemSize + 5; ++offset) { | 1513 for (int offset = 0; offset < kMemSize + 5; ++offset) { |
1547 for (int index = 0; index < kMemSize + 5; ++index) { | 1514 for (int index = 0; index < kMemSize + 5; ++index) { |
1548 WasmRunner<int32_t> r(execution_mode); | 1515 WasmRunner<int32_t> r(execution_mode); |
1549 r.module().AddMemoryElems<byte>(kMemSize); | 1516 r.module().AddMemoryElems<byte>(kMemSize); |
1550 r.module().RandomizeMemory(); | 1517 r.module().RandomizeMemory(); |
1551 | 1518 |
1552 BUILD(r, | 1519 BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, |
1553 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); | 1520 WASM_I32V_2(index))); |
1554 | 1521 |
1555 if ((offset + index) <= static_cast<int>((kMemSize - sizeof(int32_t)))) { | 1522 if ((offset + index) <= static_cast<int>((kMemSize - sizeof(int32_t)))) { |
1556 CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call()); | 1523 CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call()); |
1557 } else { | 1524 } else { |
1558 CHECK_TRAP(r.Call()); | 1525 CHECK_TRAP(r.Call()); |
1559 } | 1526 } |
1560 } | 1527 } |
1561 } | 1528 } |
1562 } | 1529 } |
1563 | 1530 |
1564 WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob) { | 1531 WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob) { |
1565 const int kMemSize = 24; | 1532 const int kMemSize = 24; |
1566 for (int offset = 0; offset < kMemSize + 5; offset += 4) { | 1533 for (int offset = 0; offset < kMemSize + 5; offset += 4) { |
1567 for (int index = 0; index < kMemSize + 5; index += 4) { | 1534 for (int index = 0; index < kMemSize + 5; index += 4) { |
1568 WasmRunner<int32_t> r(execution_mode); | 1535 WasmRunner<int32_t> r(execution_mode); |
1569 r.module().AddMemoryElems<byte>(kMemSize); | 1536 r.module().AddMemoryElems<byte>(kMemSize); |
1570 r.module().RandomizeMemory(); | 1537 r.module().RandomizeMemory(); |
1571 | 1538 |
1572 BUILD(r, | 1539 BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, |
1573 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); | 1540 WASM_I32V_2(index))); |
1574 | 1541 |
1575 if ((offset + index) <= static_cast<int>((kMemSize - sizeof(int32_t)))) { | 1542 if ((offset + index) <= static_cast<int>((kMemSize - sizeof(int32_t)))) { |
1576 CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call()); | 1543 CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call()); |
1577 } else { | 1544 } else { |
1578 CHECK_TRAP(r.Call()); | 1545 CHECK_TRAP(r.Call()); |
1579 } | 1546 } |
1580 } | 1547 } |
1581 } | 1548 } |
1582 } | 1549 } |
1583 | 1550 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 CHECK_EQ(r.module().ReadMemory(&memory[i]), r.Call(i * 4)); | 1628 CHECK_EQ(r.module().ReadMemory(&memory[i]), r.Call(i * 4)); |
1662 } | 1629 } |
1663 } | 1630 } |
1664 | 1631 |
1665 WASM_EXEC_TEST(MemI32_Sum) { | 1632 WASM_EXEC_TEST(MemI32_Sum) { |
1666 const int kNumElems = 20; | 1633 const int kNumElems = 20; |
1667 WasmRunner<uint32_t, int32_t> r(execution_mode); | 1634 WasmRunner<uint32_t, int32_t> r(execution_mode); |
1668 uint32_t* memory = r.module().AddMemoryElems<uint32_t>(kNumElems); | 1635 uint32_t* memory = r.module().AddMemoryElems<uint32_t>(kNumElems); |
1669 const byte kSum = r.AllocateLocal(kWasmI32); | 1636 const byte kSum = r.AllocateLocal(kWasmI32); |
1670 | 1637 |
1671 BUILD( | 1638 BUILD(r, WASM_WHILE( |
1672 r, | 1639 WASM_GET_LOCAL(0), |
1673 WASM_WHILE( | 1640 WASM_BLOCK( |
1674 WASM_GET_LOCAL(0), | 1641 WASM_SET_LOCAL( |
1675 WASM_BLOCK( | 1642 kSum, WASM_I32_ADD(WASM_GET_LOCAL(kSum), |
1676 WASM_SET_LOCAL(kSum, | |
1677 WASM_I32_ADD(WASM_GET_LOCAL(kSum), | |
1678 WASM_LOAD_MEM(MachineType::Int32(), | 1643 WASM_LOAD_MEM(MachineType::Int32(), |
1679 WASM_GET_LOCAL(0)))), | 1644 WASM_GET_LOCAL(0)))), |
1680 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), | 1645 WASM_SET_LOCAL( |
1681 WASM_GET_LOCAL(1)); | 1646 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(4))))), |
| 1647 WASM_GET_LOCAL(1)); |
1682 | 1648 |
1683 // Run 4 trials. | 1649 // Run 4 trials. |
1684 for (int i = 0; i < 3; ++i) { | 1650 for (int i = 0; i < 3; ++i) { |
1685 r.module().RandomizeMemory(i * 33); | 1651 r.module().RandomizeMemory(i * 33); |
1686 uint32_t expected = 0; | 1652 uint32_t expected = 0; |
1687 for (size_t j = kNumElems - 1; j > 0; --j) { | 1653 for (size_t j = kNumElems - 1; j > 0; --j) { |
1688 expected += r.module().ReadMemory(&memory[j]); | 1654 expected += r.module().ReadMemory(&memory[j]); |
1689 } | 1655 } |
1690 uint32_t result = r.Call(4 * (kNumElems - 1)); | 1656 uint32_t result = r.Call(4 * (kNumElems - 1)); |
1691 CHECK_EQ(expected, result); | 1657 CHECK_EQ(expected, result); |
1692 } | 1658 } |
1693 } | 1659 } |
1694 | 1660 |
1695 WASM_EXEC_TEST(CheckMachIntsZero) { | 1661 WASM_EXEC_TEST(CheckMachIntsZero) { |
1696 const int kNumElems = 55; | 1662 const int kNumElems = 55; |
1697 WasmRunner<uint32_t, int32_t> r(execution_mode); | 1663 WasmRunner<uint32_t, int32_t> r(execution_mode); |
1698 r.module().AddMemoryElems<uint32_t>(kNumElems); | 1664 r.module().AddMemoryElems<uint32_t>(kNumElems); |
1699 | 1665 |
1700 BUILD(r, // -- | 1666 BUILD(r, // -- |
1701 /**/ kExprLoop, kLocalVoid, // -- | 1667 /**/ kExprLoop, kLocalVoid, // -- |
1702 /* */ kExprGetLocal, 0, // -- | 1668 /* */ kExprGetLocal, 0, // -- |
1703 /* */ kExprIf, kLocalVoid, // -- | 1669 /* */ kExprIf, kLocalVoid, // -- |
1704 /* */ kExprGetLocal, 0, // -- | 1670 /* */ kExprGetLocal, 0, // -- |
1705 /* */ kExprI32LoadMem, 0, 0, // -- | 1671 /* */ kExprI32LoadMem, 0, 0, // -- |
1706 /* */ kExprIf, kLocalVoid, // -- | 1672 /* */ kExprIf, kLocalVoid, // -- |
1707 /* */ kExprI8Const, 255, // -- | 1673 /* */ kExprI32Const, 127, // -- |
1708 /* */ kExprReturn, // -- | 1674 /* */ kExprReturn, // -- |
1709 /* */ kExprEnd, // -- | 1675 /* */ kExprEnd, // -- |
1710 /* */ kExprGetLocal, 0, // -- | 1676 /* */ kExprGetLocal, 0, // -- |
1711 /* */ kExprI8Const, 4, // -- | 1677 /* */ kExprI32Const, 4, // -- |
1712 /* */ kExprI32Sub, // -- | 1678 /* */ kExprI32Sub, // -- |
1713 /* */ kExprTeeLocal, 0, // -- | 1679 /* */ kExprTeeLocal, 0, // -- |
1714 /* */ kExprBr, DEPTH_0, // -- | 1680 /* */ kExprBr, DEPTH_0, // -- |
1715 /* */ kExprEnd, // -- | 1681 /* */ kExprEnd, // -- |
1716 /**/ kExprEnd, // -- | 1682 /**/ kExprEnd, // -- |
1717 /**/ kExprI8Const, 0); // -- | 1683 /**/ kExprI32Const, 0); // -- |
1718 | 1684 |
1719 r.module().BlankMemory(); | 1685 r.module().BlankMemory(); |
1720 CHECK_EQ(0, r.Call((kNumElems - 1) * 4)); | 1686 CHECK_EQ(0, r.Call((kNumElems - 1) * 4)); |
1721 } | 1687 } |
1722 | 1688 |
1723 WASM_EXEC_TEST(MemF32_Sum) { | 1689 WASM_EXEC_TEST(MemF32_Sum) { |
1724 const int kSize = 5; | 1690 const int kSize = 5; |
1725 WasmRunner<int32_t, int32_t> r(execution_mode); | 1691 WasmRunner<int32_t, int32_t> r(execution_mode); |
1726 r.module().AddMemoryElems<float>(kSize); | 1692 r.module().AddMemoryElems<float>(kSize); |
1727 float* buffer = r.module().raw_mem_start<float>(); | 1693 float* buffer = r.module().raw_mem_start<float>(); |
1728 r.module().WriteMemory(&buffer[0], -99.25f); | 1694 r.module().WriteMemory(&buffer[0], -99.25f); |
1729 r.module().WriteMemory(&buffer[1], -888.25f); | 1695 r.module().WriteMemory(&buffer[1], -888.25f); |
1730 r.module().WriteMemory(&buffer[2], -77.25f); | 1696 r.module().WriteMemory(&buffer[2], -77.25f); |
1731 r.module().WriteMemory(&buffer[3], 66666.25f); | 1697 r.module().WriteMemory(&buffer[3], 66666.25f); |
1732 r.module().WriteMemory(&buffer[4], 5555.25f); | 1698 r.module().WriteMemory(&buffer[4], 5555.25f); |
1733 const byte kSum = r.AllocateLocal(kWasmF32); | 1699 const byte kSum = r.AllocateLocal(kWasmF32); |
1734 | 1700 |
1735 BUILD( | 1701 BUILD(r, WASM_WHILE( |
1736 r, | 1702 WASM_GET_LOCAL(0), |
1737 WASM_WHILE( | 1703 WASM_BLOCK( |
1738 WASM_GET_LOCAL(0), | 1704 WASM_SET_LOCAL( |
1739 WASM_BLOCK( | 1705 kSum, WASM_F32_ADD(WASM_GET_LOCAL(kSum), |
1740 WASM_SET_LOCAL(kSum, | |
1741 WASM_F32_ADD(WASM_GET_LOCAL(kSum), | |
1742 WASM_LOAD_MEM(MachineType::Float32(), | 1706 WASM_LOAD_MEM(MachineType::Float32(), |
1743 WASM_GET_LOCAL(0)))), | 1707 WASM_GET_LOCAL(0)))), |
1744 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), | 1708 WASM_SET_LOCAL( |
1745 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)), | 1709 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(4))))), |
1746 WASM_GET_LOCAL(0)); | 1710 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)), |
| 1711 WASM_GET_LOCAL(0)); |
1747 | 1712 |
1748 CHECK_EQ(0, r.Call(4 * (kSize - 1))); | 1713 CHECK_EQ(0, r.Call(4 * (kSize - 1))); |
1749 CHECK_NE(-99.25f, r.module().ReadMemory(&buffer[0])); | 1714 CHECK_NE(-99.25f, r.module().ReadMemory(&buffer[0])); |
1750 CHECK_EQ(71256.0f, r.module().ReadMemory(&buffer[0])); | 1715 CHECK_EQ(71256.0f, r.module().ReadMemory(&buffer[0])); |
1751 } | 1716 } |
1752 | 1717 |
1753 template <typename T> | 1718 template <typename T> |
1754 T GenerateAndRunFold(WasmExecutionMode execution_mode, WasmOpcode binop, | 1719 T GenerateAndRunFold(WasmExecutionMode execution_mode, WasmOpcode binop, |
1755 T* buffer, uint32_t size, ValueType astType, | 1720 T* buffer, uint32_t size, ValueType astType, |
1756 MachineType memType) { | 1721 MachineType memType) { |
1757 WasmRunner<int32_t, int32_t> r(execution_mode); | 1722 WasmRunner<int32_t, int32_t> r(execution_mode); |
1758 T* memory = r.module().AddMemoryElems<T>(size); | 1723 T* memory = r.module().AddMemoryElems<T>(size); |
1759 for (uint32_t i = 0; i < size; ++i) { | 1724 for (uint32_t i = 0; i < size; ++i) { |
1760 r.module().WriteMemory(&memory[i], buffer[i]); | 1725 r.module().WriteMemory(&memory[i], buffer[i]); |
1761 } | 1726 } |
1762 const byte kAccum = r.AllocateLocal(astType); | 1727 const byte kAccum = r.AllocateLocal(astType); |
1763 | 1728 |
1764 BUILD(r, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)), | 1729 BUILD( |
1765 WASM_WHILE( | 1730 r, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)), |
1766 WASM_GET_LOCAL(0), | 1731 WASM_WHILE( |
1767 WASM_BLOCK(WASM_SET_LOCAL( | 1732 WASM_GET_LOCAL(0), |
1768 kAccum, WASM_BINOP(binop, WASM_GET_LOCAL(kAccum), | 1733 WASM_BLOCK(WASM_SET_LOCAL( |
1769 WASM_LOAD_MEM( | 1734 kAccum, |
1770 memType, WASM_GET_LOCAL(0)))), | 1735 WASM_BINOP(binop, WASM_GET_LOCAL(kAccum), |
1771 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), | 1736 WASM_LOAD_MEM(memType, WASM_GET_LOCAL(0)))), |
1772 WASM_I8(sizeof(T)))))), | 1737 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), |
1773 WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)), | 1738 WASM_I32V_1(sizeof(T)))))), |
1774 WASM_GET_LOCAL(0)); | 1739 WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)), |
| 1740 WASM_GET_LOCAL(0)); |
1775 r.Call(static_cast<int>(sizeof(T) * (size - 1))); | 1741 r.Call(static_cast<int>(sizeof(T) * (size - 1))); |
1776 return r.module().ReadMemory(&memory[0]); | 1742 return r.module().ReadMemory(&memory[0]); |
1777 } | 1743 } |
1778 | 1744 |
1779 WASM_EXEC_TEST(MemF64_Mul) { | 1745 WASM_EXEC_TEST(MemF64_Mul) { |
1780 const size_t kSize = 6; | 1746 const size_t kSize = 6; |
1781 double buffer[kSize] = {1, 2, 2, 2, 2, 2}; | 1747 double buffer[kSize] = {1, 2, 2, 2, 2, 2}; |
1782 double result = | 1748 double result = |
1783 GenerateAndRunFold<double>(execution_mode, kExprF64Mul, buffer, kSize, | 1749 GenerateAndRunFold<double>(execution_mode, kExprF64Mul, buffer, kSize, |
1784 kWasmF64, MachineType::Float64()); | 1750 kWasmF64, MachineType::Float64()); |
(...skipping 10 matching lines...) Expand all Loading... |
1795 WasmRunner<int32_t, int32_t> r(execution_mode); | 1761 WasmRunner<int32_t, int32_t> r(execution_mode); |
1796 r.module().AddMemoryElems<int8_t>(16); | 1762 r.module().AddMemoryElems<int8_t>(16); |
1797 | 1763 |
1798 // Only build the graph and compile, don't run. | 1764 // Only build the graph and compile, don't run. |
1799 BUILD(r, WASM_LOOP(WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO), WASM_DROP), | 1765 BUILD(r, WASM_LOOP(WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO), WASM_DROP), |
1800 WASM_ZERO); | 1766 WASM_ZERO); |
1801 } | 1767 } |
1802 | 1768 |
1803 WASM_EXEC_TEST(Unreachable0a) { | 1769 WASM_EXEC_TEST(Unreachable0a) { |
1804 WasmRunner<int32_t, int32_t> r(execution_mode); | 1770 WasmRunner<int32_t, int32_t> r(execution_mode); |
1805 BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I8(9)), RET(WASM_GET_LOCAL(0)))); | 1771 BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I32V_1(9)), RET(WASM_GET_LOCAL(0)))); |
1806 CHECK_EQ(9, r.Call(0)); | 1772 CHECK_EQ(9, r.Call(0)); |
1807 CHECK_EQ(9, r.Call(1)); | 1773 CHECK_EQ(9, r.Call(1)); |
1808 } | 1774 } |
1809 | 1775 |
1810 WASM_EXEC_TEST(Unreachable0b) { | 1776 WASM_EXEC_TEST(Unreachable0b) { |
1811 WasmRunner<int32_t, int32_t> r(execution_mode); | 1777 WasmRunner<int32_t, int32_t> r(execution_mode); |
1812 BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I8(7)), WASM_UNREACHABLE)); | 1778 BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I32V_1(7)), WASM_UNREACHABLE)); |
1813 CHECK_EQ(7, r.Call(0)); | 1779 CHECK_EQ(7, r.Call(0)); |
1814 CHECK_EQ(7, r.Call(1)); | 1780 CHECK_EQ(7, r.Call(1)); |
1815 } | 1781 } |
1816 | 1782 |
1817 TEST(Build_Wasm_Unreachable1) { | 1783 TEST(Build_Wasm_Unreachable1) { |
1818 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); | 1784 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); |
1819 BUILD(r, WASM_UNREACHABLE); | 1785 BUILD(r, WASM_UNREACHABLE); |
1820 } | 1786 } |
1821 | 1787 |
1822 TEST(Build_Wasm_Unreachable2) { | 1788 TEST(Build_Wasm_Unreachable2) { |
(...skipping 20 matching lines...) Expand all Loading... |
1843 WASM_EXEC_TEST(Unreachable_Load) { | 1809 WASM_EXEC_TEST(Unreachable_Load) { |
1844 WasmRunner<int32_t, int32_t> r(execution_mode); | 1810 WasmRunner<int32_t, int32_t> r(execution_mode); |
1845 BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)), | 1811 BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)), |
1846 WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0)))); | 1812 WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0)))); |
1847 CHECK_EQ(11, r.Call(11)); | 1813 CHECK_EQ(11, r.Call(11)); |
1848 CHECK_EQ(21, r.Call(21)); | 1814 CHECK_EQ(21, r.Call(21)); |
1849 } | 1815 } |
1850 | 1816 |
1851 WASM_EXEC_TEST(Infinite_Loop_not_taken1) { | 1817 WASM_EXEC_TEST(Infinite_Loop_not_taken1) { |
1852 WasmRunner<int32_t, int32_t> r(execution_mode); | 1818 WasmRunner<int32_t, int32_t> r(execution_mode); |
1853 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I8(45)); | 1819 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I32V_1(45)); |
1854 // Run the code, but don't go into the infinite loop. | 1820 // Run the code, but don't go into the infinite loop. |
1855 CHECK_EQ(45, r.Call(0)); | 1821 CHECK_EQ(45, r.Call(0)); |
1856 } | 1822 } |
1857 | 1823 |
1858 WASM_EXEC_TEST(Infinite_Loop_not_taken2) { | 1824 WASM_EXEC_TEST(Infinite_Loop_not_taken2) { |
1859 WasmRunner<int32_t, int32_t> r(execution_mode); | 1825 WasmRunner<int32_t, int32_t> r(execution_mode); |
1860 BUILD(r, | 1826 BUILD(r, WASM_BLOCK_I(WASM_IF_ELSE(WASM_GET_LOCAL(0), |
1861 WASM_BLOCK_I(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(45)), | 1827 WASM_BRV(1, WASM_I32V_1(45)), |
1862 WASM_INFINITE_LOOP))); | 1828 WASM_INFINITE_LOOP))); |
1863 // Run the code, but don't go into the infinite loop. | 1829 // Run the code, but don't go into the infinite loop. |
1864 CHECK_EQ(45, r.Call(1)); | 1830 CHECK_EQ(45, r.Call(1)); |
1865 } | 1831 } |
1866 | 1832 |
1867 WASM_EXEC_TEST(Infinite_Loop_not_taken2_brif) { | 1833 WASM_EXEC_TEST(Infinite_Loop_not_taken2_brif) { |
1868 WasmRunner<int32_t, int32_t> r(execution_mode); | 1834 WasmRunner<int32_t, int32_t> r(execution_mode); |
1869 BUILD(r, WASM_BLOCK_I(WASM_BRV_IF(0, WASM_I8(45), WASM_GET_LOCAL(0)), | 1835 BUILD(r, WASM_BLOCK_I(WASM_BRV_IF(0, WASM_I32V_1(45), WASM_GET_LOCAL(0)), |
1870 WASM_INFINITE_LOOP)); | 1836 WASM_INFINITE_LOOP)); |
1871 // Run the code, but don't go into the infinite loop. | 1837 // Run the code, but don't go into the infinite loop. |
1872 CHECK_EQ(45, r.Call(1)); | 1838 CHECK_EQ(45, r.Call(1)); |
1873 } | 1839 } |
1874 | 1840 |
1875 static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) { | 1841 static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) { |
1876 Isolate* isolate = CcTest::InitIsolateOnce(); | 1842 Isolate* isolate = CcTest::InitIsolateOnce(); |
1877 Zone zone(isolate->allocator(), ZONE_NAME); | 1843 Zone zone(isolate->allocator(), ZONE_NAME); |
1878 HandleScope scope(isolate); | 1844 HandleScope scope(isolate); |
1879 // Enable all optional operators. | 1845 // Enable all optional operators. |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2140 WasmRunner<int32_t> r(execution_mode); | 2106 WasmRunner<int32_t> r(execution_mode); |
2141 | 2107 |
2142 const byte kMemOffset = 8; | 2108 const byte kMemOffset = 8; |
2143 const int32_t kElemNum = kMemOffset / sizeof(int32_t); | 2109 const int32_t kElemNum = kMemOffset / sizeof(int32_t); |
2144 const int32_t kExpected = 414444; | 2110 const int32_t kExpected = 414444; |
2145 // Build the target function. | 2111 // Build the target function. |
2146 TestSignatures sigs; | 2112 TestSignatures sigs; |
2147 int32_t* memory = r.module().AddMemoryElems<int32_t>(16 / sizeof(int32_t)); | 2113 int32_t* memory = r.module().AddMemoryElems<int32_t>(16 / sizeof(int32_t)); |
2148 r.module().RandomizeMemory(); | 2114 r.module().RandomizeMemory(); |
2149 WasmFunctionCompiler& t = r.NewFunction(sigs.v_v()); | 2115 WasmFunctionCompiler& t = r.NewFunction(sigs.v_v()); |
2150 BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(kMemOffset), | 2116 BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I32V_1(kMemOffset), |
2151 WASM_I32V_3(kExpected))); | 2117 WASM_I32V_3(kExpected))); |
2152 | 2118 |
2153 // Build the calling function. | 2119 // Build the calling function. |
2154 BUILD(r, WASM_CALL_FUNCTION0(t.function_index()), | 2120 BUILD(r, WASM_CALL_FUNCTION0(t.function_index()), |
2155 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kMemOffset))); | 2121 WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(kMemOffset))); |
2156 | 2122 |
2157 int32_t result = r.Call(); | 2123 int32_t result = r.Call(); |
2158 CHECK_EQ(kExpected, result); | 2124 CHECK_EQ(kExpected, result); |
2159 CHECK_EQ(static_cast<int64_t>(kExpected), | 2125 CHECK_EQ(static_cast<int64_t>(kExpected), |
2160 static_cast<int64_t>(r.module().ReadMemory(&memory[kElemNum]))); | 2126 static_cast<int64_t>(r.module().ReadMemory(&memory[kElemNum]))); |
2161 } | 2127 } |
2162 | 2128 |
2163 WASM_EXEC_TEST(Call_Int32Add) { | 2129 WASM_EXEC_TEST(Call_Int32Add) { |
2164 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); | 2130 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); |
2165 | 2131 |
(...skipping 29 matching lines...) Expand all Loading... |
2195 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(*i - *j, r.Call(*i, *j)); } | 2161 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(*i - *j, r.Call(*i, *j)); } |
2196 } | 2162 } |
2197 } | 2163 } |
2198 | 2164 |
2199 WASM_EXEC_TEST(Call_Float64Sub) { | 2165 WASM_EXEC_TEST(Call_Float64Sub) { |
2200 WasmRunner<int32_t> r(execution_mode); | 2166 WasmRunner<int32_t> r(execution_mode); |
2201 double* memory = r.module().AddMemoryElems<double>(16); | 2167 double* memory = r.module().AddMemoryElems<double>(16); |
2202 | 2168 |
2203 BUILD(r, WASM_STORE_MEM( | 2169 BUILD(r, WASM_STORE_MEM( |
2204 MachineType::Float64(), WASM_ZERO, | 2170 MachineType::Float64(), WASM_ZERO, |
2205 WASM_F64_SUB(WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO), | 2171 WASM_F64_SUB( |
2206 WASM_LOAD_MEM(MachineType::Float64(), WASM_I8(8)))), | 2172 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO), |
2207 WASM_I8(107)); | 2173 WASM_LOAD_MEM(MachineType::Float64(), WASM_I32V_1(8)))), |
| 2174 WASM_I32V_2(107)); |
2208 | 2175 |
2209 FOR_FLOAT64_INPUTS(i) { | 2176 FOR_FLOAT64_INPUTS(i) { |
2210 FOR_FLOAT64_INPUTS(j) { | 2177 FOR_FLOAT64_INPUTS(j) { |
2211 r.module().WriteMemory(&memory[0], *i); | 2178 r.module().WriteMemory(&memory[0], *i); |
2212 r.module().WriteMemory(&memory[1], *j); | 2179 r.module().WriteMemory(&memory[1], *j); |
2213 double expected = *i - *j; | 2180 double expected = *i - *j; |
2214 CHECK_EQ(107, r.Call()); | 2181 CHECK_EQ(107, r.Call()); |
2215 | 2182 |
2216 if (expected != expected) { | 2183 if (expected != expected) { |
2217 CHECK(r.module().ReadMemory(&memory[0]) != | 2184 CHECK(r.module().ReadMemory(&memory[0]) != |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2265 // Build the calling function. | 2232 // Build the calling function. |
2266 // ========================================================================= | 2233 // ========================================================================= |
2267 std::vector<byte> code; | 2234 std::vector<byte> code; |
2268 | 2235 |
2269 // Load the offset for the store. | 2236 // Load the offset for the store. |
2270 ADD_CODE(code, WASM_ZERO); | 2237 ADD_CODE(code, WASM_ZERO); |
2271 | 2238 |
2272 // Load the arguments. | 2239 // Load the arguments. |
2273 for (int i = 0; i < num_params; ++i) { | 2240 for (int i = 0; i < num_params; ++i) { |
2274 int offset = (i + 1) * kElemSize; | 2241 int offset = (i + 1) * kElemSize; |
2275 ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset))); | 2242 ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I32V_2(offset))); |
2276 } | 2243 } |
2277 | 2244 |
2278 // Call the selector function. | 2245 // Call the selector function. |
2279 ADD_CODE(code, WASM_CALL_FUNCTION0(t.function_index())); | 2246 ADD_CODE(code, WASM_CALL_FUNCTION0(t.function_index())); |
2280 | 2247 |
2281 // Store the result in memory. | 2248 // Store the result in memory. |
2282 ADD_CODE(code, | 2249 ADD_CODE(code, |
2283 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(result, true)), | 2250 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(result, true)), |
2284 ZERO_ALIGNMENT, ZERO_OFFSET); | 2251 ZERO_ALIGNMENT, ZERO_OFFSET); |
2285 | 2252 |
(...skipping 22 matching lines...) Expand all Loading... |
2308 WASM_EXEC_TEST(MixedCall_1) { Run_WasmMixedCall_N(execution_mode, 1); } | 2275 WASM_EXEC_TEST(MixedCall_1) { Run_WasmMixedCall_N(execution_mode, 1); } |
2309 WASM_EXEC_TEST(MixedCall_2) { Run_WasmMixedCall_N(execution_mode, 2); } | 2276 WASM_EXEC_TEST(MixedCall_2) { Run_WasmMixedCall_N(execution_mode, 2); } |
2310 WASM_EXEC_TEST(MixedCall_3) { Run_WasmMixedCall_N(execution_mode, 3); } | 2277 WASM_EXEC_TEST(MixedCall_3) { Run_WasmMixedCall_N(execution_mode, 3); } |
2311 | 2278 |
2312 WASM_EXEC_TEST(AddCall) { | 2279 WASM_EXEC_TEST(AddCall) { |
2313 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); | 2280 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); |
2314 WasmFunctionCompiler& t1 = r.NewFunction<int32_t, int32_t, int32_t>(); | 2281 WasmFunctionCompiler& t1 = r.NewFunction<int32_t, int32_t, int32_t>(); |
2315 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2282 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2316 | 2283 |
2317 byte local = r.AllocateLocal(kWasmI32); | 2284 byte local = r.AllocateLocal(kWasmI32); |
2318 BUILD(r, WASM_SET_LOCAL(local, WASM_I8(99)), | 2285 BUILD(r, WASM_SET_LOCAL(local, WASM_I32V_2(99)), |
2319 WASM_I32_ADD(WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(0), | 2286 WASM_I32_ADD(WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(0), |
2320 WASM_GET_LOCAL(0)), | 2287 WASM_GET_LOCAL(0)), |
2321 WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(1), | 2288 WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(1), |
2322 WASM_GET_LOCAL(local)))); | 2289 WASM_GET_LOCAL(local)))); |
2323 | 2290 |
2324 CHECK_EQ(198, r.Call(0)); | 2291 CHECK_EQ(198, r.Call(0)); |
2325 CHECK_EQ(200, r.Call(1)); | 2292 CHECK_EQ(200, r.Call(1)); |
2326 CHECK_EQ(100, r.Call(-49)); | 2293 CHECK_EQ(100, r.Call(-49)); |
2327 } | 2294 } |
2328 | 2295 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2402 #endif | 2369 #endif |
2403 } | 2370 } |
2404 | 2371 |
2405 WASM_EXEC_TEST(MultiReturnSelect_f64) { | 2372 WASM_EXEC_TEST(MultiReturnSelect_f64) { |
2406 static const double inputs[] = {3.333333, 44444.44, -55.555555, -7777.777}; | 2373 static const double inputs[] = {3.333333, 44444.44, -55.555555, -7777.777}; |
2407 RunMultiReturnSelect<double>(execution_mode, inputs); | 2374 RunMultiReturnSelect<double>(execution_mode, inputs); |
2408 } | 2375 } |
2409 | 2376 |
2410 WASM_EXEC_TEST(ExprBlock2a) { | 2377 WASM_EXEC_TEST(ExprBlock2a) { |
2411 WasmRunner<int32_t, int32_t> r(execution_mode); | 2378 WasmRunner<int32_t, int32_t> r(execution_mode); |
2412 BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), | 2379 BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I32V_1(1))), |
2413 WASM_I8(1))); | 2380 WASM_I32V_1(1))); |
2414 CHECK_EQ(1, r.Call(0)); | 2381 CHECK_EQ(1, r.Call(0)); |
2415 CHECK_EQ(1, r.Call(1)); | 2382 CHECK_EQ(1, r.Call(1)); |
2416 } | 2383 } |
2417 | 2384 |
2418 WASM_EXEC_TEST(ExprBlock2b) { | 2385 WASM_EXEC_TEST(ExprBlock2b) { |
2419 WasmRunner<int32_t, int32_t> r(execution_mode); | 2386 WasmRunner<int32_t, int32_t> r(execution_mode); |
2420 BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), | 2387 BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I32V_1(1))), |
2421 WASM_I8(2))); | 2388 WASM_I32V_1(2))); |
2422 CHECK_EQ(2, r.Call(0)); | 2389 CHECK_EQ(2, r.Call(0)); |
2423 CHECK_EQ(1, r.Call(1)); | 2390 CHECK_EQ(1, r.Call(1)); |
2424 } | 2391 } |
2425 | 2392 |
2426 WASM_EXEC_TEST(ExprBlock2c) { | 2393 WASM_EXEC_TEST(ExprBlock2c) { |
2427 WasmRunner<int32_t, int32_t> r(execution_mode); | 2394 WasmRunner<int32_t, int32_t> r(execution_mode); |
2428 BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(1), WASM_GET_LOCAL(0)), | 2395 BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I32V_1(1), WASM_GET_LOCAL(0)), |
2429 WASM_I8(1))); | 2396 WASM_I32V_1(1))); |
2430 CHECK_EQ(1, r.Call(0)); | 2397 CHECK_EQ(1, r.Call(0)); |
2431 CHECK_EQ(1, r.Call(1)); | 2398 CHECK_EQ(1, r.Call(1)); |
2432 } | 2399 } |
2433 | 2400 |
2434 WASM_EXEC_TEST(ExprBlock2d) { | 2401 WASM_EXEC_TEST(ExprBlock2d) { |
2435 WasmRunner<int32_t, int32_t> r(execution_mode); | 2402 WasmRunner<int32_t, int32_t> r(execution_mode); |
2436 BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(1), WASM_GET_LOCAL(0)), | 2403 BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I32V_1(1), WASM_GET_LOCAL(0)), |
2437 WASM_I8(2))); | 2404 WASM_I32V_1(2))); |
2438 CHECK_EQ(2, r.Call(0)); | 2405 CHECK_EQ(2, r.Call(0)); |
2439 CHECK_EQ(1, r.Call(1)); | 2406 CHECK_EQ(1, r.Call(1)); |
2440 } | 2407 } |
2441 | 2408 |
2442 WASM_EXEC_TEST(ExprBlock_ManualSwitch) { | 2409 WASM_EXEC_TEST(ExprBlock_ManualSwitch) { |
2443 WasmRunner<int32_t, int32_t> r(execution_mode); | 2410 WasmRunner<int32_t, int32_t> r(execution_mode); |
2444 BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1)), | 2411 BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(1)), |
2445 WASM_BRV(1, WASM_I8(11))), | 2412 WASM_BRV(1, WASM_I32V_1(11))), |
2446 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2)), | 2413 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(2)), |
2447 WASM_BRV(1, WASM_I8(12))), | 2414 WASM_BRV(1, WASM_I32V_1(12))), |
2448 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3)), | 2415 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(3)), |
2449 WASM_BRV(1, WASM_I8(13))), | 2416 WASM_BRV(1, WASM_I32V_1(13))), |
2450 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4)), | 2417 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(4)), |
2451 WASM_BRV(1, WASM_I8(14))), | 2418 WASM_BRV(1, WASM_I32V_1(14))), |
2452 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5)), | 2419 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(5)), |
2453 WASM_BRV(1, WASM_I8(15))), | 2420 WASM_BRV(1, WASM_I32V_1(15))), |
2454 WASM_I8(99))); | 2421 WASM_I32V_2(99))); |
2455 CHECK_EQ(99, r.Call(0)); | 2422 CHECK_EQ(99, r.Call(0)); |
2456 CHECK_EQ(11, r.Call(1)); | 2423 CHECK_EQ(11, r.Call(1)); |
2457 CHECK_EQ(12, r.Call(2)); | 2424 CHECK_EQ(12, r.Call(2)); |
2458 CHECK_EQ(13, r.Call(3)); | 2425 CHECK_EQ(13, r.Call(3)); |
2459 CHECK_EQ(14, r.Call(4)); | 2426 CHECK_EQ(14, r.Call(4)); |
2460 CHECK_EQ(15, r.Call(5)); | 2427 CHECK_EQ(15, r.Call(5)); |
2461 CHECK_EQ(99, r.Call(6)); | 2428 CHECK_EQ(99, r.Call(6)); |
2462 } | 2429 } |
2463 | 2430 |
2464 WASM_EXEC_TEST(ExprBlock_ManualSwitch_brif) { | 2431 WASM_EXEC_TEST(ExprBlock_ManualSwitch_brif) { |
2465 WasmRunner<int32_t, int32_t> r(execution_mode); | 2432 WasmRunner<int32_t, int32_t> r(execution_mode); |
2466 BUILD(r, | 2433 BUILD(r, WASM_BLOCK_I( |
2467 WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(11), | 2434 WASM_BRV_IFD(0, WASM_I32V_1(11), |
2468 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1))), | 2435 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(1))), |
2469 WASM_BRV_IFD(0, WASM_I8(12), | 2436 WASM_BRV_IFD(0, WASM_I32V_1(12), |
2470 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2))), | 2437 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(2))), |
2471 WASM_BRV_IFD(0, WASM_I8(13), | 2438 WASM_BRV_IFD(0, WASM_I32V_1(13), |
2472 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3))), | 2439 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(3))), |
2473 WASM_BRV_IFD(0, WASM_I8(14), | 2440 WASM_BRV_IFD(0, WASM_I32V_1(14), |
2474 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4))), | 2441 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(4))), |
2475 WASM_BRV_IFD(0, WASM_I8(15), | 2442 WASM_BRV_IFD(0, WASM_I32V_1(15), |
2476 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5))), | 2443 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(5))), |
2477 WASM_I8(99))); | 2444 WASM_I32V_2(99))); |
2478 CHECK_EQ(99, r.Call(0)); | 2445 CHECK_EQ(99, r.Call(0)); |
2479 CHECK_EQ(11, r.Call(1)); | 2446 CHECK_EQ(11, r.Call(1)); |
2480 CHECK_EQ(12, r.Call(2)); | 2447 CHECK_EQ(12, r.Call(2)); |
2481 CHECK_EQ(13, r.Call(3)); | 2448 CHECK_EQ(13, r.Call(3)); |
2482 CHECK_EQ(14, r.Call(4)); | 2449 CHECK_EQ(14, r.Call(4)); |
2483 CHECK_EQ(15, r.Call(5)); | 2450 CHECK_EQ(15, r.Call(5)); |
2484 CHECK_EQ(99, r.Call(6)); | 2451 CHECK_EQ(99, r.Call(6)); |
2485 } | 2452 } |
2486 | 2453 |
2487 WASM_EXEC_TEST(If_nested) { | 2454 WASM_EXEC_TEST(If_nested) { |
2488 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); | 2455 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); |
2489 | 2456 |
2490 BUILD(r, WASM_IF_ELSE_I( | 2457 BUILD( |
2491 WASM_GET_LOCAL(0), | 2458 r, |
2492 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)), | 2459 WASM_IF_ELSE_I( |
2493 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14)))); | 2460 WASM_GET_LOCAL(0), |
| 2461 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(11), WASM_I32V_1(12)), |
| 2462 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(13), WASM_I32V_1(14)))); |
2494 | 2463 |
2495 CHECK_EQ(11, r.Call(1, 1)); | 2464 CHECK_EQ(11, r.Call(1, 1)); |
2496 CHECK_EQ(12, r.Call(1, 0)); | 2465 CHECK_EQ(12, r.Call(1, 0)); |
2497 CHECK_EQ(13, r.Call(0, 1)); | 2466 CHECK_EQ(13, r.Call(0, 1)); |
2498 CHECK_EQ(14, r.Call(0, 0)); | 2467 CHECK_EQ(14, r.Call(0, 0)); |
2499 } | 2468 } |
2500 | 2469 |
2501 WASM_EXEC_TEST(ExprBlock_if) { | 2470 WASM_EXEC_TEST(ExprBlock_if) { |
2502 WasmRunner<int32_t, int32_t> r(execution_mode); | 2471 WasmRunner<int32_t, int32_t> r(execution_mode); |
2503 | 2472 |
2504 BUILD(r, | 2473 BUILD(r, WASM_BLOCK_I(WASM_IF_ELSE_I(WASM_GET_LOCAL(0), |
2505 WASM_BLOCK_I(WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(11)), | 2474 WASM_BRV(0, WASM_I32V_1(11)), |
2506 WASM_BRV(1, WASM_I8(14))))); | 2475 WASM_BRV(1, WASM_I32V_1(14))))); |
2507 | 2476 |
2508 CHECK_EQ(11, r.Call(1)); | 2477 CHECK_EQ(11, r.Call(1)); |
2509 CHECK_EQ(14, r.Call(0)); | 2478 CHECK_EQ(14, r.Call(0)); |
2510 } | 2479 } |
2511 | 2480 |
2512 WASM_EXEC_TEST(ExprBlock_nested_ifs) { | 2481 WASM_EXEC_TEST(ExprBlock_nested_ifs) { |
2513 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); | 2482 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); |
2514 | 2483 |
2515 BUILD(r, WASM_BLOCK_I(WASM_IF_ELSE_I( | 2484 BUILD(r, WASM_BLOCK_I(WASM_IF_ELSE_I( |
2516 WASM_GET_LOCAL(0), | 2485 WASM_GET_LOCAL(0), |
2517 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(11)), | 2486 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I32V_1(11)), |
2518 WASM_BRV(1, WASM_I8(12))), | 2487 WASM_BRV(1, WASM_I32V_1(12))), |
2519 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(13)), | 2488 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I32V_1(13)), |
2520 WASM_BRV(1, WASM_I8(14)))))); | 2489 WASM_BRV(1, WASM_I32V_1(14)))))); |
2521 | 2490 |
2522 CHECK_EQ(11, r.Call(1, 1)); | 2491 CHECK_EQ(11, r.Call(1, 1)); |
2523 CHECK_EQ(12, r.Call(1, 0)); | 2492 CHECK_EQ(12, r.Call(1, 0)); |
2524 CHECK_EQ(13, r.Call(0, 1)); | 2493 CHECK_EQ(13, r.Call(0, 1)); |
2525 CHECK_EQ(14, r.Call(0, 0)); | 2494 CHECK_EQ(14, r.Call(0, 0)); |
2526 } | 2495 } |
2527 | 2496 |
2528 WASM_EXEC_TEST_WITH_TRAP(SimpleCallIndirect) { | 2497 WASM_EXEC_TEST_WITH_TRAP(SimpleCallIndirect) { |
2529 TestSignatures sigs; | 2498 TestSignatures sigs; |
2530 WasmRunner<int32_t, int32_t> r(execution_mode); | 2499 WasmRunner<int32_t, int32_t> r(execution_mode); |
(...skipping 13 matching lines...) Expand all Loading... |
2544 | 2513 |
2545 // Function table. | 2514 // Function table. |
2546 uint16_t indirect_function_table[] = { | 2515 uint16_t indirect_function_table[] = { |
2547 static_cast<uint16_t>(t1.function_index()), | 2516 static_cast<uint16_t>(t1.function_index()), |
2548 static_cast<uint16_t>(t2.function_index())}; | 2517 static_cast<uint16_t>(t2.function_index())}; |
2549 r.module().AddIndirectFunctionTable(indirect_function_table, | 2518 r.module().AddIndirectFunctionTable(indirect_function_table, |
2550 arraysize(indirect_function_table)); | 2519 arraysize(indirect_function_table)); |
2551 r.module().PopulateIndirectFunctionTable(); | 2520 r.module().PopulateIndirectFunctionTable(); |
2552 | 2521 |
2553 // Build the caller function. | 2522 // Build the caller function. |
2554 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); | 2523 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I32V_2(66), |
| 2524 WASM_I32V_1(22))); |
2555 | 2525 |
2556 CHECK_EQ(88, r.Call(0)); | 2526 CHECK_EQ(88, r.Call(0)); |
2557 CHECK_EQ(44, r.Call(1)); | 2527 CHECK_EQ(44, r.Call(1)); |
2558 CHECK_TRAP(r.Call(2)); | 2528 CHECK_TRAP(r.Call(2)); |
2559 } | 2529 } |
2560 | 2530 |
2561 WASM_EXEC_TEST_WITH_TRAP(MultipleCallIndirect) { | 2531 WASM_EXEC_TEST_WITH_TRAP(MultipleCallIndirect) { |
2562 TestSignatures sigs; | 2532 TestSignatures sigs; |
2563 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_mode); | 2533 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_mode); |
2564 | 2534 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2609 WasmFunctionCompiler& t1 = r.NewFunction(sigs.i_ii()); | 2579 WasmFunctionCompiler& t1 = r.NewFunction(sigs.i_ii()); |
2610 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2580 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2611 t1.SetSigIndex(1); | 2581 t1.SetSigIndex(1); |
2612 | 2582 |
2613 // Signature table. | 2583 // Signature table. |
2614 r.module().AddSignature(sigs.f_ff()); | 2584 r.module().AddSignature(sigs.f_ff()); |
2615 r.module().AddSignature(sigs.i_ii()); | 2585 r.module().AddSignature(sigs.i_ii()); |
2616 r.module().AddIndirectFunctionTable(nullptr, 0); | 2586 r.module().AddIndirectFunctionTable(nullptr, 0); |
2617 | 2587 |
2618 // Build the caller function. | 2588 // Build the caller function. |
2619 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); | 2589 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I32V_2(66), |
| 2590 WASM_I32V_1(22))); |
2620 | 2591 |
2621 CHECK_TRAP(r.Call(0)); | 2592 CHECK_TRAP(r.Call(0)); |
2622 CHECK_TRAP(r.Call(1)); | 2593 CHECK_TRAP(r.Call(1)); |
2623 CHECK_TRAP(r.Call(2)); | 2594 CHECK_TRAP(r.Call(2)); |
2624 } | 2595 } |
2625 | 2596 |
2626 WASM_EXEC_TEST_WITH_TRAP(CallIndirect_canonical) { | 2597 WASM_EXEC_TEST_WITH_TRAP(CallIndirect_canonical) { |
2627 TestSignatures sigs; | 2598 TestSignatures sigs; |
2628 WasmRunner<int32_t, int32_t> r(execution_mode); | 2599 WasmRunner<int32_t, int32_t> r(execution_mode); |
2629 | 2600 |
(...skipping 18 matching lines...) Expand all Loading... |
2648 uint16_t i1 = static_cast<uint16_t>(t1.function_index()); | 2619 uint16_t i1 = static_cast<uint16_t>(t1.function_index()); |
2649 uint16_t i2 = static_cast<uint16_t>(t2.function_index()); | 2620 uint16_t i2 = static_cast<uint16_t>(t2.function_index()); |
2650 uint16_t i3 = static_cast<uint16_t>(t3.function_index()); | 2621 uint16_t i3 = static_cast<uint16_t>(t3.function_index()); |
2651 uint16_t indirect_function_table[] = {i1, i2, i3, i1, i2}; | 2622 uint16_t indirect_function_table[] = {i1, i2, i3, i1, i2}; |
2652 | 2623 |
2653 r.module().AddIndirectFunctionTable(indirect_function_table, | 2624 r.module().AddIndirectFunctionTable(indirect_function_table, |
2654 arraysize(indirect_function_table)); | 2625 arraysize(indirect_function_table)); |
2655 r.module().PopulateIndirectFunctionTable(); | 2626 r.module().PopulateIndirectFunctionTable(); |
2656 | 2627 |
2657 // Build the caller function. | 2628 // Build the caller function. |
2658 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(77), WASM_I8(11))); | 2629 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I32V_2(77), |
| 2630 WASM_I32V_1(11))); |
2659 | 2631 |
2660 CHECK_EQ(88, r.Call(0)); | 2632 CHECK_EQ(88, r.Call(0)); |
2661 CHECK_EQ(66, r.Call(1)); | 2633 CHECK_EQ(66, r.Call(1)); |
2662 CHECK_TRAP(r.Call(2)); | 2634 CHECK_TRAP(r.Call(2)); |
2663 CHECK_EQ(88, r.Call(3)); | 2635 CHECK_EQ(88, r.Call(3)); |
2664 CHECK_EQ(66, r.Call(4)); | 2636 CHECK_EQ(66, r.Call(4)); |
2665 CHECK_TRAP(r.Call(5)); | 2637 CHECK_TRAP(r.Call(5)); |
2666 } | 2638 } |
2667 | 2639 |
2668 WASM_EXEC_TEST(F32Floor) { | 2640 WASM_EXEC_TEST(F32Floor) { |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2862 r.module().AddSignature(sig); | 2834 r.module().AddSignature(sig); |
2863 r.module().AddSignature(sig); | 2835 r.module().AddSignature(sig); |
2864 r.module().AddIndirectFunctionTable(nullptr, 0); | 2836 r.module().AddIndirectFunctionTable(nullptr, 0); |
2865 | 2837 |
2866 WasmFunctionCompiler& t = r.NewFunction(sig); | 2838 WasmFunctionCompiler& t = r.NewFunction(sig); |
2867 | 2839 |
2868 std::vector<byte> code; | 2840 std::vector<byte> code; |
2869 for (byte p = 0; p < num_params; ++p) { | 2841 for (byte p = 0; p < num_params; ++p) { |
2870 ADD_CODE(code, kExprGetLocal, p); | 2842 ADD_CODE(code, kExprGetLocal, p); |
2871 } | 2843 } |
2872 ADD_CODE(code, kExprI8Const, 0); | 2844 ADD_CODE(code, kExprI32Const, 0); |
2873 ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO); | 2845 ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO); |
2874 | 2846 |
2875 t.Build(&code[0], &code[0] + code.size()); | 2847 t.Build(&code[0], &code[0] + code.size()); |
2876 } | 2848 } |
2877 } | 2849 } |
2878 | 2850 |
2879 TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kWasmI32); } | 2851 TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kWasmI32); } |
2880 | 2852 |
2881 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kWasmF32); } | 2853 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kWasmF32); } |
2882 | 2854 |
2883 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kWasmF64); } | 2855 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kWasmF64); } |
2884 | 2856 |
2885 WASM_EXEC_TEST_WITH_TRAP(Int32RemS_dead) { | 2857 WASM_EXEC_TEST_WITH_TRAP(Int32RemS_dead) { |
2886 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); | 2858 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); |
2887 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP, | 2859 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP, |
2888 WASM_ZERO); | 2860 WASM_ZERO); |
2889 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 2861 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
2890 CHECK_EQ(0, r.Call(133, 100)); | 2862 CHECK_EQ(0, r.Call(133, 100)); |
2891 CHECK_EQ(0, r.Call(kMin, -1)); | 2863 CHECK_EQ(0, r.Call(kMin, -1)); |
2892 CHECK_EQ(0, r.Call(0, 1)); | 2864 CHECK_EQ(0, r.Call(0, 1)); |
2893 CHECK_TRAP(r.Call(100, 0)); | 2865 CHECK_TRAP(r.Call(100, 0)); |
2894 CHECK_TRAP(r.Call(-1001, 0)); | 2866 CHECK_TRAP(r.Call(-1001, 0)); |
2895 CHECK_TRAP(r.Call(kMin, 0)); | 2867 CHECK_TRAP(r.Call(kMin, 0)); |
2896 } | 2868 } |
OLD | NEW |