Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(641)

Side by Side Diff: test/cctest/wasm/test-run-wasm.cc

Issue 2361053004: Revert of [wasm] Master CL for Binary 0xC changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-result.h ('k') | test/cctest/wasm/test-run-wasm-64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/test-signatures.h" 15 #include "test/cctest/wasm/test-signatures.h"
16 #include "test/cctest/wasm/wasm-run-utils.h" 16 #include "test/cctest/wasm/wasm-run-utils.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 B2(a, b) kExprBlock, a, b, kExprEnd
25 #define B2(a, b) WASM_BLOCK(a, b) 25 #define B1(a) kExprBlock, a, kExprEnd
26 #define B3(a, b, c) WASM_BLOCK(a, b, c) 26 #define RET(x) x, kExprReturn, 1
27 #define RET(x) x, kExprReturn 27 #define RET_I8(x) kExprI8Const, x, kExprReturn, 1
28 #define RET_I8(x) kExprI8Const, x, kExprReturn
29 28
30 WASM_EXEC_TEST(Int8Const) { 29 WASM_EXEC_TEST(Int8Const) {
31 WasmRunner<int32_t> r(execution_mode); 30 WasmRunner<int32_t> r(execution_mode);
32 const byte kExpectedValue = 121; 31 const byte kExpectedValue = 121;
33 // return(kExpectedValue) 32 // return(kExpectedValue)
34 BUILD(r, WASM_I8(kExpectedValue)); 33 BUILD(r, WASM_I8(kExpectedValue));
35 CHECK_EQ(kExpectedValue, r.Call()); 34 CHECK_EQ(kExpectedValue, r.Call());
36 } 35 }
37 36
38 WASM_EXEC_TEST(Int8Const_end) { 37 WASM_EXEC_TEST(Int8Const_fallthru1) {
39 WasmRunner<int32_t> r(execution_mode); 38 WasmRunner<int32_t> r(execution_mode);
40 const byte kExpectedValue = 121; 39 const byte kExpectedValue = 122;
41 // return(kExpectedValue) 40 // kExpectedValue
42 BUILD(r, WASM_I8(kExpectedValue), kExprEnd); 41 BUILD(r, WASM_I8(kExpectedValue));
43 CHECK_EQ(kExpectedValue, r.Call()); 42 CHECK_EQ(kExpectedValue, r.Call());
44 } 43 }
45 44
46 WASM_EXEC_TEST(Int8Const_fallthru2) { 45 WASM_EXEC_TEST(Int8Const_fallthru2) {
47 WasmRunner<int32_t> r(execution_mode); 46 WasmRunner<int32_t> r(execution_mode);
48 const byte kExpectedValue = 123; 47 const byte kExpectedValue = 123;
49 // -99 kExpectedValue 48 // -99 kExpectedValue
50 BUILD(r, WASM_I8(-99), WASM_DROP, WASM_I8(kExpectedValue)); 49 BUILD(r, WASM_I8(-99), WASM_I8(kExpectedValue));
51 CHECK_EQ(kExpectedValue, r.Call()); 50 CHECK_EQ(kExpectedValue, r.Call());
52 } 51 }
53 52
54 WASM_EXEC_TEST(Int8Const_all) { 53 WASM_EXEC_TEST(Int8Const_all) {
55 for (int value = -128; value <= 127; ++value) { 54 for (int value = -128; value <= 127; ++value) {
56 WasmRunner<int32_t> r(execution_mode); 55 WasmRunner<int32_t> r(execution_mode);
57 // return(value) 56 // return(value)
58 BUILD(r, WASM_I8(value)); 57 BUILD(r, WASM_I8(value));
59 int32_t result = r.Call(); 58 int32_t result = r.Call();
60 CHECK_EQ(value, result); 59 CHECK_EQ(value, result);
(...skipping 11 matching lines...) Expand all
72 WASM_EXEC_TEST(Int32Const_many) { 71 WASM_EXEC_TEST(Int32Const_many) {
73 FOR_INT32_INPUTS(i) { 72 FOR_INT32_INPUTS(i) {
74 WasmRunner<int32_t> r(execution_mode); 73 WasmRunner<int32_t> r(execution_mode);
75 const int32_t kExpectedValue = *i; 74 const int32_t kExpectedValue = *i;
76 // return(kExpectedValue) 75 // return(kExpectedValue)
77 BUILD(r, WASM_I32V(kExpectedValue)); 76 BUILD(r, WASM_I32V(kExpectedValue));
78 CHECK_EQ(kExpectedValue, r.Call()); 77 CHECK_EQ(kExpectedValue, r.Call());
79 } 78 }
80 } 79 }
81 80
82 WASM_EXEC_TEST(MemorySize1) { 81 WASM_EXEC_TEST(MemorySize) {
83 TestingModule module(execution_mode); 82 TestingModule module(execution_mode);
84 WasmRunner<int32_t> r(&module); 83 WasmRunner<int32_t> r(&module);
85 module.AddMemory(WasmModule::kPageSize * 1); 84 module.AddMemory(1024);
86 BUILD(r, kExprMemorySize); 85 BUILD(r, kExprMemorySize);
87 CHECK_EQ(1, r.Call()); 86 CHECK_EQ(1024, r.Call());
88 }
89
90 WASM_EXEC_TEST(MemorySize2) {
91 TestingModule module(execution_mode);
92 WasmRunner<int32_t> r(&module);
93 module.AddMemory(WasmModule::kPageSize * 3);
94 BUILD(r, kExprMemorySize);
95 CHECK_EQ(3, r.Call());
96 } 87 }
97 88
98 WASM_EXEC_TEST(Int32Param0) { 89 WASM_EXEC_TEST(Int32Param0) {
99 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 90 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
100 // return(local[0]) 91 // return(local[0])
101 BUILD(r, WASM_GET_LOCAL(0)); 92 BUILD(r, WASM_GET_LOCAL(0));
102 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } 93 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
103 } 94 }
104 95
105 WASM_EXEC_TEST(Int32Param0_fallthru) { 96 WASM_EXEC_TEST(Int32Param0_fallthru) {
(...skipping 25 matching lines...) Expand all
131 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } 122 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); }
132 } 123 }
133 124
134 WASM_EXEC_TEST(Int32Add_P_fallthru) { 125 WASM_EXEC_TEST(Int32Add_P_fallthru) {
135 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 126 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
136 // p0 + 13 127 // p0 + 13
137 BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0))); 128 BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0)));
138 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } 129 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); }
139 } 130 }
140 131
141 static void RunInt32AddTest(WasmExecutionMode execution_mode, const byte* code, 132 WASM_EXEC_TEST(Int32Add_P2) {
142 size_t size) {
143 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), 133 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
144 MachineType::Int32()); 134 MachineType::Int32());
145 r.Build(code, code + size); 135 // p0 + p1
136 BUILD(r, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
146 FOR_INT32_INPUTS(i) { 137 FOR_INT32_INPUTS(i) {
147 FOR_INT32_INPUTS(j) { 138 FOR_INT32_INPUTS(j) {
148 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) + 139 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) +
149 static_cast<uint32_t>(*j)); 140 static_cast<uint32_t>(*j));
150 CHECK_EQ(expected, r.Call(*i, *j)); 141 CHECK_EQ(expected, r.Call(*i, *j));
151 } 142 }
152 } 143 }
153 } 144 }
154 145
155 WASM_EXEC_TEST(Int32Add_P2) {
156 FLAG_wasm_mv_prototype = true;
157 static const byte code[] = {
158 WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
159 RunInt32AddTest(execution_mode, code, sizeof(code));
160 }
161
162 WASM_EXEC_TEST(Int32Add_block1) {
163 FLAG_wasm_mv_prototype = true;
164 static const byte code[] = {
165 WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)),
166 kExprI32Add};
167 RunInt32AddTest(execution_mode, code, sizeof(code));
168 }
169
170 WASM_EXEC_TEST(Int32Add_block2) {
171 FLAG_wasm_mv_prototype = true;
172 static const byte code[] = {
173 WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
174 kExprBr, DEPTH_0),
175 kExprI32Add};
176 RunInt32AddTest(execution_mode, code, sizeof(code));
177 }
178
179 WASM_EXEC_TEST(Int32Add_multi_if) {
180 FLAG_wasm_mv_prototype = true;
181 static const byte code[] = {
182 WASM_IF_ELSE_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0),
183 WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)),
184 WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))),
185 kExprI32Add};
186 RunInt32AddTest(execution_mode, code, sizeof(code));
187 }
188
189 WASM_EXEC_TEST(Float32Add) { 146 WASM_EXEC_TEST(Float32Add) {
190 WasmRunner<int32_t> r(execution_mode); 147 WasmRunner<int32_t> r(execution_mode);
191 // int(11.5f + 44.5f) 148 // int(11.5f + 44.5f)
192 BUILD(r, 149 BUILD(r,
193 WASM_I32_SCONVERT_F32(WASM_F32_ADD(WASM_F32(11.5f), WASM_F32(44.5f)))); 150 WASM_I32_SCONVERT_F32(WASM_F32_ADD(WASM_F32(11.5f), WASM_F32(44.5f))));
194 CHECK_EQ(56, r.Call()); 151 CHECK_EQ(56, r.Call());
195 } 152 }
196 153
197 WASM_EXEC_TEST(Float64Add) { 154 WASM_EXEC_TEST(Float64Add) {
198 WasmRunner<int32_t> r(execution_mode); 155 WasmRunner<int32_t> r(execution_mode);
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 } 426 }
470 } 427 }
471 } 428 }
472 } 429 }
473 430
474 WASM_EXEC_TEST(Int32DivS_trap_effect) { 431 WASM_EXEC_TEST(Int32DivS_trap_effect) {
475 TestingModule module(execution_mode); 432 TestingModule module(execution_mode);
476 module.AddMemoryElems<int32_t>(8); 433 module.AddMemoryElems<int32_t>(8);
477 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32()); 434 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
478 435
479 BUILD(r, WASM_IF_ELSE_I( 436 BUILD(r,
480 WASM_GET_LOCAL(0), 437 WASM_IF_ELSE(WASM_GET_LOCAL(0),
481 WASM_I32_DIVS( 438 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(),
482 WASM_BLOCK_I(WASM_STORE_MEM(MachineType::Int8(), WASM_ZERO, 439 WASM_ZERO, WASM_GET_LOCAL(0)),
483 WASM_GET_LOCAL(0)), 440 WASM_GET_LOCAL(1)),
484 WASM_GET_LOCAL(0)), 441 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(),
485 WASM_GET_LOCAL(1)), 442 WASM_ZERO, WASM_GET_LOCAL(0)),
486 WASM_I32_DIVS( 443 WASM_GET_LOCAL(1))));
487 WASM_BLOCK_I(WASM_STORE_MEM(MachineType::Int8(), WASM_ZERO,
488 WASM_GET_LOCAL(0)),
489 WASM_GET_LOCAL(0)),
490 WASM_GET_LOCAL(1))));
491 CHECK_EQ(0, r.Call(0, 100)); 444 CHECK_EQ(0, r.Call(0, 100));
492 CHECK_TRAP(r.Call(8, 0)); 445 CHECK_TRAP(r.Call(8, 0));
493 CHECK_TRAP(r.Call(4, 0)); 446 CHECK_TRAP(r.Call(4, 0));
494 CHECK_TRAP(r.Call(0, 0)); 447 CHECK_TRAP(r.Call(0, 0));
495 } 448 }
496 449
497 void TestFloat32Binop(WasmExecutionMode execution_mode, WasmOpcode opcode, 450 void TestFloat32Binop(WasmExecutionMode execution_mode, WasmOpcode opcode,
498 int32_t expected, float a, float b) { 451 int32_t expected, float a, float b) {
499 { 452 {
500 WasmRunner<int32_t> r(execution_mode); 453 WasmRunner<int32_t> r(execution_mode);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 611
659 FOR_FLOAT64_INPUTS(i) { 612 FOR_FLOAT64_INPUTS(i) {
660 CHECK_EQ(0x8000000000000000, 613 CHECK_EQ(0x8000000000000000,
661 bit_cast<uint64_t>(*i) ^ bit_cast<uint64_t>(r.Call(*i))); 614 bit_cast<uint64_t>(*i) ^ bit_cast<uint64_t>(r.Call(*i)));
662 } 615 }
663 } 616 }
664 617
665 WASM_EXEC_TEST(IfElse_P) { 618 WASM_EXEC_TEST(IfElse_P) {
666 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 619 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
667 // if (p0) return 11; else return 22; 620 // if (p0) return 11; else return 22;
668 BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), // -- 621 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
669 WASM_I8(11), // -- 622 WASM_I8(11), // --
670 WASM_I8(22))); // -- 623 WASM_I8(22))); // --
671 FOR_INT32_INPUTS(i) { 624 FOR_INT32_INPUTS(i) {
672 int32_t expected = *i ? 11 : 22; 625 int32_t expected = *i ? 11 : 22;
673 CHECK_EQ(expected, r.Call(*i)); 626 CHECK_EQ(expected, r.Call(*i));
674 } 627 }
675 } 628 }
676 #define EMPTY
677 629
678 WASM_EXEC_TEST(If_empty1) { 630 WASM_EXEC_TEST(If_empty1) {
679 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(), 631 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
680 MachineType::Uint32()); 632 MachineType::Uint32());
681 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kLocalVoid, kExprEnd, WASM_GET_LOCAL(1)); 633 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprEnd, WASM_GET_LOCAL(1));
682 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 9, *i)); } 634 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 9, *i)); }
683 } 635 }
684 636
685 WASM_EXEC_TEST(IfElse_empty1) { 637 WASM_EXEC_TEST(IfElse_empty1) {
686 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(), 638 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
687 MachineType::Uint32()); 639 MachineType::Uint32());
688 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kLocalVoid, kExprElse, kExprEnd, 640 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprElse, kExprEnd, WASM_GET_LOCAL(1));
689 WASM_GET_LOCAL(1));
690 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 8, *i)); } 641 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 8, *i)); }
691 } 642 }
692 643
693 WASM_EXEC_TEST(IfElse_empty2) { 644 WASM_EXEC_TEST(IfElse_empty2) {
694 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(), 645 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
695 MachineType::Uint32()); 646 MachineType::Uint32());
696 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kLocalVoid, WASM_NOP, kExprElse, 647 BUILD(r, WASM_GET_LOCAL(0), kExprIf, WASM_ZERO, kExprElse, kExprEnd,
697 kExprEnd, WASM_GET_LOCAL(1)); 648 WASM_GET_LOCAL(1));
698 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 7, *i)); } 649 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 7, *i)); }
699 } 650 }
700 651
701 WASM_EXEC_TEST(IfElse_empty3) { 652 WASM_EXEC_TEST(IfElse_empty3) {
702 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(), 653 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
703 MachineType::Uint32()); 654 MachineType::Uint32());
704 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kLocalVoid, kExprElse, WASM_NOP, 655 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprElse, WASM_ZERO, kExprEnd,
705 kExprEnd, WASM_GET_LOCAL(1)); 656 WASM_GET_LOCAL(1));
706 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 6, *i)); } 657 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 6, *i)); }
707 } 658 }
708 659
709 WASM_EXEC_TEST(If_chain1) { 660 WASM_EXEC_TEST(If_chain) {
710 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 661 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
711 // if (p0) 13; if (p0) 14; 15 662 // if (p0) 13; if (p0) 14; 15
712 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP), 663 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_I8(13)),
713 WASM_IF(WASM_GET_LOCAL(0), WASM_NOP), WASM_I8(15)); 664 WASM_IF(WASM_GET_LOCAL(0), WASM_I8(14)), WASM_I8(15));
714 FOR_INT32_INPUTS(i) { CHECK_EQ(15, r.Call(*i)); } 665 FOR_INT32_INPUTS(i) { CHECK_EQ(15, r.Call(*i)); }
715 } 666 }
716 667
717 WASM_EXEC_TEST(If_chain_set) { 668 WASM_EXEC_TEST(If_chain_set) {
718 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), 669 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
719 MachineType::Int32()); 670 MachineType::Int32());
720 // if (p0) p1 = 73; if (p0) p1 = 74; p1 671 // if (p0) p1 = 73; if (p0) p1 = 74; p1
721 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(73))), 672 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(73))),
722 WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(74))), 673 WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(74))),
723 WASM_GET_LOCAL(1)); 674 WASM_GET_LOCAL(1));
724 FOR_INT32_INPUTS(i) { 675 FOR_INT32_INPUTS(i) {
725 int32_t expected = *i ? 74 : *i; 676 int32_t expected = *i ? 74 : *i;
726 CHECK_EQ(expected, r.Call(*i, *i)); 677 CHECK_EQ(expected, r.Call(*i, *i));
727 } 678 }
728 } 679 }
729 680
730 WASM_EXEC_TEST(IfElse_Unreachable1) { 681 WASM_EXEC_TEST(IfElse_Unreachable1) {
731 WasmRunner<int32_t> r(execution_mode); 682 WasmRunner<int32_t> r(execution_mode);
732 // 0 ? unreachable : 27 683 // if (0) unreachable; else return 22;
733 BUILD(r, WASM_IF_ELSE_I(WASM_ZERO, // -- 684 BUILD(r, WASM_IF_ELSE(WASM_ZERO, // --
734 WASM_UNREACHABLE, // -- 685 WASM_UNREACHABLE, // --
735 WASM_I8(27))); // -- 686 WASM_I8(27))); // --
736 CHECK_EQ(27, r.Call()); 687 CHECK_EQ(27, r.Call());
737 } 688 }
738 689
739 WASM_EXEC_TEST(IfElse_Unreachable2) {
740 WasmRunner<int32_t> r(execution_mode);
741 // 1 ? 28 : unreachable
742 BUILD(r, WASM_IF_ELSE_I(WASM_I8(1), // --
743 WASM_I8(28), // --
744 WASM_UNREACHABLE)); // --
745 CHECK_EQ(28, r.Call());
746 }
747
748 WASM_EXEC_TEST(Return12) { 690 WASM_EXEC_TEST(Return12) {
749 WasmRunner<int32_t> r(execution_mode); 691 WasmRunner<int32_t> r(execution_mode);
750 692
751 BUILD(r, RET_I8(12)); 693 BUILD(r, RET_I8(12));
752 CHECK_EQ(12, r.Call()); 694 CHECK_EQ(12, r.Call());
753 } 695 }
754 696
755 WASM_EXEC_TEST(Return17) { 697 WASM_EXEC_TEST(Return17) {
756 WasmRunner<int32_t> r(execution_mode); 698 WasmRunner<int32_t> r(execution_mode);
757 699
758 BUILD(r, WASM_BLOCK(RET_I8(17))); 700 BUILD(r, B1(RET_I8(17)));
759 CHECK_EQ(17, r.Call()); 701 CHECK_EQ(17, r.Call());
760 } 702 }
761 703
762 WASM_EXEC_TEST(Return_I32) { 704 WASM_EXEC_TEST(Return_I32) {
763 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 705 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
764 706
765 BUILD(r, RET(WASM_GET_LOCAL(0))); 707 BUILD(r, RET(WASM_GET_LOCAL(0)));
766 708
767 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } 709 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
768 } 710 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 BUILD(r, WASM_SELECT(WASM_I8(11), WASM_I8(22), WASM_GET_LOCAL(0))); 747 BUILD(r, WASM_SELECT(WASM_I8(11), WASM_I8(22), WASM_GET_LOCAL(0)));
806 FOR_INT32_INPUTS(i) { 748 FOR_INT32_INPUTS(i) {
807 int32_t expected = *i ? 11 : 22; 749 int32_t expected = *i ? 11 : 22;
808 CHECK_EQ(expected, r.Call(*i)); 750 CHECK_EQ(expected, r.Call(*i));
809 } 751 }
810 } 752 }
811 753
812 WASM_EXEC_TEST(Select_strict1) { 754 WASM_EXEC_TEST(Select_strict1) {
813 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 755 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
814 // select(a=0, a=1, a=2); return a 756 // select(a=0, a=1, a=2); return a
815 BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(0, WASM_I8(0)), 757 BUILD(r, B2(WASM_SELECT(WASM_SET_LOCAL(0, WASM_I8(0)),
816 WASM_TEE_LOCAL(0, WASM_I8(1)), 758 WASM_SET_LOCAL(0, WASM_I8(1)),
817 WASM_TEE_LOCAL(0, WASM_I8(2))), 759 WASM_SET_LOCAL(0, WASM_I8(2))),
818 WASM_DROP, WASM_GET_LOCAL(0)); 760 WASM_GET_LOCAL(0)));
819 FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); } 761 FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); }
820 } 762 }
821 763
822 WASM_EXEC_TEST(Select_strict2) { 764 WASM_EXEC_TEST(Select_strict2) {
823 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 765 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
824 r.AllocateLocal(kAstI32); 766 r.AllocateLocal(kAstI32);
825 r.AllocateLocal(kAstI32); 767 r.AllocateLocal(kAstI32);
826 // select(b=5, c=6, a) 768 // select(b=5, c=6, a)
827 BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I8(5)), 769 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)),
828 WASM_TEE_LOCAL(2, WASM_I8(6)), WASM_GET_LOCAL(0))); 770 WASM_SET_LOCAL(2, WASM_I8(6)), WASM_GET_LOCAL(0)));
829 FOR_INT32_INPUTS(i) { 771 FOR_INT32_INPUTS(i) {
830 int32_t expected = *i ? 5 : 6; 772 int32_t expected = *i ? 5 : 6;
831 CHECK_EQ(expected, r.Call(*i)); 773 CHECK_EQ(expected, r.Call(*i));
832 } 774 }
833 } 775 }
834 776
835 WASM_EXEC_TEST(Select_strict3) { 777 WASM_EXEC_TEST(Select_strict3) {
836 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 778 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
837 r.AllocateLocal(kAstI32); 779 r.AllocateLocal(kAstI32);
838 r.AllocateLocal(kAstI32); 780 r.AllocateLocal(kAstI32);
839 // select(b=5, c=6, a=b) 781 // select(b=5, c=6, a=b)
840 BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I8(5)), 782 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)),
841 WASM_TEE_LOCAL(2, WASM_I8(6)), 783 WASM_SET_LOCAL(2, WASM_I8(6)),
842 WASM_TEE_LOCAL(0, WASM_GET_LOCAL(1)))); 784 WASM_SET_LOCAL(0, WASM_GET_LOCAL(1))));
843 FOR_INT32_INPUTS(i) { 785 FOR_INT32_INPUTS(i) {
844 int32_t expected = 5; 786 int32_t expected = 5;
845 CHECK_EQ(expected, r.Call(*i)); 787 CHECK_EQ(expected, r.Call(*i));
846 } 788 }
847 } 789 }
848 790
849 WASM_EXEC_TEST(BrIf_strict) { 791 WASM_EXEC_TEST(BrIf_strict) {
850 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 792 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
851 BUILD(r, WASM_BLOCK_I(WASM_BRV_IF(0, WASM_GET_LOCAL(0), 793 BUILD(
852 WASM_TEE_LOCAL(0, WASM_I8(99))))); 794 r,
795 B2(B1(WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(99)))),
796 WASM_GET_LOCAL(0)));
853 797
854 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } 798 FOR_INT32_INPUTS(i) { CHECK_EQ(99, r.Call(*i)); }
855 }
856
857 WASM_EXEC_TEST(Br_height) {
858 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
859 BUILD(r,
860 WASM_BLOCK_I(
861 WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)),
862 WASM_RETURN1(WASM_I8(9)), WASM_I8(7), WASM_I8(7)),
863 WASM_BRV(0, WASM_I8(8))));
864
865 for (int32_t i = 0; i < 5; i++) {
866 int32_t expected = i != 0 ? 8 : 9;
867 CHECK_EQ(expected, r.Call(i));
868 }
869 } 799 }
870 800
871 WASM_EXEC_TEST(BrTable0a) { 801 WASM_EXEC_TEST(BrTable0a) {
872 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 802 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
873 BUILD(r, B1(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))), 803 BUILD(r,
874 WASM_I8(91)); 804 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), WASM_I8(91)));
875 FOR_INT32_INPUTS(i) { CHECK_EQ(91, r.Call(*i)); } 805 FOR_INT32_INPUTS(i) { CHECK_EQ(91, r.Call(*i)); }
876 } 806 }
877 807
878 WASM_EXEC_TEST(BrTable0b) { 808 WASM_EXEC_TEST(BrTable0b) {
879 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 809 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
880 BUILD(r, 810 BUILD(r,
881 B1(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(0)))), 811 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(0))),
882 WASM_I8(92)); 812 WASM_I8(92)));
883 FOR_INT32_INPUTS(i) { CHECK_EQ(92, r.Call(*i)); } 813 FOR_INT32_INPUTS(i) { CHECK_EQ(92, r.Call(*i)); }
884 } 814 }
885 815
886 WASM_EXEC_TEST(BrTable0c) { 816 WASM_EXEC_TEST(BrTable0c) {
887 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 817 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
888 BUILD( 818 BUILD(
889 r, 819 r,
890 B1(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(1))), 820 B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(1))),
891 RET_I8(76))), 821 RET_I8(76)),
892 WASM_I8(77)); 822 WASM_I8(77)));
893 FOR_INT32_INPUTS(i) { 823 FOR_INT32_INPUTS(i) {
894 int32_t expected = *i == 0 ? 76 : 77; 824 int32_t expected = *i == 0 ? 76 : 77;
895 CHECK_EQ(expected, r.Call(*i)); 825 CHECK_EQ(expected, r.Call(*i));
896 } 826 }
897 } 827 }
898 828
899 WASM_EXEC_TEST(BrTable1) { 829 WASM_EXEC_TEST(BrTable1) {
900 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 830 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
901 BUILD(r, B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), RET_I8(93)); 831 BUILD(r, B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), RET_I8(93));
902 FOR_INT32_INPUTS(i) { CHECK_EQ(93, r.Call(*i)); } 832 FOR_INT32_INPUTS(i) { CHECK_EQ(93, r.Call(*i)); }
903 } 833 }
904 834
905 WASM_EXEC_TEST(BrTable_loop) { 835 WASM_EXEC_TEST(BrTable_loop) {
906 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 836 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
907 BUILD(r, 837 BUILD(r, B2(WASM_LOOP(WASM_BR_TABLE(WASM_INC_LOCAL_BY(0, 1), 2, BR_TARGET(2),
908 B2(B1(WASM_LOOP(WASM_BR_TABLE(WASM_INC_LOCAL_BYV(0, 1), 2, BR_TARGET(2), 838 BR_TARGET(1), BR_TARGET(0))),
909 BR_TARGET(1), BR_TARGET(0)))), 839 RET_I8(99)),
910 RET_I8(99)),
911 WASM_I8(98)); 840 WASM_I8(98));
912 CHECK_EQ(99, r.Call(0)); 841 CHECK_EQ(99, r.Call(0));
913 CHECK_EQ(98, r.Call(-1)); 842 CHECK_EQ(98, r.Call(-1));
914 CHECK_EQ(98, r.Call(-2)); 843 CHECK_EQ(98, r.Call(-2));
915 CHECK_EQ(98, r.Call(-3)); 844 CHECK_EQ(98, r.Call(-3));
916 CHECK_EQ(98, r.Call(-100)); 845 CHECK_EQ(98, r.Call(-100));
917 } 846 }
918 847
919 WASM_EXEC_TEST(BrTable_br) { 848 WASM_EXEC_TEST(BrTable_br) {
920 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 849 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 module.WriteMemory(&memory[0], expected); 974 module.WriteMemory(&memory[0], expected);
1046 CHECK_EQ(expected, r.Call()); 975 CHECK_EQ(expected, r.Call());
1047 } 976 }
1048 } 977 }
1049 978
1050 WASM_EXEC_TEST(I32ReinterpretF32) { 979 WASM_EXEC_TEST(I32ReinterpretF32) {
1051 TestingModule module(execution_mode); 980 TestingModule module(execution_mode);
1052 int32_t* memory = module.AddMemoryElems<int32_t>(8); 981 int32_t* memory = module.AddMemoryElems<int32_t>(8);
1053 WasmRunner<int32_t> r(&module, MachineType::Int32()); 982 WasmRunner<int32_t> r(&module, MachineType::Int32());
1054 983
1055 BUILD(r, WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, 984 BUILD(r,
1056 WASM_F32_REINTERPRET_I32(WASM_GET_LOCAL(0))), 985 WASM_BLOCK(WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO,
1057 WASM_I8(107)); 986 WASM_F32_REINTERPRET_I32(WASM_GET_LOCAL(0))),
987 WASM_I8(107)));
1058 988
1059 FOR_INT32_INPUTS(i) { 989 FOR_INT32_INPUTS(i) {
1060 int32_t expected = *i; 990 int32_t expected = *i;
1061 CHECK_EQ(107, r.Call(expected)); 991 CHECK_EQ(107, r.Call(expected));
1062 CHECK_EQ(expected, module.ReadMemory(&memory[0])); 992 CHECK_EQ(expected, module.ReadMemory(&memory[0]));
1063 } 993 }
1064 } 994 }
1065 995
1066 WASM_EXEC_TEST(LoadStoreLoad) { 996 WASM_EXEC_TEST(ReturnStore) {
1067 TestingModule module(execution_mode); 997 TestingModule module(execution_mode);
1068 int32_t* memory = module.AddMemoryElems<int32_t>(8); 998 int32_t* memory = module.AddMemoryElems<int32_t>(8);
1069 WasmRunner<int32_t> r(&module); 999 WasmRunner<int32_t> r(&module);
1070 1000
1071 BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, 1001 BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO,
1072 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), 1002 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)));
1073 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO));
1074 1003
1075 FOR_INT32_INPUTS(i) { 1004 FOR_INT32_INPUTS(i) {
1076 int32_t expected = *i; 1005 int32_t expected = *i;
1077 module.WriteMemory(&memory[0], expected); 1006 module.WriteMemory(&memory[0], expected);
1078 CHECK_EQ(expected, r.Call()); 1007 CHECK_EQ(expected, r.Call());
1079 } 1008 }
1080 } 1009 }
1081 1010
1082 WASM_EXEC_TEST(VoidReturn1) { 1011 WASM_EXEC_TEST(VoidReturn1) {
1083 // We use a wrapper function because WasmRunner<void> does not exist. 1012 // We use a wrapper function because WasmRunner<void> does not exist.
1084 1013
1085 // Build the test function. 1014 // Build the test function.
1086 TestSignatures sigs; 1015 TestSignatures sigs;
1087 TestingModule module(execution_mode); 1016 TestingModule module(execution_mode);
1088 WasmFunctionCompiler t(sigs.v_v(), &module); 1017 WasmFunctionCompiler t(sigs.v_v(), &module);
1089 BUILD(t, kExprNop); 1018 BUILD(t, kExprNop);
1090 uint32_t index = t.CompileAndAdd(); 1019 uint32_t index = t.CompileAndAdd();
1091 1020
1092 const int32_t kExpected = -414444; 1021 const int32_t kExpected = -414444;
1093 // Build the calling function. 1022 // Build the calling function.
1094 WasmRunner<int32_t> r(&module); 1023 WasmRunner<int32_t> r(&module);
1095 BUILD(r, WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected)); 1024 BUILD(r, B2(WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected)));
1096 1025
1097 int32_t result = r.Call(); 1026 int32_t result = r.Call();
1098 CHECK_EQ(kExpected, result); 1027 CHECK_EQ(kExpected, result);
1099 } 1028 }
1100 1029
1101 WASM_EXEC_TEST(VoidReturn2) { 1030 WASM_EXEC_TEST(VoidReturn2) {
1102 // We use a wrapper function because WasmRunner<void> does not exist. 1031 // We use a wrapper function because WasmRunner<void> does not exist.
1103 // Build the test function. 1032 // Build the test function.
1104 TestSignatures sigs; 1033 TestSignatures sigs;
1105 TestingModule module(execution_mode); 1034 TestingModule module(execution_mode);
1106 WasmFunctionCompiler t(sigs.v_v(), &module); 1035 WasmFunctionCompiler t(sigs.v_v(), &module);
1107 BUILD(t, WASM_RETURN0); 1036 BUILD(t, WASM_RETURN0);
1108 uint32_t index = t.CompileAndAdd(); 1037 uint32_t index = t.CompileAndAdd();
1109 1038
1110 const int32_t kExpected = -414444; 1039 const int32_t kExpected = -414444;
1111 // Build the calling function. 1040 // Build the calling function.
1112 WasmRunner<int32_t> r(&module); 1041 WasmRunner<int32_t> r(&module);
1113 BUILD(r, B1(WASM_CALL_FUNCTION0(index)), WASM_I32V_3(kExpected)); 1042 BUILD(r, B2(WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected)));
1114 1043
1115 int32_t result = r.Call(); 1044 int32_t result = r.Call();
1116 CHECK_EQ(kExpected, result); 1045 CHECK_EQ(kExpected, result);
1117 } 1046 }
1118 1047
1119 WASM_EXEC_TEST(BrEmpty) { 1048 WASM_EXEC_TEST(Block_empty) {
1120 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1049 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1121 BUILD(r, WASM_BRV(0, WASM_GET_LOCAL(0))); 1050 BUILD(r, kExprBlock, kExprEnd, WASM_GET_LOCAL(0));
1122 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } 1051 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
1123 } 1052 }
1124 1053
1125 WASM_EXEC_TEST(BrIfEmpty) {
1126 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1127 BUILD(r, WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
1128 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
1129 }
1130
1131 WASM_EXEC_TEST(Block_empty) {
1132 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1133 BUILD(r, kExprBlock, kLocalVoid, kExprEnd, WASM_GET_LOCAL(0));
1134 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
1135 }
1136
1137 WASM_EXEC_TEST(Block_empty_br1) { 1054 WASM_EXEC_TEST(Block_empty_br1) {
1138 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1055 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1139 BUILD(r, B1(WASM_BR(0)), WASM_GET_LOCAL(0)); 1056 BUILD(r, B1(WASM_BR(0)), WASM_GET_LOCAL(0));
1140 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } 1057 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
1141 } 1058 }
1142 1059
1143 WASM_EXEC_TEST(Block_empty_brif1) { 1060 WASM_EXEC_TEST(Block_empty_brif1) {
1144 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1061 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1145 BUILD(r, WASM_BLOCK(WASM_BR_IF(0, WASM_ZERO)), WASM_GET_LOCAL(0)); 1062 BUILD(r, B1(WASM_BR_IF(0, WASM_ZERO)), WASM_GET_LOCAL(0));
1146 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } 1063 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
1147 } 1064 }
1148 1065
1149 WASM_EXEC_TEST(Block_empty_brif2) { 1066 WASM_EXEC_TEST(Block_empty_brif2) {
1150 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(), 1067 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
1151 MachineType::Uint32()); 1068 MachineType::Uint32());
1152 BUILD(r, WASM_BLOCK(WASM_BR_IF(0, WASM_GET_LOCAL(1))), WASM_GET_LOCAL(0)); 1069 BUILD(r, B1(WASM_BR_IF(0, WASM_GET_LOCAL(1))), WASM_GET_LOCAL(0));
1153 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); } 1070 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); }
1154 } 1071 }
1155 1072
1156 WASM_EXEC_TEST(Block_i) {
1157 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1158 BUILD(r, WASM_BLOCK_I(WASM_GET_LOCAL(0)));
1159 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
1160 }
1161
1162 WASM_EXEC_TEST(Block_f) {
1163 WasmRunner<float> r(execution_mode, MachineType::Float32());
1164 BUILD(r, WASM_BLOCK_F(WASM_GET_LOCAL(0)));
1165 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(*i, r.Call(*i)); }
1166 }
1167
1168 WASM_EXEC_TEST(Block_d) {
1169 WasmRunner<double> r(execution_mode, MachineType::Float64());
1170 BUILD(r, WASM_BLOCK_D(WASM_GET_LOCAL(0)));
1171 FOR_FLOAT64_INPUTS(i) { CHECK_FLOAT_EQ(*i, r.Call(*i)); }
1172 }
1173
1174 WASM_EXEC_TEST(Block_br2) { 1073 WASM_EXEC_TEST(Block_br2) {
1175 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1074 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1176 BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); 1075 BUILD(r, B1(WASM_BRV(0, WASM_GET_LOCAL(0))));
1177 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } 1076 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
1178 } 1077 }
1179 1078
1180 WASM_EXEC_TEST(Block_If_P) { 1079 WASM_EXEC_TEST(Block_If_P) {
1181 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1080 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1182 // block { if (p0) break 51; 52; } 1081 // { if (p0) return 51; return 52; }
1183 BUILD(r, WASM_BLOCK_I( // -- 1082 BUILD(r, B2( // --
1184 WASM_IF(WASM_GET_LOCAL(0), // -- 1083 WASM_IF(WASM_GET_LOCAL(0), // --
1185 WASM_BRV(1, WASM_I8(51))), // -- 1084 WASM_BRV(1, WASM_I8(51))), // --
1186 WASM_I8(52))); // -- 1085 WASM_I8(52))); // --
1187 FOR_INT32_INPUTS(i) { 1086 FOR_INT32_INPUTS(i) {
1188 int32_t expected = *i ? 51 : 52; 1087 int32_t expected = *i ? 51 : 52;
1189 CHECK_EQ(expected, r.Call(*i)); 1088 CHECK_EQ(expected, r.Call(*i));
1190 } 1089 }
1191 } 1090 }
1192 1091
1193 WASM_EXEC_TEST(Loop_empty) { 1092 WASM_EXEC_TEST(Loop_empty) {
1194 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1093 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1195 BUILD(r, kExprLoop, kLocalVoid, kExprEnd, WASM_GET_LOCAL(0)); 1094 BUILD(r, kExprLoop, kExprEnd, WASM_GET_LOCAL(0));
1196 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } 1095 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
1197 } 1096 }
1198 1097
1199 WASM_EXEC_TEST(Loop_i) {
1200 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1201 BUILD(r, WASM_LOOP_I(WASM_GET_LOCAL(0)));
1202 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
1203 }
1204
1205 WASM_EXEC_TEST(Loop_f) {
1206 WasmRunner<float> r(execution_mode, MachineType::Float32());
1207 BUILD(r, WASM_LOOP_F(WASM_GET_LOCAL(0)));
1208 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(*i, r.Call(*i)); }
1209 }
1210
1211 WASM_EXEC_TEST(Loop_d) {
1212 WasmRunner<double> r(execution_mode, MachineType::Float64());
1213 BUILD(r, WASM_LOOP_D(WASM_GET_LOCAL(0)));
1214 FOR_FLOAT64_INPUTS(i) { CHECK_FLOAT_EQ(*i, r.Call(*i)); }
1215 }
1216
1217 WASM_EXEC_TEST(Loop_empty_br1) { 1098 WASM_EXEC_TEST(Loop_empty_br1) {
1218 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1099 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1219 BUILD(r, B1(WASM_LOOP(WASM_BR(1))), WASM_GET_LOCAL(0)); 1100 BUILD(r, WASM_LOOP(WASM_BR(1)), WASM_GET_LOCAL(0));
1220 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } 1101 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
1221 } 1102 }
1222 1103
1223 WASM_EXEC_TEST(Loop_empty_brif1) { 1104 WASM_EXEC_TEST(Loop_empty_brif1) {
1224 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1105 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1225 BUILD(r, B1(WASM_LOOP(WASM_BR_IF(1, WASM_ZERO))), WASM_GET_LOCAL(0)); 1106 BUILD(r, WASM_LOOP(WASM_BR_IF(1, WASM_ZERO)), WASM_GET_LOCAL(0));
1226 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } 1107 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
1227 } 1108 }
1228 1109
1229 WASM_EXEC_TEST(Loop_empty_brif2) { 1110 WASM_EXEC_TEST(Loop_empty_brif2) {
1230 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(), 1111 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
1231 MachineType::Uint32()); 1112 MachineType::Uint32());
1232 BUILD(r, WASM_LOOP_I(WASM_BRV_IF(1, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); 1113 BUILD(r, WASM_LOOP(WASM_BR_IF(1, WASM_GET_LOCAL(1))), WASM_GET_LOCAL(0));
1233 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); } 1114 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); }
1234 } 1115 }
1235 1116
1236 WASM_EXEC_TEST(Loop_empty_brif3) {
1237 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
1238 MachineType::Uint32(), MachineType::Uint32());
1239 BUILD(r, WASM_LOOP(WASM_BRV_IFD(1, WASM_GET_LOCAL(2), WASM_GET_LOCAL(0))),
1240 WASM_GET_LOCAL(1));
1241 FOR_UINT32_INPUTS(i) {
1242 FOR_UINT32_INPUTS(j) {
1243 CHECK_EQ(*i, r.Call(0, *i, *j));
1244 CHECK_EQ(*j, r.Call(1, *i, *j));
1245 }
1246 }
1247 }
1248
1249 WASM_EXEC_TEST(Block_BrIf_P) { 1117 WASM_EXEC_TEST(Block_BrIf_P) {
1250 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1118 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1251 BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(51), WASM_GET_LOCAL(0)), 1119 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(51), WASM_GET_LOCAL(0)), WASM_I8(52)));
1252 WASM_I8(52)));
1253 FOR_INT32_INPUTS(i) { 1120 FOR_INT32_INPUTS(i) {
1254 int32_t expected = *i ? 51 : 52; 1121 int32_t expected = *i ? 51 : 52;
1255 CHECK_EQ(expected, r.Call(*i)); 1122 CHECK_EQ(expected, r.Call(*i));
1256 } 1123 }
1257 } 1124 }
1258 1125
1259 WASM_EXEC_TEST(Block_IfElse_P_assign) { 1126 WASM_EXEC_TEST(Block_IfElse_P_assign) {
1260 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1127 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1261 // { if (p0) p0 = 71; else p0 = 72; return p0; } 1128 // { if (p0) p0 = 71; else p0 = 72; return p0; }
1262 BUILD(r, // -- 1129 BUILD(r, B2( // --
1263 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- 1130 WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
1264 WASM_SET_LOCAL(0, WASM_I8(71)), // -- 1131 WASM_SET_LOCAL(0, WASM_I8(71)), // --
1265 WASM_SET_LOCAL(0, WASM_I8(72))), // -- 1132 WASM_SET_LOCAL(0, WASM_I8(72))), // --
1266 WASM_GET_LOCAL(0)); 1133 WASM_GET_LOCAL(0)));
1267 FOR_INT32_INPUTS(i) { 1134 FOR_INT32_INPUTS(i) {
1268 int32_t expected = *i ? 71 : 72; 1135 int32_t expected = *i ? 71 : 72;
1269 CHECK_EQ(expected, r.Call(*i)); 1136 CHECK_EQ(expected, r.Call(*i));
1270 } 1137 }
1271 } 1138 }
1272 1139
1273 WASM_EXEC_TEST(Block_IfElse_P_return) { 1140 WASM_EXEC_TEST(Block_IfElse_P_return) {
1274 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1141 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1275 // if (p0) return 81; else return 82; 1142 // if (p0) return 81; else return 82;
1276 BUILD(r, // -- 1143 BUILD(r, // --
1277 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- 1144 WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
1278 RET_I8(81), // -- 1145 RET_I8(81), // --
1279 RET_I8(82))); // -- 1146 RET_I8(82))); // --
1280 FOR_INT32_INPUTS(i) { 1147 FOR_INT32_INPUTS(i) {
1281 int32_t expected = *i ? 81 : 82; 1148 int32_t expected = *i ? 81 : 82;
1282 CHECK_EQ(expected, r.Call(*i)); 1149 CHECK_EQ(expected, r.Call(*i));
1283 } 1150 }
1284 } 1151 }
1285 1152
1286 WASM_EXEC_TEST(Block_If_P_assign) { 1153 WASM_EXEC_TEST(Block_If_P_assign) {
1287 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1154 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1288 // { if (p0) p0 = 61; p0; } 1155 // { if (p0) p0 = 61; p0; }
1289 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(61))), 1156 BUILD(r,
1290 WASM_GET_LOCAL(0)); 1157 WASM_BLOCK(WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(61))),
1158 WASM_GET_LOCAL(0)));
1291 FOR_INT32_INPUTS(i) { 1159 FOR_INT32_INPUTS(i) {
1292 int32_t expected = *i ? 61 : *i; 1160 int32_t expected = *i ? 61 : *i;
1293 CHECK_EQ(expected, r.Call(*i)); 1161 CHECK_EQ(expected, r.Call(*i));
1294 } 1162 }
1295 } 1163 }
1296 1164
1297 WASM_EXEC_TEST(DanglingAssign) { 1165 WASM_EXEC_TEST(DanglingAssign) {
1298 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1166 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1299 // { return 0; p0 = 0; } 1167 // { return 0; p0 = 0; }
1300 BUILD(r, B2(RET_I8(99), WASM_SET_LOCAL(0, WASM_ZERO))); 1168 BUILD(r, B2(RET_I8(99), WASM_SET_LOCAL(0, WASM_ZERO)));
1301 CHECK_EQ(99, r.Call(1)); 1169 CHECK_EQ(99, r.Call(1));
1302 } 1170 }
1303 1171
1304 WASM_EXEC_TEST(ExprIf_P) { 1172 WASM_EXEC_TEST(ExprIf_P) {
1305 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1173 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1306 // p0 ? 11 : 22; 1174 // p0 ? 11 : 22;
1307 BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), // -- 1175 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
1308 WASM_I8(11), // -- 1176 WASM_I8(11), // --
1309 WASM_I8(22))); // -- 1177 WASM_I8(22))); // --
1178 FOR_INT32_INPUTS(i) {
1179 int32_t expected = *i ? 11 : 22;
1180 CHECK_EQ(expected, r.Call(*i));
1181 }
1182 }
1183
1184 WASM_EXEC_TEST(ExprIf_P_fallthru) {
1185 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1186 // p0 ? 11 : 22;
1187 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
1188 WASM_I8(11), // --
1189 WASM_I8(22))); // --
1310 FOR_INT32_INPUTS(i) { 1190 FOR_INT32_INPUTS(i) {
1311 int32_t expected = *i ? 11 : 22; 1191 int32_t expected = *i ? 11 : 22;
1312 CHECK_EQ(expected, r.Call(*i)); 1192 CHECK_EQ(expected, r.Call(*i));
1313 } 1193 }
1314 } 1194 }
1315 1195
1316 WASM_EXEC_TEST(CountDown) { 1196 WASM_EXEC_TEST(CountDown) {
1317 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1197 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1318 BUILD(r, WASM_LOOP(WASM_IFB( 1198 BUILD(r, WASM_BLOCK(
1319 WASM_GET_LOCAL(0), 1199 WASM_LOOP(WASM_IF(
1320 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), 1200 WASM_GET_LOCAL(0),
1321 WASM_BR(1))), 1201 WASM_BRV(1, WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0),
1322 WASM_GET_LOCAL(0)); 1202 WASM_I8(1)))))),
1203 WASM_GET_LOCAL(0)));
1323 CHECK_EQ(0, r.Call(1)); 1204 CHECK_EQ(0, r.Call(1));
1324 CHECK_EQ(0, r.Call(10)); 1205 CHECK_EQ(0, r.Call(10));
1325 CHECK_EQ(0, r.Call(100)); 1206 CHECK_EQ(0, r.Call(100));
1326 } 1207 }
1327 1208
1328 WASM_EXEC_TEST(CountDown_fallthru) { 1209 WASM_EXEC_TEST(CountDown_fallthru) {
1329 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1210 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1330 BUILD(r, WASM_LOOP( 1211 BUILD(r, WASM_BLOCK(
1331 WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), 1212 WASM_LOOP(WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), WASM_BREAK(1)),
1332 WASM_BRV(2, WASM_GET_LOCAL(0))), 1213 WASM_SET_LOCAL(
1333 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), 1214 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))),
1334 WASM_CONTINUE(0)), 1215 WASM_CONTINUE(0)),
1335 WASM_GET_LOCAL(0)); 1216 WASM_GET_LOCAL(0)));
1336 CHECK_EQ(0, r.Call(1)); 1217 CHECK_EQ(0, r.Call(1));
1337 CHECK_EQ(0, r.Call(10)); 1218 CHECK_EQ(0, r.Call(10));
1338 CHECK_EQ(0, r.Call(100)); 1219 CHECK_EQ(0, r.Call(100));
1339 } 1220 }
1340 1221
1341 WASM_EXEC_TEST(WhileCountDown) { 1222 WASM_EXEC_TEST(WhileCountDown) {
1342 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1223 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1343 BUILD(r, WASM_WHILE( 1224 BUILD(r,
1344 WASM_GET_LOCAL(0), 1225 WASM_BLOCK(WASM_WHILE(WASM_GET_LOCAL(0),
1345 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1)))), 1226 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0),
1346 WASM_GET_LOCAL(0)); 1227 WASM_I8(1)))),
1228 WASM_GET_LOCAL(0)));
1347 CHECK_EQ(0, r.Call(1)); 1229 CHECK_EQ(0, r.Call(1));
1348 CHECK_EQ(0, r.Call(10)); 1230 CHECK_EQ(0, r.Call(10));
1349 CHECK_EQ(0, r.Call(100)); 1231 CHECK_EQ(0, r.Call(100));
1350 } 1232 }
1351 1233
1352 WASM_EXEC_TEST(Loop_if_break1) { 1234 WASM_EXEC_TEST(Loop_if_break1) {
1353 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), 1235 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1354 MachineType::Int32()); 1236 BUILD(r, B2(WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(1)),
1355 BUILD(r, WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(2, WASM_GET_LOCAL(1))), 1237 WASM_SET_LOCAL(0, WASM_I8(99))),
1356 WASM_SET_LOCAL(0, WASM_I8(99))), 1238 WASM_GET_LOCAL(0)));
1357 WASM_GET_LOCAL(0)); 1239 CHECK_EQ(99, r.Call(0));
1358 CHECK_EQ(99, r.Call(0, 11)); 1240 CHECK_EQ(3, r.Call(3));
1359 CHECK_EQ(65, r.Call(3, 65)); 1241 CHECK_EQ(10000, r.Call(10000));
1360 CHECK_EQ(10001, r.Call(10000, 10001)); 1242 CHECK_EQ(-29, r.Call(-29));
1361 CHECK_EQ(-29, r.Call(-28, -29));
1362 } 1243 }
1363 1244
1364 WASM_EXEC_TEST(Loop_if_break2) { 1245 WASM_EXEC_TEST(Loop_if_break2) {
1365 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), 1246 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1366 MachineType::Int32()); 1247 BUILD(r, B2(WASM_LOOP(WASM_BR_IF(1, WASM_GET_LOCAL(0)),
1367 BUILD(r, WASM_LOOP(WASM_BRV_IF(1, WASM_GET_LOCAL(1), WASM_GET_LOCAL(0)), 1248 WASM_SET_LOCAL(0, WASM_I8(99))),
1368 WASM_DROP, WASM_SET_LOCAL(0, WASM_I8(99))), 1249 WASM_GET_LOCAL(0)));
1369 WASM_GET_LOCAL(0)); 1250 CHECK_EQ(99, r.Call(0));
1370 CHECK_EQ(99, r.Call(0, 33)); 1251 CHECK_EQ(3, r.Call(3));
1371 CHECK_EQ(3, r.Call(1, 3)); 1252 CHECK_EQ(10000, r.Call(10000));
1372 CHECK_EQ(10000, r.Call(99, 10000)); 1253 CHECK_EQ(-29, r.Call(-29));
1373 CHECK_EQ(-29, r.Call(-11, -29));
1374 } 1254 }
1375 1255
1376 WASM_EXEC_TEST(Loop_if_break_fallthru) { 1256 WASM_EXEC_TEST(Loop_if_break_fallthru) {
1377 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1257 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1378 BUILD(r, B1(WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2)), 1258 BUILD(r, B1(WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(1)),
1379 WASM_SET_LOCAL(0, WASM_I8(93)))), 1259 WASM_SET_LOCAL(0, WASM_I8(93)))),
1380 WASM_GET_LOCAL(0)); 1260 WASM_GET_LOCAL(0));
1381 CHECK_EQ(93, r.Call(0)); 1261 CHECK_EQ(93, r.Call(0));
1382 CHECK_EQ(3, r.Call(3)); 1262 CHECK_EQ(3, r.Call(3));
1383 CHECK_EQ(10001, r.Call(10001)); 1263 CHECK_EQ(10001, r.Call(10001));
1384 CHECK_EQ(-22, r.Call(-22)); 1264 CHECK_EQ(-22, r.Call(-22));
1385 } 1265 }
1386 1266
1387 WASM_EXEC_TEST(Loop_if_break_fallthru2) {
1388 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1389 BUILD(r, B1(B1(WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2)),
1390 WASM_SET_LOCAL(0, WASM_I8(93))))),
1391 WASM_GET_LOCAL(0));
1392 CHECK_EQ(93, r.Call(0));
1393 CHECK_EQ(3, r.Call(3));
1394 CHECK_EQ(10001, r.Call(10001));
1395 CHECK_EQ(-22, r.Call(-22));
1396 }
1397
1398 WASM_EXEC_TEST(IfBreak1) { 1267 WASM_EXEC_TEST(IfBreak1) {
1399 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1268 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1400 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), WASM_UNREACHABLE)), 1269 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), WASM_UNREACHABLE)),
1401 WASM_I8(91)); 1270 WASM_I8(91));
1402 CHECK_EQ(91, r.Call(0)); 1271 CHECK_EQ(91, r.Call(0));
1403 CHECK_EQ(91, r.Call(1)); 1272 CHECK_EQ(91, r.Call(1));
1404 CHECK_EQ(91, r.Call(-8734)); 1273 CHECK_EQ(91, r.Call(-8734));
1405 } 1274 }
1406 1275
1407 WASM_EXEC_TEST(IfBreak2) { 1276 WASM_EXEC_TEST(IfBreak2) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), 1349 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
1481 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), 1350 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(),
1482 MachineType::Float64()}; 1351 MachineType::Float64()};
1483 1352
1484 for (size_t m = 0; m < arraysize(machineTypes); ++m) { 1353 for (size_t m = 0; m < arraysize(machineTypes); ++m) {
1485 module.RandomizeMemory(1116 + static_cast<int>(m)); 1354 module.RandomizeMemory(1116 + static_cast<int>(m));
1486 WasmRunner<int32_t> r(&module, MachineType::Uint32()); 1355 WasmRunner<int32_t> r(&module, MachineType::Uint32());
1487 uint32_t boundary = 24 - WasmOpcodes::MemSize(machineTypes[m]); 1356 uint32_t boundary = 24 - WasmOpcodes::MemSize(machineTypes[m]);
1488 1357
1489 BUILD(r, WASM_LOAD_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0)), 1358 BUILD(r, WASM_LOAD_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0)),
1490 WASM_DROP, WASM_ZERO); 1359 WASM_ZERO);
1491 1360
1492 CHECK_EQ(0, r.Call(boundary)); // in bounds. 1361 CHECK_EQ(0, r.Call(boundary)); // in bounds.
1493 1362
1494 for (uint32_t offset = boundary + 1; offset < boundary + 19; ++offset) { 1363 for (uint32_t offset = boundary + 1; offset < boundary + 19; ++offset) {
1495 CHECK_TRAP(r.Call(offset)); // out of bounds. 1364 CHECK_TRAP(r.Call(offset)); // out of bounds.
1496 } 1365 }
1497 } 1366 }
1498 } 1367 }
1499 1368
1500 WASM_EXEC_TEST(LoadMemI32_offset) { 1369 WASM_EXEC_TEST(LoadMemI32_offset) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 } 1437 }
1569 1438
1570 WASM_EXEC_TEST(StoreMemI32_alignment) { 1439 WASM_EXEC_TEST(StoreMemI32_alignment) {
1571 TestingModule module(execution_mode); 1440 TestingModule module(execution_mode);
1572 int32_t* memory = module.AddMemoryElems<int32_t>(4); 1441 int32_t* memory = module.AddMemoryElems<int32_t>(4);
1573 const int32_t kWritten = 0x12345678; 1442 const int32_t kWritten = 0x12345678;
1574 1443
1575 for (byte i = 0; i <= 2; ++i) { 1444 for (byte i = 0; i <= 2; ++i) {
1576 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1445 WasmRunner<int32_t> r(&module, MachineType::Int32());
1577 BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int32(), WASM_ZERO, i, 1446 BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int32(), WASM_ZERO, i,
1578 WASM_GET_LOCAL(0)), 1447 WASM_GET_LOCAL(0)));
1579 WASM_GET_LOCAL(0));
1580 module.RandomizeMemory(1111); 1448 module.RandomizeMemory(1111);
1581 memory[0] = 0; 1449 memory[0] = 0;
1582 1450
1583 CHECK_EQ(kWritten, r.Call(kWritten)); 1451 CHECK_EQ(kWritten, r.Call(kWritten));
1584 CHECK_EQ(kWritten, module.ReadMemory(&memory[0])); 1452 CHECK_EQ(kWritten, module.ReadMemory(&memory[0]));
1585 } 1453 }
1586 } 1454 }
1587 1455
1588 WASM_EXEC_TEST(StoreMemI32_offset) { 1456 WASM_EXEC_TEST(StoreMemI32_offset) {
1589 TestingModule module(execution_mode); 1457 TestingModule module(execution_mode);
1590 int32_t* memory = module.AddMemoryElems<int32_t>(4); 1458 int32_t* memory = module.AddMemoryElems<int32_t>(4);
1591 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1459 WasmRunner<int32_t> r(&module, MachineType::Int32());
1592 const int32_t kWritten = 0xaabbccdd; 1460 const int32_t kWritten = 0xaabbccdd;
1593 1461
1594 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0), 1462 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0),
1595 WASM_I32V_5(kWritten)), 1463 WASM_I32V_5(kWritten)));
1596 WASM_I32V_5(kWritten));
1597 1464
1598 for (int i = 0; i < 2; ++i) { 1465 for (int i = 0; i < 2; ++i) {
1599 module.RandomizeMemory(1111); 1466 module.RandomizeMemory(1111);
1600 module.WriteMemory(&memory[0], 66666666); 1467 module.WriteMemory(&memory[0], 66666666);
1601 module.WriteMemory(&memory[1], 77777777); 1468 module.WriteMemory(&memory[1], 77777777);
1602 module.WriteMemory(&memory[2], 88888888); 1469 module.WriteMemory(&memory[2], 88888888);
1603 module.WriteMemory(&memory[3], 99999999); 1470 module.WriteMemory(&memory[3], 99999999);
1604 CHECK_EQ(kWritten, r.Call(i * 4)); 1471 CHECK_EQ(kWritten, r.Call(i * 4));
1605 CHECK_EQ(66666666, module.ReadMemory(&memory[0])); 1472 CHECK_EQ(66666666, module.ReadMemory(&memory[0]));
1606 CHECK_EQ(i == 0 ? kWritten : 77777777, module.ReadMemory(&memory[1])); 1473 CHECK_EQ(i == 0 ? kWritten : 77777777, module.ReadMemory(&memory[1]));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 } 1519 }
1653 } 1520 }
1654 1521
1655 WASM_EXEC_TEST(MemI32_Sum) { 1522 WASM_EXEC_TEST(MemI32_Sum) {
1656 const int kNumElems = 20; 1523 const int kNumElems = 20;
1657 TestingModule module(execution_mode); 1524 TestingModule module(execution_mode);
1658 uint32_t* memory = module.AddMemoryElems<uint32_t>(kNumElems); 1525 uint32_t* memory = module.AddMemoryElems<uint32_t>(kNumElems);
1659 WasmRunner<uint32_t> r(&module, MachineType::Int32()); 1526 WasmRunner<uint32_t> r(&module, MachineType::Int32());
1660 const byte kSum = r.AllocateLocal(kAstI32); 1527 const byte kSum = r.AllocateLocal(kAstI32);
1661 1528
1662 BUILD( 1529 BUILD(r,
1663 r, 1530 WASM_BLOCK(
1664 WASM_WHILE( 1531 WASM_WHILE(
1665 WASM_GET_LOCAL(0), 1532 WASM_GET_LOCAL(0),
1666 WASM_BLOCK( 1533 WASM_BLOCK(
1667 WASM_SET_LOCAL(kSum, 1534 WASM_SET_LOCAL(
1668 WASM_I32_ADD(WASM_GET_LOCAL(kSum), 1535 kSum, WASM_I32_ADD(WASM_GET_LOCAL(kSum),
1669 WASM_LOAD_MEM(MachineType::Int32(), 1536 WASM_LOAD_MEM(MachineType::Int32(),
1670 WASM_GET_LOCAL(0)))), 1537 WASM_GET_LOCAL(0)))),
1671 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), 1538 WASM_SET_LOCAL(
1672 WASM_GET_LOCAL(1)); 1539 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))),
1540 WASM_GET_LOCAL(1)));
1673 1541
1674 // Run 4 trials. 1542 // Run 4 trials.
1675 for (int i = 0; i < 3; ++i) { 1543 for (int i = 0; i < 3; ++i) {
1676 module.RandomizeMemory(i * 33); 1544 module.RandomizeMemory(i * 33);
1677 uint32_t expected = 0; 1545 uint32_t expected = 0;
1678 for (size_t j = kNumElems - 1; j > 0; --j) { 1546 for (size_t j = kNumElems - 1; j > 0; --j) {
1679 expected += module.ReadMemory(&memory[j]); 1547 expected += module.ReadMemory(&memory[j]);
1680 } 1548 }
1681 uint32_t result = r.Call(4 * (kNumElems - 1)); 1549 uint32_t result = r.Call(4 * (kNumElems - 1));
1682 CHECK_EQ(expected, result); 1550 CHECK_EQ(expected, result);
1683 } 1551 }
1684 } 1552 }
1685 1553
1686 WASM_EXEC_TEST(CheckMachIntsZero) { 1554 WASM_EXEC_TEST(CheckMachIntsZero) {
1687 const int kNumElems = 55; 1555 const int kNumElems = 55;
1688 TestingModule module(execution_mode); 1556 TestingModule module(execution_mode);
1689 module.AddMemoryElems<uint32_t>(kNumElems); 1557 module.AddMemoryElems<uint32_t>(kNumElems);
1690 WasmRunner<uint32_t> r(&module, MachineType::Int32()); 1558 WasmRunner<uint32_t> r(&module, MachineType::Int32());
1691 1559
1692 BUILD(r, // -- 1560 BUILD(r, kExprLoop, kExprGetLocal, 0, kExprIf, kExprGetLocal, 0,
1693 /**/ kExprLoop, kLocalVoid, // -- 1561 kExprI32LoadMem, 0, 0, kExprIf, kExprI8Const, 255, kExprReturn, ARITY_1,
1694 /* */ kExprGetLocal, 0, // -- 1562 kExprEnd, kExprGetLocal, 0, kExprI8Const, 4, kExprI32Sub, kExprSetLocal,
1695 /* */ kExprIf, kLocalVoid, // -- 1563 0, kExprBr, ARITY_1, DEPTH_0, kExprEnd, kExprEnd, kExprI8Const, 0);
1696 /* */ kExprGetLocal, 0, // --
1697 /* */ kExprI32LoadMem, 0, 0, // --
1698 /* */ kExprIf, kLocalVoid, // --
1699 /* */ kExprI8Const, 255, // --
1700 /* */ kExprReturn, // --
1701 /* */ kExprEnd, // --
1702 /* */ kExprGetLocal, 0, // --
1703 /* */ kExprI8Const, 4, // --
1704 /* */ kExprI32Sub, // --
1705 /* */ kExprTeeLocal, 0, // --
1706 /* */ kExprBr, DEPTH_0, // --
1707 /* */ kExprEnd, // --
1708 /**/ kExprEnd, // --
1709 /**/ kExprI8Const, 0); // --
1710 1564
1711 module.BlankMemory(); 1565 module.BlankMemory();
1712 CHECK_EQ(0, r.Call((kNumElems - 1) * 4)); 1566 CHECK_EQ(0, r.Call((kNumElems - 1) * 4));
1713 } 1567 }
1714 1568
1715 WASM_EXEC_TEST(MemF32_Sum) { 1569 WASM_EXEC_TEST(MemF32_Sum) {
1716 const int kSize = 5; 1570 const int kSize = 5;
1717 TestingModule module(execution_mode); 1571 TestingModule module(execution_mode);
1718 module.AddMemoryElems<float>(kSize); 1572 module.AddMemoryElems<float>(kSize);
1719 float* buffer = module.raw_mem_start<float>(); 1573 float* buffer = module.raw_mem_start<float>();
1720 module.WriteMemory(&buffer[0], -99.25f); 1574 module.WriteMemory(&buffer[0], -99.25f);
1721 module.WriteMemory(&buffer[1], -888.25f); 1575 module.WriteMemory(&buffer[1], -888.25f);
1722 module.WriteMemory(&buffer[2], -77.25f); 1576 module.WriteMemory(&buffer[2], -77.25f);
1723 module.WriteMemory(&buffer[3], 66666.25f); 1577 module.WriteMemory(&buffer[3], 66666.25f);
1724 module.WriteMemory(&buffer[4], 5555.25f); 1578 module.WriteMemory(&buffer[4], 5555.25f);
1725 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1579 WasmRunner<int32_t> r(&module, MachineType::Int32());
1726 const byte kSum = r.AllocateLocal(kAstF32); 1580 const byte kSum = r.AllocateLocal(kAstF32);
1727 1581
1728 BUILD( 1582 BUILD(r,
1729 r, 1583 WASM_BLOCK(
1730 WASM_WHILE( 1584 WASM_WHILE(
1731 WASM_GET_LOCAL(0), 1585 WASM_GET_LOCAL(0),
1732 WASM_BLOCK( 1586 WASM_BLOCK(
1733 WASM_SET_LOCAL(kSum, 1587 WASM_SET_LOCAL(
1734 WASM_F32_ADD(WASM_GET_LOCAL(kSum), 1588 kSum, WASM_F32_ADD(WASM_GET_LOCAL(kSum),
1735 WASM_LOAD_MEM(MachineType::Float32(), 1589 WASM_LOAD_MEM(MachineType::Float32(),
1736 WASM_GET_LOCAL(0)))), 1590 WASM_GET_LOCAL(0)))),
1737 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), 1591 WASM_SET_LOCAL(
1738 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)), 1592 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))),
1739 WASM_GET_LOCAL(0)); 1593 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO,
1594 WASM_GET_LOCAL(kSum)),
1595 WASM_GET_LOCAL(0)));
1740 1596
1741 CHECK_EQ(0, r.Call(4 * (kSize - 1))); 1597 CHECK_EQ(0, r.Call(4 * (kSize - 1)));
1742 CHECK_NE(-99.25f, module.ReadMemory(&buffer[0])); 1598 CHECK_NE(-99.25f, module.ReadMemory(&buffer[0]));
1743 CHECK_EQ(71256.0f, module.ReadMemory(&buffer[0])); 1599 CHECK_EQ(71256.0f, module.ReadMemory(&buffer[0]));
1744 } 1600 }
1745 1601
1746 template <typename T> 1602 template <typename T>
1747 T GenerateAndRunFold(WasmExecutionMode execution_mode, WasmOpcode binop, 1603 T GenerateAndRunFold(WasmExecutionMode execution_mode, WasmOpcode binop,
1748 T* buffer, uint32_t size, LocalType astType, 1604 T* buffer, uint32_t size, LocalType astType,
1749 MachineType memType) { 1605 MachineType memType) {
1750 TestingModule module(execution_mode); 1606 TestingModule module(execution_mode);
1751 T* memory = module.AddMemoryElems<T>(size); 1607 T* memory = module.AddMemoryElems<T>(size);
1752 for (uint32_t i = 0; i < size; ++i) { 1608 for (uint32_t i = 0; i < size; ++i) {
1753 module.WriteMemory(&memory[i], buffer[i]); 1609 module.WriteMemory(&memory[i], buffer[i]);
1754 } 1610 }
1755 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1611 WasmRunner<int32_t> r(&module, MachineType::Int32());
1756 const byte kAccum = r.AllocateLocal(astType); 1612 const byte kAccum = r.AllocateLocal(astType);
1757 1613
1758 BUILD(r, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)), 1614 BUILD(r, WASM_BLOCK(
1759 WASM_WHILE( 1615 WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)),
1760 WASM_GET_LOCAL(0), 1616 WASM_WHILE(
1761 WASM_BLOCK(WASM_SET_LOCAL( 1617 WASM_GET_LOCAL(0),
1618 WASM_BLOCK(
1619 WASM_SET_LOCAL(
1762 kAccum, WASM_BINOP(binop, WASM_GET_LOCAL(kAccum), 1620 kAccum, WASM_BINOP(binop, WASM_GET_LOCAL(kAccum),
1763 WASM_LOAD_MEM( 1621 WASM_LOAD_MEM(
1764 memType, WASM_GET_LOCAL(0)))), 1622 memType, WASM_GET_LOCAL(0)))),
1765 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), 1623 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0),
1766 WASM_I8(sizeof(T)))))), 1624 WASM_I8(sizeof(T)))))),
1767 WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)), 1625 WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)),
1768 WASM_GET_LOCAL(0)); 1626 WASM_GET_LOCAL(0)));
1769 r.Call(static_cast<int>(sizeof(T) * (size - 1))); 1627 r.Call(static_cast<int>(sizeof(T) * (size - 1)));
1770 return module.ReadMemory(&memory[0]); 1628 return module.ReadMemory(&memory[0]);
1771 } 1629 }
1772 1630
1773 WASM_EXEC_TEST(MemF64_Mul) { 1631 WASM_EXEC_TEST(MemF64_Mul) {
1774 const size_t kSize = 6; 1632 const size_t kSize = 6;
1775 double buffer[kSize] = {1, 2, 2, 2, 2, 2}; 1633 double buffer[kSize] = {1, 2, 2, 2, 2, 2};
1776 double result = 1634 double result =
1777 GenerateAndRunFold<double>(execution_mode, kExprF64Mul, buffer, kSize, 1635 GenerateAndRunFold<double>(execution_mode, kExprF64Mul, buffer, kSize,
1778 kAstF64, MachineType::Float64()); 1636 kAstF64, MachineType::Float64());
1779 CHECK_EQ(32, result); 1637 CHECK_EQ(32, result);
1780 } 1638 }
1781 1639
1782 WASM_EXEC_TEST(Build_Wasm_Infinite_Loop) { 1640 WASM_EXEC_TEST(Build_Wasm_Infinite_Loop) {
1783 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1641 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1784 // Only build the graph and compile, don't run. 1642 // Only build the graph and compile, don't run.
1785 BUILD(r, WASM_INFINITE_LOOP); 1643 BUILD(r, WASM_INFINITE_LOOP);
1786 } 1644 }
1787 1645
1788 WASM_EXEC_TEST(Build_Wasm_Infinite_Loop_effect) { 1646 WASM_EXEC_TEST(Build_Wasm_Infinite_Loop_effect) {
1789 TestingModule module(execution_mode); 1647 TestingModule module(execution_mode);
1790 module.AddMemoryElems<int8_t>(16); 1648 module.AddMemoryElems<int8_t>(16);
1791 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1649 WasmRunner<int32_t> r(&module, MachineType::Int32());
1792 1650
1793 // Only build the graph and compile, don't run. 1651 // Only build the graph and compile, don't run.
1794 BUILD(r, WASM_LOOP(WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO), WASM_DROP), 1652 BUILD(r, WASM_LOOP(WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)));
1795 WASM_ZERO);
1796 } 1653 }
1797 1654
1798 WASM_EXEC_TEST(Unreachable0a) { 1655 WASM_EXEC_TEST(Unreachable0a) {
1799 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1656 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1800 BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I8(9)), RET(WASM_GET_LOCAL(0)))); 1657 BUILD(r, B2(WASM_BRV(0, WASM_I8(9)), RET(WASM_GET_LOCAL(0))));
1801 CHECK_EQ(9, r.Call(0)); 1658 CHECK_EQ(9, r.Call(0));
1802 CHECK_EQ(9, r.Call(1)); 1659 CHECK_EQ(9, r.Call(1));
1803 } 1660 }
1804 1661
1805 WASM_EXEC_TEST(Unreachable0b) { 1662 WASM_EXEC_TEST(Unreachable0b) {
1806 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1663 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1807 BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I8(7)), WASM_UNREACHABLE)); 1664 BUILD(r, B2(WASM_BRV(0, WASM_I8(7)), WASM_UNREACHABLE));
1808 CHECK_EQ(7, r.Call(0)); 1665 CHECK_EQ(7, r.Call(0));
1809 CHECK_EQ(7, r.Call(1)); 1666 CHECK_EQ(7, r.Call(1));
1810 } 1667 }
1811 1668
1812 TEST(Build_Wasm_Unreachable1) { 1669 TEST(Build_Wasm_Unreachable1) {
1813 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); 1670 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
1814 BUILD(r, WASM_UNREACHABLE); 1671 BUILD(r, WASM_UNREACHABLE);
1815 } 1672 }
1816 1673
1817 TEST(Build_Wasm_Unreachable2) { 1674 TEST(Build_Wasm_Unreachable2) {
(...skipping 12 matching lines...) Expand all
1830 } 1687 }
1831 1688
1832 TEST(Build_Wasm_UnreachableIf2) { 1689 TEST(Build_Wasm_UnreachableIf2) {
1833 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); 1690 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
1834 BUILD(r, WASM_UNREACHABLE, 1691 BUILD(r, WASM_UNREACHABLE,
1835 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE)); 1692 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE));
1836 } 1693 }
1837 1694
1838 WASM_EXEC_TEST(Unreachable_Load) { 1695 WASM_EXEC_TEST(Unreachable_Load) {
1839 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1696 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1840 BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)), 1697 BUILD(r, B2(WASM_BRV(0, WASM_GET_LOCAL(0)),
1841 WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0)))); 1698 WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0))));
1842 CHECK_EQ(11, r.Call(11)); 1699 CHECK_EQ(11, r.Call(11));
1843 CHECK_EQ(21, r.Call(21)); 1700 CHECK_EQ(21, r.Call(21));
1844 } 1701 }
1845 1702
1846 WASM_EXEC_TEST(Infinite_Loop_not_taken1) { 1703 WASM_EXEC_TEST(Infinite_Loop_not_taken1) {
1847 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1704 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1848 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I8(45)); 1705 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I8(45)));
1849 // Run the code, but don't go into the infinite loop. 1706 // Run the code, but don't go into the infinite loop.
1850 CHECK_EQ(45, r.Call(0)); 1707 CHECK_EQ(45, r.Call(0));
1851 } 1708 }
1852 1709
1853 WASM_EXEC_TEST(Infinite_Loop_not_taken2) { 1710 WASM_EXEC_TEST(Infinite_Loop_not_taken2) {
1854 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1711 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1855 BUILD(r, 1712 BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(45)),
1856 WASM_BLOCK_I(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(45)), 1713 WASM_INFINITE_LOOP)));
1857 WASM_INFINITE_LOOP)));
1858 // Run the code, but don't go into the infinite loop. 1714 // Run the code, but don't go into the infinite loop.
1859 CHECK_EQ(45, r.Call(1)); 1715 CHECK_EQ(45, r.Call(1));
1860 } 1716 }
1861 1717
1862 WASM_EXEC_TEST(Infinite_Loop_not_taken2_brif) { 1718 WASM_EXEC_TEST(Infinite_Loop_not_taken2_brif) {
1863 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 1719 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
1864 BUILD(r, WASM_BLOCK_I(WASM_BRV_IF(0, WASM_I8(45), WASM_GET_LOCAL(0)), 1720 BUILD(r,
1865 WASM_INFINITE_LOOP)); 1721 B2(WASM_BRV_IF(0, WASM_I8(45), WASM_GET_LOCAL(0)), WASM_INFINITE_LOOP));
1866 // Run the code, but don't go into the infinite loop. 1722 // Run the code, but don't go into the infinite loop.
1867 CHECK_EQ(45, r.Call(1)); 1723 CHECK_EQ(45, r.Call(1));
1868 } 1724 }
1869 1725
1870 static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) { 1726 static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) {
1871 Isolate* isolate = CcTest::InitIsolateOnce(); 1727 Isolate* isolate = CcTest::InitIsolateOnce();
1872 Zone zone(isolate->allocator()); 1728 Zone zone(isolate->allocator());
1873 HandleScope scope(isolate); 1729 HandleScope scope(isolate);
1874 // Enable all optional operators. 1730 // Enable all optional operators.
1875 CommonOperatorBuilder common(&zone); 1731 CommonOperatorBuilder common(&zone);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 int32_t expected = memory[i] | (memory[i + 1] << 8); 1814 int32_t expected = memory[i] | (memory[i + 1] << 8);
1959 CHECK_EQ(expected, r.Call(i)); 1815 CHECK_EQ(expected, r.Call(i));
1960 } 1816 }
1961 } 1817 }
1962 1818
1963 WASM_EXEC_TEST(Int32Global) { 1819 WASM_EXEC_TEST(Int32Global) {
1964 TestingModule module(execution_mode); 1820 TestingModule module(execution_mode);
1965 int32_t* global = module.AddGlobal<int32_t>(kAstI32); 1821 int32_t* global = module.AddGlobal<int32_t>(kAstI32);
1966 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1822 WasmRunner<int32_t> r(&module, MachineType::Int32());
1967 // global = global + p0 1823 // global = global + p0
1968 BUILD(r, 1824 BUILD(r, WASM_SET_GLOBAL(
1969 WASM_SET_GLOBAL(0, WASM_I32_ADD(WASM_GET_GLOBAL(0), WASM_GET_LOCAL(0))), 1825 0, WASM_I32_ADD(WASM_GET_GLOBAL(0), WASM_GET_LOCAL(0))));
1970 WASM_ZERO);
1971 1826
1972 *global = 116; 1827 *global = 116;
1973 for (int i = 9; i < 444444; i += 111111) { 1828 for (int i = 9; i < 444444; i += 111111) {
1974 int32_t expected = *global + i; 1829 int32_t expected = *global + i;
1975 r.Call(i); 1830 r.Call(i);
1976 CHECK_EQ(expected, *global); 1831 CHECK_EQ(expected, *global);
1977 } 1832 }
1978 } 1833 }
1979 1834
1980 WASM_EXEC_TEST(Int32Globals_DontAlias) { 1835 WASM_EXEC_TEST(Int32Globals_DontAlias) {
1981 const int kNumGlobals = 3; 1836 const int kNumGlobals = 3;
1982 TestingModule module(execution_mode); 1837 TestingModule module(execution_mode);
1983 int32_t* globals[] = {module.AddGlobal<int32_t>(kAstI32), 1838 int32_t* globals[] = {module.AddGlobal<int32_t>(kAstI32),
1984 module.AddGlobal<int32_t>(kAstI32), 1839 module.AddGlobal<int32_t>(kAstI32),
1985 module.AddGlobal<int32_t>(kAstI32)}; 1840 module.AddGlobal<int32_t>(kAstI32)};
1986 1841
1987 for (int g = 0; g < kNumGlobals; ++g) { 1842 for (int g = 0; g < kNumGlobals; ++g) {
1988 // global = global + p0 1843 // global = global + p0
1989 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1844 WasmRunner<int32_t> r(&module, MachineType::Int32());
1990 BUILD(r, WASM_SET_GLOBAL( 1845 BUILD(r, WASM_SET_GLOBAL(
1991 g, WASM_I32_ADD(WASM_GET_GLOBAL(g), WASM_GET_LOCAL(0))), 1846 g, WASM_I32_ADD(WASM_GET_GLOBAL(g), WASM_GET_LOCAL(0))));
1992 WASM_GET_GLOBAL(g));
1993 1847
1994 // Check that reading/writing global number {g} doesn't alter the others. 1848 // Check that reading/writing global number {g} doesn't alter the others.
1995 *globals[g] = 116 * g; 1849 *globals[g] = 116 * g;
1996 int32_t before[kNumGlobals]; 1850 int32_t before[kNumGlobals];
1997 for (int i = 9; i < 444444; i += 111113) { 1851 for (int i = 9; i < 444444; i += 111113) {
1998 int32_t sum = *globals[g] + i; 1852 int32_t sum = *globals[g] + i;
1999 for (int j = 0; j < kNumGlobals; ++j) before[j] = *globals[j]; 1853 for (int j = 0; j < kNumGlobals; ++j) before[j] = *globals[j];
2000 int32_t result = r.Call(i); 1854 r.Call(i);
2001 CHECK_EQ(sum, result);
2002 for (int j = 0; j < kNumGlobals; ++j) { 1855 for (int j = 0; j < kNumGlobals; ++j) {
2003 int32_t expected = j == g ? sum : before[j]; 1856 int32_t expected = j == g ? sum : before[j];
2004 CHECK_EQ(expected, *globals[j]); 1857 CHECK_EQ(expected, *globals[j]);
2005 } 1858 }
2006 } 1859 }
2007 } 1860 }
2008 } 1861 }
2009 1862
2010 WASM_EXEC_TEST(Float32Global) { 1863 WASM_EXEC_TEST(Float32Global) {
2011 TestingModule module(execution_mode); 1864 TestingModule module(execution_mode);
2012 float* global = module.AddGlobal<float>(kAstF32); 1865 float* global = module.AddGlobal<float>(kAstF32);
2013 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1866 WasmRunner<int32_t> r(&module, MachineType::Int32());
2014 // global = global + p0 1867 // global = global + p0
2015 BUILD(r, WASM_SET_GLOBAL( 1868 BUILD(r, B2(WASM_SET_GLOBAL(
2016 0, WASM_F32_ADD(WASM_GET_GLOBAL(0), 1869 0, WASM_F32_ADD(WASM_GET_GLOBAL(0),
2017 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))), 1870 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))),
2018 WASM_ZERO); 1871 WASM_ZERO));
2019 1872
2020 *global = 1.25; 1873 *global = 1.25;
2021 for (int i = 9; i < 4444; i += 1111) { 1874 for (int i = 9; i < 4444; i += 1111) {
2022 volatile float expected = *global + i; 1875 volatile float expected = *global + i;
2023 r.Call(i); 1876 r.Call(i);
2024 CHECK_EQ(expected, *global); 1877 CHECK_EQ(expected, *global);
2025 } 1878 }
2026 } 1879 }
2027 1880
2028 WASM_EXEC_TEST(Float64Global) { 1881 WASM_EXEC_TEST(Float64Global) {
2029 TestingModule module(execution_mode); 1882 TestingModule module(execution_mode);
2030 double* global = module.AddGlobal<double>(kAstF64); 1883 double* global = module.AddGlobal<double>(kAstF64);
2031 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1884 WasmRunner<int32_t> r(&module, MachineType::Int32());
2032 // global = global + p0 1885 // global = global + p0
2033 BUILD(r, WASM_SET_GLOBAL( 1886 BUILD(r, B2(WASM_SET_GLOBAL(
2034 0, WASM_F64_ADD(WASM_GET_GLOBAL(0), 1887 0, WASM_F64_ADD(WASM_GET_GLOBAL(0),
2035 WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))), 1888 WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))),
2036 WASM_ZERO); 1889 WASM_ZERO));
2037 1890
2038 *global = 1.25; 1891 *global = 1.25;
2039 for (int i = 9; i < 4444; i += 1111) { 1892 for (int i = 9; i < 4444; i += 1111) {
2040 volatile double expected = *global + i; 1893 volatile double expected = *global + i;
2041 r.Call(i); 1894 r.Call(i);
2042 CHECK_EQ(expected, *global); 1895 CHECK_EQ(expected, *global);
2043 } 1896 }
2044 } 1897 }
2045 1898
2046 WASM_EXEC_TEST(MixedGlobals) { 1899 WASM_EXEC_TEST(MixedGlobals) {
2047 TestingModule module(execution_mode); 1900 TestingModule module(execution_mode);
2048 int32_t* unused = module.AddGlobal<int32_t>(kAstI32); 1901 int32_t* unused = module.AddGlobal<int32_t>(kAstI32);
2049 byte* memory = module.AddMemory(32); 1902 byte* memory = module.AddMemory(32);
2050 1903
2051 int32_t* var_int32 = module.AddGlobal<int32_t>(kAstI32); 1904 int32_t* var_int32 = module.AddGlobal<int32_t>(kAstI32);
2052 uint32_t* var_uint32 = module.AddGlobal<uint32_t>(kAstI32); 1905 uint32_t* var_uint32 = module.AddGlobal<uint32_t>(kAstI32);
2053 float* var_float = module.AddGlobal<float>(kAstF32); 1906 float* var_float = module.AddGlobal<float>(kAstF32);
2054 double* var_double = module.AddGlobal<double>(kAstF64); 1907 double* var_double = module.AddGlobal<double>(kAstF64);
2055 1908
2056 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1909 WasmRunner<int32_t> r(&module, MachineType::Int32());
2057 1910
2058 BUILD(r, WASM_SET_GLOBAL(1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), 1911 BUILD(
2059 WASM_SET_GLOBAL(2, WASM_LOAD_MEM(MachineType::Uint32(), WASM_ZERO)), 1912 r,
2060 WASM_SET_GLOBAL(3, WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO)), 1913 WASM_BLOCK(
2061 WASM_SET_GLOBAL(4, WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)), 1914 WASM_SET_GLOBAL(1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)),
2062 WASM_ZERO); 1915 WASM_SET_GLOBAL(2, WASM_LOAD_MEM(MachineType::Uint32(), WASM_ZERO)),
1916 WASM_SET_GLOBAL(3, WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO)),
1917 WASM_SET_GLOBAL(4, WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)),
1918 WASM_ZERO));
2063 1919
2064 memory[0] = 0xaa; 1920 memory[0] = 0xaa;
2065 memory[1] = 0xcc; 1921 memory[1] = 0xcc;
2066 memory[2] = 0x55; 1922 memory[2] = 0x55;
2067 memory[3] = 0xee; 1923 memory[3] = 0xee;
2068 memory[4] = 0x33; 1924 memory[4] = 0x33;
2069 memory[5] = 0x22; 1925 memory[5] = 0x22;
2070 memory[6] = 0x11; 1926 memory[6] = 0x11;
2071 memory[7] = 0x99; 1927 memory[7] = 0x99;
2072 r.Call(1); 1928 r.Call(1);
(...skipping 28 matching lines...) Expand all
2101 LocalType param_types[20]; 1957 LocalType param_types[20];
2102 for (int i = 0; i < 20; ++i) param_types[i] = kAstF32; 1958 for (int i = 0; i < 20; ++i) param_types[i] = kAstF32;
2103 FunctionSig sig(1, 19, param_types); 1959 FunctionSig sig(1, 19, param_types);
2104 TestingModule module(execution_mode); 1960 TestingModule module(execution_mode);
2105 WasmFunctionCompiler t(&sig, &module); 1961 WasmFunctionCompiler t(&sig, &module);
2106 BUILD(t, WASM_GET_LOCAL(17)); 1962 BUILD(t, WASM_GET_LOCAL(17));
2107 uint32_t index = t.CompileAndAdd(); 1963 uint32_t index = t.CompileAndAdd();
2108 1964
2109 // Build the calling function. 1965 // Build the calling function.
2110 WasmRunner<float> r(&module); 1966 WasmRunner<float> r(&module);
2111 BUILD(r, WASM_CALL_FUNCTION( 1967 BUILD(r, WASM_CALL_FUNCTIONN(
2112 index, WASM_F32(1.0f), WASM_F32(2.0f), WASM_F32(4.0f), 1968 19, index, WASM_F32(1.0f), WASM_F32(2.0f), WASM_F32(4.0f),
2113 WASM_F32(8.0f), WASM_F32(16.0f), WASM_F32(32.0f), 1969 WASM_F32(8.0f), WASM_F32(16.0f), WASM_F32(32.0f),
2114 WASM_F32(64.0f), WASM_F32(128.0f), WASM_F32(256.0f), 1970 WASM_F32(64.0f), WASM_F32(128.0f), WASM_F32(256.0f),
2115 WASM_F32(1.5f), WASM_F32(2.5f), WASM_F32(4.5f), WASM_F32(8.5f), 1971 WASM_F32(1.5f), WASM_F32(2.5f), WASM_F32(4.5f), WASM_F32(8.5f),
2116 WASM_F32(16.5f), WASM_F32(32.5f), WASM_F32(64.5f), 1972 WASM_F32(16.5f), WASM_F32(32.5f), WASM_F32(64.5f),
2117 WASM_F32(128.5f), WASM_F32(256.5f), WASM_F32(512.5f))); 1973 WASM_F32(128.5f), WASM_F32(256.5f), WASM_F32(512.5f)));
2118 1974
2119 float result = r.Call(); 1975 float result = r.Call();
2120 CHECK_EQ(256.5f, result); 1976 CHECK_EQ(256.5f, result);
2121 } 1977 }
2122 1978
2123 WASM_EXEC_TEST(CallF64StackParameter) { 1979 WASM_EXEC_TEST(CallF64StackParameter) {
2124 // Build the target function. 1980 // Build the target function.
2125 LocalType param_types[20]; 1981 LocalType param_types[20];
2126 for (int i = 0; i < 20; ++i) param_types[i] = kAstF64; 1982 for (int i = 0; i < 20; ++i) param_types[i] = kAstF64;
2127 FunctionSig sig(1, 19, param_types); 1983 FunctionSig sig(1, 19, param_types);
2128 TestingModule module(execution_mode); 1984 TestingModule module(execution_mode);
2129 WasmFunctionCompiler t(&sig, &module); 1985 WasmFunctionCompiler t(&sig, &module);
2130 BUILD(t, WASM_GET_LOCAL(17)); 1986 BUILD(t, WASM_GET_LOCAL(17));
2131 uint32_t index = t.CompileAndAdd(); 1987 uint32_t index = t.CompileAndAdd();
2132 1988
2133 // Build the calling function. 1989 // Build the calling function.
2134 WasmRunner<double> r(&module); 1990 WasmRunner<double> r(&module);
2135 BUILD(r, WASM_CALL_FUNCTION(index, WASM_F64(1.0), WASM_F64(2.0), 1991 BUILD(r, WASM_CALL_FUNCTIONN(19, index, WASM_F64(1.0), WASM_F64(2.0),
2136 WASM_F64(4.0), WASM_F64(8.0), WASM_F64(16.0), 1992 WASM_F64(4.0), WASM_F64(8.0), WASM_F64(16.0),
2137 WASM_F64(32.0), WASM_F64(64.0), WASM_F64(128.0), 1993 WASM_F64(32.0), WASM_F64(64.0), WASM_F64(128.0),
2138 WASM_F64(256.0), WASM_F64(1.5), WASM_F64(2.5), 1994 WASM_F64(256.0), WASM_F64(1.5), WASM_F64(2.5),
2139 WASM_F64(4.5), WASM_F64(8.5), WASM_F64(16.5), 1995 WASM_F64(4.5), WASM_F64(8.5), WASM_F64(16.5),
2140 WASM_F64(32.5), WASM_F64(64.5), WASM_F64(128.5), 1996 WASM_F64(32.5), WASM_F64(64.5), WASM_F64(128.5),
2141 WASM_F64(256.5), WASM_F64(512.5))); 1997 WASM_F64(256.5), WASM_F64(512.5)));
2142 1998
2143 float result = r.Call(); 1999 float result = r.Call();
2144 CHECK_EQ(256.5, result); 2000 CHECK_EQ(256.5, result);
2145 } 2001 }
2146 2002
2147 WASM_EXEC_TEST(CallVoid) { 2003 WASM_EXEC_TEST(CallVoid) {
2148 const byte kMemOffset = 8; 2004 const byte kMemOffset = 8;
2149 const int32_t kElemNum = kMemOffset / sizeof(int32_t); 2005 const int32_t kElemNum = kMemOffset / sizeof(int32_t);
2150 const int32_t kExpected = 414444; 2006 const int32_t kExpected = 414444;
2151 // Build the target function. 2007 // Build the target function.
(...skipping 20 matching lines...) Expand all
2172 WASM_EXEC_TEST(Call_Int32Add) { 2028 WASM_EXEC_TEST(Call_Int32Add) {
2173 // Build the target function. 2029 // Build the target function.
2174 TestSignatures sigs; 2030 TestSignatures sigs;
2175 TestingModule module(execution_mode); 2031 TestingModule module(execution_mode);
2176 WasmFunctionCompiler t(sigs.i_ii(), &module); 2032 WasmFunctionCompiler t(sigs.i_ii(), &module);
2177 BUILD(t, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2033 BUILD(t, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2178 uint32_t index = t.CompileAndAdd(); 2034 uint32_t index = t.CompileAndAdd();
2179 2035
2180 // Build the caller function. 2036 // Build the caller function.
2181 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32()); 2037 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
2182 BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2038 BUILD(r, WASM_CALL_FUNCTION2(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2183 2039
2184 FOR_INT32_INPUTS(i) { 2040 FOR_INT32_INPUTS(i) {
2185 FOR_INT32_INPUTS(j) { 2041 FOR_INT32_INPUTS(j) {
2186 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) + 2042 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) +
2187 static_cast<uint32_t>(*j)); 2043 static_cast<uint32_t>(*j));
2188 CHECK_EQ(expected, r.Call(*i, *j)); 2044 CHECK_EQ(expected, r.Call(*i, *j));
2189 } 2045 }
2190 } 2046 }
2191 } 2047 }
2192 2048
2193 WASM_EXEC_TEST(Call_Float32Sub) { 2049 WASM_EXEC_TEST(Call_Float32Sub) {
2194 TestSignatures sigs; 2050 TestSignatures sigs;
2195 TestingModule module(execution_mode); 2051 TestingModule module(execution_mode);
2196 WasmFunctionCompiler t(sigs.f_ff(), &module); 2052 WasmFunctionCompiler t(sigs.f_ff(), &module);
2197 2053
2198 // Build the target function. 2054 // Build the target function.
2199 BUILD(t, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2055 BUILD(t, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2200 uint32_t index = t.CompileAndAdd(); 2056 uint32_t index = t.CompileAndAdd();
2201 2057
2202 // Builder the caller function. 2058 // Builder the caller function.
2203 WasmRunner<float> r(&module, MachineType::Float32(), MachineType::Float32()); 2059 WasmRunner<float> r(&module, MachineType::Float32(), MachineType::Float32());
2204 BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2060 BUILD(r, WASM_CALL_FUNCTION2(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2205 2061
2206 FOR_FLOAT32_INPUTS(i) { 2062 FOR_FLOAT32_INPUTS(i) {
2207 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(*i - *j, r.Call(*i, *j)); } 2063 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(*i - *j, r.Call(*i, *j)); }
2208 } 2064 }
2209 } 2065 }
2210 2066
2211 WASM_EXEC_TEST(Call_Float64Sub) { 2067 WASM_EXEC_TEST(Call_Float64Sub) {
2212 TestingModule module(execution_mode); 2068 TestingModule module(execution_mode);
2213 double* memory = module.AddMemoryElems<double>(16); 2069 double* memory = module.AddMemoryElems<double>(16);
2214 WasmRunner<int32_t> r(&module); 2070 WasmRunner<int32_t> r(&module);
2215 2071
2216 BUILD(r, WASM_STORE_MEM( 2072 BUILD(r,
2217 MachineType::Float64(), WASM_ZERO, 2073 WASM_BLOCK(WASM_STORE_MEM(
2218 WASM_F64_SUB(WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO), 2074 MachineType::Float64(), WASM_ZERO,
2219 WASM_LOAD_MEM(MachineType::Float64(), WASM_I8(8)))), 2075 WASM_F64_SUB(
2220 WASM_I8(107)); 2076 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO),
2077 WASM_LOAD_MEM(MachineType::Float64(), WASM_I8(8)))),
2078 WASM_I8(107)));
2221 2079
2222 FOR_FLOAT64_INPUTS(i) { 2080 FOR_FLOAT64_INPUTS(i) {
2223 FOR_FLOAT64_INPUTS(j) { 2081 FOR_FLOAT64_INPUTS(j) {
2224 module.WriteMemory(&memory[0], *i); 2082 module.WriteMemory(&memory[0], *i);
2225 module.WriteMemory(&memory[1], *j); 2083 module.WriteMemory(&memory[1], *j);
2226 double expected = *i - *j; 2084 double expected = *i - *j;
2227 CHECK_EQ(107, r.Call()); 2085 CHECK_EQ(107, r.Call());
2228 2086
2229 if (expected != expected) { 2087 if (expected != expected) {
2230 CHECK(module.ReadMemory(&memory[0]) != module.ReadMemory(&memory[0])); 2088 CHECK(module.ReadMemory(&memory[0]) != module.ReadMemory(&memory[0]));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2284 // Load the offset for the store. 2142 // Load the offset for the store.
2285 ADD_CODE(code, WASM_ZERO); 2143 ADD_CODE(code, WASM_ZERO);
2286 2144
2287 // Load the arguments. 2145 // Load the arguments.
2288 for (int i = 0; i < num_params; ++i) { 2146 for (int i = 0; i < num_params; ++i) {
2289 int offset = (i + 1) * kElemSize; 2147 int offset = (i + 1) * kElemSize;
2290 ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset))); 2148 ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset)));
2291 } 2149 }
2292 2150
2293 // Call the selector function. 2151 // Call the selector function.
2294 ADD_CODE(code, kExprCallFunction, static_cast<byte>(index)); 2152 ADD_CODE(code, kExprCallFunction, static_cast<byte>(num_params),
2153 static_cast<byte>(index));
2295 2154
2296 // Store the result in memory. 2155 // Store the result in memory.
2297 ADD_CODE(code, 2156 ADD_CODE(code,
2298 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(result, true)), 2157 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(result, true)),
2299 ZERO_ALIGNMENT, ZERO_OFFSET); 2158 ZERO_ALIGNMENT, ZERO_OFFSET);
2300 2159
2301 // Return the expected value. 2160 // Return the expected value.
2302 ADD_CODE(code, WASM_I32V_2(kExpected)); 2161 ADD_CODE(code, WASM_I32V_2(kExpected));
2303 2162
2304 r.Build(&code[0], &code[0] + code.size()); 2163 r.Build(&code[0], &code[0] + code.size());
(...skipping 21 matching lines...) Expand all
2326 2185
2327 WASM_EXEC_TEST(AddCall) { 2186 WASM_EXEC_TEST(AddCall) {
2328 TestSignatures sigs; 2187 TestSignatures sigs;
2329 TestingModule module(execution_mode); 2188 TestingModule module(execution_mode);
2330 WasmFunctionCompiler t1(sigs.i_ii(), &module); 2189 WasmFunctionCompiler t1(sigs.i_ii(), &module);
2331 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2190 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2332 t1.CompileAndAdd(); 2191 t1.CompileAndAdd();
2333 2192
2334 WasmRunner<int32_t> r(&module, MachineType::Int32()); 2193 WasmRunner<int32_t> r(&module, MachineType::Int32());
2335 byte local = r.AllocateLocal(kAstI32); 2194 byte local = r.AllocateLocal(kAstI32);
2336 BUILD(r, WASM_SET_LOCAL(local, WASM_I8(99)), 2195 BUILD(r, B2(WASM_SET_LOCAL(local, WASM_I8(99)),
2337 WASM_I32_ADD(WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(0), 2196 WASM_I32_ADD(
2338 WASM_GET_LOCAL(0)), 2197 WASM_CALL_FUNCTION2(t1.function_index(), WASM_GET_LOCAL(0),
2339 WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(1), 2198 WASM_GET_LOCAL(0)),
2340 WASM_GET_LOCAL(local)))); 2199 WASM_CALL_FUNCTION2(t1.function_index(), WASM_GET_LOCAL(1),
2200 WASM_GET_LOCAL(local)))));
2341 2201
2342 CHECK_EQ(198, r.Call(0)); 2202 CHECK_EQ(198, r.Call(0));
2343 CHECK_EQ(200, r.Call(1)); 2203 CHECK_EQ(200, r.Call(1));
2344 CHECK_EQ(100, r.Call(-49)); 2204 CHECK_EQ(100, r.Call(-49));
2345 } 2205 }
2346 2206
2347 WASM_EXEC_TEST(MultiReturnSub) { 2207 WASM_EXEC_TEST(CountDown_expr) {
2348 FLAG_wasm_mv_prototype = true; 2208 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
2349 LocalType storage[] = {kAstI32, kAstI32, kAstI32, kAstI32}; 2209 BUILD(r, WASM_LOOP(
2350 FunctionSig sig_ii_ii(2, 2, storage); 2210 WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)),
2351 TestingModule module(execution_mode); 2211 WASM_BREAKV(1, WASM_GET_LOCAL(0))),
2352 WasmFunctionCompiler t1(&sig_ii_ii, &module); 2212 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))),
2353 BUILD(t1, WASM_GET_LOCAL(1), WASM_GET_LOCAL(0)); 2213 WASM_CONTINUE(0)));
2354 t1.CompileAndAdd(); 2214 CHECK_EQ(0, r.Call(1));
2355 2215 CHECK_EQ(0, r.Call(10));
2356 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32()); 2216 CHECK_EQ(0, r.Call(100));
2357 BUILD(r, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), kExprCallFunction, 0,
2358 kExprI32Sub);
2359
2360 FOR_INT32_INPUTS(i) {
2361 FOR_INT32_INPUTS(j) {
2362 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*j) -
2363 static_cast<uint32_t>(*i));
2364 CHECK_EQ(expected, r.Call(*i, *j));
2365 }
2366 }
2367 }
2368
2369 template <typename T>
2370 void RunMultiReturnSelect(WasmExecutionMode execution_mode, LocalType type,
2371 const T* inputs) {
2372 FLAG_wasm_mv_prototype = true;
2373 LocalType storage[] = {type, type, type, type, type, type};
2374 const size_t kNumReturns = 2;
2375 const size_t kNumParams = arraysize(storage) - kNumReturns;
2376 FunctionSig sig(kNumReturns, kNumParams, storage);
2377
2378 for (size_t i = 0; i < kNumParams; i++) {
2379 for (size_t j = 0; j < kNumParams; j++) {
2380 for (int k = 0; k < 2; k++) {
2381 TestingModule module(execution_mode);
2382 WasmFunctionCompiler r1(&sig, &module);
2383
2384 BUILD(r1, WASM_GET_LOCAL(i), WASM_GET_LOCAL(j));
2385 r1.CompileAndAdd();
2386
2387 MachineType machine_type = WasmOpcodes::MachineTypeFor(type);
2388 WasmRunner<T> r2(&module, machine_type, machine_type, machine_type,
2389 machine_type);
2390
2391 if (k == 0) {
2392 BUILD(r2, WASM_CALL_FUNCTION(r1.function_index(), WASM_GET_LOCAL(0),
2393 WASM_GET_LOCAL(1), WASM_GET_LOCAL(2),
2394 WASM_GET_LOCAL(3)),
2395 WASM_DROP);
2396 } else {
2397 BUILD(r2, WASM_CALL_FUNCTION(r1.function_index(), WASM_GET_LOCAL(0),
2398 WASM_GET_LOCAL(1), WASM_GET_LOCAL(2),
2399 WASM_GET_LOCAL(3)),
2400 kExprSetLocal, 0, WASM_DROP, WASM_GET_LOCAL(0));
2401 }
2402
2403 T expected = inputs[k == 0 ? i : j];
2404 CHECK_EQ(expected, r2.Call(inputs[0], inputs[1], inputs[2], inputs[3]));
2405 }
2406 }
2407 }
2408 }
2409
2410 WASM_EXEC_TEST(MultiReturnSelect_i32) {
2411 static const int32_t inputs[] = {3333333, 4444444, -55555555, -7777777};
2412 RunMultiReturnSelect<int32_t>(execution_mode, kAstI32, inputs);
2413 }
2414
2415 WASM_EXEC_TEST(MultiReturnSelect_f32) {
2416 static const float inputs[] = {33.33333f, 444.4444f, -55555.555f, -77777.77f};
2417 RunMultiReturnSelect<float>(execution_mode, kAstF32, inputs);
2418 }
2419
2420 WASM_EXEC_TEST(MultiReturnSelect_i64) {
2421 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64
2422 // TODO(titzer): implement int64-lowering for multiple return values
2423 static const int64_t inputs[] = {33333338888, 44444446666, -555555553333,
2424 -77777771111};
2425 RunMultiReturnSelect<int64_t>(execution_mode, kAstI64, inputs);
2426 #endif
2427 }
2428
2429 WASM_EXEC_TEST(MultiReturnSelect_f64) {
2430 static const double inputs[] = {3.333333, 44444.44, -55.555555, -7777.777};
2431 RunMultiReturnSelect<double>(execution_mode, kAstF64, inputs);
2432 } 2217 }
2433 2218
2434 WASM_EXEC_TEST(ExprBlock2a) { 2219 WASM_EXEC_TEST(ExprBlock2a) {
2435 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 2220 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
2436 BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), 2221 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), WASM_I8(1)));
2437 WASM_I8(1)));
2438 CHECK_EQ(1, r.Call(0)); 2222 CHECK_EQ(1, r.Call(0));
2439 CHECK_EQ(1, r.Call(1)); 2223 CHECK_EQ(1, r.Call(1));
2440 } 2224 }
2441 2225
2442 WASM_EXEC_TEST(ExprBlock2b) { 2226 WASM_EXEC_TEST(ExprBlock2b) {
2443 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 2227 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
2444 BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), 2228 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), WASM_I8(2)));
2445 WASM_I8(2)));
2446 CHECK_EQ(2, r.Call(0)); 2229 CHECK_EQ(2, r.Call(0));
2447 CHECK_EQ(1, r.Call(1)); 2230 CHECK_EQ(1, r.Call(1));
2448 } 2231 }
2449 2232
2450 WASM_EXEC_TEST(ExprBlock2c) { 2233 WASM_EXEC_TEST(ExprBlock2c) {
2451 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 2234 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
2452 BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(1), WASM_GET_LOCAL(0)), 2235 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), WASM_I8(1)));
2453 WASM_I8(1)));
2454 CHECK_EQ(1, r.Call(0)); 2236 CHECK_EQ(1, r.Call(0));
2455 CHECK_EQ(1, r.Call(1)); 2237 CHECK_EQ(1, r.Call(1));
2456 } 2238 }
2457 2239
2458 WASM_EXEC_TEST(ExprBlock2d) { 2240 WASM_EXEC_TEST(ExprBlock2d) {
2459 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 2241 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
2460 BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(1), WASM_GET_LOCAL(0)), 2242 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), WASM_I8(2)));
2461 WASM_I8(2)));
2462 CHECK_EQ(2, r.Call(0)); 2243 CHECK_EQ(2, r.Call(0));
2463 CHECK_EQ(1, r.Call(1)); 2244 CHECK_EQ(1, r.Call(1));
2464 } 2245 }
2465 2246
2466 WASM_EXEC_TEST(ExprBlock_ManualSwitch) { 2247 WASM_EXEC_TEST(ExprBlock_ManualSwitch) {
2467 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 2248 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
2468 BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1)), 2249 BUILD(r, WASM_BLOCK(WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1)),
2469 WASM_BRV(1, WASM_I8(11))), 2250 WASM_BRV(1, WASM_I8(11))),
2470 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2)), 2251 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2)),
2471 WASM_BRV(1, WASM_I8(12))), 2252 WASM_BRV(1, WASM_I8(12))),
2472 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3)), 2253 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3)),
2473 WASM_BRV(1, WASM_I8(13))), 2254 WASM_BRV(1, WASM_I8(13))),
2474 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4)), 2255 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4)),
2475 WASM_BRV(1, WASM_I8(14))), 2256 WASM_BRV(1, WASM_I8(14))),
2476 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5)), 2257 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5)),
2477 WASM_BRV(1, WASM_I8(15))), 2258 WASM_BRV(1, WASM_I8(15))),
2478 WASM_I8(99))); 2259 WASM_I8(99)));
2479 CHECK_EQ(99, r.Call(0)); 2260 CHECK_EQ(99, r.Call(0));
2480 CHECK_EQ(11, r.Call(1)); 2261 CHECK_EQ(11, r.Call(1));
2481 CHECK_EQ(12, r.Call(2)); 2262 CHECK_EQ(12, r.Call(2));
2482 CHECK_EQ(13, r.Call(3)); 2263 CHECK_EQ(13, r.Call(3));
2483 CHECK_EQ(14, r.Call(4)); 2264 CHECK_EQ(14, r.Call(4));
2484 CHECK_EQ(15, r.Call(5)); 2265 CHECK_EQ(15, r.Call(5));
2485 CHECK_EQ(99, r.Call(6)); 2266 CHECK_EQ(99, r.Call(6));
2486 } 2267 }
2487 2268
2488 WASM_EXEC_TEST(ExprBlock_ManualSwitch_brif) { 2269 WASM_EXEC_TEST(ExprBlock_ManualSwitch_brif) {
2489 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 2270 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
2490 BUILD(r, 2271 BUILD(r, WASM_BLOCK(WASM_BRV_IF(0, WASM_I8(11),
2491 WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(11),
2492 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1))), 2272 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1))),
2493 WASM_BRV_IFD(0, WASM_I8(12), 2273 WASM_BRV_IF(0, WASM_I8(12),
2494 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2))), 2274 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2))),
2495 WASM_BRV_IFD(0, WASM_I8(13), 2275 WASM_BRV_IF(0, WASM_I8(13),
2496 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3))), 2276 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3))),
2497 WASM_BRV_IFD(0, WASM_I8(14), 2277 WASM_BRV_IF(0, WASM_I8(14),
2498 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4))), 2278 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4))),
2499 WASM_BRV_IFD(0, WASM_I8(15), 2279 WASM_BRV_IF(0, WASM_I8(15),
2500 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5))), 2280 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5))),
2501 WASM_I8(99))); 2281 WASM_I8(99)));
2502 CHECK_EQ(99, r.Call(0)); 2282 CHECK_EQ(99, r.Call(0));
2503 CHECK_EQ(11, r.Call(1)); 2283 CHECK_EQ(11, r.Call(1));
2504 CHECK_EQ(12, r.Call(2)); 2284 CHECK_EQ(12, r.Call(2));
2505 CHECK_EQ(13, r.Call(3)); 2285 CHECK_EQ(13, r.Call(3));
2506 CHECK_EQ(14, r.Call(4)); 2286 CHECK_EQ(14, r.Call(4));
2507 CHECK_EQ(15, r.Call(5)); 2287 CHECK_EQ(15, r.Call(5));
2508 CHECK_EQ(99, r.Call(6)); 2288 CHECK_EQ(99, r.Call(6));
2509 } 2289 }
2510 2290
2511 WASM_EXEC_TEST(If_nested) { 2291 WASM_EXEC_TEST(nested_ifs) {
2512 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), 2292 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
2513 MachineType::Int32()); 2293 MachineType::Int32());
2514 2294
2515 BUILD(r, WASM_IF_ELSE_I( 2295 BUILD(r, WASM_IF_ELSE(
2516 WASM_GET_LOCAL(0), 2296 WASM_GET_LOCAL(0),
2517 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)), 2297 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)),
2518 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14)))); 2298 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14))));
2519 2299
2520 CHECK_EQ(11, r.Call(1, 1)); 2300 CHECK_EQ(11, r.Call(1, 1));
2521 CHECK_EQ(12, r.Call(1, 0)); 2301 CHECK_EQ(12, r.Call(1, 0));
2522 CHECK_EQ(13, r.Call(0, 1)); 2302 CHECK_EQ(13, r.Call(0, 1));
2523 CHECK_EQ(14, r.Call(0, 0)); 2303 CHECK_EQ(14, r.Call(0, 0));
2524 } 2304 }
2525 2305
2526 WASM_EXEC_TEST(ExprBlock_if) { 2306 WASM_EXEC_TEST(ExprBlock_if) {
2527 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 2307 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
2528 2308
2529 BUILD(r, 2309 BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(11)),
2530 WASM_BLOCK_I(WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(11)), 2310 WASM_BRV(1, WASM_I8(14)))));
2531 WASM_BRV(1, WASM_I8(14)))));
2532 2311
2533 CHECK_EQ(11, r.Call(1)); 2312 CHECK_EQ(11, r.Call(1));
2534 CHECK_EQ(14, r.Call(0)); 2313 CHECK_EQ(14, r.Call(0));
2535 } 2314 }
2536 2315
2537 WASM_EXEC_TEST(ExprBlock_nested_ifs) { 2316 WASM_EXEC_TEST(ExprBlock_nested_ifs) {
2538 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), 2317 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
2539 MachineType::Int32()); 2318 MachineType::Int32());
2540 2319
2541 BUILD(r, WASM_BLOCK_I(WASM_IF_ELSE_I( 2320 BUILD(r, WASM_BLOCK(WASM_IF_ELSE(
2542 WASM_GET_LOCAL(0), 2321 WASM_GET_LOCAL(0),
2543 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(11)), 2322 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(11)),
2544 WASM_BRV(1, WASM_I8(12))), 2323 WASM_BRV(1, WASM_I8(12))),
2545 WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(13)), 2324 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(13)),
2546 WASM_BRV(1, WASM_I8(14)))))); 2325 WASM_BRV(1, WASM_I8(14))))));
2547 2326
2548 CHECK_EQ(11, r.Call(1, 1)); 2327 CHECK_EQ(11, r.Call(1, 1));
2549 CHECK_EQ(12, r.Call(1, 0)); 2328 CHECK_EQ(12, r.Call(1, 0));
2329 CHECK_EQ(13, r.Call(0, 1));
2330 CHECK_EQ(14, r.Call(0, 0));
2331 }
2332
2333 WASM_EXEC_TEST(ExprLoop_nested_ifs) {
2334 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
2335 MachineType::Int32());
2336
2337 BUILD(r, WASM_LOOP(WASM_IF_ELSE(
2338 WASM_GET_LOCAL(0),
2339 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(1, WASM_I8(11)),
2340 WASM_BRV(3, WASM_I8(12))),
2341 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(1, WASM_I8(13)),
2342 WASM_BRV(3, WASM_I8(14))))));
2343
2344 CHECK_EQ(11, r.Call(1, 1));
2345 CHECK_EQ(12, r.Call(1, 0));
2550 CHECK_EQ(13, r.Call(0, 1)); 2346 CHECK_EQ(13, r.Call(0, 1));
2551 CHECK_EQ(14, r.Call(0, 0)); 2347 CHECK_EQ(14, r.Call(0, 0));
2552 } 2348 }
2553 2349
2554 WASM_EXEC_TEST(SimpleCallIndirect) { 2350 WASM_EXEC_TEST(SimpleCallIndirect) {
2555 TestSignatures sigs; 2351 TestSignatures sigs;
2556 TestingModule module(execution_mode); 2352 TestingModule module(execution_mode);
2557 2353
2558 WasmFunctionCompiler t1(sigs.i_ii(), &module); 2354 WasmFunctionCompiler t1(sigs.i_ii(), &module);
2559 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2355 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
2851 TestingModule module(kExecuteCompiled); 2647 TestingModule module(kExecuteCompiled);
2852 FunctionSig* sig = sigs.many(&zone, kAstStmt, param, num_params); 2648 FunctionSig* sig = sigs.many(&zone, kAstStmt, param, num_params);
2853 2649
2854 module.AddSignature(sig); 2650 module.AddSignature(sig);
2855 module.AddSignature(sig); 2651 module.AddSignature(sig);
2856 module.AddIndirectFunctionTable(nullptr, 0); 2652 module.AddIndirectFunctionTable(nullptr, 0);
2857 2653
2858 WasmFunctionCompiler t(sig, &module); 2654 WasmFunctionCompiler t(sig, &module);
2859 2655
2860 std::vector<byte> code; 2656 std::vector<byte> code;
2657 ADD_CODE(code, kExprI8Const, 0);
2861 for (byte p = 0; p < num_params; ++p) { 2658 for (byte p = 0; p < num_params; ++p) {
2862 ADD_CODE(code, kExprGetLocal, p); 2659 ADD_CODE(code, kExprGetLocal, p);
2863 } 2660 }
2864 ADD_CODE(code, kExprI8Const, 0); 2661 ADD_CODE(code, kExprCallIndirect, static_cast<byte>(num_params), 1);
2865 ADD_CODE(code, kExprCallIndirect, 1);
2866 2662
2867 t.Build(&code[0], &code[0] + code.size()); 2663 t.Build(&code[0], &code[0] + code.size());
2868 t.Compile(); 2664 t.Compile();
2869 } 2665 }
2870 } 2666 }
2871 2667
2872 TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kAstI32); } 2668 TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kAstI32); }
2873 2669
2874 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } 2670 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); }
2875 2671
2876 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } 2672 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); }
2877 2673
2878 WASM_EXEC_TEST(Int32RemS_dead) { 2674 WASM_EXEC_TEST(Int32RemS_dead) {
2879 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), 2675 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
2880 MachineType::Int32()); 2676 MachineType::Int32());
2881 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP, 2677 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO);
2882 WASM_ZERO);
2883 const int32_t kMin = std::numeric_limits<int32_t>::min(); 2678 const int32_t kMin = std::numeric_limits<int32_t>::min();
2884 CHECK_EQ(0, r.Call(133, 100)); 2679 CHECK_EQ(0, r.Call(133, 100));
2885 CHECK_EQ(0, r.Call(kMin, -1)); 2680 CHECK_EQ(0, r.Call(kMin, -1));
2886 CHECK_EQ(0, r.Call(0, 1)); 2681 CHECK_EQ(0, r.Call(0, 1));
2887 CHECK_TRAP(r.Call(100, 0)); 2682 CHECK_TRAP(r.Call(100, 0));
2888 CHECK_TRAP(r.Call(-1001, 0)); 2683 CHECK_TRAP(r.Call(-1001, 0));
2889 CHECK_TRAP(r.Call(kMin, 0)); 2684 CHECK_TRAP(r.Call(kMin, 0));
2890 } 2685 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-result.h ('k') | test/cctest/wasm/test-run-wasm-64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698