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