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

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

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

Powered by Google App Engine
This is Rietveld 408576698