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

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

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