OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdint.h> | 5 #include <stdint.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "src/base/platform/elapsed-timer.h" | 9 #include "src/base/platform/elapsed-timer.h" |
10 | 10 |
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 B2(a, b) kExprBlock, a, b, kExprEnd |
25 #define B1(a) kExprBlock, a, kExprEnd | 25 #define B1(a) kExprBlock, a, kExprEnd |
26 #define RET(x) x, kExprReturn, 1 | 26 #define RET(x) x, kExprReturn, 1 |
27 #define RET_I8(x) kExprI8Const, x, kExprReturn, 1 | 27 #define RET_I8(x) kExprI8Const, x, kExprReturn, 1 |
28 | 28 |
29 WASM_EXEC_TEST(Int8Const) { | 29 WASM_EXEC_TEST(Int8Const) { |
30 WasmRunner<int32_t> r; | 30 WasmRunner<int32_t> r(execution_mode); |
31 const byte kExpectedValue = 121; | 31 const byte kExpectedValue = 121; |
32 // return(kExpectedValue) | 32 // return(kExpectedValue) |
33 BUILD(r, WASM_I8(kExpectedValue)); | 33 BUILD(r, WASM_I8(kExpectedValue)); |
34 CHECK_EQ(kExpectedValue, r.Call()); | 34 CHECK_EQ(kExpectedValue, r.Call()); |
35 } | 35 } |
36 | 36 |
37 WASM_EXEC_TEST(Int8Const_fallthru1) { | 37 WASM_EXEC_TEST(Int8Const_fallthru1) { |
38 WasmRunner<int32_t> r; | 38 WasmRunner<int32_t> r(execution_mode); |
39 const byte kExpectedValue = 122; | 39 const byte kExpectedValue = 122; |
40 // kExpectedValue | 40 // kExpectedValue |
41 BUILD(r, WASM_I8(kExpectedValue)); | 41 BUILD(r, WASM_I8(kExpectedValue)); |
42 CHECK_EQ(kExpectedValue, r.Call()); | 42 CHECK_EQ(kExpectedValue, r.Call()); |
43 } | 43 } |
44 | 44 |
45 WASM_EXEC_TEST(Int8Const_fallthru2) { | 45 WASM_EXEC_TEST(Int8Const_fallthru2) { |
46 WasmRunner<int32_t> r; | 46 WasmRunner<int32_t> r(execution_mode); |
47 const byte kExpectedValue = 123; | 47 const byte kExpectedValue = 123; |
48 // -99 kExpectedValue | 48 // -99 kExpectedValue |
49 BUILD(r, WASM_I8(-99), WASM_I8(kExpectedValue)); | 49 BUILD(r, WASM_I8(-99), WASM_I8(kExpectedValue)); |
50 CHECK_EQ(kExpectedValue, r.Call()); | 50 CHECK_EQ(kExpectedValue, r.Call()); |
51 } | 51 } |
52 | 52 |
53 WASM_EXEC_TEST(Int8Const_all) { | 53 WASM_EXEC_TEST(Int8Const_all) { |
54 for (int value = -128; value <= 127; value++) { | 54 for (int value = -128; value <= 127; value++) { |
55 WasmRunner<int32_t> r; | 55 WasmRunner<int32_t> r(execution_mode); |
56 // return(value) | 56 // return(value) |
57 BUILD(r, WASM_I8(value)); | 57 BUILD(r, WASM_I8(value)); |
58 int32_t result = r.Call(); | 58 int32_t result = r.Call(); |
59 CHECK_EQ(value, result); | 59 CHECK_EQ(value, result); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 WASM_EXEC_TEST(Int32Const) { | 63 WASM_EXEC_TEST(Int32Const) { |
64 WasmRunner<int32_t> r; | 64 WasmRunner<int32_t> r(execution_mode); |
65 const int32_t kExpectedValue = 0x11223344; | 65 const int32_t kExpectedValue = 0x11223344; |
66 // return(kExpectedValue) | 66 // return(kExpectedValue) |
67 BUILD(r, WASM_I32V_5(kExpectedValue)); | 67 BUILD(r, WASM_I32V_5(kExpectedValue)); |
68 CHECK_EQ(kExpectedValue, r.Call()); | 68 CHECK_EQ(kExpectedValue, r.Call()); |
69 } | 69 } |
70 | 70 |
71 WASM_EXEC_TEST(Int32Const_many) { | 71 WASM_EXEC_TEST(Int32Const_many) { |
72 FOR_INT32_INPUTS(i) { | 72 FOR_INT32_INPUTS(i) { |
73 WasmRunner<int32_t> r; | 73 WasmRunner<int32_t> r(execution_mode); |
74 const int32_t kExpectedValue = *i; | 74 const int32_t kExpectedValue = *i; |
75 // return(kExpectedValue) | 75 // return(kExpectedValue) |
76 BUILD(r, WASM_I32V(kExpectedValue)); | 76 BUILD(r, WASM_I32V(kExpectedValue)); |
77 CHECK_EQ(kExpectedValue, r.Call()); | 77 CHECK_EQ(kExpectedValue, r.Call()); |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 WASM_EXEC_TEST(MemorySize) { | 81 WASM_EXEC_TEST(MemorySize) { |
82 TestingModule module; | 82 TestingModule module(execution_mode); |
83 WasmRunner<int32_t> r(&module); | 83 WasmRunner<int32_t> r(&module); |
84 module.AddMemory(1024); | 84 module.AddMemory(1024); |
85 BUILD(r, kExprMemorySize); | 85 BUILD(r, kExprMemorySize); |
86 CHECK_EQ(1024, r.Call()); | 86 CHECK_EQ(1024, r.Call()); |
87 } | 87 } |
88 | 88 |
89 WASM_EXEC_TEST(Int32Param0) { | 89 WASM_EXEC_TEST(Int32Param0) { |
90 WasmRunner<int32_t> r(MachineType::Int32()); | 90 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
91 // return(local[0]) | 91 // return(local[0]) |
92 BUILD(r, WASM_GET_LOCAL(0)); | 92 BUILD(r, WASM_GET_LOCAL(0)); |
93 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 93 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
94 } | 94 } |
95 | 95 |
96 WASM_EXEC_TEST(Int32Param0_fallthru) { | 96 WASM_EXEC_TEST(Int32Param0_fallthru) { |
97 WasmRunner<int32_t> r(MachineType::Int32()); | 97 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
98 // local[0] | 98 // local[0] |
99 BUILD(r, WASM_GET_LOCAL(0)); | 99 BUILD(r, WASM_GET_LOCAL(0)); |
100 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 100 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
101 } | 101 } |
102 | 102 |
103 WASM_EXEC_TEST(Int32Param1) { | 103 WASM_EXEC_TEST(Int32Param1) { |
104 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 104 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 105 MachineType::Int32()); |
105 // local[1] | 106 // local[1] |
106 BUILD(r, WASM_GET_LOCAL(1)); | 107 BUILD(r, WASM_GET_LOCAL(1)); |
107 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(-111, *i)); } | 108 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(-111, *i)); } |
108 } | 109 } |
109 | 110 |
110 WASM_EXEC_TEST(Int32Add) { | 111 WASM_EXEC_TEST(Int32Add) { |
111 WasmRunner<int32_t> r; | 112 WasmRunner<int32_t> r(execution_mode); |
112 // 11 + 44 | 113 // 11 + 44 |
113 BUILD(r, WASM_I32_ADD(WASM_I8(11), WASM_I8(44))); | 114 BUILD(r, WASM_I32_ADD(WASM_I8(11), WASM_I8(44))); |
114 CHECK_EQ(55, r.Call()); | 115 CHECK_EQ(55, r.Call()); |
115 } | 116 } |
116 | 117 |
117 WASM_EXEC_TEST(Int32Add_P) { | 118 WASM_EXEC_TEST(Int32Add_P) { |
118 WasmRunner<int32_t> r(MachineType::Int32()); | 119 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
119 // p0 + 13 | 120 // p0 + 13 |
120 BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0))); | 121 BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0))); |
121 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } | 122 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } |
122 } | 123 } |
123 | 124 |
124 WASM_EXEC_TEST(Int32Add_P_fallthru) { | 125 WASM_EXEC_TEST(Int32Add_P_fallthru) { |
125 WasmRunner<int32_t> r(MachineType::Int32()); | 126 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
126 // p0 + 13 | 127 // p0 + 13 |
127 BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0))); | 128 BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0))); |
128 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } | 129 FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } |
129 } | 130 } |
130 | 131 |
131 WASM_EXEC_TEST(Int32Add_P2) { | 132 WASM_EXEC_TEST(Int32Add_P2) { |
132 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 133 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 134 MachineType::Int32()); |
133 // p0 + p1 | 135 // p0 + p1 |
134 BUILD(r, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 136 BUILD(r, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
135 FOR_INT32_INPUTS(i) { | 137 FOR_INT32_INPUTS(i) { |
136 FOR_INT32_INPUTS(j) { | 138 FOR_INT32_INPUTS(j) { |
137 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) + | 139 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) + |
138 static_cast<uint32_t>(*j)); | 140 static_cast<uint32_t>(*j)); |
139 CHECK_EQ(expected, r.Call(*i, *j)); | 141 CHECK_EQ(expected, r.Call(*i, *j)); |
140 } | 142 } |
141 } | 143 } |
142 } | 144 } |
143 | 145 |
144 WASM_EXEC_TEST(Float32Add) { | 146 WASM_EXEC_TEST(Float32Add) { |
145 WasmRunner<int32_t> r; | 147 WasmRunner<int32_t> r(execution_mode); |
146 // int(11.5f + 44.5f) | 148 // int(11.5f + 44.5f) |
147 BUILD(r, | 149 BUILD(r, |
148 WASM_I32_SCONVERT_F32(WASM_F32_ADD(WASM_F32(11.5f), WASM_F32(44.5f)))); | 150 WASM_I32_SCONVERT_F32(WASM_F32_ADD(WASM_F32(11.5f), WASM_F32(44.5f)))); |
149 CHECK_EQ(56, r.Call()); | 151 CHECK_EQ(56, r.Call()); |
150 } | 152 } |
151 | 153 |
152 WASM_EXEC_TEST(Float64Add) { | 154 WASM_EXEC_TEST(Float64Add) { |
153 WasmRunner<int32_t> r; | 155 WasmRunner<int32_t> r(execution_mode); |
154 // return int(13.5d + 43.5d) | 156 // return int(13.5d + 43.5d) |
155 BUILD(r, WASM_I32_SCONVERT_F64(WASM_F64_ADD(WASM_F64(13.5), WASM_F64(43.5)))); | 157 BUILD(r, WASM_I32_SCONVERT_F64(WASM_F64_ADD(WASM_F64(13.5), WASM_F64(43.5)))); |
156 CHECK_EQ(57, r.Call()); | 158 CHECK_EQ(57, r.Call()); |
157 } | 159 } |
158 | 160 |
159 void TestInt32Binop(WasmOpcode opcode, int32_t expected, int32_t a, int32_t b) { | 161 void TestInt32Binop(WasmExecutionMode execution_mode, WasmOpcode opcode, |
| 162 int32_t expected, int32_t a, int32_t b) { |
160 { | 163 { |
161 WasmRunner<int32_t> r; | 164 WasmRunner<int32_t> r(execution_mode); |
162 // K op K | 165 // K op K |
163 BUILD(r, WASM_BINOP(opcode, WASM_I32V(a), WASM_I32V(b))); | 166 BUILD(r, WASM_BINOP(opcode, WASM_I32V(a), WASM_I32V(b))); |
164 CHECK_EQ(expected, r.Call()); | 167 CHECK_EQ(expected, r.Call()); |
165 } | 168 } |
166 { | 169 { |
167 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 170 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 171 MachineType::Int32()); |
168 // a op b | 172 // a op b |
169 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 173 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
170 CHECK_EQ(expected, r.Call(a, b)); | 174 CHECK_EQ(expected, r.Call(a, b)); |
171 } | 175 } |
172 } | 176 } |
173 | 177 |
174 WASM_EXEC_TEST(Int32Binops) { | 178 WASM_EXEC_TEST(Int32Binops) { |
175 TestInt32Binop(kExprI32Add, 88888888, 33333333, 55555555); | 179 TestInt32Binop(execution_mode, kExprI32Add, 88888888, 33333333, 55555555); |
176 TestInt32Binop(kExprI32Sub, -1111111, 7777777, 8888888); | 180 TestInt32Binop(execution_mode, kExprI32Sub, -1111111, 7777777, 8888888); |
177 TestInt32Binop(kExprI32Mul, 65130756, 88734, 734); | 181 TestInt32Binop(execution_mode, kExprI32Mul, 65130756, 88734, 734); |
178 TestInt32Binop(kExprI32DivS, -66, -4777344, 72384); | 182 TestInt32Binop(execution_mode, kExprI32DivS, -66, -4777344, 72384); |
179 TestInt32Binop(kExprI32DivU, 805306368, 0xF0000000, 5); | 183 TestInt32Binop(execution_mode, kExprI32DivU, 805306368, 0xF0000000, 5); |
180 TestInt32Binop(kExprI32RemS, -3, -3003, 1000); | 184 TestInt32Binop(execution_mode, kExprI32RemS, -3, -3003, 1000); |
181 TestInt32Binop(kExprI32RemU, 4, 4004, 1000); | 185 TestInt32Binop(execution_mode, kExprI32RemU, 4, 4004, 1000); |
182 TestInt32Binop(kExprI32And, 0xEE, 0xFFEE, 0xFF0000FF); | 186 TestInt32Binop(execution_mode, kExprI32And, 0xEE, 0xFFEE, 0xFF0000FF); |
183 TestInt32Binop(kExprI32Ior, 0xF0FF00FF, 0xF0F000EE, 0x000F0011); | 187 TestInt32Binop(execution_mode, kExprI32Ior, 0xF0FF00FF, 0xF0F000EE, |
184 TestInt32Binop(kExprI32Xor, 0xABCDEF01, 0xABCDEFFF, 0xFE); | 188 0x000F0011); |
185 TestInt32Binop(kExprI32Shl, 0xA0000000, 0xA, 28); | 189 TestInt32Binop(execution_mode, kExprI32Xor, 0xABCDEF01, 0xABCDEFFF, 0xFE); |
186 TestInt32Binop(kExprI32ShrU, 0x07000010, 0x70000100, 4); | 190 TestInt32Binop(execution_mode, kExprI32Shl, 0xA0000000, 0xA, 28); |
187 TestInt32Binop(kExprI32ShrS, 0xFF000000, 0x80000000, 7); | 191 TestInt32Binop(execution_mode, kExprI32ShrU, 0x07000010, 0x70000100, 4); |
188 TestInt32Binop(kExprI32Ror, 0x01000000, 0x80000000, 7); | 192 TestInt32Binop(execution_mode, kExprI32ShrS, 0xFF000000, 0x80000000, 7); |
189 TestInt32Binop(kExprI32Ror, 0x01000000, 0x80000000, 39); | 193 TestInt32Binop(execution_mode, kExprI32Ror, 0x01000000, 0x80000000, 7); |
190 TestInt32Binop(kExprI32Rol, 0x00000040, 0x80000000, 7); | 194 TestInt32Binop(execution_mode, kExprI32Ror, 0x01000000, 0x80000000, 39); |
191 TestInt32Binop(kExprI32Rol, 0x00000040, 0x80000000, 39); | 195 TestInt32Binop(execution_mode, kExprI32Rol, 0x00000040, 0x80000000, 7); |
192 TestInt32Binop(kExprI32Eq, 1, -99, -99); | 196 TestInt32Binop(execution_mode, kExprI32Rol, 0x00000040, 0x80000000, 39); |
193 TestInt32Binop(kExprI32Ne, 0, -97, -97); | 197 TestInt32Binop(execution_mode, kExprI32Eq, 1, -99, -99); |
| 198 TestInt32Binop(execution_mode, kExprI32Ne, 0, -97, -97); |
194 | 199 |
195 TestInt32Binop(kExprI32LtS, 1, -4, 4); | 200 TestInt32Binop(execution_mode, kExprI32LtS, 1, -4, 4); |
196 TestInt32Binop(kExprI32LeS, 0, -2, -3); | 201 TestInt32Binop(execution_mode, kExprI32LeS, 0, -2, -3); |
197 TestInt32Binop(kExprI32LtU, 1, 0, -6); | 202 TestInt32Binop(execution_mode, kExprI32LtU, 1, 0, -6); |
198 TestInt32Binop(kExprI32LeU, 1, 98978, 0xF0000000); | 203 TestInt32Binop(execution_mode, kExprI32LeU, 1, 98978, 0xF0000000); |
199 | 204 |
200 TestInt32Binop(kExprI32GtS, 1, 4, -4); | 205 TestInt32Binop(execution_mode, kExprI32GtS, 1, 4, -4); |
201 TestInt32Binop(kExprI32GeS, 0, -3, -2); | 206 TestInt32Binop(execution_mode, kExprI32GeS, 0, -3, -2); |
202 TestInt32Binop(kExprI32GtU, 1, -6, 0); | 207 TestInt32Binop(execution_mode, kExprI32GtU, 1, -6, 0); |
203 TestInt32Binop(kExprI32GeU, 1, 0xF0000000, 98978); | 208 TestInt32Binop(execution_mode, kExprI32GeU, 1, 0xF0000000, 98978); |
204 } | 209 } |
205 | 210 |
206 void TestInt32Unop(WasmOpcode opcode, int32_t expected, int32_t a) { | 211 void TestInt32Unop(WasmExecutionMode execution_mode, WasmOpcode opcode, |
| 212 int32_t expected, int32_t a) { |
207 { | 213 { |
208 WasmRunner<int32_t> r; | 214 WasmRunner<int32_t> r(execution_mode); |
209 // return op K | 215 // return op K |
210 BUILD(r, WASM_UNOP(opcode, WASM_I32V(a))); | 216 BUILD(r, WASM_UNOP(opcode, WASM_I32V(a))); |
211 CHECK_EQ(expected, r.Call()); | 217 CHECK_EQ(expected, r.Call()); |
212 } | 218 } |
213 { | 219 { |
214 WasmRunner<int32_t> r(MachineType::Int32()); | 220 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
215 // return op a | 221 // return op a |
216 BUILD(r, WASM_UNOP(opcode, WASM_GET_LOCAL(0))); | 222 BUILD(r, WASM_UNOP(opcode, WASM_GET_LOCAL(0))); |
217 CHECK_EQ(expected, r.Call(a)); | 223 CHECK_EQ(expected, r.Call(a)); |
218 } | 224 } |
219 } | 225 } |
220 | 226 |
221 WASM_EXEC_TEST(Int32Clz) { | 227 WASM_EXEC_TEST(Int32Clz) { |
222 TestInt32Unop(kExprI32Clz, 0, 0x80001000); | 228 TestInt32Unop(execution_mode, kExprI32Clz, 0, 0x80001000); |
223 TestInt32Unop(kExprI32Clz, 1, 0x40000500); | 229 TestInt32Unop(execution_mode, kExprI32Clz, 1, 0x40000500); |
224 TestInt32Unop(kExprI32Clz, 2, 0x20000300); | 230 TestInt32Unop(execution_mode, kExprI32Clz, 2, 0x20000300); |
225 TestInt32Unop(kExprI32Clz, 3, 0x10000003); | 231 TestInt32Unop(execution_mode, kExprI32Clz, 3, 0x10000003); |
226 TestInt32Unop(kExprI32Clz, 4, 0x08050000); | 232 TestInt32Unop(execution_mode, kExprI32Clz, 4, 0x08050000); |
227 TestInt32Unop(kExprI32Clz, 5, 0x04006000); | 233 TestInt32Unop(execution_mode, kExprI32Clz, 5, 0x04006000); |
228 TestInt32Unop(kExprI32Clz, 6, 0x02000000); | 234 TestInt32Unop(execution_mode, kExprI32Clz, 6, 0x02000000); |
229 TestInt32Unop(kExprI32Clz, 7, 0x010000a0); | 235 TestInt32Unop(execution_mode, kExprI32Clz, 7, 0x010000a0); |
230 TestInt32Unop(kExprI32Clz, 8, 0x00800c00); | 236 TestInt32Unop(execution_mode, kExprI32Clz, 8, 0x00800c00); |
231 TestInt32Unop(kExprI32Clz, 9, 0x00400000); | 237 TestInt32Unop(execution_mode, kExprI32Clz, 9, 0x00400000); |
232 TestInt32Unop(kExprI32Clz, 10, 0x0020000d); | 238 TestInt32Unop(execution_mode, kExprI32Clz, 10, 0x0020000d); |
233 TestInt32Unop(kExprI32Clz, 11, 0x00100f00); | 239 TestInt32Unop(execution_mode, kExprI32Clz, 11, 0x00100f00); |
234 TestInt32Unop(kExprI32Clz, 12, 0x00080000); | 240 TestInt32Unop(execution_mode, kExprI32Clz, 12, 0x00080000); |
235 TestInt32Unop(kExprI32Clz, 13, 0x00041000); | 241 TestInt32Unop(execution_mode, kExprI32Clz, 13, 0x00041000); |
236 TestInt32Unop(kExprI32Clz, 14, 0x00020020); | 242 TestInt32Unop(execution_mode, kExprI32Clz, 14, 0x00020020); |
237 TestInt32Unop(kExprI32Clz, 15, 0x00010300); | 243 TestInt32Unop(execution_mode, kExprI32Clz, 15, 0x00010300); |
238 TestInt32Unop(kExprI32Clz, 16, 0x00008040); | 244 TestInt32Unop(execution_mode, kExprI32Clz, 16, 0x00008040); |
239 TestInt32Unop(kExprI32Clz, 17, 0x00004005); | 245 TestInt32Unop(execution_mode, kExprI32Clz, 17, 0x00004005); |
240 TestInt32Unop(kExprI32Clz, 18, 0x00002050); | 246 TestInt32Unop(execution_mode, kExprI32Clz, 18, 0x00002050); |
241 TestInt32Unop(kExprI32Clz, 19, 0x00001700); | 247 TestInt32Unop(execution_mode, kExprI32Clz, 19, 0x00001700); |
242 TestInt32Unop(kExprI32Clz, 20, 0x00000870); | 248 TestInt32Unop(execution_mode, kExprI32Clz, 20, 0x00000870); |
243 TestInt32Unop(kExprI32Clz, 21, 0x00000405); | 249 TestInt32Unop(execution_mode, kExprI32Clz, 21, 0x00000405); |
244 TestInt32Unop(kExprI32Clz, 22, 0x00000203); | 250 TestInt32Unop(execution_mode, kExprI32Clz, 22, 0x00000203); |
245 TestInt32Unop(kExprI32Clz, 23, 0x00000101); | 251 TestInt32Unop(execution_mode, kExprI32Clz, 23, 0x00000101); |
246 TestInt32Unop(kExprI32Clz, 24, 0x00000089); | 252 TestInt32Unop(execution_mode, kExprI32Clz, 24, 0x00000089); |
247 TestInt32Unop(kExprI32Clz, 25, 0x00000041); | 253 TestInt32Unop(execution_mode, kExprI32Clz, 25, 0x00000041); |
248 TestInt32Unop(kExprI32Clz, 26, 0x00000022); | 254 TestInt32Unop(execution_mode, kExprI32Clz, 26, 0x00000022); |
249 TestInt32Unop(kExprI32Clz, 27, 0x00000013); | 255 TestInt32Unop(execution_mode, kExprI32Clz, 27, 0x00000013); |
250 TestInt32Unop(kExprI32Clz, 28, 0x00000008); | 256 TestInt32Unop(execution_mode, kExprI32Clz, 28, 0x00000008); |
251 TestInt32Unop(kExprI32Clz, 29, 0x00000004); | 257 TestInt32Unop(execution_mode, kExprI32Clz, 29, 0x00000004); |
252 TestInt32Unop(kExprI32Clz, 30, 0x00000002); | 258 TestInt32Unop(execution_mode, kExprI32Clz, 30, 0x00000002); |
253 TestInt32Unop(kExprI32Clz, 31, 0x00000001); | 259 TestInt32Unop(execution_mode, kExprI32Clz, 31, 0x00000001); |
254 TestInt32Unop(kExprI32Clz, 32, 0x00000000); | 260 TestInt32Unop(execution_mode, kExprI32Clz, 32, 0x00000000); |
255 } | 261 } |
256 | 262 |
257 WASM_EXEC_TEST(Int32Ctz) { | 263 WASM_EXEC_TEST(Int32Ctz) { |
258 TestInt32Unop(kExprI32Ctz, 32, 0x00000000); | 264 TestInt32Unop(execution_mode, kExprI32Ctz, 32, 0x00000000); |
259 TestInt32Unop(kExprI32Ctz, 31, 0x80000000); | 265 TestInt32Unop(execution_mode, kExprI32Ctz, 31, 0x80000000); |
260 TestInt32Unop(kExprI32Ctz, 30, 0x40000000); | 266 TestInt32Unop(execution_mode, kExprI32Ctz, 30, 0x40000000); |
261 TestInt32Unop(kExprI32Ctz, 29, 0x20000000); | 267 TestInt32Unop(execution_mode, kExprI32Ctz, 29, 0x20000000); |
262 TestInt32Unop(kExprI32Ctz, 28, 0x10000000); | 268 TestInt32Unop(execution_mode, kExprI32Ctz, 28, 0x10000000); |
263 TestInt32Unop(kExprI32Ctz, 27, 0xa8000000); | 269 TestInt32Unop(execution_mode, kExprI32Ctz, 27, 0xa8000000); |
264 TestInt32Unop(kExprI32Ctz, 26, 0xf4000000); | 270 TestInt32Unop(execution_mode, kExprI32Ctz, 26, 0xf4000000); |
265 TestInt32Unop(kExprI32Ctz, 25, 0x62000000); | 271 TestInt32Unop(execution_mode, kExprI32Ctz, 25, 0x62000000); |
266 TestInt32Unop(kExprI32Ctz, 24, 0x91000000); | 272 TestInt32Unop(execution_mode, kExprI32Ctz, 24, 0x91000000); |
267 TestInt32Unop(kExprI32Ctz, 23, 0xcd800000); | 273 TestInt32Unop(execution_mode, kExprI32Ctz, 23, 0xcd800000); |
268 TestInt32Unop(kExprI32Ctz, 22, 0x09400000); | 274 TestInt32Unop(execution_mode, kExprI32Ctz, 22, 0x09400000); |
269 TestInt32Unop(kExprI32Ctz, 21, 0xaf200000); | 275 TestInt32Unop(execution_mode, kExprI32Ctz, 21, 0xaf200000); |
270 TestInt32Unop(kExprI32Ctz, 20, 0xac100000); | 276 TestInt32Unop(execution_mode, kExprI32Ctz, 20, 0xac100000); |
271 TestInt32Unop(kExprI32Ctz, 19, 0xe0b80000); | 277 TestInt32Unop(execution_mode, kExprI32Ctz, 19, 0xe0b80000); |
272 TestInt32Unop(kExprI32Ctz, 18, 0x9ce40000); | 278 TestInt32Unop(execution_mode, kExprI32Ctz, 18, 0x9ce40000); |
273 TestInt32Unop(kExprI32Ctz, 17, 0xc7920000); | 279 TestInt32Unop(execution_mode, kExprI32Ctz, 17, 0xc7920000); |
274 TestInt32Unop(kExprI32Ctz, 16, 0xb8f10000); | 280 TestInt32Unop(execution_mode, kExprI32Ctz, 16, 0xb8f10000); |
275 TestInt32Unop(kExprI32Ctz, 15, 0x3b9f8000); | 281 TestInt32Unop(execution_mode, kExprI32Ctz, 15, 0x3b9f8000); |
276 TestInt32Unop(kExprI32Ctz, 14, 0xdb4c4000); | 282 TestInt32Unop(execution_mode, kExprI32Ctz, 14, 0xdb4c4000); |
277 TestInt32Unop(kExprI32Ctz, 13, 0xe9a32000); | 283 TestInt32Unop(execution_mode, kExprI32Ctz, 13, 0xe9a32000); |
278 TestInt32Unop(kExprI32Ctz, 12, 0xfca61000); | 284 TestInt32Unop(execution_mode, kExprI32Ctz, 12, 0xfca61000); |
279 TestInt32Unop(kExprI32Ctz, 11, 0x6c8a7800); | 285 TestInt32Unop(execution_mode, kExprI32Ctz, 11, 0x6c8a7800); |
280 TestInt32Unop(kExprI32Ctz, 10, 0x8ce5a400); | 286 TestInt32Unop(execution_mode, kExprI32Ctz, 10, 0x8ce5a400); |
281 TestInt32Unop(kExprI32Ctz, 9, 0xcb7d0200); | 287 TestInt32Unop(execution_mode, kExprI32Ctz, 9, 0xcb7d0200); |
282 TestInt32Unop(kExprI32Ctz, 8, 0xcb4dc100); | 288 TestInt32Unop(execution_mode, kExprI32Ctz, 8, 0xcb4dc100); |
283 TestInt32Unop(kExprI32Ctz, 7, 0xdfbec580); | 289 TestInt32Unop(execution_mode, kExprI32Ctz, 7, 0xdfbec580); |
284 TestInt32Unop(kExprI32Ctz, 6, 0x27a9db40); | 290 TestInt32Unop(execution_mode, kExprI32Ctz, 6, 0x27a9db40); |
285 TestInt32Unop(kExprI32Ctz, 5, 0xde3bcb20); | 291 TestInt32Unop(execution_mode, kExprI32Ctz, 5, 0xde3bcb20); |
286 TestInt32Unop(kExprI32Ctz, 4, 0xd7e8a610); | 292 TestInt32Unop(execution_mode, kExprI32Ctz, 4, 0xd7e8a610); |
287 TestInt32Unop(kExprI32Ctz, 3, 0x9afdbc88); | 293 TestInt32Unop(execution_mode, kExprI32Ctz, 3, 0x9afdbc88); |
288 TestInt32Unop(kExprI32Ctz, 2, 0x9afdbc84); | 294 TestInt32Unop(execution_mode, kExprI32Ctz, 2, 0x9afdbc84); |
289 TestInt32Unop(kExprI32Ctz, 1, 0x9afdbc82); | 295 TestInt32Unop(execution_mode, kExprI32Ctz, 1, 0x9afdbc82); |
290 TestInt32Unop(kExprI32Ctz, 0, 0x9afdbc81); | 296 TestInt32Unop(execution_mode, kExprI32Ctz, 0, 0x9afdbc81); |
291 } | 297 } |
292 | 298 |
293 WASM_EXEC_TEST(Int32Popcnt) { | 299 WASM_EXEC_TEST(Int32Popcnt) { |
294 TestInt32Unop(kExprI32Popcnt, 32, 0xffffffff); | 300 TestInt32Unop(execution_mode, kExprI32Popcnt, 32, 0xffffffff); |
295 TestInt32Unop(kExprI32Popcnt, 0, 0x00000000); | 301 TestInt32Unop(execution_mode, kExprI32Popcnt, 0, 0x00000000); |
296 TestInt32Unop(kExprI32Popcnt, 1, 0x00008000); | 302 TestInt32Unop(execution_mode, kExprI32Popcnt, 1, 0x00008000); |
297 TestInt32Unop(kExprI32Popcnt, 13, 0x12345678); | 303 TestInt32Unop(execution_mode, kExprI32Popcnt, 13, 0x12345678); |
298 TestInt32Unop(kExprI32Popcnt, 19, 0xfedcba09); | 304 TestInt32Unop(execution_mode, kExprI32Popcnt, 19, 0xfedcba09); |
299 } | 305 } |
300 | 306 |
301 WASM_EXEC_TEST(I32Eqz) { | 307 WASM_EXEC_TEST(I32Eqz) { |
302 TestInt32Unop(kExprI32Eqz, 0, 1); | 308 TestInt32Unop(execution_mode, kExprI32Eqz, 0, 1); |
303 TestInt32Unop(kExprI32Eqz, 0, -1); | 309 TestInt32Unop(execution_mode, kExprI32Eqz, 0, -1); |
304 TestInt32Unop(kExprI32Eqz, 0, -827343); | 310 TestInt32Unop(execution_mode, kExprI32Eqz, 0, -827343); |
305 TestInt32Unop(kExprI32Eqz, 0, 8888888); | 311 TestInt32Unop(execution_mode, kExprI32Eqz, 0, 8888888); |
306 TestInt32Unop(kExprI32Eqz, 1, 0); | 312 TestInt32Unop(execution_mode, kExprI32Eqz, 1, 0); |
307 } | 313 } |
308 | 314 |
309 WASM_EXEC_TEST(I32Shl) { | 315 WASM_EXEC_TEST(I32Shl) { |
310 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 316 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(), |
| 317 MachineType::Uint32()); |
311 BUILD(r, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 318 BUILD(r, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
312 | 319 |
313 FOR_UINT32_INPUTS(i) { | 320 FOR_UINT32_INPUTS(i) { |
314 FOR_UINT32_INPUTS(j) { | 321 FOR_UINT32_INPUTS(j) { |
315 uint32_t expected = (*i) << (*j & 0x1f); | 322 uint32_t expected = (*i) << (*j & 0x1f); |
316 CHECK_EQ(expected, r.Call(*i, *j)); | 323 CHECK_EQ(expected, r.Call(*i, *j)); |
317 } | 324 } |
318 } | 325 } |
319 } | 326 } |
320 | 327 |
321 WASM_EXEC_TEST(I32Shr) { | 328 WASM_EXEC_TEST(I32Shr) { |
322 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 329 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(), |
| 330 MachineType::Uint32()); |
323 BUILD(r, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 331 BUILD(r, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
324 | 332 |
325 FOR_UINT32_INPUTS(i) { | 333 FOR_UINT32_INPUTS(i) { |
326 FOR_UINT32_INPUTS(j) { | 334 FOR_UINT32_INPUTS(j) { |
327 uint32_t expected = (*i) >> (*j & 0x1f); | 335 uint32_t expected = (*i) >> (*j & 0x1f); |
328 CHECK_EQ(expected, r.Call(*i, *j)); | 336 CHECK_EQ(expected, r.Call(*i, *j)); |
329 } | 337 } |
330 } | 338 } |
331 } | 339 } |
332 | 340 |
333 WASM_EXEC_TEST(I32Sar) { | 341 WASM_EXEC_TEST(I32Sar) { |
334 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 342 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 343 MachineType::Int32()); |
335 BUILD(r, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 344 BUILD(r, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
336 | 345 |
337 FOR_INT32_INPUTS(i) { | 346 FOR_INT32_INPUTS(i) { |
338 FOR_INT32_INPUTS(j) { | 347 FOR_INT32_INPUTS(j) { |
339 int32_t expected = (*i) >> (*j & 0x1f); | 348 int32_t expected = (*i) >> (*j & 0x1f); |
340 CHECK_EQ(expected, r.Call(*i, *j)); | 349 CHECK_EQ(expected, r.Call(*i, *j)); |
341 } | 350 } |
342 } | 351 } |
343 } | 352 } |
344 | 353 |
345 WASM_EXEC_TEST(Int32DivS_trap) { | 354 WASM_EXEC_TEST(Int32DivS_trap) { |
346 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 355 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 356 MachineType::Int32()); |
347 BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 357 BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
348 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 358 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
349 CHECK_EQ(0, r.Call(0, 100)); | 359 CHECK_EQ(0, r.Call(0, 100)); |
350 CHECK_TRAP(r.Call(100, 0)); | 360 CHECK_TRAP(r.Call(100, 0)); |
351 CHECK_TRAP(r.Call(-1001, 0)); | 361 CHECK_TRAP(r.Call(-1001, 0)); |
352 CHECK_TRAP(r.Call(kMin, -1)); | 362 CHECK_TRAP(r.Call(kMin, -1)); |
353 CHECK_TRAP(r.Call(kMin, 0)); | 363 CHECK_TRAP(r.Call(kMin, 0)); |
354 } | 364 } |
355 | 365 |
356 WASM_EXEC_TEST(Int32RemS_trap) { | 366 WASM_EXEC_TEST(Int32RemS_trap) { |
357 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 367 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 368 MachineType::Int32()); |
358 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 369 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
359 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 370 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
360 CHECK_EQ(33, r.Call(133, 100)); | 371 CHECK_EQ(33, r.Call(133, 100)); |
361 CHECK_EQ(0, r.Call(kMin, -1)); | 372 CHECK_EQ(0, r.Call(kMin, -1)); |
362 CHECK_TRAP(r.Call(100, 0)); | 373 CHECK_TRAP(r.Call(100, 0)); |
363 CHECK_TRAP(r.Call(-1001, 0)); | 374 CHECK_TRAP(r.Call(-1001, 0)); |
364 CHECK_TRAP(r.Call(kMin, 0)); | 375 CHECK_TRAP(r.Call(kMin, 0)); |
365 } | 376 } |
366 | 377 |
367 WASM_EXEC_TEST(Int32DivU_trap) { | 378 WASM_EXEC_TEST(Int32DivU_trap) { |
368 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 379 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 380 MachineType::Int32()); |
369 BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 381 BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
370 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 382 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
371 CHECK_EQ(0, r.Call(0, 100)); | 383 CHECK_EQ(0, r.Call(0, 100)); |
372 CHECK_EQ(0, r.Call(kMin, -1)); | 384 CHECK_EQ(0, r.Call(kMin, -1)); |
373 CHECK_TRAP(r.Call(100, 0)); | 385 CHECK_TRAP(r.Call(100, 0)); |
374 CHECK_TRAP(r.Call(-1001, 0)); | 386 CHECK_TRAP(r.Call(-1001, 0)); |
375 CHECK_TRAP(r.Call(kMin, 0)); | 387 CHECK_TRAP(r.Call(kMin, 0)); |
376 } | 388 } |
377 | 389 |
378 WASM_EXEC_TEST(Int32RemU_trap) { | 390 WASM_EXEC_TEST(Int32RemU_trap) { |
379 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 391 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 392 MachineType::Int32()); |
380 BUILD(r, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 393 BUILD(r, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
381 CHECK_EQ(17, r.Call(217, 100)); | 394 CHECK_EQ(17, r.Call(217, 100)); |
382 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 395 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
383 CHECK_TRAP(r.Call(100, 0)); | 396 CHECK_TRAP(r.Call(100, 0)); |
384 CHECK_TRAP(r.Call(-1001, 0)); | 397 CHECK_TRAP(r.Call(-1001, 0)); |
385 CHECK_TRAP(r.Call(kMin, 0)); | 398 CHECK_TRAP(r.Call(kMin, 0)); |
386 CHECK_EQ(kMin, r.Call(kMin, -1)); | 399 CHECK_EQ(kMin, r.Call(kMin, -1)); |
387 } | 400 } |
388 | 401 |
389 WASM_EXEC_TEST(Int32DivS_byzero_const) { | 402 WASM_EXEC_TEST(Int32DivS_byzero_const) { |
390 for (int8_t denom = -2; denom < 8; denom++) { | 403 for (int8_t denom = -2; denom < 8; denom++) { |
391 WasmRunner<int32_t> r(MachineType::Int32()); | 404 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
392 BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom))); | 405 BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom))); |
393 for (int32_t val = -7; val < 8; val++) { | 406 for (int32_t val = -7; val < 8; val++) { |
394 if (denom == 0) { | 407 if (denom == 0) { |
395 CHECK_TRAP(r.Call(val)); | 408 CHECK_TRAP(r.Call(val)); |
396 } else { | 409 } else { |
397 CHECK_EQ(val / denom, r.Call(val)); | 410 CHECK_EQ(val / denom, r.Call(val)); |
398 } | 411 } |
399 } | 412 } |
400 } | 413 } |
401 } | 414 } |
402 | 415 |
403 WASM_EXEC_TEST(Int32DivU_byzero_const) { | 416 WASM_EXEC_TEST(Int32DivU_byzero_const) { |
404 for (uint32_t denom = 0xfffffffe; denom < 8; denom++) { | 417 for (uint32_t denom = 0xfffffffe; denom < 8; denom++) { |
405 WasmRunner<uint32_t> r(MachineType::Uint32()); | 418 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32()); |
406 BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(denom))); | 419 BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(denom))); |
407 | 420 |
408 for (uint32_t val = 0xfffffff0; val < 8; val++) { | 421 for (uint32_t val = 0xfffffff0; val < 8; val++) { |
409 if (denom == 0) { | 422 if (denom == 0) { |
410 CHECK_TRAP(r.Call(val)); | 423 CHECK_TRAP(r.Call(val)); |
411 } else { | 424 } else { |
412 CHECK_EQ(val / denom, r.Call(val)); | 425 CHECK_EQ(val / denom, r.Call(val)); |
413 } | 426 } |
414 } | 427 } |
415 } | 428 } |
416 } | 429 } |
417 | 430 |
418 WASM_EXEC_TEST(Int32DivS_trap_effect) { | 431 WASM_EXEC_TEST(Int32DivS_trap_effect) { |
419 TestingModule module; | 432 TestingModule module(execution_mode); |
420 module.AddMemoryElems<int32_t>(8); | 433 module.AddMemoryElems<int32_t>(8); |
421 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32()); | 434 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32()); |
422 | 435 |
423 BUILD(r, | 436 BUILD(r, |
424 WASM_IF_ELSE(WASM_GET_LOCAL(0), | 437 WASM_IF_ELSE(WASM_GET_LOCAL(0), |
425 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(), | 438 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(), |
426 WASM_ZERO, WASM_GET_LOCAL(0)), | 439 WASM_ZERO, WASM_GET_LOCAL(0)), |
427 WASM_GET_LOCAL(1)), | 440 WASM_GET_LOCAL(1)), |
428 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(), | 441 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(), |
429 WASM_ZERO, WASM_GET_LOCAL(0)), | 442 WASM_ZERO, WASM_GET_LOCAL(0)), |
430 WASM_GET_LOCAL(1)))); | 443 WASM_GET_LOCAL(1)))); |
431 CHECK_EQ(0, r.Call(0, 100)); | 444 CHECK_EQ(0, r.Call(0, 100)); |
432 CHECK_TRAP(r.Call(8, 0)); | 445 CHECK_TRAP(r.Call(8, 0)); |
433 CHECK_TRAP(r.Call(4, 0)); | 446 CHECK_TRAP(r.Call(4, 0)); |
434 CHECK_TRAP(r.Call(0, 0)); | 447 CHECK_TRAP(r.Call(0, 0)); |
435 } | 448 } |
436 | 449 |
437 void TestFloat32Binop(WasmOpcode opcode, int32_t expected, float a, float b) { | 450 void TestFloat32Binop(WasmExecutionMode execution_mode, WasmOpcode opcode, |
| 451 int32_t expected, float a, float b) { |
438 { | 452 { |
439 WasmRunner<int32_t> r; | 453 WasmRunner<int32_t> r(execution_mode); |
440 // return K op K | 454 // return K op K |
441 BUILD(r, WASM_BINOP(opcode, WASM_F32(a), WASM_F32(b))); | 455 BUILD(r, WASM_BINOP(opcode, WASM_F32(a), WASM_F32(b))); |
442 CHECK_EQ(expected, r.Call()); | 456 CHECK_EQ(expected, r.Call()); |
443 } | 457 } |
444 { | 458 { |
445 WasmRunner<int32_t> r(MachineType::Float32(), MachineType::Float32()); | 459 WasmRunner<int32_t> r(execution_mode, MachineType::Float32(), |
| 460 MachineType::Float32()); |
446 // return a op b | 461 // return a op b |
447 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 462 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
448 CHECK_EQ(expected, r.Call(a, b)); | 463 CHECK_EQ(expected, r.Call(a, b)); |
449 } | 464 } |
450 } | 465 } |
451 | 466 |
452 void TestFloat32BinopWithConvert(WasmOpcode opcode, int32_t expected, float a, | 467 void TestFloat32BinopWithConvert(WasmExecutionMode execution_mode, |
| 468 WasmOpcode opcode, int32_t expected, float a, |
453 float b) { | 469 float b) { |
454 { | 470 { |
455 WasmRunner<int32_t> r; | 471 WasmRunner<int32_t> r(execution_mode); |
456 // return int(K op K) | 472 // return int(K op K) |
457 BUILD(r, | 473 BUILD(r, |
458 WASM_I32_SCONVERT_F32(WASM_BINOP(opcode, WASM_F32(a), WASM_F32(b)))); | 474 WASM_I32_SCONVERT_F32(WASM_BINOP(opcode, WASM_F32(a), WASM_F32(b)))); |
459 CHECK_EQ(expected, r.Call()); | 475 CHECK_EQ(expected, r.Call()); |
460 } | 476 } |
461 { | 477 { |
462 WasmRunner<int32_t> r(MachineType::Float32(), MachineType::Float32()); | 478 WasmRunner<int32_t> r(execution_mode, MachineType::Float32(), |
| 479 MachineType::Float32()); |
463 // return int(a op b) | 480 // return int(a op b) |
464 BUILD(r, WASM_I32_SCONVERT_F32( | 481 BUILD(r, WASM_I32_SCONVERT_F32( |
465 WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); | 482 WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); |
466 CHECK_EQ(expected, r.Call(a, b)); | 483 CHECK_EQ(expected, r.Call(a, b)); |
467 } | 484 } |
468 } | 485 } |
469 | 486 |
470 void TestFloat32UnopWithConvert(WasmOpcode opcode, int32_t expected, float a) { | 487 void TestFloat32UnopWithConvert(WasmExecutionMode execution_mode, |
| 488 WasmOpcode opcode, int32_t expected, float a) { |
471 { | 489 { |
472 WasmRunner<int32_t> r; | 490 WasmRunner<int32_t> r(execution_mode); |
473 // return int(op(K)) | 491 // return int(op(K)) |
474 BUILD(r, WASM_I32_SCONVERT_F32(WASM_UNOP(opcode, WASM_F32(a)))); | 492 BUILD(r, WASM_I32_SCONVERT_F32(WASM_UNOP(opcode, WASM_F32(a)))); |
475 CHECK_EQ(expected, r.Call()); | 493 CHECK_EQ(expected, r.Call()); |
476 } | 494 } |
477 { | 495 { |
478 WasmRunner<int32_t> r(MachineType::Float32()); | 496 WasmRunner<int32_t> r(execution_mode, MachineType::Float32()); |
479 // return int(op(a)) | 497 // return int(op(a)) |
480 BUILD(r, WASM_I32_SCONVERT_F32(WASM_UNOP(opcode, WASM_GET_LOCAL(0)))); | 498 BUILD(r, WASM_I32_SCONVERT_F32(WASM_UNOP(opcode, WASM_GET_LOCAL(0)))); |
481 CHECK_EQ(expected, r.Call(a)); | 499 CHECK_EQ(expected, r.Call(a)); |
482 } | 500 } |
483 } | 501 } |
484 | 502 |
485 void TestFloat64Binop(WasmOpcode opcode, int32_t expected, double a, double b) { | 503 void TestFloat64Binop(WasmExecutionMode execution_mode, WasmOpcode opcode, |
| 504 int32_t expected, double a, double b) { |
486 { | 505 { |
487 WasmRunner<int32_t> r; | 506 WasmRunner<int32_t> r(execution_mode); |
488 // return K op K | 507 // return K op K |
489 BUILD(r, WASM_BINOP(opcode, WASM_F64(a), WASM_F64(b))); | 508 BUILD(r, WASM_BINOP(opcode, WASM_F64(a), WASM_F64(b))); |
490 CHECK_EQ(expected, r.Call()); | 509 CHECK_EQ(expected, r.Call()); |
491 } | 510 } |
492 { | 511 { |
493 WasmRunner<int32_t> r(MachineType::Float64(), MachineType::Float64()); | 512 WasmRunner<int32_t> r(execution_mode, MachineType::Float64(), |
| 513 MachineType::Float64()); |
494 // return a op b | 514 // return a op b |
495 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 515 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
496 CHECK_EQ(expected, r.Call(a, b)); | 516 CHECK_EQ(expected, r.Call(a, b)); |
497 } | 517 } |
498 } | 518 } |
499 | 519 |
500 void TestFloat64BinopWithConvert(WasmOpcode opcode, int32_t expected, double a, | 520 void TestFloat64BinopWithConvert(WasmExecutionMode execution_mode, |
| 521 WasmOpcode opcode, int32_t expected, double a, |
501 double b) { | 522 double b) { |
502 { | 523 { |
503 WasmRunner<int32_t> r; | 524 WasmRunner<int32_t> r(execution_mode); |
504 // return int(K op K) | 525 // return int(K op K) |
505 BUILD(r, | 526 BUILD(r, |
506 WASM_I32_SCONVERT_F64(WASM_BINOP(opcode, WASM_F64(a), WASM_F64(b)))); | 527 WASM_I32_SCONVERT_F64(WASM_BINOP(opcode, WASM_F64(a), WASM_F64(b)))); |
507 CHECK_EQ(expected, r.Call()); | 528 CHECK_EQ(expected, r.Call()); |
508 } | 529 } |
509 { | 530 { |
510 WasmRunner<int32_t> r(MachineType::Float64(), MachineType::Float64()); | 531 WasmRunner<int32_t> r(execution_mode, MachineType::Float64(), |
| 532 MachineType::Float64()); |
511 BUILD(r, WASM_I32_SCONVERT_F64( | 533 BUILD(r, WASM_I32_SCONVERT_F64( |
512 WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); | 534 WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))); |
513 CHECK_EQ(expected, r.Call(a, b)); | 535 CHECK_EQ(expected, r.Call(a, b)); |
514 } | 536 } |
515 } | 537 } |
516 | 538 |
517 void TestFloat64UnopWithConvert(WasmOpcode opcode, int32_t expected, double a) { | 539 void TestFloat64UnopWithConvert(WasmExecutionMode execution_mode, |
| 540 WasmOpcode opcode, int32_t expected, double a) { |
518 { | 541 { |
519 WasmRunner<int32_t> r; | 542 WasmRunner<int32_t> r(execution_mode); |
520 // return int(op(K)) | 543 // return int(op(K)) |
521 BUILD(r, WASM_I32_SCONVERT_F64(WASM_UNOP(opcode, WASM_F64(a)))); | 544 BUILD(r, WASM_I32_SCONVERT_F64(WASM_UNOP(opcode, WASM_F64(a)))); |
522 CHECK_EQ(expected, r.Call()); | 545 CHECK_EQ(expected, r.Call()); |
523 } | 546 } |
524 { | 547 { |
525 WasmRunner<int32_t> r(MachineType::Float64()); | 548 WasmRunner<int32_t> r(execution_mode, MachineType::Float64()); |
526 // return int(op(a)) | 549 // return int(op(a)) |
527 BUILD(r, WASM_I32_SCONVERT_F64(WASM_UNOP(opcode, WASM_GET_LOCAL(0)))); | 550 BUILD(r, WASM_I32_SCONVERT_F64(WASM_UNOP(opcode, WASM_GET_LOCAL(0)))); |
528 CHECK_EQ(expected, r.Call(a)); | 551 CHECK_EQ(expected, r.Call(a)); |
529 } | 552 } |
530 } | 553 } |
531 | 554 |
532 WASM_EXEC_TEST(Float32Binops) { | 555 WASM_EXEC_TEST(Float32Binops) { |
533 TestFloat32Binop(kExprF32Eq, 1, 8.125f, 8.125f); | 556 TestFloat32Binop(execution_mode, kExprF32Eq, 1, 8.125f, 8.125f); |
534 TestFloat32Binop(kExprF32Ne, 1, 8.125f, 8.127f); | 557 TestFloat32Binop(execution_mode, kExprF32Ne, 1, 8.125f, 8.127f); |
535 TestFloat32Binop(kExprF32Lt, 1, -9.5f, -9.0f); | 558 TestFloat32Binop(execution_mode, kExprF32Lt, 1, -9.5f, -9.0f); |
536 TestFloat32Binop(kExprF32Le, 1, -1111.0f, -1111.0f); | 559 TestFloat32Binop(execution_mode, kExprF32Le, 1, -1111.0f, -1111.0f); |
537 TestFloat32Binop(kExprF32Gt, 1, -9.0f, -9.5f); | 560 TestFloat32Binop(execution_mode, kExprF32Gt, 1, -9.0f, -9.5f); |
538 TestFloat32Binop(kExprF32Ge, 1, -1111.0f, -1111.0f); | 561 TestFloat32Binop(execution_mode, kExprF32Ge, 1, -1111.0f, -1111.0f); |
539 | 562 |
540 TestFloat32BinopWithConvert(kExprF32Add, 10, 3.5f, 6.5f); | 563 TestFloat32BinopWithConvert(execution_mode, kExprF32Add, 10, 3.5f, 6.5f); |
541 TestFloat32BinopWithConvert(kExprF32Sub, 2, 44.5f, 42.5f); | 564 TestFloat32BinopWithConvert(execution_mode, kExprF32Sub, 2, 44.5f, 42.5f); |
542 TestFloat32BinopWithConvert(kExprF32Mul, -66, -132.1f, 0.5f); | 565 TestFloat32BinopWithConvert(execution_mode, kExprF32Mul, -66, -132.1f, 0.5f); |
543 TestFloat32BinopWithConvert(kExprF32Div, 11, 22.1f, 2.0f); | 566 TestFloat32BinopWithConvert(execution_mode, kExprF32Div, 11, 22.1f, 2.0f); |
544 } | 567 } |
545 | 568 |
546 WASM_EXEC_TEST(Float32Unops) { | 569 WASM_EXEC_TEST(Float32Unops) { |
547 TestFloat32UnopWithConvert(kExprF32Abs, 8, 8.125f); | 570 TestFloat32UnopWithConvert(execution_mode, kExprF32Abs, 8, 8.125f); |
548 TestFloat32UnopWithConvert(kExprF32Abs, 9, -9.125f); | 571 TestFloat32UnopWithConvert(execution_mode, kExprF32Abs, 9, -9.125f); |
549 TestFloat32UnopWithConvert(kExprF32Neg, -213, 213.125f); | 572 TestFloat32UnopWithConvert(execution_mode, kExprF32Neg, -213, 213.125f); |
550 TestFloat32UnopWithConvert(kExprF32Sqrt, 12, 144.4f); | 573 TestFloat32UnopWithConvert(execution_mode, kExprF32Sqrt, 12, 144.4f); |
551 } | 574 } |
552 | 575 |
553 WASM_EXEC_TEST(Float64Binops) { | 576 WASM_EXEC_TEST(Float64Binops) { |
554 TestFloat64Binop(kExprF64Eq, 1, 16.25, 16.25); | 577 TestFloat64Binop(execution_mode, kExprF64Eq, 1, 16.25, 16.25); |
555 TestFloat64Binop(kExprF64Ne, 1, 16.25, 16.15); | 578 TestFloat64Binop(execution_mode, kExprF64Ne, 1, 16.25, 16.15); |
556 TestFloat64Binop(kExprF64Lt, 1, -32.4, 11.7); | 579 TestFloat64Binop(execution_mode, kExprF64Lt, 1, -32.4, 11.7); |
557 TestFloat64Binop(kExprF64Le, 1, -88.9, -88.9); | 580 TestFloat64Binop(execution_mode, kExprF64Le, 1, -88.9, -88.9); |
558 TestFloat64Binop(kExprF64Gt, 1, 11.7, -32.4); | 581 TestFloat64Binop(execution_mode, kExprF64Gt, 1, 11.7, -32.4); |
559 TestFloat64Binop(kExprF64Ge, 1, -88.9, -88.9); | 582 TestFloat64Binop(execution_mode, kExprF64Ge, 1, -88.9, -88.9); |
560 | 583 |
561 TestFloat64BinopWithConvert(kExprF64Add, 100, 43.5, 56.5); | 584 TestFloat64BinopWithConvert(execution_mode, kExprF64Add, 100, 43.5, 56.5); |
562 TestFloat64BinopWithConvert(kExprF64Sub, 200, 12200.1, 12000.1); | 585 TestFloat64BinopWithConvert(execution_mode, kExprF64Sub, 200, 12200.1, |
563 TestFloat64BinopWithConvert(kExprF64Mul, -33, 134, -0.25); | 586 12000.1); |
564 TestFloat64BinopWithConvert(kExprF64Div, -1111, -2222.3, 2); | 587 TestFloat64BinopWithConvert(execution_mode, kExprF64Mul, -33, 134, -0.25); |
| 588 TestFloat64BinopWithConvert(execution_mode, kExprF64Div, -1111, -2222.3, 2); |
565 } | 589 } |
566 | 590 |
567 WASM_EXEC_TEST(Float64Unops) { | 591 WASM_EXEC_TEST(Float64Unops) { |
568 TestFloat64UnopWithConvert(kExprF64Abs, 108, 108.125); | 592 TestFloat64UnopWithConvert(execution_mode, kExprF64Abs, 108, 108.125); |
569 TestFloat64UnopWithConvert(kExprF64Abs, 209, -209.125); | 593 TestFloat64UnopWithConvert(execution_mode, kExprF64Abs, 209, -209.125); |
570 TestFloat64UnopWithConvert(kExprF64Neg, -209, 209.125); | 594 TestFloat64UnopWithConvert(execution_mode, kExprF64Neg, -209, 209.125); |
571 TestFloat64UnopWithConvert(kExprF64Sqrt, 13, 169.4); | 595 TestFloat64UnopWithConvert(execution_mode, kExprF64Sqrt, 13, 169.4); |
572 } | 596 } |
573 | 597 |
574 WASM_EXEC_TEST(Float32Neg) { | 598 WASM_EXEC_TEST(Float32Neg) { |
575 WasmRunner<float> r(MachineType::Float32()); | 599 WasmRunner<float> r(execution_mode, MachineType::Float32()); |
576 BUILD(r, WASM_F32_NEG(WASM_GET_LOCAL(0))); | 600 BUILD(r, WASM_F32_NEG(WASM_GET_LOCAL(0))); |
577 | 601 |
578 FOR_FLOAT32_INPUTS(i) { | 602 FOR_FLOAT32_INPUTS(i) { |
579 CHECK_EQ(0x80000000, | 603 CHECK_EQ(0x80000000, |
580 bit_cast<uint32_t>(*i) ^ bit_cast<uint32_t>(r.Call(*i))); | 604 bit_cast<uint32_t>(*i) ^ bit_cast<uint32_t>(r.Call(*i))); |
581 } | 605 } |
582 } | 606 } |
583 | 607 |
584 WASM_EXEC_TEST(Float32SubMinusZero) { | 608 WASM_EXEC_TEST(Float32SubMinusZero) { |
585 WasmRunner<float> r(MachineType::Float32()); | 609 WasmRunner<float> r(execution_mode, MachineType::Float32()); |
586 BUILD(r, WASM_F32_SUB(WASM_F32(-0.0), WASM_GET_LOCAL(0))); | 610 BUILD(r, WASM_F32_SUB(WASM_F32(-0.0), WASM_GET_LOCAL(0))); |
587 | 611 |
588 CHECK_EQ(0x7fe00000, bit_cast<uint32_t>(r.Call(bit_cast<float>(0x7fa00000)))); | 612 CHECK_EQ(0x7fe00000, bit_cast<uint32_t>(r.Call(bit_cast<float>(0x7fa00000)))); |
589 } | 613 } |
590 | 614 |
591 WASM_EXEC_TEST(Float64SubMinusZero) { | 615 WASM_EXEC_TEST(Float64SubMinusZero) { |
592 WasmRunner<double> r(MachineType::Float64()); | 616 WasmRunner<double> r(execution_mode, MachineType::Float64()); |
593 BUILD(r, WASM_F64_SUB(WASM_F64(-0.0), WASM_GET_LOCAL(0))); | 617 BUILD(r, WASM_F64_SUB(WASM_F64(-0.0), WASM_GET_LOCAL(0))); |
594 | 618 |
595 CHECK_EQ(0x7ff8123456789abc, | 619 CHECK_EQ(0x7ff8123456789abc, |
596 bit_cast<uint64_t>(r.Call(bit_cast<double>(0x7ff0123456789abc)))); | 620 bit_cast<uint64_t>(r.Call(bit_cast<double>(0x7ff0123456789abc)))); |
597 } | 621 } |
598 | 622 |
599 WASM_EXEC_TEST(Float64Neg) { | 623 WASM_EXEC_TEST(Float64Neg) { |
600 WasmRunner<double> r(MachineType::Float64()); | 624 WasmRunner<double> r(execution_mode, MachineType::Float64()); |
601 BUILD(r, WASM_F64_NEG(WASM_GET_LOCAL(0))); | 625 BUILD(r, WASM_F64_NEG(WASM_GET_LOCAL(0))); |
602 | 626 |
603 FOR_FLOAT64_INPUTS(i) { | 627 FOR_FLOAT64_INPUTS(i) { |
604 CHECK_EQ(0x8000000000000000, | 628 CHECK_EQ(0x8000000000000000, |
605 bit_cast<uint64_t>(*i) ^ bit_cast<uint64_t>(r.Call(*i))); | 629 bit_cast<uint64_t>(*i) ^ bit_cast<uint64_t>(r.Call(*i))); |
606 } | 630 } |
607 } | 631 } |
608 | 632 |
609 WASM_EXEC_TEST(IfElse_P) { | 633 WASM_EXEC_TEST(IfElse_P) { |
610 WasmRunner<int32_t> r(MachineType::Int32()); | 634 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
611 // if (p0) return 11; else return 22; | 635 // if (p0) return 11; else return 22; |
612 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- | 636 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- |
613 WASM_I8(11), // -- | 637 WASM_I8(11), // -- |
614 WASM_I8(22))); // -- | 638 WASM_I8(22))); // -- |
615 FOR_INT32_INPUTS(i) { | 639 FOR_INT32_INPUTS(i) { |
616 int32_t expected = *i ? 11 : 22; | 640 int32_t expected = *i ? 11 : 22; |
617 CHECK_EQ(expected, r.Call(*i)); | 641 CHECK_EQ(expected, r.Call(*i)); |
618 } | 642 } |
619 } | 643 } |
620 | 644 |
621 WASM_EXEC_TEST(If_empty1) { | 645 WASM_EXEC_TEST(If_empty1) { |
622 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 646 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(), |
| 647 MachineType::Uint32()); |
623 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprEnd, WASM_GET_LOCAL(1)); | 648 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprEnd, WASM_GET_LOCAL(1)); |
624 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 9, *i)); } | 649 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 9, *i)); } |
625 } | 650 } |
626 | 651 |
627 WASM_EXEC_TEST(IfElse_empty1) { | 652 WASM_EXEC_TEST(IfElse_empty1) { |
628 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 653 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(), |
| 654 MachineType::Uint32()); |
629 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprElse, kExprEnd, WASM_GET_LOCAL(1)); | 655 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprElse, kExprEnd, WASM_GET_LOCAL(1)); |
630 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 8, *i)); } | 656 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 8, *i)); } |
631 } | 657 } |
632 | 658 |
633 WASM_EXEC_TEST(IfElse_empty2) { | 659 WASM_EXEC_TEST(IfElse_empty2) { |
634 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 660 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(), |
| 661 MachineType::Uint32()); |
635 BUILD(r, WASM_GET_LOCAL(0), kExprIf, WASM_ZERO, kExprElse, kExprEnd, | 662 BUILD(r, WASM_GET_LOCAL(0), kExprIf, WASM_ZERO, kExprElse, kExprEnd, |
636 WASM_GET_LOCAL(1)); | 663 WASM_GET_LOCAL(1)); |
637 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 7, *i)); } | 664 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 7, *i)); } |
638 } | 665 } |
639 | 666 |
640 WASM_EXEC_TEST(IfElse_empty3) { | 667 WASM_EXEC_TEST(IfElse_empty3) { |
641 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 668 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(), |
| 669 MachineType::Uint32()); |
642 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprElse, WASM_ZERO, kExprEnd, | 670 BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprElse, WASM_ZERO, kExprEnd, |
643 WASM_GET_LOCAL(1)); | 671 WASM_GET_LOCAL(1)); |
644 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 6, *i)); } | 672 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 6, *i)); } |
645 } | 673 } |
646 | 674 |
647 WASM_EXEC_TEST(If_chain) { | 675 WASM_EXEC_TEST(If_chain) { |
648 WasmRunner<int32_t> r(MachineType::Int32()); | 676 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
649 // if (p0) 13; if (p0) 14; 15 | 677 // if (p0) 13; if (p0) 14; 15 |
650 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_I8(13)), | 678 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_I8(13)), |
651 WASM_IF(WASM_GET_LOCAL(0), WASM_I8(14)), WASM_I8(15)); | 679 WASM_IF(WASM_GET_LOCAL(0), WASM_I8(14)), WASM_I8(15)); |
652 FOR_INT32_INPUTS(i) { CHECK_EQ(15, r.Call(*i)); } | 680 FOR_INT32_INPUTS(i) { CHECK_EQ(15, r.Call(*i)); } |
653 } | 681 } |
654 | 682 |
655 WASM_EXEC_TEST(If_chain_set) { | 683 WASM_EXEC_TEST(If_chain_set) { |
656 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 684 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 685 MachineType::Int32()); |
657 // if (p0) p1 = 73; if (p0) p1 = 74; p1 | 686 // if (p0) p1 = 73; if (p0) p1 = 74; p1 |
658 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(73))), | 687 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(73))), |
659 WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(74))), | 688 WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(74))), |
660 WASM_GET_LOCAL(1)); | 689 WASM_GET_LOCAL(1)); |
661 FOR_INT32_INPUTS(i) { | 690 FOR_INT32_INPUTS(i) { |
662 int32_t expected = *i ? 74 : *i; | 691 int32_t expected = *i ? 74 : *i; |
663 CHECK_EQ(expected, r.Call(*i, *i)); | 692 CHECK_EQ(expected, r.Call(*i, *i)); |
664 } | 693 } |
665 } | 694 } |
666 | 695 |
667 WASM_EXEC_TEST(IfElse_Unreachable1) { | 696 WASM_EXEC_TEST(IfElse_Unreachable1) { |
668 WasmRunner<int32_t> r; | 697 WasmRunner<int32_t> r(execution_mode); |
669 // if (0) unreachable; else return 22; | 698 // if (0) unreachable; else return 22; |
670 BUILD(r, WASM_IF_ELSE(WASM_ZERO, // -- | 699 BUILD(r, WASM_IF_ELSE(WASM_ZERO, // -- |
671 WASM_UNREACHABLE, // -- | 700 WASM_UNREACHABLE, // -- |
672 WASM_I8(27))); // -- | 701 WASM_I8(27))); // -- |
673 CHECK_EQ(27, r.Call()); | 702 CHECK_EQ(27, r.Call()); |
674 } | 703 } |
675 | 704 |
676 WASM_EXEC_TEST(Return12) { | 705 WASM_EXEC_TEST(Return12) { |
677 WasmRunner<int32_t> r; | 706 WasmRunner<int32_t> r(execution_mode); |
678 | 707 |
679 BUILD(r, RET_I8(12)); | 708 BUILD(r, RET_I8(12)); |
680 CHECK_EQ(12, r.Call()); | 709 CHECK_EQ(12, r.Call()); |
681 } | 710 } |
682 | 711 |
683 WASM_EXEC_TEST(Return17) { | 712 WASM_EXEC_TEST(Return17) { |
684 WasmRunner<int32_t> r; | 713 WasmRunner<int32_t> r(execution_mode); |
685 | 714 |
686 BUILD(r, B1(RET_I8(17))); | 715 BUILD(r, B1(RET_I8(17))); |
687 CHECK_EQ(17, r.Call()); | 716 CHECK_EQ(17, r.Call()); |
688 } | 717 } |
689 | 718 |
690 WASM_EXEC_TEST(Return_I32) { | 719 WASM_EXEC_TEST(Return_I32) { |
691 WasmRunner<int32_t> r(MachineType::Int32()); | 720 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
692 | 721 |
693 BUILD(r, RET(WASM_GET_LOCAL(0))); | 722 BUILD(r, RET(WASM_GET_LOCAL(0))); |
694 | 723 |
695 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 724 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
696 } | 725 } |
697 | 726 |
698 WASM_EXEC_TEST(Return_F32) { | 727 WASM_EXEC_TEST(Return_F32) { |
699 WasmRunner<float> r(MachineType::Float32()); | 728 WasmRunner<float> r(execution_mode, MachineType::Float32()); |
700 | 729 |
701 BUILD(r, RET(WASM_GET_LOCAL(0))); | 730 BUILD(r, RET(WASM_GET_LOCAL(0))); |
702 | 731 |
703 FOR_FLOAT32_INPUTS(i) { | 732 FOR_FLOAT32_INPUTS(i) { |
704 float expect = *i; | 733 float expect = *i; |
705 float result = r.Call(expect); | 734 float result = r.Call(expect); |
706 if (std::isnan(expect)) { | 735 if (std::isnan(expect)) { |
707 CHECK(std::isnan(result)); | 736 CHECK(std::isnan(result)); |
708 } else { | 737 } else { |
709 CHECK_EQ(expect, result); | 738 CHECK_EQ(expect, result); |
710 } | 739 } |
711 } | 740 } |
712 } | 741 } |
713 | 742 |
714 WASM_EXEC_TEST(Return_F64) { | 743 WASM_EXEC_TEST(Return_F64) { |
715 WasmRunner<double> r(MachineType::Float64()); | 744 WasmRunner<double> r(execution_mode, MachineType::Float64()); |
716 | 745 |
717 BUILD(r, RET(WASM_GET_LOCAL(0))); | 746 BUILD(r, RET(WASM_GET_LOCAL(0))); |
718 | 747 |
719 FOR_FLOAT64_INPUTS(i) { | 748 FOR_FLOAT64_INPUTS(i) { |
720 double expect = *i; | 749 double expect = *i; |
721 double result = r.Call(expect); | 750 double result = r.Call(expect); |
722 if (std::isnan(expect)) { | 751 if (std::isnan(expect)) { |
723 CHECK(std::isnan(result)); | 752 CHECK(std::isnan(result)); |
724 } else { | 753 } else { |
725 CHECK_EQ(expect, result); | 754 CHECK_EQ(expect, result); |
726 } | 755 } |
727 } | 756 } |
728 } | 757 } |
729 | 758 |
730 WASM_EXEC_TEST(Select) { | 759 WASM_EXEC_TEST(Select) { |
731 WasmRunner<int32_t> r(MachineType::Int32()); | 760 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
732 // return select(11, 22, a); | 761 // return select(11, 22, a); |
733 BUILD(r, WASM_SELECT(WASM_I8(11), WASM_I8(22), WASM_GET_LOCAL(0))); | 762 BUILD(r, WASM_SELECT(WASM_I8(11), WASM_I8(22), WASM_GET_LOCAL(0))); |
734 FOR_INT32_INPUTS(i) { | 763 FOR_INT32_INPUTS(i) { |
735 int32_t expected = *i ? 11 : 22; | 764 int32_t expected = *i ? 11 : 22; |
736 CHECK_EQ(expected, r.Call(*i)); | 765 CHECK_EQ(expected, r.Call(*i)); |
737 } | 766 } |
738 } | 767 } |
739 | 768 |
740 WASM_EXEC_TEST(Select_strict1) { | 769 WASM_EXEC_TEST(Select_strict1) { |
741 WasmRunner<int32_t> r(MachineType::Int32()); | 770 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
742 // select(a=0, a=1, a=2); return a | 771 // select(a=0, a=1, a=2); return a |
743 BUILD(r, B2(WASM_SELECT(WASM_SET_LOCAL(0, WASM_I8(0)), | 772 BUILD(r, B2(WASM_SELECT(WASM_SET_LOCAL(0, WASM_I8(0)), |
744 WASM_SET_LOCAL(0, WASM_I8(1)), | 773 WASM_SET_LOCAL(0, WASM_I8(1)), |
745 WASM_SET_LOCAL(0, WASM_I8(2))), | 774 WASM_SET_LOCAL(0, WASM_I8(2))), |
746 WASM_GET_LOCAL(0))); | 775 WASM_GET_LOCAL(0))); |
747 FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); } | 776 FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); } |
748 } | 777 } |
749 | 778 |
750 WASM_EXEC_TEST(Select_strict2) { | 779 WASM_EXEC_TEST(Select_strict2) { |
751 WasmRunner<int32_t> r(MachineType::Int32()); | 780 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
752 r.AllocateLocal(kAstI32); | 781 r.AllocateLocal(kAstI32); |
753 r.AllocateLocal(kAstI32); | 782 r.AllocateLocal(kAstI32); |
754 // select(b=5, c=6, a) | 783 // select(b=5, c=6, a) |
755 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)), | 784 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)), |
756 WASM_SET_LOCAL(2, WASM_I8(6)), WASM_GET_LOCAL(0))); | 785 WASM_SET_LOCAL(2, WASM_I8(6)), WASM_GET_LOCAL(0))); |
757 FOR_INT32_INPUTS(i) { | 786 FOR_INT32_INPUTS(i) { |
758 int32_t expected = *i ? 5 : 6; | 787 int32_t expected = *i ? 5 : 6; |
759 CHECK_EQ(expected, r.Call(*i)); | 788 CHECK_EQ(expected, r.Call(*i)); |
760 } | 789 } |
761 } | 790 } |
762 | 791 |
763 WASM_EXEC_TEST(Select_strict3) { | 792 WASM_EXEC_TEST(Select_strict3) { |
764 WasmRunner<int32_t> r(MachineType::Int32()); | 793 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
765 r.AllocateLocal(kAstI32); | 794 r.AllocateLocal(kAstI32); |
766 r.AllocateLocal(kAstI32); | 795 r.AllocateLocal(kAstI32); |
767 // select(b=5, c=6, a=b) | 796 // select(b=5, c=6, a=b) |
768 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)), | 797 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)), |
769 WASM_SET_LOCAL(2, WASM_I8(6)), | 798 WASM_SET_LOCAL(2, WASM_I8(6)), |
770 WASM_SET_LOCAL(0, WASM_GET_LOCAL(1)))); | 799 WASM_SET_LOCAL(0, WASM_GET_LOCAL(1)))); |
771 FOR_INT32_INPUTS(i) { | 800 FOR_INT32_INPUTS(i) { |
772 int32_t expected = 5; | 801 int32_t expected = 5; |
773 CHECK_EQ(expected, r.Call(*i)); | 802 CHECK_EQ(expected, r.Call(*i)); |
774 } | 803 } |
775 } | 804 } |
776 | 805 |
777 WASM_EXEC_TEST(BrIf_strict) { | 806 WASM_EXEC_TEST(BrIf_strict) { |
778 WasmRunner<int32_t> r(MachineType::Int32()); | 807 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
779 BUILD( | 808 BUILD( |
780 r, | 809 r, |
781 B2(B1(WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(99)))), | 810 B2(B1(WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(99)))), |
782 WASM_GET_LOCAL(0))); | 811 WASM_GET_LOCAL(0))); |
783 | 812 |
784 FOR_INT32_INPUTS(i) { CHECK_EQ(99, r.Call(*i)); } | 813 FOR_INT32_INPUTS(i) { CHECK_EQ(99, r.Call(*i)); } |
785 } | 814 } |
786 | 815 |
787 WASM_EXEC_TEST(BrTable0a) { | 816 WASM_EXEC_TEST(BrTable0a) { |
788 WasmRunner<int32_t> r(MachineType::Int32()); | 817 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
789 BUILD(r, | 818 BUILD(r, |
790 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), WASM_I8(91))); | 819 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), WASM_I8(91))); |
791 FOR_INT32_INPUTS(i) { CHECK_EQ(91, r.Call(*i)); } | 820 FOR_INT32_INPUTS(i) { CHECK_EQ(91, r.Call(*i)); } |
792 } | 821 } |
793 | 822 |
794 WASM_EXEC_TEST(BrTable0b) { | 823 WASM_EXEC_TEST(BrTable0b) { |
795 WasmRunner<int32_t> r(MachineType::Int32()); | 824 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
796 BUILD(r, | 825 BUILD(r, |
797 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(0))), | 826 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(0))), |
798 WASM_I8(92))); | 827 WASM_I8(92))); |
799 FOR_INT32_INPUTS(i) { CHECK_EQ(92, r.Call(*i)); } | 828 FOR_INT32_INPUTS(i) { CHECK_EQ(92, r.Call(*i)); } |
800 } | 829 } |
801 | 830 |
802 WASM_EXEC_TEST(BrTable0c) { | 831 WASM_EXEC_TEST(BrTable0c) { |
803 WasmRunner<int32_t> r(MachineType::Int32()); | 832 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
804 BUILD( | 833 BUILD( |
805 r, | 834 r, |
806 B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(1))), | 835 B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(1))), |
807 RET_I8(76)), | 836 RET_I8(76)), |
808 WASM_I8(77))); | 837 WASM_I8(77))); |
809 FOR_INT32_INPUTS(i) { | 838 FOR_INT32_INPUTS(i) { |
810 int32_t expected = *i == 0 ? 76 : 77; | 839 int32_t expected = *i == 0 ? 76 : 77; |
811 CHECK_EQ(expected, r.Call(*i)); | 840 CHECK_EQ(expected, r.Call(*i)); |
812 } | 841 } |
813 } | 842 } |
814 | 843 |
815 WASM_EXEC_TEST(BrTable1) { | 844 WASM_EXEC_TEST(BrTable1) { |
816 WasmRunner<int32_t> r(MachineType::Int32()); | 845 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
817 BUILD(r, B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), RET_I8(93)); | 846 BUILD(r, B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), RET_I8(93)); |
818 FOR_INT32_INPUTS(i) { CHECK_EQ(93, r.Call(*i)); } | 847 FOR_INT32_INPUTS(i) { CHECK_EQ(93, r.Call(*i)); } |
819 } | 848 } |
820 | 849 |
821 WASM_EXEC_TEST(BrTable_loop) { | 850 WASM_EXEC_TEST(BrTable_loop) { |
822 WasmRunner<int32_t> r(MachineType::Int32()); | 851 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
823 BUILD(r, | 852 BUILD(r, |
824 B2(WASM_LOOP(1, WASM_BR_TABLE(WASM_INC_LOCAL_BY(0, 1), 2, BR_TARGET(2), | 853 B2(WASM_LOOP(1, WASM_BR_TABLE(WASM_INC_LOCAL_BY(0, 1), 2, BR_TARGET(2), |
825 BR_TARGET(1), BR_TARGET(0))), | 854 BR_TARGET(1), BR_TARGET(0))), |
826 RET_I8(99)), | 855 RET_I8(99)), |
827 WASM_I8(98)); | 856 WASM_I8(98)); |
828 CHECK_EQ(99, r.Call(0)); | 857 CHECK_EQ(99, r.Call(0)); |
829 CHECK_EQ(98, r.Call(-1)); | 858 CHECK_EQ(98, r.Call(-1)); |
830 CHECK_EQ(98, r.Call(-2)); | 859 CHECK_EQ(98, r.Call(-2)); |
831 CHECK_EQ(98, r.Call(-3)); | 860 CHECK_EQ(98, r.Call(-3)); |
832 CHECK_EQ(98, r.Call(-100)); | 861 CHECK_EQ(98, r.Call(-100)); |
833 } | 862 } |
834 | 863 |
835 WASM_EXEC_TEST(BrTable_br) { | 864 WASM_EXEC_TEST(BrTable_br) { |
836 WasmRunner<int32_t> r(MachineType::Int32()); | 865 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
837 BUILD(r, | 866 BUILD(r, |
838 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(1), BR_TARGET(0))), | 867 B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(1), BR_TARGET(0))), |
839 RET_I8(91)), | 868 RET_I8(91)), |
840 WASM_I8(99)); | 869 WASM_I8(99)); |
841 CHECK_EQ(99, r.Call(0)); | 870 CHECK_EQ(99, r.Call(0)); |
842 CHECK_EQ(91, r.Call(1)); | 871 CHECK_EQ(91, r.Call(1)); |
843 CHECK_EQ(91, r.Call(2)); | 872 CHECK_EQ(91, r.Call(2)); |
844 CHECK_EQ(91, r.Call(3)); | 873 CHECK_EQ(91, r.Call(3)); |
845 } | 874 } |
846 | 875 |
847 WASM_EXEC_TEST(BrTable_br2) { | 876 WASM_EXEC_TEST(BrTable_br2) { |
848 WasmRunner<int32_t> r(MachineType::Int32()); | 877 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
849 | 878 |
850 BUILD(r, B2(B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 3, BR_TARGET(1), | 879 BUILD(r, B2(B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 3, BR_TARGET(1), |
851 BR_TARGET(2), BR_TARGET(3), BR_TARGET(0))), | 880 BR_TARGET(2), BR_TARGET(3), BR_TARGET(0))), |
852 RET_I8(85)), | 881 RET_I8(85)), |
853 RET_I8(86)), | 882 RET_I8(86)), |
854 RET_I8(87)), | 883 RET_I8(87)), |
855 WASM_I8(88)); | 884 WASM_I8(88)); |
856 CHECK_EQ(86, r.Call(0)); | 885 CHECK_EQ(86, r.Call(0)); |
857 CHECK_EQ(87, r.Call(1)); | 886 CHECK_EQ(87, r.Call(1)); |
858 CHECK_EQ(88, r.Call(2)); | 887 CHECK_EQ(88, r.Call(2)); |
(...skipping 10 matching lines...) Expand all Loading... |
869 byte code[] = {B2(B2(B2(B2(B1(WASM_BR_TABLE( | 898 byte code[] = {B2(B2(B2(B2(B1(WASM_BR_TABLE( |
870 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]), | 899 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]), |
871 BR_TARGET(cases[1]), BR_TARGET(cases[2]), | 900 BR_TARGET(cases[1]), BR_TARGET(cases[2]), |
872 BR_TARGET(cases[3]))), | 901 BR_TARGET(cases[3]))), |
873 RET_I8(70)), | 902 RET_I8(70)), |
874 RET_I8(71)), | 903 RET_I8(71)), |
875 RET_I8(72)), | 904 RET_I8(72)), |
876 RET_I8(73)), | 905 RET_I8(73)), |
877 WASM_I8(75)}; | 906 WASM_I8(75)}; |
878 | 907 |
879 WasmRunner<int32_t> r(MachineType::Int32()); | 908 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
880 r.Build(code, code + arraysize(code)); | 909 r.Build(code, code + arraysize(code)); |
881 | 910 |
882 for (int x = -3; x < 50; x++) { | 911 for (int x = -3; x < 50; x++) { |
883 int index = (x > 3 || x < 0) ? 3 : x; | 912 int index = (x > 3 || x < 0) ? 3 : x; |
884 int32_t expected = 70 + cases[index]; | 913 int32_t expected = 70 + cases[index]; |
885 CHECK_EQ(expected, r.Call(x)); | 914 CHECK_EQ(expected, r.Call(x)); |
886 } | 915 } |
887 } | 916 } |
888 } | 917 } |
889 } | 918 } |
890 | 919 |
891 WASM_EXEC_TEST(BrTable4x4) { | 920 WASM_EXEC_TEST(BrTable4x4) { |
892 for (byte a = 0; a < 4; a++) { | 921 for (byte a = 0; a < 4; a++) { |
893 for (byte b = 0; b < 4; b++) { | 922 for (byte b = 0; b < 4; b++) { |
894 for (byte c = 0; c < 4; c++) { | 923 for (byte c = 0; c < 4; c++) { |
895 for (byte d = 0; d < 4; d++) { | 924 for (byte d = 0; d < 4; d++) { |
896 for (int i = 0; i < 4; i++) { | 925 for (int i = 0; i < 4; i++) { |
897 uint32_t cases[] = {a, b, c, d}; | 926 uint32_t cases[] = {a, b, c, d}; |
898 byte code[] = { | 927 byte code[] = { |
899 B2(B2(B2(B2(B1(WASM_BR_TABLE( | 928 B2(B2(B2(B2(B1(WASM_BR_TABLE( |
900 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]), | 929 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]), |
901 BR_TARGET(cases[1]), BR_TARGET(cases[2]), | 930 BR_TARGET(cases[1]), BR_TARGET(cases[2]), |
902 BR_TARGET(cases[3]))), | 931 BR_TARGET(cases[3]))), |
903 RET_I8(50)), | 932 RET_I8(50)), |
904 RET_I8(51)), | 933 RET_I8(51)), |
905 RET_I8(52)), | 934 RET_I8(52)), |
906 RET_I8(53)), | 935 RET_I8(53)), |
907 WASM_I8(55)}; | 936 WASM_I8(55)}; |
908 | 937 |
909 WasmRunner<int32_t> r(MachineType::Int32()); | 938 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
910 r.Build(code, code + arraysize(code)); | 939 r.Build(code, code + arraysize(code)); |
911 | 940 |
912 for (int x = -6; x < 47; x++) { | 941 for (int x = -6; x < 47; x++) { |
913 int index = (x > 3 || x < 0) ? 3 : x; | 942 int index = (x > 3 || x < 0) ? 3 : x; |
914 int32_t expected = 50 + cases[index]; | 943 int32_t expected = 50 + cases[index]; |
915 CHECK_EQ(expected, r.Call(x)); | 944 CHECK_EQ(expected, r.Call(x)); |
916 } | 945 } |
917 } | 946 } |
918 } | 947 } |
919 } | 948 } |
920 } | 949 } |
921 } | 950 } |
922 } | 951 } |
923 | 952 |
924 WASM_EXEC_TEST(BrTable4_fallthru) { | 953 WASM_EXEC_TEST(BrTable4_fallthru) { |
925 byte code[] = { | 954 byte code[] = { |
926 B2(B2(B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 3, BR_TARGET(0), | 955 B2(B2(B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 3, BR_TARGET(0), |
927 BR_TARGET(1), BR_TARGET(2), BR_TARGET(3))), | 956 BR_TARGET(1), BR_TARGET(2), BR_TARGET(3))), |
928 WASM_INC_LOCAL_BY(1, 1)), | 957 WASM_INC_LOCAL_BY(1, 1)), |
929 WASM_INC_LOCAL_BY(1, 2)), | 958 WASM_INC_LOCAL_BY(1, 2)), |
930 WASM_INC_LOCAL_BY(1, 4)), | 959 WASM_INC_LOCAL_BY(1, 4)), |
931 WASM_INC_LOCAL_BY(1, 8)), | 960 WASM_INC_LOCAL_BY(1, 8)), |
932 WASM_GET_LOCAL(1)}; | 961 WASM_GET_LOCAL(1)}; |
933 | 962 |
934 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 963 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 964 MachineType::Int32()); |
935 r.Build(code, code + arraysize(code)); | 965 r.Build(code, code + arraysize(code)); |
936 | 966 |
937 CHECK_EQ(15, r.Call(0, 0)); | 967 CHECK_EQ(15, r.Call(0, 0)); |
938 CHECK_EQ(14, r.Call(1, 0)); | 968 CHECK_EQ(14, r.Call(1, 0)); |
939 CHECK_EQ(12, r.Call(2, 0)); | 969 CHECK_EQ(12, r.Call(2, 0)); |
940 CHECK_EQ(8, r.Call(3, 0)); | 970 CHECK_EQ(8, r.Call(3, 0)); |
941 CHECK_EQ(8, r.Call(4, 0)); | 971 CHECK_EQ(8, r.Call(4, 0)); |
942 | 972 |
943 CHECK_EQ(115, r.Call(0, 100)); | 973 CHECK_EQ(115, r.Call(0, 100)); |
944 CHECK_EQ(114, r.Call(1, 100)); | 974 CHECK_EQ(114, r.Call(1, 100)); |
945 CHECK_EQ(112, r.Call(2, 100)); | 975 CHECK_EQ(112, r.Call(2, 100)); |
946 CHECK_EQ(108, r.Call(3, 100)); | 976 CHECK_EQ(108, r.Call(3, 100)); |
947 CHECK_EQ(108, r.Call(4, 100)); | 977 CHECK_EQ(108, r.Call(4, 100)); |
948 } | 978 } |
949 | 979 |
950 WASM_EXEC_TEST(F32ReinterpretI32) { | 980 WASM_EXEC_TEST(F32ReinterpretI32) { |
951 TestingModule module; | 981 TestingModule module(execution_mode); |
952 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 982 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
953 WasmRunner<int32_t> r(&module); | 983 WasmRunner<int32_t> r(&module); |
954 | 984 |
955 BUILD(r, WASM_I32_REINTERPRET_F32( | 985 BUILD(r, WASM_I32_REINTERPRET_F32( |
956 WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO))); | 986 WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO))); |
957 | 987 |
958 FOR_INT32_INPUTS(i) { | 988 FOR_INT32_INPUTS(i) { |
959 int32_t expected = *i; | 989 int32_t expected = *i; |
960 memory[0] = expected; | 990 memory[0] = expected; |
961 CHECK_EQ(expected, r.Call()); | 991 CHECK_EQ(expected, r.Call()); |
962 } | 992 } |
963 } | 993 } |
964 | 994 |
965 WASM_EXEC_TEST(I32ReinterpretF32) { | 995 WASM_EXEC_TEST(I32ReinterpretF32) { |
966 TestingModule module; | 996 TestingModule module(execution_mode); |
967 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 997 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
968 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 998 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
969 | 999 |
970 BUILD(r, WASM_BLOCK( | 1000 BUILD(r, WASM_BLOCK( |
971 2, WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, | 1001 2, WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, |
972 WASM_F32_REINTERPRET_I32(WASM_GET_LOCAL(0))), | 1002 WASM_F32_REINTERPRET_I32(WASM_GET_LOCAL(0))), |
973 WASM_I8(107))); | 1003 WASM_I8(107))); |
974 | 1004 |
975 FOR_INT32_INPUTS(i) { | 1005 FOR_INT32_INPUTS(i) { |
976 int32_t expected = *i; | 1006 int32_t expected = *i; |
977 CHECK_EQ(107, r.Call(expected)); | 1007 CHECK_EQ(107, r.Call(expected)); |
978 CHECK_EQ(expected, memory[0]); | 1008 CHECK_EQ(expected, memory[0]); |
979 } | 1009 } |
980 } | 1010 } |
981 | 1011 |
982 WASM_EXEC_TEST(ReturnStore) { | 1012 WASM_EXEC_TEST(ReturnStore) { |
983 TestingModule module; | 1013 TestingModule module(execution_mode); |
984 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 1014 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
985 WasmRunner<int32_t> r(&module); | 1015 WasmRunner<int32_t> r(&module); |
986 | 1016 |
987 BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, | 1017 BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, |
988 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO))); | 1018 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO))); |
989 | 1019 |
990 FOR_INT32_INPUTS(i) { | 1020 FOR_INT32_INPUTS(i) { |
991 int32_t expected = *i; | 1021 int32_t expected = *i; |
992 memory[0] = expected; | 1022 memory[0] = expected; |
993 CHECK_EQ(expected, r.Call()); | 1023 CHECK_EQ(expected, r.Call()); |
994 } | 1024 } |
995 } | 1025 } |
996 | 1026 |
997 WASM_EXEC_TEST(VoidReturn1) { | 1027 WASM_EXEC_TEST(VoidReturn1) { |
998 // We use a wrapper function because WasmRunner<void> does not exist. | 1028 // We use a wrapper function because WasmRunner<void> does not exist. |
999 | 1029 |
1000 // Build the test function. | 1030 // Build the test function. |
1001 TestSignatures sigs; | 1031 TestSignatures sigs; |
1002 TestingModule module; | 1032 TestingModule module(execution_mode); |
1003 WasmFunctionCompiler t(sigs.v_v(), &module); | 1033 WasmFunctionCompiler t(sigs.v_v(), &module); |
1004 BUILD(t, kExprNop); | 1034 BUILD(t, kExprNop); |
1005 uint32_t index = t.CompileAndAdd(); | 1035 uint32_t index = t.CompileAndAdd(); |
1006 | 1036 |
1007 const int32_t kExpected = -414444; | 1037 const int32_t kExpected = -414444; |
1008 // Build the calling function. | 1038 // Build the calling function. |
1009 WasmRunner<int32_t> r(&module); | 1039 WasmRunner<int32_t> r(&module); |
1010 BUILD(r, B2(WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected))); | 1040 BUILD(r, B2(WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected))); |
1011 | 1041 |
1012 int32_t result = r.Call(); | 1042 int32_t result = r.Call(); |
1013 CHECK_EQ(kExpected, result); | 1043 CHECK_EQ(kExpected, result); |
1014 } | 1044 } |
1015 | 1045 |
1016 WASM_EXEC_TEST(VoidReturn2) { | 1046 WASM_EXEC_TEST(VoidReturn2) { |
1017 // We use a wrapper function because WasmRunner<void> does not exist. | 1047 // We use a wrapper function because WasmRunner<void> does not exist. |
1018 // Build the test function. | 1048 // Build the test function. |
1019 TestSignatures sigs; | 1049 TestSignatures sigs; |
1020 TestingModule module; | 1050 TestingModule module(execution_mode); |
1021 WasmFunctionCompiler t(sigs.v_v(), &module); | 1051 WasmFunctionCompiler t(sigs.v_v(), &module); |
1022 BUILD(t, WASM_RETURN0); | 1052 BUILD(t, WASM_RETURN0); |
1023 uint32_t index = t.CompileAndAdd(); | 1053 uint32_t index = t.CompileAndAdd(); |
1024 | 1054 |
1025 const int32_t kExpected = -414444; | 1055 const int32_t kExpected = -414444; |
1026 // Build the calling function. | 1056 // Build the calling function. |
1027 WasmRunner<int32_t> r(&module); | 1057 WasmRunner<int32_t> r(&module); |
1028 BUILD(r, B2(WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected))); | 1058 BUILD(r, B2(WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected))); |
1029 | 1059 |
1030 int32_t result = r.Call(); | 1060 int32_t result = r.Call(); |
1031 CHECK_EQ(kExpected, result); | 1061 CHECK_EQ(kExpected, result); |
1032 } | 1062 } |
1033 | 1063 |
1034 WASM_EXEC_TEST(Block_empty) { | 1064 WASM_EXEC_TEST(Block_empty) { |
1035 WasmRunner<int32_t> r(MachineType::Int32()); | 1065 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1036 BUILD(r, kExprBlock, kExprEnd, WASM_GET_LOCAL(0)); | 1066 BUILD(r, kExprBlock, kExprEnd, WASM_GET_LOCAL(0)); |
1037 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1067 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
1038 } | 1068 } |
1039 | 1069 |
1040 WASM_EXEC_TEST(Block_empty_br1) { | 1070 WASM_EXEC_TEST(Block_empty_br1) { |
1041 WasmRunner<int32_t> r(MachineType::Int32()); | 1071 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1042 BUILD(r, B1(WASM_BR(0)), WASM_GET_LOCAL(0)); | 1072 BUILD(r, B1(WASM_BR(0)), WASM_GET_LOCAL(0)); |
1043 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1073 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
1044 } | 1074 } |
1045 | 1075 |
1046 WASM_EXEC_TEST(Block_empty_brif1) { | 1076 WASM_EXEC_TEST(Block_empty_brif1) { |
1047 WasmRunner<int32_t> r(MachineType::Int32()); | 1077 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1048 BUILD(r, B1(WASM_BR_IF(0, WASM_ZERO)), WASM_GET_LOCAL(0)); | 1078 BUILD(r, B1(WASM_BR_IF(0, WASM_ZERO)), WASM_GET_LOCAL(0)); |
1049 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1079 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
1050 } | 1080 } |
1051 | 1081 |
1052 WASM_EXEC_TEST(Block_empty_brif2) { | 1082 WASM_EXEC_TEST(Block_empty_brif2) { |
1053 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 1083 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(), |
| 1084 MachineType::Uint32()); |
1054 BUILD(r, B1(WASM_BR_IF(0, WASM_GET_LOCAL(1))), WASM_GET_LOCAL(0)); | 1085 BUILD(r, B1(WASM_BR_IF(0, WASM_GET_LOCAL(1))), WASM_GET_LOCAL(0)); |
1055 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); } | 1086 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); } |
1056 } | 1087 } |
1057 | 1088 |
1058 WASM_EXEC_TEST(Block_br2) { | 1089 WASM_EXEC_TEST(Block_br2) { |
1059 WasmRunner<int32_t> r(MachineType::Int32()); | 1090 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1060 BUILD(r, B1(WASM_BRV(0, WASM_GET_LOCAL(0)))); | 1091 BUILD(r, B1(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
1061 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1092 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
1062 } | 1093 } |
1063 | 1094 |
1064 WASM_EXEC_TEST(Block_If_P) { | 1095 WASM_EXEC_TEST(Block_If_P) { |
1065 WasmRunner<int32_t> r(MachineType::Int32()); | 1096 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1066 // { if (p0) return 51; return 52; } | 1097 // { if (p0) return 51; return 52; } |
1067 BUILD(r, B2( // -- | 1098 BUILD(r, B2( // -- |
1068 WASM_IF(WASM_GET_LOCAL(0), // -- | 1099 WASM_IF(WASM_GET_LOCAL(0), // -- |
1069 WASM_BRV(1, WASM_I8(51))), // -- | 1100 WASM_BRV(1, WASM_I8(51))), // -- |
1070 WASM_I8(52))); // -- | 1101 WASM_I8(52))); // -- |
1071 FOR_INT32_INPUTS(i) { | 1102 FOR_INT32_INPUTS(i) { |
1072 int32_t expected = *i ? 51 : 52; | 1103 int32_t expected = *i ? 51 : 52; |
1073 CHECK_EQ(expected, r.Call(*i)); | 1104 CHECK_EQ(expected, r.Call(*i)); |
1074 } | 1105 } |
1075 } | 1106 } |
1076 | 1107 |
1077 WASM_EXEC_TEST(Loop_empty) { | 1108 WASM_EXEC_TEST(Loop_empty) { |
1078 WasmRunner<int32_t> r(MachineType::Int32()); | 1109 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1079 BUILD(r, kExprLoop, kExprEnd, WASM_GET_LOCAL(0)); | 1110 BUILD(r, kExprLoop, kExprEnd, WASM_GET_LOCAL(0)); |
1080 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1111 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
1081 } | 1112 } |
1082 | 1113 |
1083 WASM_EXEC_TEST(Loop_empty_br1) { | 1114 WASM_EXEC_TEST(Loop_empty_br1) { |
1084 WasmRunner<int32_t> r(MachineType::Int32()); | 1115 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1085 BUILD(r, WASM_LOOP(1, WASM_BR(1)), WASM_GET_LOCAL(0)); | 1116 BUILD(r, WASM_LOOP(1, WASM_BR(1)), WASM_GET_LOCAL(0)); |
1086 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1117 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
1087 } | 1118 } |
1088 | 1119 |
1089 WASM_EXEC_TEST(Loop_empty_brif1) { | 1120 WASM_EXEC_TEST(Loop_empty_brif1) { |
1090 WasmRunner<int32_t> r(MachineType::Int32()); | 1121 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1091 BUILD(r, WASM_LOOP(1, WASM_BR_IF(1, WASM_ZERO)), WASM_GET_LOCAL(0)); | 1122 BUILD(r, WASM_LOOP(1, WASM_BR_IF(1, WASM_ZERO)), WASM_GET_LOCAL(0)); |
1092 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } | 1123 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } |
1093 } | 1124 } |
1094 | 1125 |
1095 WASM_EXEC_TEST(Loop_empty_brif2) { | 1126 WASM_EXEC_TEST(Loop_empty_brif2) { |
1096 WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32()); | 1127 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(), |
| 1128 MachineType::Uint32()); |
1097 BUILD(r, WASM_LOOP(1, WASM_BR_IF(1, WASM_GET_LOCAL(1))), WASM_GET_LOCAL(0)); | 1129 BUILD(r, WASM_LOOP(1, WASM_BR_IF(1, WASM_GET_LOCAL(1))), WASM_GET_LOCAL(0)); |
1098 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); } | 1130 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); } |
1099 } | 1131 } |
1100 | 1132 |
1101 WASM_EXEC_TEST(Block_BrIf_P) { | 1133 WASM_EXEC_TEST(Block_BrIf_P) { |
1102 WasmRunner<int32_t> r(MachineType::Int32()); | 1134 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1103 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(51), WASM_GET_LOCAL(0)), WASM_I8(52))); | 1135 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(51), WASM_GET_LOCAL(0)), WASM_I8(52))); |
1104 FOR_INT32_INPUTS(i) { | 1136 FOR_INT32_INPUTS(i) { |
1105 int32_t expected = *i ? 51 : 52; | 1137 int32_t expected = *i ? 51 : 52; |
1106 CHECK_EQ(expected, r.Call(*i)); | 1138 CHECK_EQ(expected, r.Call(*i)); |
1107 } | 1139 } |
1108 } | 1140 } |
1109 | 1141 |
1110 WASM_EXEC_TEST(Block_IfElse_P_assign) { | 1142 WASM_EXEC_TEST(Block_IfElse_P_assign) { |
1111 WasmRunner<int32_t> r(MachineType::Int32()); | 1143 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1112 // { if (p0) p0 = 71; else p0 = 72; return p0; } | 1144 // { if (p0) p0 = 71; else p0 = 72; return p0; } |
1113 BUILD(r, B2( // -- | 1145 BUILD(r, B2( // -- |
1114 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- | 1146 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- |
1115 WASM_SET_LOCAL(0, WASM_I8(71)), // -- | 1147 WASM_SET_LOCAL(0, WASM_I8(71)), // -- |
1116 WASM_SET_LOCAL(0, WASM_I8(72))), // -- | 1148 WASM_SET_LOCAL(0, WASM_I8(72))), // -- |
1117 WASM_GET_LOCAL(0))); | 1149 WASM_GET_LOCAL(0))); |
1118 FOR_INT32_INPUTS(i) { | 1150 FOR_INT32_INPUTS(i) { |
1119 int32_t expected = *i ? 71 : 72; | 1151 int32_t expected = *i ? 71 : 72; |
1120 CHECK_EQ(expected, r.Call(*i)); | 1152 CHECK_EQ(expected, r.Call(*i)); |
1121 } | 1153 } |
1122 } | 1154 } |
1123 | 1155 |
1124 WASM_EXEC_TEST(Block_IfElse_P_return) { | 1156 WASM_EXEC_TEST(Block_IfElse_P_return) { |
1125 WasmRunner<int32_t> r(MachineType::Int32()); | 1157 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1126 // if (p0) return 81; else return 82; | 1158 // if (p0) return 81; else return 82; |
1127 BUILD(r, // -- | 1159 BUILD(r, // -- |
1128 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- | 1160 WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- |
1129 RET_I8(81), // -- | 1161 RET_I8(81), // -- |
1130 RET_I8(82))); // -- | 1162 RET_I8(82))); // -- |
1131 FOR_INT32_INPUTS(i) { | 1163 FOR_INT32_INPUTS(i) { |
1132 int32_t expected = *i ? 81 : 82; | 1164 int32_t expected = *i ? 81 : 82; |
1133 CHECK_EQ(expected, r.Call(*i)); | 1165 CHECK_EQ(expected, r.Call(*i)); |
1134 } | 1166 } |
1135 } | 1167 } |
1136 | 1168 |
1137 WASM_EXEC_TEST(Block_If_P_assign) { | 1169 WASM_EXEC_TEST(Block_If_P_assign) { |
1138 WasmRunner<int32_t> r(MachineType::Int32()); | 1170 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1139 // { if (p0) p0 = 61; p0; } | 1171 // { if (p0) p0 = 61; p0; } |
1140 BUILD(r, WASM_BLOCK( | 1172 BUILD(r, WASM_BLOCK( |
1141 2, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(61))), | 1173 2, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(61))), |
1142 WASM_GET_LOCAL(0))); | 1174 WASM_GET_LOCAL(0))); |
1143 FOR_INT32_INPUTS(i) { | 1175 FOR_INT32_INPUTS(i) { |
1144 int32_t expected = *i ? 61 : *i; | 1176 int32_t expected = *i ? 61 : *i; |
1145 CHECK_EQ(expected, r.Call(*i)); | 1177 CHECK_EQ(expected, r.Call(*i)); |
1146 } | 1178 } |
1147 } | 1179 } |
1148 | 1180 |
1149 WASM_EXEC_TEST(DanglingAssign) { | 1181 WASM_EXEC_TEST(DanglingAssign) { |
1150 WasmRunner<int32_t> r(MachineType::Int32()); | 1182 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1151 // { return 0; p0 = 0; } | 1183 // { return 0; p0 = 0; } |
1152 BUILD(r, B2(RET_I8(99), WASM_SET_LOCAL(0, WASM_ZERO))); | 1184 BUILD(r, B2(RET_I8(99), WASM_SET_LOCAL(0, WASM_ZERO))); |
1153 CHECK_EQ(99, r.Call(1)); | 1185 CHECK_EQ(99, r.Call(1)); |
1154 } | 1186 } |
1155 | 1187 |
1156 WASM_EXEC_TEST(ExprIf_P) { | 1188 WASM_EXEC_TEST(ExprIf_P) { |
1157 WasmRunner<int32_t> r(MachineType::Int32()); | 1189 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1158 // p0 ? 11 : 22; | 1190 // p0 ? 11 : 22; |
1159 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- | 1191 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- |
1160 WASM_I8(11), // -- | 1192 WASM_I8(11), // -- |
1161 WASM_I8(22))); // -- | 1193 WASM_I8(22))); // -- |
1162 FOR_INT32_INPUTS(i) { | 1194 FOR_INT32_INPUTS(i) { |
1163 int32_t expected = *i ? 11 : 22; | 1195 int32_t expected = *i ? 11 : 22; |
1164 CHECK_EQ(expected, r.Call(*i)); | 1196 CHECK_EQ(expected, r.Call(*i)); |
1165 } | 1197 } |
1166 } | 1198 } |
1167 | 1199 |
1168 WASM_EXEC_TEST(ExprIf_P_fallthru) { | 1200 WASM_EXEC_TEST(ExprIf_P_fallthru) { |
1169 WasmRunner<int32_t> r(MachineType::Int32()); | 1201 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1170 // p0 ? 11 : 22; | 1202 // p0 ? 11 : 22; |
1171 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- | 1203 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- |
1172 WASM_I8(11), // -- | 1204 WASM_I8(11), // -- |
1173 WASM_I8(22))); // -- | 1205 WASM_I8(22))); // -- |
1174 FOR_INT32_INPUTS(i) { | 1206 FOR_INT32_INPUTS(i) { |
1175 int32_t expected = *i ? 11 : 22; | 1207 int32_t expected = *i ? 11 : 22; |
1176 CHECK_EQ(expected, r.Call(*i)); | 1208 CHECK_EQ(expected, r.Call(*i)); |
1177 } | 1209 } |
1178 } | 1210 } |
1179 | 1211 |
1180 WASM_EXEC_TEST(CountDown) { | 1212 WASM_EXEC_TEST(CountDown) { |
1181 WasmRunner<int32_t> r(MachineType::Int32()); | 1213 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1182 BUILD(r, | 1214 BUILD(r, |
1183 WASM_BLOCK( | 1215 WASM_BLOCK( |
1184 2, WASM_LOOP( | 1216 2, WASM_LOOP( |
1185 1, WASM_IF(WASM_GET_LOCAL(0), | 1217 1, WASM_IF(WASM_GET_LOCAL(0), |
1186 WASM_BRV(1, WASM_SET_LOCAL( | 1218 WASM_BRV(1, WASM_SET_LOCAL( |
1187 0, WASM_I32_SUB(WASM_GET_LOCAL(0), | 1219 0, WASM_I32_SUB(WASM_GET_LOCAL(0), |
1188 WASM_I8(1)))))), | 1220 WASM_I8(1)))))), |
1189 WASM_GET_LOCAL(0))); | 1221 WASM_GET_LOCAL(0))); |
1190 CHECK_EQ(0, r.Call(1)); | 1222 CHECK_EQ(0, r.Call(1)); |
1191 CHECK_EQ(0, r.Call(10)); | 1223 CHECK_EQ(0, r.Call(10)); |
1192 CHECK_EQ(0, r.Call(100)); | 1224 CHECK_EQ(0, r.Call(100)); |
1193 } | 1225 } |
1194 | 1226 |
1195 WASM_EXEC_TEST(CountDown_fallthru) { | 1227 WASM_EXEC_TEST(CountDown_fallthru) { |
1196 WasmRunner<int32_t> r(MachineType::Int32()); | 1228 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1197 BUILD(r, | 1229 BUILD(r, |
1198 WASM_BLOCK( | 1230 WASM_BLOCK( |
1199 2, WASM_LOOP(3, WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), WASM_BREAK(1)), | 1231 2, WASM_LOOP(3, WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), WASM_BREAK(1)), |
1200 WASM_SET_LOCAL( | 1232 WASM_SET_LOCAL( |
1201 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), | 1233 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), |
1202 WASM_CONTINUE(0)), | 1234 WASM_CONTINUE(0)), |
1203 WASM_GET_LOCAL(0))); | 1235 WASM_GET_LOCAL(0))); |
1204 CHECK_EQ(0, r.Call(1)); | 1236 CHECK_EQ(0, r.Call(1)); |
1205 CHECK_EQ(0, r.Call(10)); | 1237 CHECK_EQ(0, r.Call(10)); |
1206 CHECK_EQ(0, r.Call(100)); | 1238 CHECK_EQ(0, r.Call(100)); |
1207 } | 1239 } |
1208 | 1240 |
1209 WASM_EXEC_TEST(WhileCountDown) { | 1241 WASM_EXEC_TEST(WhileCountDown) { |
1210 WasmRunner<int32_t> r(MachineType::Int32()); | 1242 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1211 BUILD(r, WASM_BLOCK( | 1243 BUILD(r, WASM_BLOCK( |
1212 2, WASM_WHILE(WASM_GET_LOCAL(0), | 1244 2, WASM_WHILE(WASM_GET_LOCAL(0), |
1213 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), | 1245 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), |
1214 WASM_I8(1)))), | 1246 WASM_I8(1)))), |
1215 WASM_GET_LOCAL(0))); | 1247 WASM_GET_LOCAL(0))); |
1216 CHECK_EQ(0, r.Call(1)); | 1248 CHECK_EQ(0, r.Call(1)); |
1217 CHECK_EQ(0, r.Call(10)); | 1249 CHECK_EQ(0, r.Call(10)); |
1218 CHECK_EQ(0, r.Call(100)); | 1250 CHECK_EQ(0, r.Call(100)); |
1219 } | 1251 } |
1220 | 1252 |
1221 WASM_EXEC_TEST(Loop_if_break1) { | 1253 WASM_EXEC_TEST(Loop_if_break1) { |
1222 WasmRunner<int32_t> r(MachineType::Int32()); | 1254 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1223 BUILD(r, B2(WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(1)), | 1255 BUILD(r, B2(WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(1)), |
1224 WASM_SET_LOCAL(0, WASM_I8(99))), | 1256 WASM_SET_LOCAL(0, WASM_I8(99))), |
1225 WASM_GET_LOCAL(0))); | 1257 WASM_GET_LOCAL(0))); |
1226 CHECK_EQ(99, r.Call(0)); | 1258 CHECK_EQ(99, r.Call(0)); |
1227 CHECK_EQ(3, r.Call(3)); | 1259 CHECK_EQ(3, r.Call(3)); |
1228 CHECK_EQ(10000, r.Call(10000)); | 1260 CHECK_EQ(10000, r.Call(10000)); |
1229 CHECK_EQ(-29, r.Call(-29)); | 1261 CHECK_EQ(-29, r.Call(-29)); |
1230 } | 1262 } |
1231 | 1263 |
1232 WASM_EXEC_TEST(Loop_if_break2) { | 1264 WASM_EXEC_TEST(Loop_if_break2) { |
1233 WasmRunner<int32_t> r(MachineType::Int32()); | 1265 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1234 BUILD(r, B2(WASM_LOOP(2, WASM_BR_IF(1, WASM_GET_LOCAL(0)), | 1266 BUILD(r, B2(WASM_LOOP(2, WASM_BR_IF(1, WASM_GET_LOCAL(0)), |
1235 WASM_SET_LOCAL(0, WASM_I8(99))), | 1267 WASM_SET_LOCAL(0, WASM_I8(99))), |
1236 WASM_GET_LOCAL(0))); | 1268 WASM_GET_LOCAL(0))); |
1237 CHECK_EQ(99, r.Call(0)); | 1269 CHECK_EQ(99, r.Call(0)); |
1238 CHECK_EQ(3, r.Call(3)); | 1270 CHECK_EQ(3, r.Call(3)); |
1239 CHECK_EQ(10000, r.Call(10000)); | 1271 CHECK_EQ(10000, r.Call(10000)); |
1240 CHECK_EQ(-29, r.Call(-29)); | 1272 CHECK_EQ(-29, r.Call(-29)); |
1241 } | 1273 } |
1242 | 1274 |
1243 WASM_EXEC_TEST(Loop_if_break_fallthru) { | 1275 WASM_EXEC_TEST(Loop_if_break_fallthru) { |
1244 WasmRunner<int32_t> r(MachineType::Int32()); | 1276 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1245 BUILD(r, B1(WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(1)), | 1277 BUILD(r, B1(WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(1)), |
1246 WASM_SET_LOCAL(0, WASM_I8(93)))), | 1278 WASM_SET_LOCAL(0, WASM_I8(93)))), |
1247 WASM_GET_LOCAL(0)); | 1279 WASM_GET_LOCAL(0)); |
1248 CHECK_EQ(93, r.Call(0)); | 1280 CHECK_EQ(93, r.Call(0)); |
1249 CHECK_EQ(3, r.Call(3)); | 1281 CHECK_EQ(3, r.Call(3)); |
1250 CHECK_EQ(10001, r.Call(10001)); | 1282 CHECK_EQ(10001, r.Call(10001)); |
1251 CHECK_EQ(-22, r.Call(-22)); | 1283 CHECK_EQ(-22, r.Call(-22)); |
1252 } | 1284 } |
1253 | 1285 |
1254 WASM_EXEC_TEST(IfBreak1) { | 1286 WASM_EXEC_TEST(IfBreak1) { |
1255 WasmRunner<int32_t> r(MachineType::Int32()); | 1287 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1256 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), WASM_UNREACHABLE)), | 1288 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), WASM_UNREACHABLE)), |
1257 WASM_I8(91)); | 1289 WASM_I8(91)); |
1258 CHECK_EQ(91, r.Call(0)); | 1290 CHECK_EQ(91, r.Call(0)); |
1259 CHECK_EQ(91, r.Call(1)); | 1291 CHECK_EQ(91, r.Call(1)); |
1260 CHECK_EQ(91, r.Call(-8734)); | 1292 CHECK_EQ(91, r.Call(-8734)); |
1261 } | 1293 } |
1262 | 1294 |
1263 WASM_EXEC_TEST(IfBreak2) { | 1295 WASM_EXEC_TEST(IfBreak2) { |
1264 WasmRunner<int32_t> r(MachineType::Int32()); | 1296 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1265 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), RET_I8(77))), | 1297 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), RET_I8(77))), |
1266 WASM_I8(81)); | 1298 WASM_I8(81)); |
1267 CHECK_EQ(81, r.Call(0)); | 1299 CHECK_EQ(81, r.Call(0)); |
1268 CHECK_EQ(81, r.Call(1)); | 1300 CHECK_EQ(81, r.Call(1)); |
1269 CHECK_EQ(81, r.Call(-8734)); | 1301 CHECK_EQ(81, r.Call(-8734)); |
1270 } | 1302 } |
1271 | 1303 |
1272 WASM_EXEC_TEST(LoadMemI32) { | 1304 WASM_EXEC_TEST(LoadMemI32) { |
1273 TestingModule module; | 1305 TestingModule module(execution_mode); |
1274 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 1306 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
1275 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1307 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1276 module.RandomizeMemory(1111); | 1308 module.RandomizeMemory(1111); |
1277 | 1309 |
1278 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(0))); | 1310 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(0))); |
1279 | 1311 |
1280 memory[0] = 99999999; | 1312 memory[0] = 99999999; |
1281 CHECK_EQ(99999999, r.Call(0)); | 1313 CHECK_EQ(99999999, r.Call(0)); |
1282 | 1314 |
1283 memory[0] = 88888888; | 1315 memory[0] = 88888888; |
1284 CHECK_EQ(88888888, r.Call(0)); | 1316 CHECK_EQ(88888888, r.Call(0)); |
1285 | 1317 |
1286 memory[0] = 77777777; | 1318 memory[0] = 77777777; |
1287 CHECK_EQ(77777777, r.Call(0)); | 1319 CHECK_EQ(77777777, r.Call(0)); |
1288 } | 1320 } |
1289 | 1321 |
1290 WASM_EXEC_TEST(Run_Wasm_LoadMemI32_alignment) { | 1322 WASM_EXEC_TEST(LoadMemI32_alignment) { |
1291 TestingModule module; | 1323 TestingModule module(execution_mode); |
1292 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 1324 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
1293 for (byte alignment = 0; alignment <= 2; alignment++) { | 1325 for (byte alignment = 0; alignment <= 2; alignment++) { |
1294 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1326 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1295 module.RandomizeMemory(1111); | 1327 module.RandomizeMemory(1111); |
1296 | 1328 |
1297 BUILD(r, | 1329 BUILD(r, |
1298 WASM_LOAD_MEM_ALIGNMENT(MachineType::Int32(), WASM_I8(0), alignment)); | 1330 WASM_LOAD_MEM_ALIGNMENT(MachineType::Int32(), WASM_I8(0), alignment)); |
1299 | 1331 |
1300 memory[0] = 0x1a2b3c4d; | 1332 memory[0] = 0x1a2b3c4d; |
1301 CHECK_EQ(0x1a2b3c4d, r.Call(0)); | 1333 CHECK_EQ(0x1a2b3c4d, r.Call(0)); |
1302 | 1334 |
1303 memory[0] = 0x5e6f7a8b; | 1335 memory[0] = 0x5e6f7a8b; |
1304 CHECK_EQ(0x5e6f7a8b, r.Call(0)); | 1336 CHECK_EQ(0x5e6f7a8b, r.Call(0)); |
1305 | 1337 |
1306 memory[0] = 0x9ca0b1c2; | 1338 memory[0] = 0x9ca0b1c2; |
1307 CHECK_EQ(0x9ca0b1c2, r.Call(0)); | 1339 CHECK_EQ(0x9ca0b1c2, r.Call(0)); |
1308 } | 1340 } |
1309 } | 1341 } |
1310 | 1342 |
1311 WASM_EXEC_TEST(Run_Wasm_LoadMemI32_oob) { | 1343 WASM_EXEC_TEST(LoadMemI32_oob) { |
1312 TestingModule module; | 1344 TestingModule module(execution_mode); |
1313 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 1345 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
1314 WasmRunner<int32_t> r(&module, MachineType::Uint32()); | 1346 WasmRunner<int32_t> r(&module, MachineType::Uint32()); |
1315 module.RandomizeMemory(1111); | 1347 module.RandomizeMemory(1111); |
1316 | 1348 |
1317 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); | 1349 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); |
1318 | 1350 |
1319 memory[0] = 88888888; | 1351 memory[0] = 88888888; |
1320 CHECK_EQ(88888888, r.Call(0u)); | 1352 CHECK_EQ(88888888, r.Call(0u)); |
1321 for (uint32_t offset = 29; offset < 40; offset++) { | 1353 for (uint32_t offset = 29; offset < 40; offset++) { |
1322 CHECK_TRAP(r.Call(offset)); | 1354 CHECK_TRAP(r.Call(offset)); |
1323 } | 1355 } |
1324 | 1356 |
1325 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { | 1357 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { |
1326 CHECK_TRAP(r.Call(offset)); | 1358 CHECK_TRAP(r.Call(offset)); |
1327 } | 1359 } |
1328 } | 1360 } |
1329 | 1361 |
1330 WASM_EXEC_TEST(LoadMem_offset_oob) { | 1362 WASM_EXEC_TEST(LoadMem_offset_oob) { |
1331 TestingModule module; | 1363 TestingModule module(execution_mode); |
1332 module.AddMemoryElems<int32_t>(8); | 1364 module.AddMemoryElems<int32_t>(8); |
1333 | 1365 |
1334 static const MachineType machineTypes[] = { | 1366 static const MachineType machineTypes[] = { |
1335 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), | 1367 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), |
1336 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), | 1368 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), |
1337 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), | 1369 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), |
1338 MachineType::Float64()}; | 1370 MachineType::Float64()}; |
1339 | 1371 |
1340 for (size_t m = 0; m < arraysize(machineTypes); m++) { | 1372 for (size_t m = 0; m < arraysize(machineTypes); m++) { |
1341 module.RandomizeMemory(1116 + static_cast<int>(m)); | 1373 module.RandomizeMemory(1116 + static_cast<int>(m)); |
1342 WasmRunner<int32_t> r(&module, MachineType::Uint32()); | 1374 WasmRunner<int32_t> r(&module, MachineType::Uint32()); |
1343 uint32_t boundary = 24 - WasmOpcodes::MemSize(machineTypes[m]); | 1375 uint32_t boundary = 24 - WasmOpcodes::MemSize(machineTypes[m]); |
1344 | 1376 |
1345 BUILD(r, WASM_LOAD_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0)), | 1377 BUILD(r, WASM_LOAD_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0)), |
1346 WASM_ZERO); | 1378 WASM_ZERO); |
1347 | 1379 |
1348 CHECK_EQ(0, r.Call(boundary)); // in bounds. | 1380 CHECK_EQ(0, r.Call(boundary)); // in bounds. |
1349 | 1381 |
1350 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { | 1382 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { |
1351 CHECK_TRAP(r.Call(offset)); // out of bounds. | 1383 CHECK_TRAP(r.Call(offset)); // out of bounds. |
1352 } | 1384 } |
1353 } | 1385 } |
1354 } | 1386 } |
1355 | 1387 |
1356 WASM_EXEC_TEST(LoadMemI32_offset) { | 1388 WASM_EXEC_TEST(LoadMemI32_offset) { |
1357 TestingModule module; | 1389 TestingModule module(execution_mode); |
1358 int32_t* memory = module.AddMemoryElems<int32_t>(4); | 1390 int32_t* memory = module.AddMemoryElems<int32_t>(4); |
1359 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1391 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1360 module.RandomizeMemory(1111); | 1392 module.RandomizeMemory(1111); |
1361 | 1393 |
1362 BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0))); | 1394 BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0))); |
1363 | 1395 |
1364 memory[0] = 66666666; | 1396 memory[0] = 66666666; |
1365 memory[1] = 77777777; | 1397 memory[1] = 77777777; |
1366 memory[2] = 88888888; | 1398 memory[2] = 88888888; |
1367 memory[3] = 99999999; | 1399 memory[3] = 99999999; |
1368 CHECK_EQ(77777777, r.Call(0)); | 1400 CHECK_EQ(77777777, r.Call(0)); |
1369 CHECK_EQ(88888888, r.Call(4)); | 1401 CHECK_EQ(88888888, r.Call(4)); |
1370 CHECK_EQ(99999999, r.Call(8)); | 1402 CHECK_EQ(99999999, r.Call(8)); |
1371 | 1403 |
1372 memory[0] = 11111111; | 1404 memory[0] = 11111111; |
1373 memory[1] = 22222222; | 1405 memory[1] = 22222222; |
1374 memory[2] = 33333333; | 1406 memory[2] = 33333333; |
1375 memory[3] = 44444444; | 1407 memory[3] = 44444444; |
1376 CHECK_EQ(22222222, r.Call(0)); | 1408 CHECK_EQ(22222222, r.Call(0)); |
1377 CHECK_EQ(33333333, r.Call(4)); | 1409 CHECK_EQ(33333333, r.Call(4)); |
1378 CHECK_EQ(44444444, r.Call(8)); | 1410 CHECK_EQ(44444444, r.Call(8)); |
1379 } | 1411 } |
1380 | 1412 |
1381 WASM_EXEC_TEST(Run_Wasm_LoadMemI32_const_oob_misaligned) { | 1413 WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) { |
1382 const int kMemSize = 12; | 1414 const int kMemSize = 12; |
1383 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable. | 1415 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable. |
1384 for (int offset = 0; offset < kMemSize + 5; offset++) { | 1416 for (int offset = 0; offset < kMemSize + 5; offset++) { |
1385 for (int index = 0; index < kMemSize + 5; index++) { | 1417 for (int index = 0; index < kMemSize + 5; index++) { |
1386 TestingModule module; | 1418 TestingModule module(execution_mode); |
1387 module.AddMemoryElems<byte>(kMemSize); | 1419 module.AddMemoryElems<byte>(kMemSize); |
1388 | 1420 |
1389 WasmRunner<int32_t> r(&module); | 1421 WasmRunner<int32_t> r(&module); |
1390 module.RandomizeMemory(); | 1422 module.RandomizeMemory(); |
1391 | 1423 |
1392 BUILD(r, | 1424 BUILD(r, |
1393 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); | 1425 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); |
1394 | 1426 |
1395 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { | 1427 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { |
1396 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); | 1428 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); |
1397 } else { | 1429 } else { |
1398 CHECK_TRAP(r.Call()); | 1430 CHECK_TRAP(r.Call()); |
1399 } | 1431 } |
1400 } | 1432 } |
1401 } | 1433 } |
1402 } | 1434 } |
1403 | 1435 |
1404 WASM_EXEC_TEST(Run_Wasm_LoadMemI32_const_oob) { | 1436 WASM_EXEC_TEST(LoadMemI32_const_oob) { |
1405 const int kMemSize = 24; | 1437 const int kMemSize = 24; |
1406 for (int offset = 0; offset < kMemSize + 5; offset += 4) { | 1438 for (int offset = 0; offset < kMemSize + 5; offset += 4) { |
1407 for (int index = 0; index < kMemSize + 5; index += 4) { | 1439 for (int index = 0; index < kMemSize + 5; index += 4) { |
1408 TestingModule module; | 1440 TestingModule module(execution_mode); |
1409 module.AddMemoryElems<byte>(kMemSize); | 1441 module.AddMemoryElems<byte>(kMemSize); |
1410 | 1442 |
1411 WasmRunner<int32_t> r(&module); | 1443 WasmRunner<int32_t> r(&module); |
1412 module.RandomizeMemory(); | 1444 module.RandomizeMemory(); |
1413 | 1445 |
1414 BUILD(r, | 1446 BUILD(r, |
1415 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); | 1447 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); |
1416 | 1448 |
1417 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { | 1449 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { |
1418 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); | 1450 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); |
1419 } else { | 1451 } else { |
1420 CHECK_TRAP(r.Call()); | 1452 CHECK_TRAP(r.Call()); |
1421 } | 1453 } |
1422 } | 1454 } |
1423 } | 1455 } |
1424 } | 1456 } |
1425 | 1457 |
1426 WASM_EXEC_TEST(Run_Wasm_StoreMemI32_alignment) { | 1458 WASM_EXEC_TEST(StoreMemI32_alignment) { |
1427 TestingModule module; | 1459 TestingModule module(execution_mode); |
1428 int32_t* memory = module.AddMemoryElems<int32_t>(4); | 1460 int32_t* memory = module.AddMemoryElems<int32_t>(4); |
1429 const int32_t kWritten = 0x12345678; | 1461 const int32_t kWritten = 0x12345678; |
1430 | 1462 |
1431 for (byte i = 0; i <= 2; i++) { | 1463 for (byte i = 0; i <= 2; i++) { |
1432 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1464 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1433 BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int32(), WASM_ZERO, i, | 1465 BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int32(), WASM_ZERO, i, |
1434 WASM_GET_LOCAL(0))); | 1466 WASM_GET_LOCAL(0))); |
1435 module.RandomizeMemory(1111); | 1467 module.RandomizeMemory(1111); |
1436 memory[0] = 0; | 1468 memory[0] = 0; |
1437 | 1469 |
1438 CHECK_EQ(kWritten, r.Call(kWritten)); | 1470 CHECK_EQ(kWritten, r.Call(kWritten)); |
1439 CHECK_EQ(kWritten, memory[0]); | 1471 CHECK_EQ(kWritten, memory[0]); |
1440 } | 1472 } |
1441 } | 1473 } |
1442 | 1474 |
1443 WASM_EXEC_TEST(Run_Wasm_StoreMemI32_offset) { | 1475 WASM_EXEC_TEST(StoreMemI32_offset) { |
1444 TestingModule module; | 1476 TestingModule module(execution_mode); |
1445 int32_t* memory = module.AddMemoryElems<int32_t>(4); | 1477 int32_t* memory = module.AddMemoryElems<int32_t>(4); |
1446 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1478 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1447 const int32_t kWritten = 0xaabbccdd; | 1479 const int32_t kWritten = 0xaabbccdd; |
1448 | 1480 |
1449 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0), | 1481 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0), |
1450 WASM_I32V_5(kWritten))); | 1482 WASM_I32V_5(kWritten))); |
1451 | 1483 |
1452 for (int i = 0; i < 2; i++) { | 1484 for (int i = 0; i < 2; i++) { |
1453 module.RandomizeMemory(1111); | 1485 module.RandomizeMemory(1111); |
1454 memory[0] = 66666666; | 1486 memory[0] = 66666666; |
1455 memory[1] = 77777777; | 1487 memory[1] = 77777777; |
1456 memory[2] = 88888888; | 1488 memory[2] = 88888888; |
1457 memory[3] = 99999999; | 1489 memory[3] = 99999999; |
1458 CHECK_EQ(kWritten, r.Call(i * 4)); | 1490 CHECK_EQ(kWritten, r.Call(i * 4)); |
1459 CHECK_EQ(66666666, memory[0]); | 1491 CHECK_EQ(66666666, memory[0]); |
1460 CHECK_EQ(i == 0 ? kWritten : 77777777, memory[1]); | 1492 CHECK_EQ(i == 0 ? kWritten : 77777777, memory[1]); |
1461 CHECK_EQ(i == 1 ? kWritten : 88888888, memory[2]); | 1493 CHECK_EQ(i == 1 ? kWritten : 88888888, memory[2]); |
1462 CHECK_EQ(i == 2 ? kWritten : 99999999, memory[3]); | 1494 CHECK_EQ(i == 2 ? kWritten : 99999999, memory[3]); |
1463 } | 1495 } |
1464 } | 1496 } |
1465 | 1497 |
1466 WASM_EXEC_TEST(StoreMem_offset_oob) { | 1498 WASM_EXEC_TEST(StoreMem_offset_oob) { |
1467 TestingModule module; | 1499 TestingModule module(execution_mode); |
1468 byte* memory = module.AddMemoryElems<byte>(32); | 1500 byte* memory = module.AddMemoryElems<byte>(32); |
1469 | 1501 |
1470 #if WASM_64 | 1502 #if WASM_64 |
1471 static const MachineType machineTypes[] = { | 1503 static const MachineType machineTypes[] = { |
1472 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), | 1504 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), |
1473 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), | 1505 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), |
1474 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), | 1506 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), |
1475 MachineType::Float64()}; | 1507 MachineType::Float64()}; |
1476 #else | 1508 #else |
1477 static const MachineType machineTypes[] = { | 1509 static const MachineType machineTypes[] = { |
(...skipping 16 matching lines...) Expand all Loading... |
1494 CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize)); | 1526 CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize)); |
1495 | 1527 |
1496 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { | 1528 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { |
1497 CHECK_TRAP(r.Call(offset)); // out of bounds. | 1529 CHECK_TRAP(r.Call(offset)); // out of bounds. |
1498 } | 1530 } |
1499 } | 1531 } |
1500 } | 1532 } |
1501 | 1533 |
1502 WASM_EXEC_TEST(LoadMemI32_P) { | 1534 WASM_EXEC_TEST(LoadMemI32_P) { |
1503 const int kNumElems = 8; | 1535 const int kNumElems = 8; |
1504 TestingModule module; | 1536 TestingModule module(execution_mode); |
1505 int32_t* memory = module.AddMemoryElems<int32_t>(kNumElems); | 1537 int32_t* memory = module.AddMemoryElems<int32_t>(kNumElems); |
1506 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1538 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1507 module.RandomizeMemory(2222); | 1539 module.RandomizeMemory(2222); |
1508 | 1540 |
1509 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); | 1541 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); |
1510 | 1542 |
1511 for (int i = 0; i < kNumElems; i++) { | 1543 for (int i = 0; i < kNumElems; i++) { |
1512 CHECK_EQ(memory[i], r.Call(i * 4)); | 1544 CHECK_EQ(memory[i], r.Call(i * 4)); |
1513 } | 1545 } |
1514 } | 1546 } |
1515 | 1547 |
1516 WASM_EXEC_TEST(MemI32_Sum) { | 1548 WASM_EXEC_TEST(MemI32_Sum) { |
1517 const int kNumElems = 20; | 1549 const int kNumElems = 20; |
1518 TestingModule module; | 1550 TestingModule module(execution_mode); |
1519 uint32_t* memory = module.AddMemoryElems<uint32_t>(kNumElems); | 1551 uint32_t* memory = module.AddMemoryElems<uint32_t>(kNumElems); |
1520 WasmRunner<uint32_t> r(&module, MachineType::Int32()); | 1552 WasmRunner<uint32_t> r(&module, MachineType::Int32()); |
1521 const byte kSum = r.AllocateLocal(kAstI32); | 1553 const byte kSum = r.AllocateLocal(kAstI32); |
1522 | 1554 |
1523 BUILD(r, WASM_BLOCK( | 1555 BUILD(r, WASM_BLOCK( |
1524 2, WASM_WHILE( | 1556 2, WASM_WHILE( |
1525 WASM_GET_LOCAL(0), | 1557 WASM_GET_LOCAL(0), |
1526 WASM_BLOCK( | 1558 WASM_BLOCK( |
1527 2, WASM_SET_LOCAL( | 1559 2, WASM_SET_LOCAL( |
1528 kSum, WASM_I32_ADD( | 1560 kSum, WASM_I32_ADD( |
(...skipping 11 matching lines...) Expand all Loading... |
1540 for (size_t j = kNumElems - 1; j > 0; j--) { | 1572 for (size_t j = kNumElems - 1; j > 0; j--) { |
1541 expected += memory[j]; | 1573 expected += memory[j]; |
1542 } | 1574 } |
1543 uint32_t result = r.Call(static_cast<int>(4 * (kNumElems - 1))); | 1575 uint32_t result = r.Call(static_cast<int>(4 * (kNumElems - 1))); |
1544 CHECK_EQ(expected, result); | 1576 CHECK_EQ(expected, result); |
1545 } | 1577 } |
1546 } | 1578 } |
1547 | 1579 |
1548 WASM_EXEC_TEST(CheckMachIntsZero) { | 1580 WASM_EXEC_TEST(CheckMachIntsZero) { |
1549 const int kNumElems = 55; | 1581 const int kNumElems = 55; |
1550 TestingModule module; | 1582 TestingModule module(execution_mode); |
1551 module.AddMemoryElems<uint32_t>(kNumElems); | 1583 module.AddMemoryElems<uint32_t>(kNumElems); |
1552 WasmRunner<uint32_t> r(&module, MachineType::Int32()); | 1584 WasmRunner<uint32_t> r(&module, MachineType::Int32()); |
1553 | 1585 |
1554 BUILD(r, kExprLoop, kExprGetLocal, 0, kExprIf, kExprGetLocal, 0, | 1586 BUILD(r, kExprLoop, kExprGetLocal, 0, kExprIf, kExprGetLocal, 0, |
1555 kExprI32LoadMem, 0, 0, kExprIf, kExprI8Const, 255, kExprReturn, ARITY_1, | 1587 kExprI32LoadMem, 0, 0, kExprIf, kExprI8Const, 255, kExprReturn, ARITY_1, |
1556 kExprEnd, kExprGetLocal, 0, kExprI8Const, 4, kExprI32Sub, kExprSetLocal, | 1588 kExprEnd, kExprGetLocal, 0, kExprI8Const, 4, kExprI32Sub, kExprSetLocal, |
1557 0, kExprBr, ARITY_1, DEPTH_0, kExprEnd, kExprEnd, kExprI8Const, 0); | 1589 0, kExprBr, ARITY_1, DEPTH_0, kExprEnd, kExprEnd, kExprI8Const, 0); |
1558 | 1590 |
1559 module.BlankMemory(); | 1591 module.BlankMemory(); |
1560 CHECK_EQ(0, r.Call((kNumElems - 1) * 4)); | 1592 CHECK_EQ(0, r.Call((kNumElems - 1) * 4)); |
1561 } | 1593 } |
1562 | 1594 |
1563 WASM_EXEC_TEST(MemF32_Sum) { | 1595 WASM_EXEC_TEST(MemF32_Sum) { |
1564 const int kSize = 5; | 1596 const int kSize = 5; |
1565 TestingModule module; | 1597 TestingModule module(execution_mode); |
1566 module.AddMemoryElems<float>(kSize); | 1598 module.AddMemoryElems<float>(kSize); |
1567 float* buffer = module.raw_mem_start<float>(); | 1599 float* buffer = module.raw_mem_start<float>(); |
1568 buffer[0] = -99.25; | 1600 buffer[0] = -99.25; |
1569 buffer[1] = -888.25; | 1601 buffer[1] = -888.25; |
1570 buffer[2] = -77.25; | 1602 buffer[2] = -77.25; |
1571 buffer[3] = 66666.25; | 1603 buffer[3] = 66666.25; |
1572 buffer[4] = 5555.25; | 1604 buffer[4] = 5555.25; |
1573 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1605 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1574 const byte kSum = r.AllocateLocal(kAstF32); | 1606 const byte kSum = r.AllocateLocal(kAstF32); |
1575 | 1607 |
(...skipping 11 matching lines...) Expand all Loading... |
1587 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, | 1619 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, |
1588 WASM_GET_LOCAL(kSum)), | 1620 WASM_GET_LOCAL(kSum)), |
1589 WASM_GET_LOCAL(0))); | 1621 WASM_GET_LOCAL(0))); |
1590 | 1622 |
1591 CHECK_EQ(0, r.Call(4 * (kSize - 1))); | 1623 CHECK_EQ(0, r.Call(4 * (kSize - 1))); |
1592 CHECK_NE(-99.25, buffer[0]); | 1624 CHECK_NE(-99.25, buffer[0]); |
1593 CHECK_EQ(71256.0f, buffer[0]); | 1625 CHECK_EQ(71256.0f, buffer[0]); |
1594 } | 1626 } |
1595 | 1627 |
1596 template <typename T> | 1628 template <typename T> |
1597 T GenerateAndRunFold(WasmOpcode binop, T* buffer, size_t size, | 1629 T GenerateAndRunFold(WasmExecutionMode execution_mode, WasmOpcode binop, |
1598 LocalType astType, MachineType memType) { | 1630 T* buffer, size_t size, LocalType astType, |
1599 TestingModule module; | 1631 MachineType memType) { |
| 1632 TestingModule module(execution_mode); |
1600 module.AddMemoryElems<T>(size); | 1633 module.AddMemoryElems<T>(size); |
1601 for (size_t i = 0; i < size; i++) { | 1634 for (size_t i = 0; i < size; i++) { |
1602 module.raw_mem_start<T>()[i] = buffer[i]; | 1635 module.raw_mem_start<T>()[i] = buffer[i]; |
1603 } | 1636 } |
1604 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1637 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1605 const byte kAccum = r.AllocateLocal(astType); | 1638 const byte kAccum = r.AllocateLocal(astType); |
1606 | 1639 |
1607 BUILD( | 1640 BUILD( |
1608 r, | 1641 r, |
1609 WASM_BLOCK( | 1642 WASM_BLOCK( |
1610 4, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)), | 1643 4, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)), |
1611 WASM_WHILE( | 1644 WASM_WHILE( |
1612 WASM_GET_LOCAL(0), | 1645 WASM_GET_LOCAL(0), |
1613 WASM_BLOCK( | 1646 WASM_BLOCK( |
1614 2, WASM_SET_LOCAL( | 1647 2, WASM_SET_LOCAL( |
1615 kAccum, | 1648 kAccum, |
1616 WASM_BINOP(binop, WASM_GET_LOCAL(kAccum), | 1649 WASM_BINOP(binop, WASM_GET_LOCAL(kAccum), |
1617 WASM_LOAD_MEM(memType, WASM_GET_LOCAL(0)))), | 1650 WASM_LOAD_MEM(memType, WASM_GET_LOCAL(0)))), |
1618 WASM_SET_LOCAL( | 1651 WASM_SET_LOCAL( |
1619 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(sizeof(T)))))), | 1652 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(sizeof(T)))))), |
1620 WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)), | 1653 WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)), |
1621 WASM_GET_LOCAL(0))); | 1654 WASM_GET_LOCAL(0))); |
1622 r.Call(static_cast<int>(sizeof(T) * (size - 1))); | 1655 r.Call(static_cast<int>(sizeof(T) * (size - 1))); |
1623 return module.raw_mem_at<double>(0); | 1656 return module.raw_mem_at<double>(0); |
1624 } | 1657 } |
1625 | 1658 |
1626 WASM_EXEC_TEST(MemF64_Mul) { | 1659 WASM_EXEC_TEST(MemF64_Mul) { |
1627 const size_t kSize = 6; | 1660 const size_t kSize = 6; |
1628 double buffer[kSize] = {1, 2, 2, 2, 2, 2}; | 1661 double buffer[kSize] = {1, 2, 2, 2, 2, 2}; |
1629 double result = GenerateAndRunFold<double>(kExprF64Mul, buffer, kSize, | 1662 double result = |
1630 kAstF64, MachineType::Float64()); | 1663 GenerateAndRunFold<double>(execution_mode, kExprF64Mul, buffer, kSize, |
| 1664 kAstF64, MachineType::Float64()); |
1631 CHECK_EQ(32, result); | 1665 CHECK_EQ(32, result); |
1632 } | 1666 } |
1633 | 1667 |
1634 TEST(Build_Wasm_Infinite_Loop) { | 1668 WASM_EXEC_TEST(Build_Wasm_Infinite_Loop) { |
1635 WasmRunner<int32_t> r(MachineType::Int32()); | 1669 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1636 // Only build the graph and compile, don't run. | 1670 // Only build the graph and compile, don't run. |
1637 BUILD(r, WASM_INFINITE_LOOP); | 1671 BUILD(r, WASM_INFINITE_LOOP); |
1638 } | 1672 } |
1639 | 1673 |
1640 TEST(Build_Wasm_Infinite_Loop_effect) { | 1674 WASM_EXEC_TEST(Build_Wasm_Infinite_Loop_effect) { |
1641 TestingModule module; | 1675 TestingModule module(execution_mode); |
1642 module.AddMemoryElems<int8_t>(16); | 1676 module.AddMemoryElems<int8_t>(16); |
1643 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1677 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1644 | 1678 |
1645 // Only build the graph and compile, don't run. | 1679 // Only build the graph and compile, don't run. |
1646 BUILD(r, WASM_LOOP(1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO))); | 1680 BUILD(r, WASM_LOOP(1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO))); |
1647 } | 1681 } |
1648 | 1682 |
1649 WASM_EXEC_TEST(Unreachable0a) { | 1683 WASM_EXEC_TEST(Unreachable0a) { |
1650 WasmRunner<int32_t> r(MachineType::Int32()); | 1684 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1651 BUILD(r, B2(WASM_BRV(0, WASM_I8(9)), RET(WASM_GET_LOCAL(0)))); | 1685 BUILD(r, B2(WASM_BRV(0, WASM_I8(9)), RET(WASM_GET_LOCAL(0)))); |
1652 CHECK_EQ(9, r.Call(0)); | 1686 CHECK_EQ(9, r.Call(0)); |
1653 CHECK_EQ(9, r.Call(1)); | 1687 CHECK_EQ(9, r.Call(1)); |
1654 } | 1688 } |
1655 | 1689 |
1656 WASM_EXEC_TEST(Unreachable0b) { | 1690 WASM_EXEC_TEST(Unreachable0b) { |
1657 WasmRunner<int32_t> r(MachineType::Int32()); | 1691 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1658 BUILD(r, B2(WASM_BRV(0, WASM_I8(7)), WASM_UNREACHABLE)); | 1692 BUILD(r, B2(WASM_BRV(0, WASM_I8(7)), WASM_UNREACHABLE)); |
1659 CHECK_EQ(7, r.Call(0)); | 1693 CHECK_EQ(7, r.Call(0)); |
1660 CHECK_EQ(7, r.Call(1)); | 1694 CHECK_EQ(7, r.Call(1)); |
1661 } | 1695 } |
1662 | 1696 |
1663 TEST(Build_Wasm_Unreachable1) { | 1697 TEST(Build_Wasm_Unreachable1) { |
1664 WasmRunner<int32_t> r(MachineType::Int32()); | 1698 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); |
1665 BUILD(r, WASM_UNREACHABLE); | 1699 BUILD(r, WASM_UNREACHABLE); |
1666 } | 1700 } |
1667 | 1701 |
1668 TEST(Build_Wasm_Unreachable2) { | 1702 TEST(Build_Wasm_Unreachable2) { |
1669 WasmRunner<int32_t> r(MachineType::Int32()); | 1703 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); |
1670 BUILD(r, WASM_UNREACHABLE, WASM_UNREACHABLE); | 1704 BUILD(r, WASM_UNREACHABLE, WASM_UNREACHABLE); |
1671 } | 1705 } |
1672 | 1706 |
1673 TEST(Build_Wasm_Unreachable3) { | 1707 TEST(Build_Wasm_Unreachable3) { |
1674 WasmRunner<int32_t> r(MachineType::Int32()); | 1708 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); |
1675 BUILD(r, WASM_UNREACHABLE, WASM_UNREACHABLE, WASM_UNREACHABLE); | 1709 BUILD(r, WASM_UNREACHABLE, WASM_UNREACHABLE, WASM_UNREACHABLE); |
1676 } | 1710 } |
1677 | 1711 |
1678 TEST(Build_Wasm_UnreachableIf1) { | 1712 TEST(Build_Wasm_UnreachableIf1) { |
1679 WasmRunner<int32_t> r(MachineType::Int32()); | 1713 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); |
1680 BUILD(r, WASM_UNREACHABLE, WASM_IF(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); | 1714 BUILD(r, WASM_UNREACHABLE, WASM_IF(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
1681 } | 1715 } |
1682 | 1716 |
1683 TEST(Build_Wasm_UnreachableIf2) { | 1717 TEST(Build_Wasm_UnreachableIf2) { |
1684 WasmRunner<int32_t> r(MachineType::Int32()); | 1718 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); |
1685 BUILD(r, WASM_UNREACHABLE, | 1719 BUILD(r, WASM_UNREACHABLE, |
1686 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE)); | 1720 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE)); |
1687 } | 1721 } |
1688 | 1722 |
1689 WASM_EXEC_TEST(Unreachable_Load) { | 1723 WASM_EXEC_TEST(Unreachable_Load) { |
1690 WasmRunner<int32_t> r(MachineType::Int32()); | 1724 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1691 BUILD(r, B2(WASM_BRV(0, WASM_GET_LOCAL(0)), | 1725 BUILD(r, B2(WASM_BRV(0, WASM_GET_LOCAL(0)), |
1692 WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0)))); | 1726 WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0)))); |
1693 CHECK_EQ(11, r.Call(11)); | 1727 CHECK_EQ(11, r.Call(11)); |
1694 CHECK_EQ(21, r.Call(21)); | 1728 CHECK_EQ(21, r.Call(21)); |
1695 } | 1729 } |
1696 | 1730 |
1697 WASM_EXEC_TEST(Infinite_Loop_not_taken1) { | 1731 WASM_EXEC_TEST(Infinite_Loop_not_taken1) { |
1698 WasmRunner<int32_t> r(MachineType::Int32()); | 1732 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1699 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I8(45))); | 1733 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I8(45))); |
1700 // Run the code, but don't go into the infinite loop. | 1734 // Run the code, but don't go into the infinite loop. |
1701 CHECK_EQ(45, r.Call(0)); | 1735 CHECK_EQ(45, r.Call(0)); |
1702 } | 1736 } |
1703 | 1737 |
1704 WASM_EXEC_TEST(Infinite_Loop_not_taken2) { | 1738 WASM_EXEC_TEST(Infinite_Loop_not_taken2) { |
1705 WasmRunner<int32_t> r(MachineType::Int32()); | 1739 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1706 BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(45)), | 1740 BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(45)), |
1707 WASM_INFINITE_LOOP))); | 1741 WASM_INFINITE_LOOP))); |
1708 // Run the code, but don't go into the infinite loop. | 1742 // Run the code, but don't go into the infinite loop. |
1709 CHECK_EQ(45, r.Call(1)); | 1743 CHECK_EQ(45, r.Call(1)); |
1710 } | 1744 } |
1711 | 1745 |
1712 WASM_EXEC_TEST(Infinite_Loop_not_taken2_brif) { | 1746 WASM_EXEC_TEST(Infinite_Loop_not_taken2_brif) { |
1713 WasmRunner<int32_t> r(MachineType::Int32()); | 1747 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
1714 BUILD(r, | 1748 BUILD(r, |
1715 B2(WASM_BRV_IF(0, WASM_I8(45), WASM_GET_LOCAL(0)), WASM_INFINITE_LOOP)); | 1749 B2(WASM_BRV_IF(0, WASM_I8(45), WASM_GET_LOCAL(0)), WASM_INFINITE_LOOP)); |
1716 // Run the code, but don't go into the infinite loop. | 1750 // Run the code, but don't go into the infinite loop. |
1717 CHECK_EQ(45, r.Call(1)); | 1751 CHECK_EQ(45, r.Call(1)); |
1718 } | 1752 } |
1719 | 1753 |
1720 static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) { | 1754 static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) { |
1721 Isolate* isolate = CcTest::InitIsolateOnce(); | 1755 Isolate* isolate = CcTest::InitIsolateOnce(); |
1722 Zone zone(isolate->allocator()); | 1756 Zone zone(isolate->allocator()); |
1723 HandleScope scope(isolate); | 1757 HandleScope scope(isolate); |
(...skipping 22 matching lines...) Expand all Loading... |
1746 // Test that the decoder can build a graph for all supported simple expressions. | 1780 // Test that the decoder can build a graph for all supported simple expressions. |
1747 #define GRAPH_BUILD_TEST(name, opcode, sig) \ | 1781 #define GRAPH_BUILD_TEST(name, opcode, sig) \ |
1748 TestBuildGraphForSimpleExpression(kExpr##name); | 1782 TestBuildGraphForSimpleExpression(kExpr##name); |
1749 | 1783 |
1750 FOREACH_SIMPLE_OPCODE(GRAPH_BUILD_TEST); | 1784 FOREACH_SIMPLE_OPCODE(GRAPH_BUILD_TEST); |
1751 | 1785 |
1752 #undef GRAPH_BUILD_TEST | 1786 #undef GRAPH_BUILD_TEST |
1753 } | 1787 } |
1754 | 1788 |
1755 WASM_EXEC_TEST(Int32LoadInt8_signext) { | 1789 WASM_EXEC_TEST(Int32LoadInt8_signext) { |
1756 TestingModule module; | 1790 TestingModule module(execution_mode); |
1757 const int kNumElems = 16; | 1791 const int kNumElems = 16; |
1758 int8_t* memory = module.AddMemoryElems<int8_t>(kNumElems); | 1792 int8_t* memory = module.AddMemoryElems<int8_t>(kNumElems); |
1759 module.RandomizeMemory(); | 1793 module.RandomizeMemory(); |
1760 memory[0] = -1; | 1794 memory[0] = -1; |
1761 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1795 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1762 BUILD(r, WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0))); | 1796 BUILD(r, WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0))); |
1763 | 1797 |
1764 for (size_t i = 0; i < kNumElems; i++) { | 1798 for (size_t i = 0; i < kNumElems; i++) { |
1765 CHECK_EQ(memory[i], r.Call(static_cast<int>(i))); | 1799 CHECK_EQ(memory[i], r.Call(static_cast<int>(i))); |
1766 } | 1800 } |
1767 } | 1801 } |
1768 | 1802 |
1769 WASM_EXEC_TEST(Int32LoadInt8_zeroext) { | 1803 WASM_EXEC_TEST(Int32LoadInt8_zeroext) { |
1770 TestingModule module; | 1804 TestingModule module(execution_mode); |
1771 const int kNumElems = 16; | 1805 const int kNumElems = 16; |
1772 byte* memory = module.AddMemory(kNumElems); | 1806 byte* memory = module.AddMemory(kNumElems); |
1773 module.RandomizeMemory(77); | 1807 module.RandomizeMemory(77); |
1774 memory[0] = 255; | 1808 memory[0] = 255; |
1775 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1809 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1776 BUILD(r, WASM_LOAD_MEM(MachineType::Uint8(), WASM_GET_LOCAL(0))); | 1810 BUILD(r, WASM_LOAD_MEM(MachineType::Uint8(), WASM_GET_LOCAL(0))); |
1777 | 1811 |
1778 for (size_t i = 0; i < kNumElems; i++) { | 1812 for (size_t i = 0; i < kNumElems; i++) { |
1779 CHECK_EQ(memory[i], r.Call(static_cast<int>(i))); | 1813 CHECK_EQ(memory[i], r.Call(static_cast<int>(i))); |
1780 } | 1814 } |
1781 } | 1815 } |
1782 | 1816 |
1783 WASM_EXEC_TEST(Int32LoadInt16_signext) { | 1817 WASM_EXEC_TEST(Int32LoadInt16_signext) { |
1784 TestingModule module; | 1818 TestingModule module(execution_mode); |
1785 const int kNumBytes = 16; | 1819 const int kNumBytes = 16; |
1786 byte* memory = module.AddMemory(kNumBytes); | 1820 byte* memory = module.AddMemory(kNumBytes); |
1787 module.RandomizeMemory(888); | 1821 module.RandomizeMemory(888); |
1788 memory[1] = 200; | 1822 memory[1] = 200; |
1789 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1823 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1790 BUILD(r, WASM_LOAD_MEM(MachineType::Int16(), WASM_GET_LOCAL(0))); | 1824 BUILD(r, WASM_LOAD_MEM(MachineType::Int16(), WASM_GET_LOCAL(0))); |
1791 | 1825 |
1792 for (size_t i = 0; i < kNumBytes; i += 2) { | 1826 for (size_t i = 0; i < kNumBytes; i += 2) { |
1793 int32_t expected = memory[i] | (static_cast<int8_t>(memory[i + 1]) << 8); | 1827 int32_t expected = memory[i] | (static_cast<int8_t>(memory[i + 1]) << 8); |
1794 CHECK_EQ(expected, r.Call(static_cast<int>(i))); | 1828 CHECK_EQ(expected, r.Call(static_cast<int>(i))); |
1795 } | 1829 } |
1796 } | 1830 } |
1797 | 1831 |
1798 WASM_EXEC_TEST(Int32LoadInt16_zeroext) { | 1832 WASM_EXEC_TEST(Int32LoadInt16_zeroext) { |
1799 TestingModule module; | 1833 TestingModule module(execution_mode); |
1800 const int kNumBytes = 16; | 1834 const int kNumBytes = 16; |
1801 byte* memory = module.AddMemory(kNumBytes); | 1835 byte* memory = module.AddMemory(kNumBytes); |
1802 module.RandomizeMemory(9999); | 1836 module.RandomizeMemory(9999); |
1803 memory[1] = 204; | 1837 memory[1] = 204; |
1804 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1838 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1805 BUILD(r, WASM_LOAD_MEM(MachineType::Uint16(), WASM_GET_LOCAL(0))); | 1839 BUILD(r, WASM_LOAD_MEM(MachineType::Uint16(), WASM_GET_LOCAL(0))); |
1806 | 1840 |
1807 for (size_t i = 0; i < kNumBytes; i += 2) { | 1841 for (size_t i = 0; i < kNumBytes; i += 2) { |
1808 int32_t expected = memory[i] | (memory[i + 1] << 8); | 1842 int32_t expected = memory[i] | (memory[i + 1] << 8); |
1809 CHECK_EQ(expected, r.Call(static_cast<int>(i))); | 1843 CHECK_EQ(expected, r.Call(static_cast<int>(i))); |
1810 } | 1844 } |
1811 } | 1845 } |
1812 | 1846 |
1813 WASM_EXEC_TEST(Int32Global) { | 1847 WASM_EXEC_TEST(Int32Global) { |
1814 TestingModule module; | 1848 TestingModule module(execution_mode); |
1815 int32_t* global = module.AddGlobal<int32_t>(MachineType::Int32()); | 1849 int32_t* global = module.AddGlobal<int32_t>(MachineType::Int32()); |
1816 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1850 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1817 // global = global + p0 | 1851 // global = global + p0 |
1818 BUILD(r, WASM_STORE_GLOBAL( | 1852 BUILD(r, WASM_STORE_GLOBAL( |
1819 0, WASM_I32_ADD(WASM_LOAD_GLOBAL(0), WASM_GET_LOCAL(0)))); | 1853 0, WASM_I32_ADD(WASM_LOAD_GLOBAL(0), WASM_GET_LOCAL(0)))); |
1820 | 1854 |
1821 *global = 116; | 1855 *global = 116; |
1822 for (int i = 9; i < 444444; i += 111111) { | 1856 for (int i = 9; i < 444444; i += 111111) { |
1823 int32_t expected = *global + i; | 1857 int32_t expected = *global + i; |
1824 r.Call(i); | 1858 r.Call(i); |
1825 CHECK_EQ(expected, *global); | 1859 CHECK_EQ(expected, *global); |
1826 } | 1860 } |
1827 } | 1861 } |
1828 | 1862 |
1829 WASM_EXEC_TEST(Int32Globals_DontAlias) { | 1863 WASM_EXEC_TEST(Int32Globals_DontAlias) { |
1830 const int kNumGlobals = 3; | 1864 const int kNumGlobals = 3; |
1831 TestingModule module; | 1865 TestingModule module(execution_mode); |
1832 int32_t* globals[] = {module.AddGlobal<int32_t>(MachineType::Int32()), | 1866 int32_t* globals[] = {module.AddGlobal<int32_t>(MachineType::Int32()), |
1833 module.AddGlobal<int32_t>(MachineType::Int32()), | 1867 module.AddGlobal<int32_t>(MachineType::Int32()), |
1834 module.AddGlobal<int32_t>(MachineType::Int32())}; | 1868 module.AddGlobal<int32_t>(MachineType::Int32())}; |
1835 | 1869 |
1836 for (int g = 0; g < kNumGlobals; g++) { | 1870 for (int g = 0; g < kNumGlobals; g++) { |
1837 // global = global + p0 | 1871 // global = global + p0 |
1838 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1872 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1839 BUILD(r, WASM_STORE_GLOBAL( | 1873 BUILD(r, WASM_STORE_GLOBAL( |
1840 g, WASM_I32_ADD(WASM_LOAD_GLOBAL(g), WASM_GET_LOCAL(0)))); | 1874 g, WASM_I32_ADD(WASM_LOAD_GLOBAL(g), WASM_GET_LOCAL(0)))); |
1841 | 1875 |
1842 // Check that reading/writing global number {g} doesn't alter the others. | 1876 // Check that reading/writing global number {g} doesn't alter the others. |
1843 *globals[g] = 116 * g; | 1877 *globals[g] = 116 * g; |
1844 int32_t before[kNumGlobals]; | 1878 int32_t before[kNumGlobals]; |
1845 for (int i = 9; i < 444444; i += 111113) { | 1879 for (int i = 9; i < 444444; i += 111113) { |
1846 int32_t sum = *globals[g] + i; | 1880 int32_t sum = *globals[g] + i; |
1847 for (int j = 0; j < kNumGlobals; j++) before[j] = *globals[j]; | 1881 for (int j = 0; j < kNumGlobals; j++) before[j] = *globals[j]; |
1848 r.Call(i); | 1882 r.Call(i); |
1849 for (int j = 0; j < kNumGlobals; j++) { | 1883 for (int j = 0; j < kNumGlobals; j++) { |
1850 int32_t expected = j == g ? sum : before[j]; | 1884 int32_t expected = j == g ? sum : before[j]; |
1851 CHECK_EQ(expected, *globals[j]); | 1885 CHECK_EQ(expected, *globals[j]); |
1852 } | 1886 } |
1853 } | 1887 } |
1854 } | 1888 } |
1855 } | 1889 } |
1856 | 1890 |
1857 WASM_EXEC_TEST(Float32Global) { | 1891 WASM_EXEC_TEST(Float32Global) { |
1858 TestingModule module; | 1892 TestingModule module(execution_mode); |
1859 float* global = module.AddGlobal<float>(MachineType::Float32()); | 1893 float* global = module.AddGlobal<float>(MachineType::Float32()); |
1860 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1894 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1861 // global = global + p0 | 1895 // global = global + p0 |
1862 BUILD(r, B2(WASM_STORE_GLOBAL( | 1896 BUILD(r, B2(WASM_STORE_GLOBAL( |
1863 0, WASM_F32_ADD(WASM_LOAD_GLOBAL(0), | 1897 0, WASM_F32_ADD(WASM_LOAD_GLOBAL(0), |
1864 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))), | 1898 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))), |
1865 WASM_ZERO)); | 1899 WASM_ZERO)); |
1866 | 1900 |
1867 *global = 1.25; | 1901 *global = 1.25; |
1868 for (int i = 9; i < 4444; i += 1111) { | 1902 for (int i = 9; i < 4444; i += 1111) { |
1869 volatile float expected = *global + i; | 1903 volatile float expected = *global + i; |
1870 r.Call(i); | 1904 r.Call(i); |
1871 CHECK_EQ(expected, *global); | 1905 CHECK_EQ(expected, *global); |
1872 } | 1906 } |
1873 } | 1907 } |
1874 | 1908 |
1875 WASM_EXEC_TEST(Float64Global) { | 1909 WASM_EXEC_TEST(Float64Global) { |
1876 TestingModule module; | 1910 TestingModule module(execution_mode); |
1877 double* global = module.AddGlobal<double>(MachineType::Float64()); | 1911 double* global = module.AddGlobal<double>(MachineType::Float64()); |
1878 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1912 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1879 // global = global + p0 | 1913 // global = global + p0 |
1880 BUILD(r, B2(WASM_STORE_GLOBAL( | 1914 BUILD(r, B2(WASM_STORE_GLOBAL( |
1881 0, WASM_F64_ADD(WASM_LOAD_GLOBAL(0), | 1915 0, WASM_F64_ADD(WASM_LOAD_GLOBAL(0), |
1882 WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))), | 1916 WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))), |
1883 WASM_ZERO)); | 1917 WASM_ZERO)); |
1884 | 1918 |
1885 *global = 1.25; | 1919 *global = 1.25; |
1886 for (int i = 9; i < 4444; i += 1111) { | 1920 for (int i = 9; i < 4444; i += 1111) { |
1887 volatile double expected = *global + i; | 1921 volatile double expected = *global + i; |
1888 r.Call(i); | 1922 r.Call(i); |
1889 CHECK_EQ(expected, *global); | 1923 CHECK_EQ(expected, *global); |
1890 } | 1924 } |
1891 } | 1925 } |
1892 | 1926 |
1893 WASM_EXEC_TEST(MixedGlobals) { | 1927 WASM_EXEC_TEST(MixedGlobals) { |
1894 TestingModule module; | 1928 TestingModule module(execution_mode); |
1895 int32_t* unused = module.AddGlobal<int32_t>(MachineType::Int32()); | 1929 int32_t* unused = module.AddGlobal<int32_t>(MachineType::Int32()); |
1896 byte* memory = module.AddMemory(32); | 1930 byte* memory = module.AddMemory(32); |
1897 | 1931 |
1898 int8_t* var_int8 = module.AddGlobal<int8_t>(MachineType::Int8()); | 1932 int8_t* var_int8 = module.AddGlobal<int8_t>(MachineType::Int8()); |
1899 uint8_t* var_uint8 = module.AddGlobal<uint8_t>(MachineType::Uint8()); | 1933 uint8_t* var_uint8 = module.AddGlobal<uint8_t>(MachineType::Uint8()); |
1900 int16_t* var_int16 = module.AddGlobal<int16_t>(MachineType::Int16()); | 1934 int16_t* var_int16 = module.AddGlobal<int16_t>(MachineType::Int16()); |
1901 uint16_t* var_uint16 = module.AddGlobal<uint16_t>(MachineType::Uint16()); | 1935 uint16_t* var_uint16 = module.AddGlobal<uint16_t>(MachineType::Uint16()); |
1902 int32_t* var_int32 = module.AddGlobal<int32_t>(MachineType::Int32()); | 1936 int32_t* var_int32 = module.AddGlobal<int32_t>(MachineType::Int32()); |
1903 uint32_t* var_uint32 = module.AddGlobal<uint32_t>(MachineType::Uint32()); | 1937 uint32_t* var_uint32 = module.AddGlobal<uint32_t>(MachineType::Uint32()); |
1904 float* var_float = module.AddGlobal<float>(MachineType::Float32()); | 1938 float* var_float = module.AddGlobal<float>(MachineType::Float32()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1941 CHECK(bit_cast<float>(0xee55ccaa) == *var_float); | 1975 CHECK(bit_cast<float>(0xee55ccaa) == *var_float); |
1942 CHECK(bit_cast<double>(0x99112233ee55ccaaULL) == *var_double); | 1976 CHECK(bit_cast<double>(0x99112233ee55ccaaULL) == *var_double); |
1943 | 1977 |
1944 USE(unused); | 1978 USE(unused); |
1945 } | 1979 } |
1946 | 1980 |
1947 WASM_EXEC_TEST(CallEmpty) { | 1981 WASM_EXEC_TEST(CallEmpty) { |
1948 const int32_t kExpected = -414444; | 1982 const int32_t kExpected = -414444; |
1949 // Build the target function. | 1983 // Build the target function. |
1950 TestSignatures sigs; | 1984 TestSignatures sigs; |
1951 TestingModule module; | 1985 TestingModule module(execution_mode); |
1952 WasmFunctionCompiler t(sigs.i_v(), &module); | 1986 WasmFunctionCompiler t(sigs.i_v(), &module); |
1953 BUILD(t, WASM_I32V_3(kExpected)); | 1987 BUILD(t, WASM_I32V_3(kExpected)); |
1954 uint32_t index = t.CompileAndAdd(); | 1988 uint32_t index = t.CompileAndAdd(); |
1955 | 1989 |
1956 // Build the calling function. | 1990 // Build the calling function. |
1957 WasmRunner<int32_t> r(&module); | 1991 WasmRunner<int32_t> r(&module); |
1958 BUILD(r, WASM_CALL_FUNCTION0(index)); | 1992 BUILD(r, WASM_CALL_FUNCTION0(index)); |
1959 | 1993 |
1960 int32_t result = r.Call(); | 1994 int32_t result = r.Call(); |
1961 CHECK_EQ(kExpected, result); | 1995 CHECK_EQ(kExpected, result); |
1962 } | 1996 } |
1963 | 1997 |
1964 WASM_EXEC_TEST(CallF32StackParameter) { | 1998 WASM_EXEC_TEST(CallF32StackParameter) { |
1965 // Build the target function. | 1999 // Build the target function. |
1966 LocalType param_types[20]; | 2000 LocalType param_types[20]; |
1967 for (int i = 0; i < 20; i++) param_types[i] = kAstF32; | 2001 for (int i = 0; i < 20; i++) param_types[i] = kAstF32; |
1968 FunctionSig sig(1, 19, param_types); | 2002 FunctionSig sig(1, 19, param_types); |
1969 TestingModule module; | 2003 TestingModule module(execution_mode); |
1970 WasmFunctionCompiler t(&sig, &module); | 2004 WasmFunctionCompiler t(&sig, &module); |
1971 BUILD(t, WASM_GET_LOCAL(17)); | 2005 BUILD(t, WASM_GET_LOCAL(17)); |
1972 uint32_t index = t.CompileAndAdd(); | 2006 uint32_t index = t.CompileAndAdd(); |
1973 | 2007 |
1974 // Build the calling function. | 2008 // Build the calling function. |
1975 WasmRunner<float> r(&module); | 2009 WasmRunner<float> r(&module); |
1976 BUILD(r, WASM_CALL_FUNCTIONN( | 2010 BUILD(r, WASM_CALL_FUNCTIONN( |
1977 19, index, WASM_F32(1.0f), WASM_F32(2.0f), WASM_F32(4.0f), | 2011 19, index, WASM_F32(1.0f), WASM_F32(2.0f), WASM_F32(4.0f), |
1978 WASM_F32(8.0f), WASM_F32(16.0f), WASM_F32(32.0f), | 2012 WASM_F32(8.0f), WASM_F32(16.0f), WASM_F32(32.0f), |
1979 WASM_F32(64.0f), WASM_F32(128.0f), WASM_F32(256.0f), | 2013 WASM_F32(64.0f), WASM_F32(128.0f), WASM_F32(256.0f), |
1980 WASM_F32(1.5f), WASM_F32(2.5f), WASM_F32(4.5f), WASM_F32(8.5f), | 2014 WASM_F32(1.5f), WASM_F32(2.5f), WASM_F32(4.5f), WASM_F32(8.5f), |
1981 WASM_F32(16.5f), WASM_F32(32.5f), WASM_F32(64.5f), | 2015 WASM_F32(16.5f), WASM_F32(32.5f), WASM_F32(64.5f), |
1982 WASM_F32(128.5f), WASM_F32(256.5f), WASM_F32(512.5f))); | 2016 WASM_F32(128.5f), WASM_F32(256.5f), WASM_F32(512.5f))); |
1983 | 2017 |
1984 float result = r.Call(); | 2018 float result = r.Call(); |
1985 CHECK_EQ(256.5f, result); | 2019 CHECK_EQ(256.5f, result); |
1986 } | 2020 } |
1987 | 2021 |
1988 WASM_EXEC_TEST(CallF64StackParameter) { | 2022 WASM_EXEC_TEST(CallF64StackParameter) { |
1989 // Build the target function. | 2023 // Build the target function. |
1990 LocalType param_types[20]; | 2024 LocalType param_types[20]; |
1991 for (int i = 0; i < 20; i++) param_types[i] = kAstF64; | 2025 for (int i = 0; i < 20; i++) param_types[i] = kAstF64; |
1992 FunctionSig sig(1, 19, param_types); | 2026 FunctionSig sig(1, 19, param_types); |
1993 TestingModule module; | 2027 TestingModule module(execution_mode); |
1994 WasmFunctionCompiler t(&sig, &module); | 2028 WasmFunctionCompiler t(&sig, &module); |
1995 BUILD(t, WASM_GET_LOCAL(17)); | 2029 BUILD(t, WASM_GET_LOCAL(17)); |
1996 uint32_t index = t.CompileAndAdd(); | 2030 uint32_t index = t.CompileAndAdd(); |
1997 | 2031 |
1998 // Build the calling function. | 2032 // Build the calling function. |
1999 WasmRunner<double> r(&module); | 2033 WasmRunner<double> r(&module); |
2000 BUILD(r, WASM_CALL_FUNCTIONN(19, index, WASM_F64(1.0), WASM_F64(2.0), | 2034 BUILD(r, WASM_CALL_FUNCTIONN(19, index, WASM_F64(1.0), WASM_F64(2.0), |
2001 WASM_F64(4.0), WASM_F64(8.0), WASM_F64(16.0), | 2035 WASM_F64(4.0), WASM_F64(8.0), WASM_F64(16.0), |
2002 WASM_F64(32.0), WASM_F64(64.0), WASM_F64(128.0), | 2036 WASM_F64(32.0), WASM_F64(64.0), WASM_F64(128.0), |
2003 WASM_F64(256.0), WASM_F64(1.5), WASM_F64(2.5), | 2037 WASM_F64(256.0), WASM_F64(1.5), WASM_F64(2.5), |
2004 WASM_F64(4.5), WASM_F64(8.5), WASM_F64(16.5), | 2038 WASM_F64(4.5), WASM_F64(8.5), WASM_F64(16.5), |
2005 WASM_F64(32.5), WASM_F64(64.5), WASM_F64(128.5), | 2039 WASM_F64(32.5), WASM_F64(64.5), WASM_F64(128.5), |
2006 WASM_F64(256.5), WASM_F64(512.5))); | 2040 WASM_F64(256.5), WASM_F64(512.5))); |
2007 | 2041 |
2008 float result = r.Call(); | 2042 float result = r.Call(); |
2009 CHECK_EQ(256.5, result); | 2043 CHECK_EQ(256.5, result); |
2010 } | 2044 } |
2011 | 2045 |
2012 WASM_EXEC_TEST(CallVoid) { | 2046 WASM_EXEC_TEST(CallVoid) { |
2013 const byte kMemOffset = 8; | 2047 const byte kMemOffset = 8; |
2014 const int32_t kElemNum = kMemOffset / sizeof(int32_t); | 2048 const int32_t kElemNum = kMemOffset / sizeof(int32_t); |
2015 const int32_t kExpected = -414444; | 2049 const int32_t kExpected = -414444; |
2016 // Build the target function. | 2050 // Build the target function. |
2017 TestSignatures sigs; | 2051 TestSignatures sigs; |
2018 TestingModule module; | 2052 TestingModule module(execution_mode); |
2019 module.AddMemory(16); | 2053 module.AddMemory(16); |
2020 module.RandomizeMemory(); | 2054 module.RandomizeMemory(); |
2021 WasmFunctionCompiler t(sigs.v_v(), &module); | 2055 WasmFunctionCompiler t(sigs.v_v(), &module); |
2022 BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(kMemOffset), | 2056 BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(kMemOffset), |
2023 WASM_I32V_3(kExpected))); | 2057 WASM_I32V_3(kExpected))); |
2024 uint32_t index = t.CompileAndAdd(); | 2058 uint32_t index = t.CompileAndAdd(); |
2025 | 2059 |
2026 // Build the calling function. | 2060 // Build the calling function. |
2027 WasmRunner<int32_t> r(&module); | 2061 WasmRunner<int32_t> r(&module); |
2028 BUILD(r, WASM_CALL_FUNCTION0(index), | 2062 BUILD(r, WASM_CALL_FUNCTION0(index), |
2029 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kMemOffset))); | 2063 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kMemOffset))); |
2030 | 2064 |
2031 int32_t result = r.Call(); | 2065 int32_t result = r.Call(); |
2032 CHECK_EQ(kExpected, result); | 2066 CHECK_EQ(kExpected, result); |
2033 CHECK_EQ(kExpected, module.raw_mem_start<int32_t>()[kElemNum]); | 2067 CHECK_EQ(kExpected, module.raw_mem_start<int32_t>()[kElemNum]); |
2034 } | 2068 } |
2035 | 2069 |
2036 WASM_EXEC_TEST(Call_Int32Add) { | 2070 WASM_EXEC_TEST(Call_Int32Add) { |
2037 // Build the target function. | 2071 // Build the target function. |
2038 TestSignatures sigs; | 2072 TestSignatures sigs; |
2039 TestingModule module; | 2073 TestingModule module(execution_mode); |
2040 WasmFunctionCompiler t(sigs.i_ii(), &module); | 2074 WasmFunctionCompiler t(sigs.i_ii(), &module); |
2041 BUILD(t, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2075 BUILD(t, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2042 uint32_t index = t.CompileAndAdd(); | 2076 uint32_t index = t.CompileAndAdd(); |
2043 | 2077 |
2044 // Build the caller function. | 2078 // Build the caller function. |
2045 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32()); | 2079 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32()); |
2046 BUILD(r, WASM_CALL_FUNCTION2(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2080 BUILD(r, WASM_CALL_FUNCTION2(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2047 | 2081 |
2048 FOR_INT32_INPUTS(i) { | 2082 FOR_INT32_INPUTS(i) { |
2049 FOR_INT32_INPUTS(j) { | 2083 FOR_INT32_INPUTS(j) { |
2050 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) + | 2084 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) + |
2051 static_cast<uint32_t>(*j)); | 2085 static_cast<uint32_t>(*j)); |
2052 CHECK_EQ(expected, r.Call(*i, *j)); | 2086 CHECK_EQ(expected, r.Call(*i, *j)); |
2053 } | 2087 } |
2054 } | 2088 } |
2055 } | 2089 } |
2056 | 2090 |
2057 WASM_EXEC_TEST(Call_Float32Sub) { | 2091 WASM_EXEC_TEST(Call_Float32Sub) { |
2058 TestSignatures sigs; | 2092 TestSignatures sigs; |
2059 TestingModule module; | 2093 TestingModule module(execution_mode); |
2060 WasmFunctionCompiler t(sigs.f_ff(), &module); | 2094 WasmFunctionCompiler t(sigs.f_ff(), &module); |
2061 | 2095 |
2062 // Build the target function. | 2096 // Build the target function. |
2063 BUILD(t, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2097 BUILD(t, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2064 uint32_t index = t.CompileAndAdd(); | 2098 uint32_t index = t.CompileAndAdd(); |
2065 | 2099 |
2066 // Builder the caller function. | 2100 // Builder the caller function. |
2067 WasmRunner<float> r(&module, MachineType::Float32(), MachineType::Float32()); | 2101 WasmRunner<float> r(&module, MachineType::Float32(), MachineType::Float32()); |
2068 BUILD(r, WASM_CALL_FUNCTION2(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2102 BUILD(r, WASM_CALL_FUNCTION2(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2069 | 2103 |
2070 FOR_FLOAT32_INPUTS(i) { | 2104 FOR_FLOAT32_INPUTS(i) { |
2071 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(*i - *j, r.Call(*i, *j)); } | 2105 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(*i - *j, r.Call(*i, *j)); } |
2072 } | 2106 } |
2073 } | 2107 } |
2074 | 2108 |
2075 WASM_EXEC_TEST(Call_Float64Sub) { | 2109 WASM_EXEC_TEST(Call_Float64Sub) { |
2076 TestingModule module; | 2110 TestingModule module(execution_mode); |
2077 double* memory = module.AddMemoryElems<double>(16); | 2111 double* memory = module.AddMemoryElems<double>(16); |
2078 WasmRunner<int32_t> r(&module); | 2112 WasmRunner<int32_t> r(&module); |
2079 | 2113 |
2080 BUILD(r, WASM_BLOCK( | 2114 BUILD(r, WASM_BLOCK( |
2081 2, WASM_STORE_MEM( | 2115 2, WASM_STORE_MEM( |
2082 MachineType::Float64(), WASM_ZERO, | 2116 MachineType::Float64(), WASM_ZERO, |
2083 WASM_F64_SUB( | 2117 WASM_F64_SUB( |
2084 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO), | 2118 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO), |
2085 WASM_LOAD_MEM(MachineType::Float64(), WASM_I8(8)))), | 2119 WASM_LOAD_MEM(MachineType::Float64(), WASM_I8(8)))), |
2086 WASM_I8(107))); | 2120 WASM_I8(107))); |
(...skipping 12 matching lines...) Expand all Loading... |
2099 } | 2133 } |
2100 } | 2134 } |
2101 } | 2135 } |
2102 | 2136 |
2103 #define ADD_CODE(vec, ...) \ | 2137 #define ADD_CODE(vec, ...) \ |
2104 do { \ | 2138 do { \ |
2105 byte __buf[] = {__VA_ARGS__}; \ | 2139 byte __buf[] = {__VA_ARGS__}; \ |
2106 for (size_t i = 0; i < sizeof(__buf); i++) vec.push_back(__buf[i]); \ | 2140 for (size_t i = 0; i < sizeof(__buf); i++) vec.push_back(__buf[i]); \ |
2107 } while (false) | 2141 } while (false) |
2108 | 2142 |
2109 static void Run_WasmMixedCall_N(int start) { | 2143 static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) { |
2110 const int kExpected = 6333; | 2144 const int kExpected = 6333; |
2111 const int kElemSize = 8; | 2145 const int kElemSize = 8; |
2112 TestSignatures sigs; | 2146 TestSignatures sigs; |
2113 | 2147 |
2114 #if WASM_64 | 2148 #if WASM_64 |
2115 static MachineType mixed[] = { | 2149 static MachineType mixed[] = { |
2116 MachineType::Int32(), MachineType::Float32(), MachineType::Int64(), | 2150 MachineType::Int32(), MachineType::Float32(), MachineType::Int64(), |
2117 MachineType::Float64(), MachineType::Float32(), MachineType::Int64(), | 2151 MachineType::Float64(), MachineType::Float32(), MachineType::Int64(), |
2118 MachineType::Int32(), MachineType::Float64(), MachineType::Float32(), | 2152 MachineType::Int32(), MachineType::Float64(), MachineType::Float32(), |
2119 MachineType::Float64(), MachineType::Int32(), MachineType::Int64(), | 2153 MachineType::Float64(), MachineType::Int32(), MachineType::Int64(), |
2120 MachineType::Int32(), MachineType::Int32()}; | 2154 MachineType::Int32(), MachineType::Int32()}; |
2121 #else | 2155 #else |
2122 static MachineType mixed[] = { | 2156 static MachineType mixed[] = { |
2123 MachineType::Int32(), MachineType::Float32(), MachineType::Float64(), | 2157 MachineType::Int32(), MachineType::Float32(), MachineType::Float64(), |
2124 MachineType::Float32(), MachineType::Int32(), MachineType::Float64(), | 2158 MachineType::Float32(), MachineType::Int32(), MachineType::Float64(), |
2125 MachineType::Float32(), MachineType::Float64(), MachineType::Int32(), | 2159 MachineType::Float32(), MachineType::Float64(), MachineType::Int32(), |
2126 MachineType::Int32(), MachineType::Int32()}; | 2160 MachineType::Int32(), MachineType::Int32()}; |
2127 #endif | 2161 #endif |
2128 | 2162 |
2129 int num_params = static_cast<int>(arraysize(mixed)) - start; | 2163 int num_params = static_cast<int>(arraysize(mixed)) - start; |
2130 for (int which = 0; which < num_params; which++) { | 2164 for (int which = 0; which < num_params; which++) { |
2131 v8::base::AccountingAllocator allocator; | 2165 v8::base::AccountingAllocator allocator; |
2132 Zone zone(&allocator); | 2166 Zone zone(&allocator); |
2133 TestingModule module; | 2167 TestingModule module(execution_mode); |
2134 module.AddMemory(1024); | 2168 module.AddMemory(1024); |
2135 MachineType* memtypes = &mixed[start]; | 2169 MachineType* memtypes = &mixed[start]; |
2136 MachineType result = memtypes[which]; | 2170 MachineType result = memtypes[which]; |
2137 | 2171 |
2138 // ========================================================================= | 2172 // ========================================================================= |
2139 // Build the selector function. | 2173 // Build the selector function. |
2140 // ========================================================================= | 2174 // ========================================================================= |
2141 uint32_t index; | 2175 uint32_t index; |
2142 FunctionSig::Builder b(&zone, 1, num_params); | 2176 FunctionSig::Builder b(&zone, 1, num_params); |
2143 b.AddReturn(WasmOpcodes::LocalTypeFor(result)); | 2177 b.AddReturn(WasmOpcodes::LocalTypeFor(result)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2186 for (int i = 0; i < size; i++) { | 2220 for (int i = 0; i < size; i++) { |
2187 int base = (which + 1) * kElemSize; | 2221 int base = (which + 1) * kElemSize; |
2188 byte expected = module.raw_mem_at<byte>(base + i); | 2222 byte expected = module.raw_mem_at<byte>(base + i); |
2189 byte result = module.raw_mem_at<byte>(i); | 2223 byte result = module.raw_mem_at<byte>(i); |
2190 CHECK_EQ(expected, result); | 2224 CHECK_EQ(expected, result); |
2191 } | 2225 } |
2192 } | 2226 } |
2193 } | 2227 } |
2194 } | 2228 } |
2195 | 2229 |
2196 WASM_EXEC_TEST(MixedCall_0) { Run_WasmMixedCall_N(0); } | 2230 WASM_EXEC_TEST(MixedCall_0) { Run_WasmMixedCall_N(execution_mode, 0); } |
2197 WASM_EXEC_TEST(MixedCall_1) { Run_WasmMixedCall_N(1); } | 2231 WASM_EXEC_TEST(MixedCall_1) { Run_WasmMixedCall_N(execution_mode, 1); } |
2198 WASM_EXEC_TEST(MixedCall_2) { Run_WasmMixedCall_N(2); } | 2232 WASM_EXEC_TEST(MixedCall_2) { Run_WasmMixedCall_N(execution_mode, 2); } |
2199 WASM_EXEC_TEST(MixedCall_3) { Run_WasmMixedCall_N(3); } | 2233 WASM_EXEC_TEST(MixedCall_3) { Run_WasmMixedCall_N(execution_mode, 3); } |
2200 | 2234 |
2201 WASM_EXEC_TEST(AddCall) { | 2235 WASM_EXEC_TEST(AddCall) { |
2202 TestSignatures sigs; | 2236 TestSignatures sigs; |
2203 TestingModule module; | 2237 TestingModule module(execution_mode); |
2204 WasmFunctionCompiler t1(sigs.i_ii(), &module); | 2238 WasmFunctionCompiler t1(sigs.i_ii(), &module); |
2205 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2239 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2206 t1.CompileAndAdd(); | 2240 t1.CompileAndAdd(); |
2207 | 2241 |
2208 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 2242 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2209 byte local = r.AllocateLocal(kAstI32); | 2243 byte local = r.AllocateLocal(kAstI32); |
2210 BUILD(r, B2(WASM_SET_LOCAL(local, WASM_I8(99)), | 2244 BUILD(r, B2(WASM_SET_LOCAL(local, WASM_I8(99)), |
2211 WASM_I32_ADD( | 2245 WASM_I32_ADD( |
2212 WASM_CALL_FUNCTION2(t1.function_index_, WASM_GET_LOCAL(0), | 2246 WASM_CALL_FUNCTION2(t1.function_index(), WASM_GET_LOCAL(0), |
2213 WASM_GET_LOCAL(0)), | 2247 WASM_GET_LOCAL(0)), |
2214 WASM_CALL_FUNCTION2(t1.function_index_, WASM_GET_LOCAL(1), | 2248 WASM_CALL_FUNCTION2(t1.function_index(), WASM_GET_LOCAL(1), |
2215 WASM_GET_LOCAL(local))))); | 2249 WASM_GET_LOCAL(local))))); |
2216 | 2250 |
2217 CHECK_EQ(198, r.Call(0)); | 2251 CHECK_EQ(198, r.Call(0)); |
2218 CHECK_EQ(200, r.Call(1)); | 2252 CHECK_EQ(200, r.Call(1)); |
2219 CHECK_EQ(100, r.Call(-49)); | 2253 CHECK_EQ(100, r.Call(-49)); |
2220 } | 2254 } |
2221 | 2255 |
2222 WASM_EXEC_TEST(CountDown_expr) { | 2256 WASM_EXEC_TEST(CountDown_expr) { |
2223 WasmRunner<int32_t> r(MachineType::Int32()); | 2257 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
2224 BUILD(r, WASM_LOOP( | 2258 BUILD(r, WASM_LOOP( |
2225 3, WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), | 2259 3, WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), |
2226 WASM_BREAKV(1, WASM_GET_LOCAL(0))), | 2260 WASM_BREAKV(1, WASM_GET_LOCAL(0))), |
2227 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), | 2261 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), |
2228 WASM_CONTINUE(0))); | 2262 WASM_CONTINUE(0))); |
2229 CHECK_EQ(0, r.Call(1)); | 2263 CHECK_EQ(0, r.Call(1)); |
2230 CHECK_EQ(0, r.Call(10)); | 2264 CHECK_EQ(0, r.Call(10)); |
2231 CHECK_EQ(0, r.Call(100)); | 2265 CHECK_EQ(0, r.Call(100)); |
2232 } | 2266 } |
2233 | 2267 |
2234 WASM_EXEC_TEST(ExprBlock2a) { | 2268 WASM_EXEC_TEST(ExprBlock2a) { |
2235 WasmRunner<int32_t> r(MachineType::Int32()); | 2269 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
2236 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), WASM_I8(1))); | 2270 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), WASM_I8(1))); |
2237 CHECK_EQ(1, r.Call(0)); | 2271 CHECK_EQ(1, r.Call(0)); |
2238 CHECK_EQ(1, r.Call(1)); | 2272 CHECK_EQ(1, r.Call(1)); |
2239 } | 2273 } |
2240 | 2274 |
2241 WASM_EXEC_TEST(ExprBlock2b) { | 2275 WASM_EXEC_TEST(ExprBlock2b) { |
2242 WasmRunner<int32_t> r(MachineType::Int32()); | 2276 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
2243 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), WASM_I8(2))); | 2277 BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), WASM_I8(2))); |
2244 CHECK_EQ(2, r.Call(0)); | 2278 CHECK_EQ(2, r.Call(0)); |
2245 CHECK_EQ(1, r.Call(1)); | 2279 CHECK_EQ(1, r.Call(1)); |
2246 } | 2280 } |
2247 | 2281 |
2248 WASM_EXEC_TEST(ExprBlock2c) { | 2282 WASM_EXEC_TEST(ExprBlock2c) { |
2249 WasmRunner<int32_t> r(MachineType::Int32()); | 2283 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
2250 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), WASM_I8(1))); | 2284 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), WASM_I8(1))); |
2251 CHECK_EQ(1, r.Call(0)); | 2285 CHECK_EQ(1, r.Call(0)); |
2252 CHECK_EQ(1, r.Call(1)); | 2286 CHECK_EQ(1, r.Call(1)); |
2253 } | 2287 } |
2254 | 2288 |
2255 WASM_EXEC_TEST(ExprBlock2d) { | 2289 WASM_EXEC_TEST(ExprBlock2d) { |
2256 WasmRunner<int32_t> r(MachineType::Int32()); | 2290 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
2257 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), WASM_I8(2))); | 2291 BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), WASM_I8(2))); |
2258 CHECK_EQ(2, r.Call(0)); | 2292 CHECK_EQ(2, r.Call(0)); |
2259 CHECK_EQ(1, r.Call(1)); | 2293 CHECK_EQ(1, r.Call(1)); |
2260 } | 2294 } |
2261 | 2295 |
2262 WASM_EXEC_TEST(ExprBlock_ManualSwitch) { | 2296 WASM_EXEC_TEST(ExprBlock_ManualSwitch) { |
2263 WasmRunner<int32_t> r(MachineType::Int32()); | 2297 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
2264 BUILD(r, WASM_BLOCK(6, WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1)), | 2298 BUILD(r, WASM_BLOCK(6, WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1)), |
2265 WASM_BRV(1, WASM_I8(11))), | 2299 WASM_BRV(1, WASM_I8(11))), |
2266 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2)), | 2300 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2)), |
2267 WASM_BRV(1, WASM_I8(12))), | 2301 WASM_BRV(1, WASM_I8(12))), |
2268 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3)), | 2302 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3)), |
2269 WASM_BRV(1, WASM_I8(13))), | 2303 WASM_BRV(1, WASM_I8(13))), |
2270 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4)), | 2304 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4)), |
2271 WASM_BRV(1, WASM_I8(14))), | 2305 WASM_BRV(1, WASM_I8(14))), |
2272 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5)), | 2306 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5)), |
2273 WASM_BRV(1, WASM_I8(15))), | 2307 WASM_BRV(1, WASM_I8(15))), |
2274 WASM_I8(99))); | 2308 WASM_I8(99))); |
2275 CHECK_EQ(99, r.Call(0)); | 2309 CHECK_EQ(99, r.Call(0)); |
2276 CHECK_EQ(11, r.Call(1)); | 2310 CHECK_EQ(11, r.Call(1)); |
2277 CHECK_EQ(12, r.Call(2)); | 2311 CHECK_EQ(12, r.Call(2)); |
2278 CHECK_EQ(13, r.Call(3)); | 2312 CHECK_EQ(13, r.Call(3)); |
2279 CHECK_EQ(14, r.Call(4)); | 2313 CHECK_EQ(14, r.Call(4)); |
2280 CHECK_EQ(15, r.Call(5)); | 2314 CHECK_EQ(15, r.Call(5)); |
2281 CHECK_EQ(99, r.Call(6)); | 2315 CHECK_EQ(99, r.Call(6)); |
2282 } | 2316 } |
2283 | 2317 |
2284 WASM_EXEC_TEST(ExprBlock_ManualSwitch_brif) { | 2318 WASM_EXEC_TEST(ExprBlock_ManualSwitch_brif) { |
2285 WasmRunner<int32_t> r(MachineType::Int32()); | 2319 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
2286 BUILD(r, | 2320 BUILD(r, |
2287 WASM_BLOCK(6, WASM_BRV_IF(0, WASM_I8(11), | 2321 WASM_BLOCK(6, WASM_BRV_IF(0, WASM_I8(11), |
2288 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1))), | 2322 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1))), |
2289 WASM_BRV_IF(0, WASM_I8(12), | 2323 WASM_BRV_IF(0, WASM_I8(12), |
2290 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2))), | 2324 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2))), |
2291 WASM_BRV_IF(0, WASM_I8(13), | 2325 WASM_BRV_IF(0, WASM_I8(13), |
2292 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3))), | 2326 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3))), |
2293 WASM_BRV_IF(0, WASM_I8(14), | 2327 WASM_BRV_IF(0, WASM_I8(14), |
2294 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4))), | 2328 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4))), |
2295 WASM_BRV_IF(0, WASM_I8(15), | 2329 WASM_BRV_IF(0, WASM_I8(15), |
2296 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5))), | 2330 WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5))), |
2297 WASM_I8(99))); | 2331 WASM_I8(99))); |
2298 CHECK_EQ(99, r.Call(0)); | 2332 CHECK_EQ(99, r.Call(0)); |
2299 CHECK_EQ(11, r.Call(1)); | 2333 CHECK_EQ(11, r.Call(1)); |
2300 CHECK_EQ(12, r.Call(2)); | 2334 CHECK_EQ(12, r.Call(2)); |
2301 CHECK_EQ(13, r.Call(3)); | 2335 CHECK_EQ(13, r.Call(3)); |
2302 CHECK_EQ(14, r.Call(4)); | 2336 CHECK_EQ(14, r.Call(4)); |
2303 CHECK_EQ(15, r.Call(5)); | 2337 CHECK_EQ(15, r.Call(5)); |
2304 CHECK_EQ(99, r.Call(6)); | 2338 CHECK_EQ(99, r.Call(6)); |
2305 } | 2339 } |
2306 | 2340 |
2307 WASM_EXEC_TEST(nested_ifs) { | 2341 WASM_EXEC_TEST(nested_ifs) { |
2308 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 2342 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 2343 MachineType::Int32()); |
2309 | 2344 |
2310 BUILD(r, WASM_IF_ELSE( | 2345 BUILD(r, WASM_IF_ELSE( |
2311 WASM_GET_LOCAL(0), | 2346 WASM_GET_LOCAL(0), |
2312 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)), | 2347 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)), |
2313 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14)))); | 2348 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14)))); |
2314 | 2349 |
2315 CHECK_EQ(11, r.Call(1, 1)); | 2350 CHECK_EQ(11, r.Call(1, 1)); |
2316 CHECK_EQ(12, r.Call(1, 0)); | 2351 CHECK_EQ(12, r.Call(1, 0)); |
2317 CHECK_EQ(13, r.Call(0, 1)); | 2352 CHECK_EQ(13, r.Call(0, 1)); |
2318 CHECK_EQ(14, r.Call(0, 0)); | 2353 CHECK_EQ(14, r.Call(0, 0)); |
2319 } | 2354 } |
2320 | 2355 |
2321 WASM_EXEC_TEST(ExprBlock_if) { | 2356 WASM_EXEC_TEST(ExprBlock_if) { |
2322 WasmRunner<int32_t> r(MachineType::Int32()); | 2357 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); |
2323 | 2358 |
2324 BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(11)), | 2359 BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(11)), |
2325 WASM_BRV(1, WASM_I8(14))))); | 2360 WASM_BRV(1, WASM_I8(14))))); |
2326 | 2361 |
2327 CHECK_EQ(11, r.Call(1)); | 2362 CHECK_EQ(11, r.Call(1)); |
2328 CHECK_EQ(14, r.Call(0)); | 2363 CHECK_EQ(14, r.Call(0)); |
2329 } | 2364 } |
2330 | 2365 |
2331 WASM_EXEC_TEST(ExprBlock_nested_ifs) { | 2366 WASM_EXEC_TEST(ExprBlock_nested_ifs) { |
2332 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 2367 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 2368 MachineType::Int32()); |
2333 | 2369 |
2334 BUILD(r, WASM_BLOCK( | 2370 BUILD(r, WASM_BLOCK( |
2335 1, WASM_IF_ELSE( | 2371 1, WASM_IF_ELSE( |
2336 WASM_GET_LOCAL(0), | 2372 WASM_GET_LOCAL(0), |
2337 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(11)), | 2373 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(11)), |
2338 WASM_BRV(1, WASM_I8(12))), | 2374 WASM_BRV(1, WASM_I8(12))), |
2339 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(13)), | 2375 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(13)), |
2340 WASM_BRV(1, WASM_I8(14)))))); | 2376 WASM_BRV(1, WASM_I8(14)))))); |
2341 | 2377 |
2342 CHECK_EQ(11, r.Call(1, 1)); | 2378 CHECK_EQ(11, r.Call(1, 1)); |
2343 CHECK_EQ(12, r.Call(1, 0)); | 2379 CHECK_EQ(12, r.Call(1, 0)); |
2344 CHECK_EQ(13, r.Call(0, 1)); | 2380 CHECK_EQ(13, r.Call(0, 1)); |
2345 CHECK_EQ(14, r.Call(0, 0)); | 2381 CHECK_EQ(14, r.Call(0, 0)); |
2346 } | 2382 } |
2347 | 2383 |
2348 WASM_EXEC_TEST(ExprLoop_nested_ifs) { | 2384 WASM_EXEC_TEST(ExprLoop_nested_ifs) { |
2349 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 2385 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 2386 MachineType::Int32()); |
2350 | 2387 |
2351 BUILD(r, WASM_LOOP( | 2388 BUILD(r, WASM_LOOP( |
2352 1, WASM_IF_ELSE( | 2389 1, WASM_IF_ELSE( |
2353 WASM_GET_LOCAL(0), | 2390 WASM_GET_LOCAL(0), |
2354 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(1, WASM_I8(11)), | 2391 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(1, WASM_I8(11)), |
2355 WASM_BRV(3, WASM_I8(12))), | 2392 WASM_BRV(3, WASM_I8(12))), |
2356 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(1, WASM_I8(13)), | 2393 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_BRV(1, WASM_I8(13)), |
2357 WASM_BRV(3, WASM_I8(14)))))); | 2394 WASM_BRV(3, WASM_I8(14)))))); |
2358 | 2395 |
2359 CHECK_EQ(11, r.Call(1, 1)); | 2396 CHECK_EQ(11, r.Call(1, 1)); |
2360 CHECK_EQ(12, r.Call(1, 0)); | 2397 CHECK_EQ(12, r.Call(1, 0)); |
2361 CHECK_EQ(13, r.Call(0, 1)); | 2398 CHECK_EQ(13, r.Call(0, 1)); |
2362 CHECK_EQ(14, r.Call(0, 0)); | 2399 CHECK_EQ(14, r.Call(0, 0)); |
2363 } | 2400 } |
2364 | 2401 |
2365 WASM_EXEC_TEST(SimpleCallIndirect) { | 2402 WASM_EXEC_TEST(SimpleCallIndirect) { |
2366 TestSignatures sigs; | 2403 TestSignatures sigs; |
2367 TestingModule module; | 2404 TestingModule module(execution_mode); |
2368 | 2405 |
2369 WasmFunctionCompiler t1(sigs.i_ii(), &module); | 2406 WasmFunctionCompiler t1(sigs.i_ii(), &module); |
2370 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2407 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2371 t1.CompileAndAdd(/*sig_index*/ 1); | 2408 t1.CompileAndAdd(/*sig_index*/ 1); |
2372 | 2409 |
2373 WasmFunctionCompiler t2(sigs.i_ii(), &module); | 2410 WasmFunctionCompiler t2(sigs.i_ii(), &module); |
2374 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2411 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2375 t2.CompileAndAdd(/*sig_index*/ 1); | 2412 t2.CompileAndAdd(/*sig_index*/ 1); |
2376 | 2413 |
2377 // Signature table. | 2414 // Signature table. |
(...skipping 10 matching lines...) Expand all Loading... |
2388 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 2425 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2389 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); | 2426 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); |
2390 | 2427 |
2391 CHECK_EQ(88, r.Call(0)); | 2428 CHECK_EQ(88, r.Call(0)); |
2392 CHECK_EQ(44, r.Call(1)); | 2429 CHECK_EQ(44, r.Call(1)); |
2393 CHECK_TRAP(r.Call(2)); | 2430 CHECK_TRAP(r.Call(2)); |
2394 } | 2431 } |
2395 | 2432 |
2396 WASM_EXEC_TEST(MultipleCallIndirect) { | 2433 WASM_EXEC_TEST(MultipleCallIndirect) { |
2397 TestSignatures sigs; | 2434 TestSignatures sigs; |
2398 TestingModule module; | 2435 TestingModule module(execution_mode); |
2399 | 2436 |
2400 WasmFunctionCompiler t1(sigs.i_ii(), &module); | 2437 WasmFunctionCompiler t1(sigs.i_ii(), &module); |
2401 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2438 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2402 t1.CompileAndAdd(/*sig_index*/ 1); | 2439 t1.CompileAndAdd(/*sig_index*/ 1); |
2403 | 2440 |
2404 WasmFunctionCompiler t2(sigs.i_ii(), &module); | 2441 WasmFunctionCompiler t2(sigs.i_ii(), &module); |
2405 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2442 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2406 t2.CompileAndAdd(/*sig_index*/ 1); | 2443 t2.CompileAndAdd(/*sig_index*/ 1); |
2407 | 2444 |
2408 // Signature table. | 2445 // Signature table. |
(...skipping 21 matching lines...) Expand all Loading... |
2430 CHECK_EQ(1, r.Call(1, 0, 9)); | 2467 CHECK_EQ(1, r.Call(1, 0, 9)); |
2431 | 2468 |
2432 CHECK_TRAP(r.Call(0, 2, 1)); | 2469 CHECK_TRAP(r.Call(0, 2, 1)); |
2433 CHECK_TRAP(r.Call(1, 2, 0)); | 2470 CHECK_TRAP(r.Call(1, 2, 0)); |
2434 CHECK_TRAP(r.Call(2, 0, 1)); | 2471 CHECK_TRAP(r.Call(2, 0, 1)); |
2435 CHECK_TRAP(r.Call(2, 1, 0)); | 2472 CHECK_TRAP(r.Call(2, 1, 0)); |
2436 } | 2473 } |
2437 | 2474 |
2438 WASM_EXEC_TEST(CallIndirect_NoTable) { | 2475 WASM_EXEC_TEST(CallIndirect_NoTable) { |
2439 TestSignatures sigs; | 2476 TestSignatures sigs; |
2440 TestingModule module; | 2477 TestingModule module(execution_mode); |
2441 | 2478 |
2442 // One function. | 2479 // One function. |
2443 WasmFunctionCompiler t1(sigs.i_ii(), &module); | 2480 WasmFunctionCompiler t1(sigs.i_ii(), &module); |
2444 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2481 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2445 t1.CompileAndAdd(/*sig_index*/ 1); | 2482 t1.CompileAndAdd(/*sig_index*/ 1); |
2446 | 2483 |
2447 // Signature table. | 2484 // Signature table. |
2448 module.AddSignature(sigs.f_ff()); | 2485 module.AddSignature(sigs.f_ff()); |
2449 module.AddSignature(sigs.i_ii()); | 2486 module.AddSignature(sigs.i_ii()); |
2450 | 2487 |
2451 // Builder the caller function. | 2488 // Builder the caller function. |
2452 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 2489 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2453 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); | 2490 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); |
2454 | 2491 |
2455 CHECK_TRAP(r.Call(0)); | 2492 CHECK_TRAP(r.Call(0)); |
2456 CHECK_TRAP(r.Call(1)); | 2493 CHECK_TRAP(r.Call(1)); |
2457 CHECK_TRAP(r.Call(2)); | 2494 CHECK_TRAP(r.Call(2)); |
2458 } | 2495 } |
2459 | 2496 |
2460 WASM_EXEC_TEST(F32Floor) { | 2497 WASM_EXEC_TEST(F32Floor) { |
2461 WasmRunner<float> r(MachineType::Float32()); | 2498 WasmRunner<float> r(execution_mode, MachineType::Float32()); |
2462 BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0))); | 2499 BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0))); |
2463 | 2500 |
2464 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(floorf(*i), r.Call(*i)); } | 2501 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(floorf(*i), r.Call(*i)); } |
2465 } | 2502 } |
2466 | 2503 |
2467 WASM_EXEC_TEST(F32Ceil) { | 2504 WASM_EXEC_TEST(F32Ceil) { |
2468 WasmRunner<float> r(MachineType::Float32()); | 2505 WasmRunner<float> r(execution_mode, MachineType::Float32()); |
2469 BUILD(r, WASM_F32_CEIL(WASM_GET_LOCAL(0))); | 2506 BUILD(r, WASM_F32_CEIL(WASM_GET_LOCAL(0))); |
2470 | 2507 |
2471 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(ceilf(*i), r.Call(*i)); } | 2508 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(ceilf(*i), r.Call(*i)); } |
2472 } | 2509 } |
2473 | 2510 |
2474 WASM_EXEC_TEST(F32Trunc) { | 2511 WASM_EXEC_TEST(F32Trunc) { |
2475 WasmRunner<float> r(MachineType::Float32()); | 2512 WasmRunner<float> r(execution_mode, MachineType::Float32()); |
2476 BUILD(r, WASM_F32_TRUNC(WASM_GET_LOCAL(0))); | 2513 BUILD(r, WASM_F32_TRUNC(WASM_GET_LOCAL(0))); |
2477 | 2514 |
2478 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(truncf(*i), r.Call(*i)); } | 2515 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(truncf(*i), r.Call(*i)); } |
2479 } | 2516 } |
2480 | 2517 |
2481 WASM_EXEC_TEST(F32NearestInt) { | 2518 WASM_EXEC_TEST(F32NearestInt) { |
2482 WasmRunner<float> r(MachineType::Float32()); | 2519 WasmRunner<float> r(execution_mode, MachineType::Float32()); |
2483 BUILD(r, WASM_F32_NEARESTINT(WASM_GET_LOCAL(0))); | 2520 BUILD(r, WASM_F32_NEARESTINT(WASM_GET_LOCAL(0))); |
2484 | 2521 |
2485 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(nearbyintf(*i), r.Call(*i)); } | 2522 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(nearbyintf(*i), r.Call(*i)); } |
2486 } | 2523 } |
2487 | 2524 |
2488 WASM_EXEC_TEST(F64Floor) { | 2525 WASM_EXEC_TEST(F64Floor) { |
2489 WasmRunner<double> r(MachineType::Float64()); | 2526 WasmRunner<double> r(execution_mode, MachineType::Float64()); |
2490 BUILD(r, WASM_F64_FLOOR(WASM_GET_LOCAL(0))); | 2527 BUILD(r, WASM_F64_FLOOR(WASM_GET_LOCAL(0))); |
2491 | 2528 |
2492 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(floor(*i), r.Call(*i)); } | 2529 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(floor(*i), r.Call(*i)); } |
2493 } | 2530 } |
2494 | 2531 |
2495 WASM_EXEC_TEST(F64Ceil) { | 2532 WASM_EXEC_TEST(F64Ceil) { |
2496 WasmRunner<double> r(MachineType::Float64()); | 2533 WasmRunner<double> r(execution_mode, MachineType::Float64()); |
2497 BUILD(r, WASM_F64_CEIL(WASM_GET_LOCAL(0))); | 2534 BUILD(r, WASM_F64_CEIL(WASM_GET_LOCAL(0))); |
2498 | 2535 |
2499 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(ceil(*i), r.Call(*i)); } | 2536 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(ceil(*i), r.Call(*i)); } |
2500 } | 2537 } |
2501 | 2538 |
2502 WASM_EXEC_TEST(F64Trunc) { | 2539 WASM_EXEC_TEST(F64Trunc) { |
2503 WasmRunner<double> r(MachineType::Float64()); | 2540 WasmRunner<double> r(execution_mode, MachineType::Float64()); |
2504 BUILD(r, WASM_F64_TRUNC(WASM_GET_LOCAL(0))); | 2541 BUILD(r, WASM_F64_TRUNC(WASM_GET_LOCAL(0))); |
2505 | 2542 |
2506 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(trunc(*i), r.Call(*i)); } | 2543 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(trunc(*i), r.Call(*i)); } |
2507 } | 2544 } |
2508 | 2545 |
2509 WASM_EXEC_TEST(F64NearestInt) { | 2546 WASM_EXEC_TEST(F64NearestInt) { |
2510 WasmRunner<double> r(MachineType::Float64()); | 2547 WasmRunner<double> r(execution_mode, MachineType::Float64()); |
2511 BUILD(r, WASM_F64_NEARESTINT(WASM_GET_LOCAL(0))); | 2548 BUILD(r, WASM_F64_NEARESTINT(WASM_GET_LOCAL(0))); |
2512 | 2549 |
2513 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(nearbyint(*i), r.Call(*i)); } | 2550 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(nearbyint(*i), r.Call(*i)); } |
2514 } | 2551 } |
2515 | 2552 |
2516 WASM_EXEC_TEST(F32Min) { | 2553 WASM_EXEC_TEST(F32Min) { |
2517 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); | 2554 WasmRunner<float> r(execution_mode, MachineType::Float32(), |
| 2555 MachineType::Float32()); |
2518 BUILD(r, WASM_F32_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2556 BUILD(r, WASM_F32_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2519 | 2557 |
2520 FOR_FLOAT32_INPUTS(i) { | 2558 FOR_FLOAT32_INPUTS(i) { |
2521 FOR_FLOAT32_INPUTS(j) { | 2559 FOR_FLOAT32_INPUTS(j) { |
2522 float expected; | 2560 float expected; |
2523 if (*i < *j) { | 2561 if (*i < *j) { |
2524 expected = *i; | 2562 expected = *i; |
2525 } else if (*j < *i) { | 2563 } else if (*j < *i) { |
2526 expected = *j; | 2564 expected = *j; |
2527 } else if (*i != *i) { | 2565 } else if (*i != *i) { |
2528 // If *i or *j is NaN, then the result is NaN. | 2566 // If *i or *j is NaN, then the result is NaN. |
2529 expected = *i; | 2567 expected = *i; |
2530 } else { | 2568 } else { |
2531 expected = *j; | 2569 expected = *j; |
2532 } | 2570 } |
2533 | 2571 |
2534 CHECK_FLOAT_EQ(expected, r.Call(*i, *j)); | 2572 CHECK_FLOAT_EQ(expected, r.Call(*i, *j)); |
2535 } | 2573 } |
2536 } | 2574 } |
2537 } | 2575 } |
2538 | 2576 |
2539 WASM_EXEC_TEST(F64Min) { | 2577 WASM_EXEC_TEST(F64Min) { |
2540 WasmRunner<double> r(MachineType::Float64(), MachineType::Float64()); | 2578 WasmRunner<double> r(execution_mode, MachineType::Float64(), |
| 2579 MachineType::Float64()); |
2541 BUILD(r, WASM_F64_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2580 BUILD(r, WASM_F64_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2542 | 2581 |
2543 FOR_FLOAT64_INPUTS(i) { | 2582 FOR_FLOAT64_INPUTS(i) { |
2544 FOR_FLOAT64_INPUTS(j) { | 2583 FOR_FLOAT64_INPUTS(j) { |
2545 double expected; | 2584 double expected; |
2546 if (*i < *j) { | 2585 if (*i < *j) { |
2547 expected = *i; | 2586 expected = *i; |
2548 } else if (*j < *i) { | 2587 } else if (*j < *i) { |
2549 expected = *j; | 2588 expected = *j; |
2550 } else if (*i != *i) { | 2589 } else if (*i != *i) { |
2551 // If *i or *j is NaN, then the result is NaN. | 2590 // If *i or *j is NaN, then the result is NaN. |
2552 expected = *i; | 2591 expected = *i; |
2553 } else { | 2592 } else { |
2554 expected = *j; | 2593 expected = *j; |
2555 } | 2594 } |
2556 | 2595 |
2557 CHECK_DOUBLE_EQ(expected, r.Call(*i, *j)); | 2596 CHECK_DOUBLE_EQ(expected, r.Call(*i, *j)); |
2558 } | 2597 } |
2559 } | 2598 } |
2560 } | 2599 } |
2561 | 2600 |
2562 WASM_EXEC_TEST(F32Max) { | 2601 WASM_EXEC_TEST(F32Max) { |
2563 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); | 2602 WasmRunner<float> r(execution_mode, MachineType::Float32(), |
| 2603 MachineType::Float32()); |
2564 BUILD(r, WASM_F32_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2604 BUILD(r, WASM_F32_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2565 | 2605 |
2566 FOR_FLOAT32_INPUTS(i) { | 2606 FOR_FLOAT32_INPUTS(i) { |
2567 FOR_FLOAT32_INPUTS(j) { | 2607 FOR_FLOAT32_INPUTS(j) { |
2568 float expected; | 2608 float expected; |
2569 if (*i > *j) { | 2609 if (*i > *j) { |
2570 expected = *i; | 2610 expected = *i; |
2571 } else if (*j > *i) { | 2611 } else if (*j > *i) { |
2572 expected = *j; | 2612 expected = *j; |
2573 } else if (*i != *i) { | 2613 } else if (*i != *i) { |
2574 // If *i or *j is NaN, then the result is NaN. | 2614 // If *i or *j is NaN, then the result is NaN. |
2575 expected = *i; | 2615 expected = *i; |
2576 } else { | 2616 } else { |
2577 expected = *j; | 2617 expected = *j; |
2578 } | 2618 } |
2579 | 2619 |
2580 CHECK_FLOAT_EQ(expected, r.Call(*i, *j)); | 2620 CHECK_FLOAT_EQ(expected, r.Call(*i, *j)); |
2581 } | 2621 } |
2582 } | 2622 } |
2583 } | 2623 } |
2584 | 2624 |
2585 WASM_EXEC_TEST(F64Max) { | 2625 WASM_EXEC_TEST(F64Max) { |
2586 WasmRunner<double> r(MachineType::Float64(), MachineType::Float64()); | 2626 WasmRunner<double> r(execution_mode, MachineType::Float64(), |
| 2627 MachineType::Float64()); |
2587 BUILD(r, WASM_F64_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2628 BUILD(r, WASM_F64_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2588 | 2629 |
2589 FOR_FLOAT64_INPUTS(i) { | 2630 FOR_FLOAT64_INPUTS(i) { |
2590 FOR_FLOAT64_INPUTS(j) { | 2631 FOR_FLOAT64_INPUTS(j) { |
2591 double expected; | 2632 double expected; |
2592 if (*i > *j) { | 2633 if (*i > *j) { |
2593 expected = *i; | 2634 expected = *i; |
2594 } else if (*j > *i) { | 2635 } else if (*j > *i) { |
2595 expected = *j; | 2636 expected = *j; |
2596 } else if (*i != *i) { | 2637 } else if (*i != *i) { |
2597 // If *i or *j is NaN, then the result is NaN. | 2638 // If *i or *j is NaN, then the result is NaN. |
2598 expected = *i; | 2639 expected = *i; |
2599 } else { | 2640 } else { |
2600 expected = *j; | 2641 expected = *j; |
2601 } | 2642 } |
2602 | 2643 |
2603 CHECK_DOUBLE_EQ(expected, r.Call(*i, *j)); | 2644 CHECK_DOUBLE_EQ(expected, r.Call(*i, *j)); |
2604 } | 2645 } |
2605 } | 2646 } |
2606 } | 2647 } |
2607 | 2648 |
2608 // TODO(ahaas): Fix on mips and reenable. | 2649 // TODO(ahaas): Fix on mips and reenable. |
2609 #if !V8_TARGET_ARCH_MIPS && !V8_TARGET_ARCH_MIPS64 | 2650 #if !V8_TARGET_ARCH_MIPS && !V8_TARGET_ARCH_MIPS64 |
2610 | 2651 |
2611 WASM_EXEC_TEST(F32Min_Snan) { | 2652 WASM_EXEC_TEST(F32Min_Snan) { |
2612 // Test that the instruction does not return a signalling NaN. | 2653 // Test that the instruction does not return a signalling NaN. |
2613 { | 2654 { |
2614 WasmRunner<float> r; | 2655 WasmRunner<float> r(execution_mode); |
2615 BUILD(r, | 2656 BUILD(r, |
2616 WASM_F32_MIN(WASM_F32(bit_cast<float>(0xff80f1e2)), WASM_F32(57.67))); | 2657 WASM_F32_MIN(WASM_F32(bit_cast<float>(0xff80f1e2)), WASM_F32(57.67))); |
2617 CHECK_EQ(0xffc0f1e2, bit_cast<uint32_t>(r.Call())); | 2658 CHECK_EQ(0xffc0f1e2, bit_cast<uint32_t>(r.Call())); |
2618 } | 2659 } |
2619 { | 2660 { |
2620 WasmRunner<float> r; | 2661 WasmRunner<float> r(execution_mode); |
2621 BUILD(r, | 2662 BUILD(r, |
2622 WASM_F32_MIN(WASM_F32(45.73), WASM_F32(bit_cast<float>(0x7f80f1e2)))); | 2663 WASM_F32_MIN(WASM_F32(45.73), WASM_F32(bit_cast<float>(0x7f80f1e2)))); |
2623 CHECK_EQ(0x7fc0f1e2, bit_cast<uint32_t>(r.Call())); | 2664 CHECK_EQ(0x7fc0f1e2, bit_cast<uint32_t>(r.Call())); |
2624 } | 2665 } |
2625 } | 2666 } |
2626 | 2667 |
2627 WASM_EXEC_TEST(F32Max_Snan) { | 2668 WASM_EXEC_TEST(F32Max_Snan) { |
2628 // Test that the instruction does not return a signalling NaN. | 2669 // Test that the instruction does not return a signalling NaN. |
2629 { | 2670 { |
2630 WasmRunner<float> r; | 2671 WasmRunner<float> r(execution_mode); |
2631 BUILD(r, | 2672 BUILD(r, |
2632 WASM_F32_MAX(WASM_F32(bit_cast<float>(0xff80f1e2)), WASM_F32(57.67))); | 2673 WASM_F32_MAX(WASM_F32(bit_cast<float>(0xff80f1e2)), WASM_F32(57.67))); |
2633 CHECK_EQ(0xffc0f1e2, bit_cast<uint32_t>(r.Call())); | 2674 CHECK_EQ(0xffc0f1e2, bit_cast<uint32_t>(r.Call())); |
2634 } | 2675 } |
2635 { | 2676 { |
2636 WasmRunner<float> r; | 2677 WasmRunner<float> r(execution_mode); |
2637 BUILD(r, | 2678 BUILD(r, |
2638 WASM_F32_MAX(WASM_F32(45.73), WASM_F32(bit_cast<float>(0x7f80f1e2)))); | 2679 WASM_F32_MAX(WASM_F32(45.73), WASM_F32(bit_cast<float>(0x7f80f1e2)))); |
2639 CHECK_EQ(0x7fc0f1e2, bit_cast<uint32_t>(r.Call())); | 2680 CHECK_EQ(0x7fc0f1e2, bit_cast<uint32_t>(r.Call())); |
2640 } | 2681 } |
2641 } | 2682 } |
2642 | 2683 |
2643 WASM_EXEC_TEST(F64Min_Snan) { | 2684 WASM_EXEC_TEST(F64Min_Snan) { |
2644 // Test that the instruction does not return a signalling NaN. | 2685 // Test that the instruction does not return a signalling NaN. |
2645 { | 2686 { |
2646 WasmRunner<double> r; | 2687 WasmRunner<double> r(execution_mode); |
2647 BUILD(r, WASM_F64_MIN(WASM_F64(bit_cast<double>(0xfff000000000f1e2)), | 2688 BUILD(r, WASM_F64_MIN(WASM_F64(bit_cast<double>(0xfff000000000f1e2)), |
2648 WASM_F64(57.67))); | 2689 WASM_F64(57.67))); |
2649 CHECK_EQ(0xfff800000000f1e2, bit_cast<uint64_t>(r.Call())); | 2690 CHECK_EQ(0xfff800000000f1e2, bit_cast<uint64_t>(r.Call())); |
2650 } | 2691 } |
2651 { | 2692 { |
2652 WasmRunner<double> r; | 2693 WasmRunner<double> r(execution_mode); |
2653 BUILD(r, WASM_F64_MIN(WASM_F64(45.73), | 2694 BUILD(r, WASM_F64_MIN(WASM_F64(45.73), |
2654 WASM_F64(bit_cast<double>(0x7ff000000000f1e2)))); | 2695 WASM_F64(bit_cast<double>(0x7ff000000000f1e2)))); |
2655 CHECK_EQ(0x7ff800000000f1e2, bit_cast<uint64_t>(r.Call())); | 2696 CHECK_EQ(0x7ff800000000f1e2, bit_cast<uint64_t>(r.Call())); |
2656 } | 2697 } |
2657 } | 2698 } |
2658 | 2699 |
2659 WASM_EXEC_TEST(F64Max_Snan) { | 2700 WASM_EXEC_TEST(F64Max_Snan) { |
2660 // Test that the instruction does not return a signalling NaN. | 2701 // Test that the instruction does not return a signalling NaN. |
2661 { | 2702 { |
2662 WasmRunner<double> r; | 2703 WasmRunner<double> r(execution_mode); |
2663 BUILD(r, WASM_F64_MAX(WASM_F64(bit_cast<double>(0xfff000000000f1e2)), | 2704 BUILD(r, WASM_F64_MAX(WASM_F64(bit_cast<double>(0xfff000000000f1e2)), |
2664 WASM_F64(57.67))); | 2705 WASM_F64(57.67))); |
2665 CHECK_EQ(0xfff800000000f1e2, bit_cast<uint64_t>(r.Call())); | 2706 CHECK_EQ(0xfff800000000f1e2, bit_cast<uint64_t>(r.Call())); |
2666 } | 2707 } |
2667 { | 2708 { |
2668 WasmRunner<double> r; | 2709 WasmRunner<double> r(execution_mode); |
2669 BUILD(r, WASM_F64_MAX(WASM_F64(45.73), | 2710 BUILD(r, WASM_F64_MAX(WASM_F64(45.73), |
2670 WASM_F64(bit_cast<double>(0x7ff000000000f1e2)))); | 2711 WASM_F64(bit_cast<double>(0x7ff000000000f1e2)))); |
2671 CHECK_EQ(0x7ff800000000f1e2, bit_cast<uint64_t>(r.Call())); | 2712 CHECK_EQ(0x7ff800000000f1e2, bit_cast<uint64_t>(r.Call())); |
2672 } | 2713 } |
2673 } | 2714 } |
2674 | 2715 |
2675 #endif | 2716 #endif |
2676 | 2717 |
2677 WASM_EXEC_TEST(I32SConvertF32) { | 2718 WASM_EXEC_TEST(I32SConvertF32) { |
2678 WasmRunner<int32_t> r(MachineType::Float32()); | 2719 WasmRunner<int32_t> r(execution_mode, MachineType::Float32()); |
2679 BUILD(r, WASM_I32_SCONVERT_F32(WASM_GET_LOCAL(0))); | 2720 BUILD(r, WASM_I32_SCONVERT_F32(WASM_GET_LOCAL(0))); |
2680 | 2721 |
2681 FOR_FLOAT32_INPUTS(i) { | 2722 FOR_FLOAT32_INPUTS(i) { |
2682 if (*i < static_cast<float>(INT32_MAX) && | 2723 if (*i < static_cast<float>(INT32_MAX) && |
2683 *i >= static_cast<float>(INT32_MIN)) { | 2724 *i >= static_cast<float>(INT32_MIN)) { |
2684 CHECK_EQ(static_cast<int32_t>(*i), r.Call(*i)); | 2725 CHECK_EQ(static_cast<int32_t>(*i), r.Call(*i)); |
2685 } else { | 2726 } else { |
2686 CHECK_TRAP32(r.Call(*i)); | 2727 CHECK_TRAP32(r.Call(*i)); |
2687 } | 2728 } |
2688 } | 2729 } |
2689 } | 2730 } |
2690 | 2731 |
2691 WASM_EXEC_TEST(I32SConvertF64) { | 2732 WASM_EXEC_TEST(I32SConvertF64) { |
2692 WasmRunner<int32_t> r(MachineType::Float64()); | 2733 WasmRunner<int32_t> r(execution_mode, MachineType::Float64()); |
2693 BUILD(r, WASM_I32_SCONVERT_F64(WASM_GET_LOCAL(0))); | 2734 BUILD(r, WASM_I32_SCONVERT_F64(WASM_GET_LOCAL(0))); |
2694 | 2735 |
2695 FOR_FLOAT64_INPUTS(i) { | 2736 FOR_FLOAT64_INPUTS(i) { |
2696 if (*i < (static_cast<double>(INT32_MAX) + 1.0) && | 2737 if (*i < (static_cast<double>(INT32_MAX) + 1.0) && |
2697 *i > (static_cast<double>(INT32_MIN) - 1.0)) { | 2738 *i > (static_cast<double>(INT32_MIN) - 1.0)) { |
2698 CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); | 2739 CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); |
2699 } else { | 2740 } else { |
2700 CHECK_TRAP32(r.Call(*i)); | 2741 CHECK_TRAP32(r.Call(*i)); |
2701 } | 2742 } |
2702 } | 2743 } |
2703 } | 2744 } |
2704 | 2745 |
2705 WASM_EXEC_TEST(I32UConvertF32) { | 2746 WASM_EXEC_TEST(I32UConvertF32) { |
2706 WasmRunner<uint32_t> r(MachineType::Float32()); | 2747 WasmRunner<uint32_t> r(execution_mode, MachineType::Float32()); |
2707 BUILD(r, WASM_I32_UCONVERT_F32(WASM_GET_LOCAL(0))); | 2748 BUILD(r, WASM_I32_UCONVERT_F32(WASM_GET_LOCAL(0))); |
2708 | 2749 |
2709 FOR_FLOAT32_INPUTS(i) { | 2750 FOR_FLOAT32_INPUTS(i) { |
2710 if (*i < (static_cast<float>(UINT32_MAX) + 1.0) && *i > -1) { | 2751 if (*i < (static_cast<float>(UINT32_MAX) + 1.0) && *i > -1) { |
2711 CHECK_EQ(static_cast<uint32_t>(*i), r.Call(*i)); | 2752 CHECK_EQ(static_cast<uint32_t>(*i), r.Call(*i)); |
2712 } else { | 2753 } else { |
2713 CHECK_TRAP32(r.Call(*i)); | 2754 CHECK_TRAP32(r.Call(*i)); |
2714 } | 2755 } |
2715 } | 2756 } |
2716 } | 2757 } |
2717 | 2758 |
2718 WASM_EXEC_TEST(I32UConvertF64) { | 2759 WASM_EXEC_TEST(I32UConvertF64) { |
2719 WasmRunner<uint32_t> r(MachineType::Float64()); | 2760 WasmRunner<uint32_t> r(execution_mode, MachineType::Float64()); |
2720 BUILD(r, WASM_I32_UCONVERT_F64(WASM_GET_LOCAL(0))); | 2761 BUILD(r, WASM_I32_UCONVERT_F64(WASM_GET_LOCAL(0))); |
2721 | 2762 |
2722 FOR_FLOAT64_INPUTS(i) { | 2763 FOR_FLOAT64_INPUTS(i) { |
2723 if (*i < (static_cast<float>(UINT32_MAX) + 1.0) && *i > -1) { | 2764 if (*i < (static_cast<float>(UINT32_MAX) + 1.0) && *i > -1) { |
2724 CHECK_EQ(static_cast<uint32_t>(*i), r.Call(*i)); | 2765 CHECK_EQ(static_cast<uint32_t>(*i), r.Call(*i)); |
2725 } else { | 2766 } else { |
2726 CHECK_TRAP32(r.Call(*i)); | 2767 CHECK_TRAP32(r.Call(*i)); |
2727 } | 2768 } |
2728 } | 2769 } |
2729 } | 2770 } |
2730 | 2771 |
2731 WASM_EXEC_TEST(F64CopySign) { | 2772 WASM_EXEC_TEST(F64CopySign) { |
2732 WasmRunner<double> r(MachineType::Float64(), MachineType::Float64()); | 2773 WasmRunner<double> r(execution_mode, MachineType::Float64(), |
| 2774 MachineType::Float64()); |
2733 BUILD(r, WASM_F64_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2775 BUILD(r, WASM_F64_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2734 | 2776 |
2735 FOR_FLOAT64_INPUTS(i) { | 2777 FOR_FLOAT64_INPUTS(i) { |
2736 FOR_FLOAT64_INPUTS(j) { CHECK_DOUBLE_EQ(copysign(*i, *j), r.Call(*i, *j)); } | 2778 FOR_FLOAT64_INPUTS(j) { CHECK_DOUBLE_EQ(copysign(*i, *j), r.Call(*i, *j)); } |
2737 } | 2779 } |
2738 } | 2780 } |
2739 | 2781 |
2740 WASM_EXEC_TEST(F32CopySign) { | 2782 WASM_EXEC_TEST(F32CopySign) { |
2741 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); | 2783 WasmRunner<float> r(execution_mode, MachineType::Float32(), |
| 2784 MachineType::Float32()); |
2742 BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2785 BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2743 | 2786 |
2744 FOR_FLOAT32_INPUTS(i) { | 2787 FOR_FLOAT32_INPUTS(i) { |
2745 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(copysignf(*i, *j), r.Call(*i, *j)); } | 2788 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(copysignf(*i, *j), r.Call(*i, *j)); } |
2746 } | 2789 } |
2747 } | 2790 } |
2748 | 2791 |
2749 void CompileCallIndirectMany(LocalType param) { | 2792 void CompileCallIndirectMany(LocalType param) { |
2750 // Make sure we don't run out of registers when compiling indirect calls | 2793 // Make sure we don't run out of registers when compiling indirect calls |
2751 // with many many parameters. | 2794 // with many many parameters. |
2752 TestSignatures sigs; | 2795 TestSignatures sigs; |
2753 for (byte num_params = 0; num_params < 40; num_params++) { | 2796 for (byte num_params = 0; num_params < 40; num_params++) { |
2754 v8::base::AccountingAllocator allocator; | 2797 v8::base::AccountingAllocator allocator; |
2755 Zone zone(&allocator); | 2798 Zone zone(&allocator); |
2756 HandleScope scope(CcTest::InitIsolateOnce()); | 2799 HandleScope scope(CcTest::InitIsolateOnce()); |
2757 TestingModule module; | 2800 TestingModule module(kExecuteCompiled); |
2758 FunctionSig* sig = sigs.many(&zone, kAstStmt, param, num_params); | 2801 FunctionSig* sig = sigs.many(&zone, kAstStmt, param, num_params); |
2759 | 2802 |
2760 module.AddSignature(sig); | 2803 module.AddSignature(sig); |
2761 module.AddSignature(sig); | 2804 module.AddSignature(sig); |
2762 module.AddIndirectFunctionTable(nullptr, 0); | 2805 module.AddIndirectFunctionTable(nullptr, 0); |
2763 | 2806 |
2764 WasmFunctionCompiler t(sig, &module); | 2807 WasmFunctionCompiler t(sig, &module); |
2765 | 2808 |
2766 std::vector<byte> code; | 2809 std::vector<byte> code; |
2767 ADD_CODE(code, kExprI8Const, 0); | 2810 ADD_CODE(code, kExprI8Const, 0); |
(...skipping 11 matching lines...) Expand all Loading... |
2779 | 2822 |
2780 #if WASM_64 | 2823 #if WASM_64 |
2781 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } | 2824 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } |
2782 #endif | 2825 #endif |
2783 | 2826 |
2784 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } | 2827 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } |
2785 | 2828 |
2786 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } | 2829 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } |
2787 | 2830 |
2788 WASM_EXEC_TEST(Int32RemS_dead) { | 2831 WASM_EXEC_TEST(Int32RemS_dead) { |
2789 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 2832 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 2833 MachineType::Int32()); |
2790 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO); | 2834 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO); |
2791 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 2835 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
2792 CHECK_EQ(0, r.Call(133, 100)); | 2836 CHECK_EQ(0, r.Call(133, 100)); |
2793 CHECK_EQ(0, r.Call(kMin, -1)); | 2837 CHECK_EQ(0, r.Call(kMin, -1)); |
2794 CHECK_EQ(0, r.Call(0, 1)); | 2838 CHECK_EQ(0, r.Call(0, 1)); |
2795 CHECK_TRAP(r.Call(100, 0)); | 2839 CHECK_TRAP(r.Call(100, 0)); |
2796 CHECK_TRAP(r.Call(-1001, 0)); | 2840 CHECK_TRAP(r.Call(-1001, 0)); |
2797 CHECK_TRAP(r.Call(kMin, 0)); | 2841 CHECK_TRAP(r.Call(kMin, 0)); |
2798 } | 2842 } |
OLD | NEW |