OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdint.h> | 5 #include <stdint.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "src/wasm/wasm-macro-gen.h" | 9 #include "src/wasm/wasm-macro-gen.h" |
10 | 10 |
11 #include "test/cctest/cctest.h" | 11 #include "test/cctest/cctest.h" |
12 #include "test/cctest/compiler/value-helper.h" | 12 #include "test/cctest/compiler/value-helper.h" |
13 #include "test/cctest/wasm/test-signatures.h" | 13 #include "test/cctest/wasm/test-signatures.h" |
14 #include "test/cctest/wasm/wasm-run-utils.h" | 14 #include "test/cctest/wasm/wasm-run-utils.h" |
15 | 15 |
16 using namespace v8::base; | 16 using namespace v8::base; |
17 using namespace v8::internal; | 17 using namespace v8::internal; |
18 using namespace v8::internal::compiler; | 18 using namespace v8::internal::compiler; |
19 using namespace v8::internal::wasm; | 19 using namespace v8::internal::wasm; |
20 | 20 |
21 #define BUILD(r, ...) \ | 21 #define BUILD(r, ...) \ |
22 do { \ | 22 do { \ |
23 byte code[] = {__VA_ARGS__}; \ | 23 byte code[] = {__VA_ARGS__}; \ |
24 r.Build(code, code + arraysize(code)); \ | 24 r.Build(code, code + arraysize(code)); \ |
25 } while (false) | 25 } while (false) |
26 | 26 |
27 | 27 |
28 TEST(Run_WasmInt8Const) { | 28 TEST(Run_WasmInt8Const) { |
29 WasmRunner<int8_t> r; | 29 WasmRunner<int32_t> r; |
30 const byte kExpectedValue = 121; | 30 const byte kExpectedValue = 121; |
31 // return(kExpectedValue) | 31 // return(kExpectedValue) |
32 BUILD(r, WASM_I8(kExpectedValue)); | 32 BUILD(r, WASM_I8(kExpectedValue)); |
33 CHECK_EQ(kExpectedValue, r.Call()); | 33 CHECK_EQ(kExpectedValue, r.Call()); |
34 } | 34 } |
35 | 35 |
36 | 36 |
37 TEST(Run_WasmInt8Const_fallthru1) { | 37 TEST(Run_WasmInt8Const_fallthru1) { |
38 WasmRunner<int8_t> r; | 38 WasmRunner<int32_t> r; |
39 const byte kExpectedValue = 122; | 39 const byte kExpectedValue = 122; |
40 // kExpectedValue | 40 // kExpectedValue |
41 BUILD(r, WASM_I8(kExpectedValue)); | 41 BUILD(r, WASM_I8(kExpectedValue)); |
42 CHECK_EQ(kExpectedValue, r.Call()); | 42 CHECK_EQ(kExpectedValue, r.Call()); |
43 } | 43 } |
44 | 44 |
45 | 45 |
46 TEST(Run_WasmInt8Const_fallthru2) { | 46 TEST(Run_WasmInt8Const_fallthru2) { |
47 WasmRunner<int8_t> r; | 47 WasmRunner<int32_t> r; |
48 const byte kExpectedValue = 123; | 48 const byte kExpectedValue = 123; |
49 // -99 kExpectedValue | 49 // -99 kExpectedValue |
50 BUILD(r, WASM_I8(-99), WASM_I8(kExpectedValue)); | 50 BUILD(r, WASM_I8(-99), WASM_I8(kExpectedValue)); |
51 CHECK_EQ(kExpectedValue, r.Call()); | 51 CHECK_EQ(kExpectedValue, r.Call()); |
52 } | 52 } |
53 | 53 |
54 | 54 |
55 TEST(Run_WasmInt8Const_all) { | 55 TEST(Run_WasmInt8Const_all) { |
56 for (int value = -128; value <= 127; value++) { | 56 for (int value = -128; value <= 127; value++) { |
57 WasmRunner<int8_t> r; | 57 WasmRunner<int32_t> r; |
58 // return(value) | 58 // return(value) |
59 BUILD(r, WASM_I8(value)); | 59 BUILD(r, WASM_I8(value)); |
60 int8_t result = r.Call(); | 60 int32_t result = r.Call(); |
61 CHECK_EQ(value, result); | 61 CHECK_EQ(value, result); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 | 65 |
66 TEST(Run_WasmInt32Const) { | 66 TEST(Run_WasmInt32Const) { |
67 WasmRunner<int32_t> r; | 67 WasmRunner<int32_t> r; |
68 const int32_t kExpectedValue = 0x11223344; | 68 const int32_t kExpectedValue = 0x11223344; |
69 // return(kExpectedValue) | 69 // return(kExpectedValue) |
70 BUILD(r, WASM_I32(kExpectedValue)); | 70 BUILD(r, WASM_I32(kExpectedValue)); |
71 CHECK_EQ(kExpectedValue, r.Call()); | 71 CHECK_EQ(kExpectedValue, r.Call()); |
72 } | 72 } |
73 | 73 |
74 | 74 |
75 TEST(Run_WasmInt32Const_many) { | 75 TEST(Run_WasmInt32Const_many) { |
76 FOR_INT32_INPUTS(i) { | 76 FOR_INT32_INPUTS(i) { |
77 WasmRunner<int32_t> r; | 77 WasmRunner<int32_t> r; |
78 const int32_t kExpectedValue = *i; | 78 const int32_t kExpectedValue = *i; |
79 // return(kExpectedValue) | 79 // return(kExpectedValue) |
80 BUILD(r, WASM_I32(kExpectedValue)); | 80 BUILD(r, WASM_I32(kExpectedValue)); |
81 CHECK_EQ(kExpectedValue, r.Call()); | 81 CHECK_EQ(kExpectedValue, r.Call()); |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 | 85 |
86 TEST(Run_WasmMemorySize) { | 86 TEST(Run_WasmMemorySize) { |
87 WasmRunner<int32_t> r; | |
88 TestingModule module; | 87 TestingModule module; |
| 88 WasmRunner<int32_t> r(&module); |
89 module.AddMemory(1024); | 89 module.AddMemory(1024); |
90 r.env()->module = &module; | |
91 BUILD(r, kExprMemorySize); | 90 BUILD(r, kExprMemorySize); |
92 CHECK_EQ(1024, r.Call()); | 91 CHECK_EQ(1024, r.Call()); |
93 } | 92 } |
94 | 93 |
95 | 94 |
96 #if WASM_64 | 95 #if WASM_64 |
97 TEST(Run_WasmInt64Const) { | 96 TEST(Run_WasmInt64Const) { |
98 WasmRunner<int64_t> r; | 97 WasmRunner<int64_t> r; |
99 const int64_t kExpectedValue = 0x1122334455667788LL; | 98 const int64_t kExpectedValue = 0x1122334455667788LL; |
100 // return(kExpectedValue) | 99 // return(kExpectedValue) |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 CHECK_TRAP(r.Call(val)); | 597 CHECK_TRAP(r.Call(val)); |
599 } else { | 598 } else { |
600 CHECK_EQ(val / denom, r.Call(val)); | 599 CHECK_EQ(val / denom, r.Call(val)); |
601 } | 600 } |
602 } | 601 } |
603 } | 602 } |
604 } | 603 } |
605 | 604 |
606 | 605 |
607 TEST(Run_WASM_Int32DivS_trap_effect) { | 606 TEST(Run_WASM_Int32DivS_trap_effect) { |
608 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | |
609 TestingModule module; | 607 TestingModule module; |
610 module.AddMemoryElems<int32_t>(8); | 608 module.AddMemoryElems<int32_t>(8); |
611 r.env()->module = &module; | 609 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32()); |
612 | 610 |
613 BUILD(r, | 611 BUILD(r, |
614 WASM_IF_ELSE(WASM_GET_LOCAL(0), | 612 WASM_IF_ELSE(WASM_GET_LOCAL(0), |
615 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(), | 613 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(), |
616 WASM_ZERO, WASM_GET_LOCAL(0)), | 614 WASM_ZERO, WASM_GET_LOCAL(0)), |
617 WASM_GET_LOCAL(1)), | 615 WASM_GET_LOCAL(1)), |
618 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(), | 616 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(), |
619 WASM_ZERO, WASM_GET_LOCAL(0)), | 617 WASM_ZERO, WASM_GET_LOCAL(0)), |
620 WASM_GET_LOCAL(1)))); | 618 WASM_GET_LOCAL(1)))); |
621 CHECK_EQ(0, r.Call(0, 100)); | 619 CHECK_EQ(0, r.Call(0, 100)); |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 | 1214 |
1217 CHECK_EQ(203, r.Call(0, 200)); | 1215 CHECK_EQ(203, r.Call(0, 200)); |
1218 CHECK_EQ(202, r.Call(1, 200)); | 1216 CHECK_EQ(202, r.Call(1, 200)); |
1219 CHECK_EQ(212, r.Call(2, 200)); | 1217 CHECK_EQ(212, r.Call(2, 200)); |
1220 CHECK_EQ(208, r.Call(3, 200)); | 1218 CHECK_EQ(208, r.Call(3, 200)); |
1221 CHECK_EQ(208, r.Call(4, 200)); | 1219 CHECK_EQ(208, r.Call(4, 200)); |
1222 } | 1220 } |
1223 | 1221 |
1224 | 1222 |
1225 TEST(Run_Wasm_F32ReinterpretI32) { | 1223 TEST(Run_Wasm_F32ReinterpretI32) { |
1226 WasmRunner<int32_t> r; | |
1227 TestingModule module; | 1224 TestingModule module; |
1228 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 1225 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
1229 r.env()->module = &module; | 1226 WasmRunner<int32_t> r(&module); |
1230 | 1227 |
1231 BUILD(r, WASM_I32_REINTERPRET_F32( | 1228 BUILD(r, WASM_I32_REINTERPRET_F32( |
1232 WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO))); | 1229 WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO))); |
1233 | 1230 |
1234 FOR_INT32_INPUTS(i) { | 1231 FOR_INT32_INPUTS(i) { |
1235 int32_t expected = *i; | 1232 int32_t expected = *i; |
1236 memory[0] = expected; | 1233 memory[0] = expected; |
1237 CHECK_EQ(expected, r.Call()); | 1234 CHECK_EQ(expected, r.Call()); |
1238 } | 1235 } |
1239 } | 1236 } |
1240 | 1237 |
1241 | 1238 |
1242 TEST(Run_Wasm_I32ReinterpretF32) { | 1239 TEST(Run_Wasm_I32ReinterpretF32) { |
1243 WasmRunner<int32_t> r(MachineType::Int32()); | |
1244 TestingModule module; | 1240 TestingModule module; |
1245 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 1241 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
1246 r.env()->module = &module; | 1242 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1247 | 1243 |
1248 BUILD(r, WASM_BLOCK( | 1244 BUILD(r, WASM_BLOCK( |
1249 2, WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, | 1245 2, WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, |
1250 WASM_F32_REINTERPRET_I32(WASM_GET_LOCAL(0))), | 1246 WASM_F32_REINTERPRET_I32(WASM_GET_LOCAL(0))), |
1251 WASM_I8(107))); | 1247 WASM_I8(107))); |
1252 | 1248 |
1253 FOR_INT32_INPUTS(i) { | 1249 FOR_INT32_INPUTS(i) { |
1254 int32_t expected = *i; | 1250 int32_t expected = *i; |
1255 CHECK_EQ(107, r.Call(expected)); | 1251 CHECK_EQ(107, r.Call(expected)); |
1256 CHECK_EQ(expected, memory[0]); | 1252 CHECK_EQ(expected, memory[0]); |
1257 } | 1253 } |
1258 } | 1254 } |
1259 | 1255 |
1260 | 1256 |
1261 TEST(Run_Wasm_ReturnStore) { | 1257 TEST(Run_Wasm_ReturnStore) { |
1262 WasmRunner<int32_t> r; | |
1263 TestingModule module; | 1258 TestingModule module; |
1264 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 1259 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
1265 r.env()->module = &module; | 1260 WasmRunner<int32_t> r(&module); |
1266 | 1261 |
1267 BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, | 1262 BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, |
1268 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO))); | 1263 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO))); |
1269 | 1264 |
1270 FOR_INT32_INPUTS(i) { | 1265 FOR_INT32_INPUTS(i) { |
1271 int32_t expected = *i; | 1266 int32_t expected = *i; |
1272 memory[0] = expected; | 1267 memory[0] = expected; |
1273 CHECK_EQ(expected, r.Call()); | 1268 CHECK_EQ(expected, r.Call()); |
1274 } | 1269 } |
1275 } | 1270 } |
1276 | 1271 |
1277 | 1272 |
1278 TEST(Run_Wasm_VoidReturn1) { | 1273 TEST(Run_Wasm_VoidReturn1) { |
1279 // We use a wrapper function because WasmRunner<void> does not exist. | 1274 // We use a wrapper function because WasmRunner<void> does not exist. |
1280 | 1275 |
1281 // Build the test function. | 1276 // Build the test function. |
1282 TestSignatures sigs; | 1277 TestSignatures sigs; |
1283 TestingModule module; | 1278 TestingModule module; |
1284 WasmFunctionCompiler t(sigs.v_v()); | 1279 WasmFunctionCompiler t(sigs.v_v(), &module); |
1285 BUILD(t, kExprNop); | 1280 BUILD(t, kExprNop); |
1286 uint32_t index = t.CompileAndAdd(&module); | 1281 uint32_t index = t.CompileAndAdd(); |
1287 | 1282 |
1288 const int32_t kExpected = -414444; | 1283 const int32_t kExpected = -414444; |
1289 // Build the calling function. | 1284 // Build the calling function. |
1290 WasmRunner<int32_t> r; | 1285 WasmRunner<int32_t> r; |
1291 r.env()->module = &module; | 1286 r.env()->module = &module; |
1292 BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32(kExpected))); | 1287 BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32(kExpected))); |
1293 | 1288 |
1294 int32_t result = r.Call(); | 1289 int32_t result = r.Call(); |
1295 CHECK_EQ(kExpected, result); | 1290 CHECK_EQ(kExpected, result); |
1296 } | 1291 } |
1297 | 1292 |
1298 | 1293 |
1299 TEST(Run_Wasm_VoidReturn2) { | 1294 TEST(Run_Wasm_VoidReturn2) { |
1300 // We use a wrapper function because WasmRunner<void> does not exist. | 1295 // We use a wrapper function because WasmRunner<void> does not exist. |
1301 // Build the test function. | 1296 // Build the test function. |
1302 TestSignatures sigs; | 1297 TestSignatures sigs; |
1303 TestingModule module; | 1298 TestingModule module; |
1304 WasmFunctionCompiler t(sigs.v_v()); | 1299 WasmFunctionCompiler t(sigs.v_v(), &module); |
1305 BUILD(t, WASM_RETURN0); | 1300 BUILD(t, WASM_RETURN0); |
1306 uint32_t index = t.CompileAndAdd(&module); | 1301 uint32_t index = t.CompileAndAdd(); |
1307 | 1302 |
1308 const int32_t kExpected = -414444; | 1303 const int32_t kExpected = -414444; |
1309 // Build the calling function. | 1304 // Build the calling function. |
1310 WasmRunner<int32_t> r; | 1305 WasmRunner<int32_t> r; |
1311 r.env()->module = &module; | 1306 r.env()->module = &module; |
1312 BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32(kExpected))); | 1307 BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32(kExpected))); |
1313 | 1308 |
1314 int32_t result = r.Call(); | 1309 int32_t result = r.Call(); |
1315 CHECK_EQ(kExpected, result); | 1310 CHECK_EQ(kExpected, result); |
1316 } | 1311 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 WASM_SET_LOCAL(0, WASM_I8(93)))), | 1487 WASM_SET_LOCAL(0, WASM_I8(93)))), |
1493 WASM_GET_LOCAL(0)); | 1488 WASM_GET_LOCAL(0)); |
1494 CHECK_EQ(93, r.Call(0)); | 1489 CHECK_EQ(93, r.Call(0)); |
1495 CHECK_EQ(3, r.Call(3)); | 1490 CHECK_EQ(3, r.Call(3)); |
1496 CHECK_EQ(10001, r.Call(10001)); | 1491 CHECK_EQ(10001, r.Call(10001)); |
1497 CHECK_EQ(-22, r.Call(-22)); | 1492 CHECK_EQ(-22, r.Call(-22)); |
1498 } | 1493 } |
1499 | 1494 |
1500 | 1495 |
1501 TEST(Run_Wasm_LoadMemI32) { | 1496 TEST(Run_Wasm_LoadMemI32) { |
1502 WasmRunner<int32_t> r(MachineType::Int32()); | |
1503 TestingModule module; | 1497 TestingModule module; |
1504 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 1498 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
| 1499 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1505 module.RandomizeMemory(1111); | 1500 module.RandomizeMemory(1111); |
1506 r.env()->module = &module; | |
1507 | 1501 |
1508 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(0))); | 1502 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(0))); |
1509 | 1503 |
1510 memory[0] = 99999999; | 1504 memory[0] = 99999999; |
1511 CHECK_EQ(99999999, r.Call(0)); | 1505 CHECK_EQ(99999999, r.Call(0)); |
1512 | 1506 |
1513 memory[0] = 88888888; | 1507 memory[0] = 88888888; |
1514 CHECK_EQ(88888888, r.Call(0)); | 1508 CHECK_EQ(88888888, r.Call(0)); |
1515 | 1509 |
1516 memory[0] = 77777777; | 1510 memory[0] = 77777777; |
1517 CHECK_EQ(77777777, r.Call(0)); | 1511 CHECK_EQ(77777777, r.Call(0)); |
1518 } | 1512 } |
1519 | 1513 |
1520 | 1514 |
1521 TEST(Run_Wasm_LoadMemI32_oob) { | 1515 TEST(Run_Wasm_LoadMemI32_oob) { |
1522 WasmRunner<int32_t> r(MachineType::Uint32()); | |
1523 TestingModule module; | 1516 TestingModule module; |
1524 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 1517 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
| 1518 WasmRunner<int32_t> r(&module, MachineType::Uint32()); |
1525 module.RandomizeMemory(1111); | 1519 module.RandomizeMemory(1111); |
1526 r.env()->module = &module; | |
1527 | 1520 |
1528 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); | 1521 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); |
1529 | 1522 |
1530 memory[0] = 88888888; | 1523 memory[0] = 88888888; |
1531 CHECK_EQ(88888888, r.Call(0u)); | 1524 CHECK_EQ(88888888, r.Call(0u)); |
1532 for (uint32_t offset = 29; offset < 40; offset++) { | 1525 for (uint32_t offset = 29; offset < 40; offset++) { |
1533 CHECK_TRAP(r.Call(offset)); | 1526 CHECK_TRAP(r.Call(offset)); |
1534 } | 1527 } |
1535 | 1528 |
1536 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { | 1529 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { |
1537 CHECK_TRAP(r.Call(offset)); | 1530 CHECK_TRAP(r.Call(offset)); |
1538 } | 1531 } |
1539 } | 1532 } |
1540 | 1533 |
1541 | 1534 |
1542 TEST(Run_Wasm_LoadMemI32_oob_asm) { | 1535 TEST(Run_Wasm_LoadMemI32_oob_asm) { |
1543 WasmRunner<int32_t> r(MachineType::Uint32()); | |
1544 TestingModule module; | 1536 TestingModule module; |
1545 module.asm_js = true; | 1537 module.asm_js = true; |
1546 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 1538 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
| 1539 WasmRunner<int32_t> r(&module, MachineType::Uint32()); |
1547 module.RandomizeMemory(1112); | 1540 module.RandomizeMemory(1112); |
1548 r.env()->module = &module; | |
1549 | 1541 |
1550 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); | 1542 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); |
1551 | 1543 |
1552 memory[0] = 999999; | 1544 memory[0] = 999999; |
1553 CHECK_EQ(999999, r.Call(0u)); | 1545 CHECK_EQ(999999, r.Call(0u)); |
1554 // TODO(titzer): offset 29-31 should also be OOB. | 1546 // TODO(titzer): offset 29-31 should also be OOB. |
1555 for (uint32_t offset = 32; offset < 40; offset++) { | 1547 for (uint32_t offset = 32; offset < 40; offset++) { |
1556 CHECK_EQ(0, r.Call(offset)); | 1548 CHECK_EQ(0, r.Call(offset)); |
1557 } | 1549 } |
1558 | 1550 |
1559 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { | 1551 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { |
1560 CHECK_EQ(0, r.Call(offset)); | 1552 CHECK_EQ(0, r.Call(offset)); |
1561 } | 1553 } |
1562 } | 1554 } |
1563 | 1555 |
1564 | 1556 |
1565 TEST(Run_Wasm_LoadMem_offset_oob) { | 1557 TEST(Run_Wasm_LoadMem_offset_oob) { |
1566 TestingModule module; | 1558 TestingModule module; |
1567 module.AddMemoryElems<int32_t>(8); | 1559 module.AddMemoryElems<int32_t>(8); |
1568 | 1560 |
1569 static const MachineType machineTypes[] = { | 1561 static const MachineType machineTypes[] = { |
1570 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), | 1562 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), |
1571 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), | 1563 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), |
1572 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), | 1564 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), |
1573 MachineType::Float64()}; | 1565 MachineType::Float64()}; |
1574 | 1566 |
1575 for (size_t m = 0; m < arraysize(machineTypes); m++) { | 1567 for (size_t m = 0; m < arraysize(machineTypes); m++) { |
1576 module.RandomizeMemory(1116 + static_cast<int>(m)); | 1568 module.RandomizeMemory(1116 + static_cast<int>(m)); |
1577 WasmRunner<int32_t> r(MachineType::Uint32()); | 1569 WasmRunner<int32_t> r(&module, MachineType::Uint32()); |
1578 r.env()->module = &module; | |
1579 uint32_t boundary = 24 - WasmOpcodes::MemSize(machineTypes[m]); | 1570 uint32_t boundary = 24 - WasmOpcodes::MemSize(machineTypes[m]); |
1580 | 1571 |
1581 BUILD(r, WASM_LOAD_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0)), | 1572 BUILD(r, WASM_LOAD_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0)), |
1582 WASM_ZERO); | 1573 WASM_ZERO); |
1583 | 1574 |
1584 CHECK_EQ(0, r.Call(boundary)); // in bounds. | 1575 CHECK_EQ(0, r.Call(boundary)); // in bounds. |
1585 | 1576 |
1586 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { | 1577 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { |
1587 CHECK_TRAP(r.Call(offset)); // out of bounds. | 1578 CHECK_TRAP(r.Call(offset)); // out of bounds. |
1588 } | 1579 } |
1589 } | 1580 } |
1590 } | 1581 } |
1591 | 1582 |
1592 | 1583 |
1593 TEST(Run_Wasm_LoadMemI32_offset) { | 1584 TEST(Run_Wasm_LoadMemI32_offset) { |
1594 WasmRunner<int32_t> r(MachineType::Int32()); | |
1595 TestingModule module; | 1585 TestingModule module; |
1596 int32_t* memory = module.AddMemoryElems<int32_t>(4); | 1586 int32_t* memory = module.AddMemoryElems<int32_t>(4); |
| 1587 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1597 module.RandomizeMemory(1111); | 1588 module.RandomizeMemory(1111); |
1598 r.env()->module = &module; | |
1599 | 1589 |
1600 BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0))); | 1590 BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0))); |
1601 | 1591 |
1602 memory[0] = 66666666; | 1592 memory[0] = 66666666; |
1603 memory[1] = 77777777; | 1593 memory[1] = 77777777; |
1604 memory[2] = 88888888; | 1594 memory[2] = 88888888; |
1605 memory[3] = 99999999; | 1595 memory[3] = 99999999; |
1606 CHECK_EQ(77777777, r.Call(0)); | 1596 CHECK_EQ(77777777, r.Call(0)); |
1607 CHECK_EQ(88888888, r.Call(4)); | 1597 CHECK_EQ(88888888, r.Call(4)); |
1608 CHECK_EQ(99999999, r.Call(8)); | 1598 CHECK_EQ(99999999, r.Call(8)); |
1609 | 1599 |
1610 memory[0] = 11111111; | 1600 memory[0] = 11111111; |
1611 memory[1] = 22222222; | 1601 memory[1] = 22222222; |
1612 memory[2] = 33333333; | 1602 memory[2] = 33333333; |
1613 memory[3] = 44444444; | 1603 memory[3] = 44444444; |
1614 CHECK_EQ(22222222, r.Call(0)); | 1604 CHECK_EQ(22222222, r.Call(0)); |
1615 CHECK_EQ(33333333, r.Call(4)); | 1605 CHECK_EQ(33333333, r.Call(4)); |
1616 CHECK_EQ(44444444, r.Call(8)); | 1606 CHECK_EQ(44444444, r.Call(8)); |
1617 } | 1607 } |
1618 | 1608 |
1619 | 1609 |
1620 #if !V8_TARGET_ARCH_MIPS && !V8_TARGET_ARCH_MIPS64 | 1610 #if !V8_TARGET_ARCH_MIPS && !V8_TARGET_ARCH_MIPS64 |
1621 | 1611 |
1622 TEST(Run_Wasm_LoadMemI32_const_oob_misaligned) { | 1612 TEST(Run_Wasm_LoadMemI32_const_oob_misaligned) { |
| 1613 const int kMemSize = 12; |
1623 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable. | 1614 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable. |
1624 TestingModule module; | |
1625 const int kMemSize = 12; | |
1626 module.AddMemoryElems<byte>(kMemSize); | |
1627 | |
1628 for (int offset = 0; offset < kMemSize + 5; offset++) { | 1615 for (int offset = 0; offset < kMemSize + 5; offset++) { |
1629 for (int index = 0; index < kMemSize + 5; index++) { | 1616 for (int index = 0; index < kMemSize + 5; index++) { |
1630 WasmRunner<int32_t> r; | 1617 TestingModule module; |
1631 r.env()->module = &module; | 1618 module.AddMemoryElems<byte>(kMemSize); |
| 1619 |
| 1620 WasmRunner<int32_t> r(&module); |
1632 module.RandomizeMemory(); | 1621 module.RandomizeMemory(); |
1633 | 1622 |
1634 BUILD(r, | 1623 BUILD(r, |
1635 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); | 1624 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); |
1636 | 1625 |
1637 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { | 1626 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { |
1638 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); | 1627 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); |
1639 } else { | 1628 } else { |
1640 CHECK_TRAP(r.Call()); | 1629 CHECK_TRAP(r.Call()); |
1641 } | 1630 } |
1642 } | 1631 } |
1643 } | 1632 } |
1644 } | 1633 } |
1645 | 1634 |
1646 #endif | 1635 #endif |
1647 | 1636 |
1648 | 1637 |
1649 TEST(Run_Wasm_LoadMemI32_const_oob) { | 1638 TEST(Run_Wasm_LoadMemI32_const_oob) { |
1650 TestingModule module; | |
1651 const int kMemSize = 24; | 1639 const int kMemSize = 24; |
1652 module.AddMemoryElems<byte>(kMemSize); | |
1653 | |
1654 for (int offset = 0; offset < kMemSize + 5; offset += 4) { | 1640 for (int offset = 0; offset < kMemSize + 5; offset += 4) { |
1655 for (int index = 0; index < kMemSize + 5; index += 4) { | 1641 for (int index = 0; index < kMemSize + 5; index += 4) { |
1656 WasmRunner<int32_t> r; | 1642 TestingModule module; |
1657 r.env()->module = &module; | 1643 module.AddMemoryElems<byte>(kMemSize); |
| 1644 |
| 1645 WasmRunner<int32_t> r(&module); |
1658 module.RandomizeMemory(); | 1646 module.RandomizeMemory(); |
1659 | 1647 |
1660 BUILD(r, | 1648 BUILD(r, |
1661 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); | 1649 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); |
1662 | 1650 |
1663 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { | 1651 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { |
1664 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); | 1652 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); |
1665 } else { | 1653 } else { |
1666 CHECK_TRAP(r.Call()); | 1654 CHECK_TRAP(r.Call()); |
1667 } | 1655 } |
1668 } | 1656 } |
1669 } | 1657 } |
1670 } | 1658 } |
1671 | 1659 |
1672 | 1660 |
1673 TEST(Run_Wasm_StoreMemI32_offset) { | 1661 TEST(Run_Wasm_StoreMemI32_offset) { |
1674 WasmRunner<int32_t> r(MachineType::Int32()); | |
1675 const int32_t kWritten = 0xaabbccdd; | |
1676 TestingModule module; | 1662 TestingModule module; |
1677 int32_t* memory = module.AddMemoryElems<int32_t>(4); | 1663 int32_t* memory = module.AddMemoryElems<int32_t>(4); |
1678 r.env()->module = &module; | 1664 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
| 1665 const int32_t kWritten = 0xaabbccdd; |
1679 | 1666 |
1680 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0), | 1667 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0), |
1681 WASM_I32(kWritten))); | 1668 WASM_I32(kWritten))); |
1682 | 1669 |
1683 for (int i = 0; i < 2; i++) { | 1670 for (int i = 0; i < 2; i++) { |
1684 module.RandomizeMemory(1111); | 1671 module.RandomizeMemory(1111); |
1685 memory[0] = 66666666; | 1672 memory[0] = 66666666; |
1686 memory[1] = 77777777; | 1673 memory[1] = 77777777; |
1687 memory[2] = 88888888; | 1674 memory[2] = 88888888; |
1688 memory[3] = 99999999; | 1675 memory[3] = 99999999; |
(...skipping 18 matching lines...) Expand all Loading... |
1707 MachineType::Float64()}; | 1694 MachineType::Float64()}; |
1708 #else | 1695 #else |
1709 static const MachineType machineTypes[] = { | 1696 static const MachineType machineTypes[] = { |
1710 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), | 1697 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), |
1711 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), | 1698 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), |
1712 MachineType::Float32(), MachineType::Float64()}; | 1699 MachineType::Float32(), MachineType::Float64()}; |
1713 #endif | 1700 #endif |
1714 | 1701 |
1715 for (size_t m = 0; m < arraysize(machineTypes); m++) { | 1702 for (size_t m = 0; m < arraysize(machineTypes); m++) { |
1716 module.RandomizeMemory(1119 + static_cast<int>(m)); | 1703 module.RandomizeMemory(1119 + static_cast<int>(m)); |
1717 WasmRunner<int32_t> r(MachineType::Uint32()); | 1704 WasmRunner<int32_t> r(&module, MachineType::Uint32()); |
1718 r.env()->module = &module; | |
1719 | 1705 |
1720 BUILD(r, WASM_STORE_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0), | 1706 BUILD(r, WASM_STORE_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0), |
1721 WASM_LOAD_MEM(machineTypes[m], WASM_ZERO)), | 1707 WASM_LOAD_MEM(machineTypes[m], WASM_ZERO)), |
1722 WASM_ZERO); | 1708 WASM_ZERO); |
1723 | 1709 |
1724 byte memsize = WasmOpcodes::MemSize(machineTypes[m]); | 1710 byte memsize = WasmOpcodes::MemSize(machineTypes[m]); |
1725 uint32_t boundary = 24 - memsize; | 1711 uint32_t boundary = 24 - memsize; |
1726 CHECK_EQ(0, r.Call(boundary)); // in bounds. | 1712 CHECK_EQ(0, r.Call(boundary)); // in bounds. |
1727 CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize)); | 1713 CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize)); |
1728 | 1714 |
1729 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { | 1715 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { |
1730 CHECK_TRAP(r.Call(offset)); // out of bounds. | 1716 CHECK_TRAP(r.Call(offset)); // out of bounds. |
1731 } | 1717 } |
1732 } | 1718 } |
1733 } | 1719 } |
1734 | 1720 |
1735 | 1721 |
1736 #if WASM_64 | 1722 #if WASM_64 |
1737 TEST(Run_Wasm_F64ReinterpretI64) { | 1723 TEST(Run_Wasm_F64ReinterpretI64) { |
1738 WasmRunner<int64_t> r; | |
1739 TestingModule module; | 1724 TestingModule module; |
1740 int64_t* memory = module.AddMemoryElems<int64_t>(8); | 1725 int64_t* memory = module.AddMemoryElems<int64_t>(8); |
1741 r.env()->module = &module; | 1726 WasmRunner<int64_t> r(&module); |
1742 | 1727 |
1743 BUILD(r, WASM_I64_REINTERPRET_F64( | 1728 BUILD(r, WASM_I64_REINTERPRET_F64( |
1744 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO))); | 1729 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO))); |
1745 | 1730 |
1746 FOR_INT32_INPUTS(i) { | 1731 FOR_INT32_INPUTS(i) { |
1747 int64_t expected = static_cast<int64_t>(*i) * 0x300010001; | 1732 int64_t expected = static_cast<int64_t>(*i) * 0x300010001; |
1748 memory[0] = expected; | 1733 memory[0] = expected; |
1749 CHECK_EQ(expected, r.Call()); | 1734 CHECK_EQ(expected, r.Call()); |
1750 } | 1735 } |
1751 } | 1736 } |
1752 | 1737 |
1753 | 1738 |
1754 TEST(Run_Wasm_I64ReinterpretF64) { | 1739 TEST(Run_Wasm_I64ReinterpretF64) { |
1755 WasmRunner<int64_t> r(MachineType::Int64()); | |
1756 TestingModule module; | 1740 TestingModule module; |
1757 int64_t* memory = module.AddMemoryElems<int64_t>(8); | 1741 int64_t* memory = module.AddMemoryElems<int64_t>(8); |
1758 r.env()->module = &module; | 1742 WasmRunner<int64_t> r(&module, MachineType::Int64()); |
1759 | 1743 |
1760 BUILD(r, WASM_BLOCK( | 1744 BUILD(r, WASM_BLOCK( |
1761 2, WASM_STORE_MEM(MachineType::Float64(), WASM_ZERO, | 1745 2, WASM_STORE_MEM(MachineType::Float64(), WASM_ZERO, |
1762 WASM_F64_REINTERPRET_I64(WASM_GET_LOCAL(0))), | 1746 WASM_F64_REINTERPRET_I64(WASM_GET_LOCAL(0))), |
1763 WASM_GET_LOCAL(0))); | 1747 WASM_GET_LOCAL(0))); |
1764 | 1748 |
1765 FOR_INT32_INPUTS(i) { | 1749 FOR_INT32_INPUTS(i) { |
1766 int64_t expected = static_cast<int64_t>(*i) * 0x300010001; | 1750 int64_t expected = static_cast<int64_t>(*i) * 0x300010001; |
1767 CHECK_EQ(expected, r.Call(expected)); | 1751 CHECK_EQ(expected, r.Call(expected)); |
1768 CHECK_EQ(expected, memory[0]); | 1752 CHECK_EQ(expected, memory[0]); |
1769 } | 1753 } |
1770 } | 1754 } |
1771 | 1755 |
1772 | 1756 |
1773 TEST(Run_Wasm_LoadMemI64) { | 1757 TEST(Run_Wasm_LoadMemI64) { |
1774 WasmRunner<int64_t> r; | |
1775 TestingModule module; | 1758 TestingModule module; |
1776 int64_t* memory = module.AddMemoryElems<int64_t>(8); | 1759 int64_t* memory = module.AddMemoryElems<int64_t>(8); |
1777 module.RandomizeMemory(1111); | 1760 module.RandomizeMemory(1111); |
1778 r.env()->module = &module; | 1761 WasmRunner<int64_t> r(&module); |
1779 | 1762 |
1780 BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_I8(0))); | 1763 BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_I8(0))); |
1781 | 1764 |
1782 memory[0] = 0xaabbccdd00112233LL; | 1765 memory[0] = 0xaabbccdd00112233LL; |
1783 CHECK_EQ(0xaabbccdd00112233LL, r.Call()); | 1766 CHECK_EQ(0xaabbccdd00112233LL, r.Call()); |
1784 | 1767 |
1785 memory[0] = 0x33aabbccdd001122LL; | 1768 memory[0] = 0x33aabbccdd001122LL; |
1786 CHECK_EQ(0x33aabbccdd001122LL, r.Call()); | 1769 CHECK_EQ(0x33aabbccdd001122LL, r.Call()); |
1787 | 1770 |
1788 memory[0] = 77777777; | 1771 memory[0] = 77777777; |
1789 CHECK_EQ(77777777, r.Call()); | 1772 CHECK_EQ(77777777, r.Call()); |
1790 } | 1773 } |
1791 #endif | 1774 #endif |
1792 | 1775 |
1793 | 1776 |
1794 TEST(Run_Wasm_LoadMemI32_P) { | 1777 TEST(Run_Wasm_LoadMemI32_P) { |
1795 const int kNumElems = 8; | 1778 const int kNumElems = 8; |
1796 WasmRunner<int32_t> r(MachineType::Int32()); | |
1797 TestingModule module; | 1779 TestingModule module; |
1798 int32_t* memory = module.AddMemoryElems<int32_t>(kNumElems); | 1780 int32_t* memory = module.AddMemoryElems<int32_t>(kNumElems); |
| 1781 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1799 module.RandomizeMemory(2222); | 1782 module.RandomizeMemory(2222); |
1800 r.env()->module = &module; | |
1801 | 1783 |
1802 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); | 1784 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); |
1803 | 1785 |
1804 for (int i = 0; i < kNumElems; i++) { | 1786 for (int i = 0; i < kNumElems; i++) { |
1805 CHECK_EQ(memory[i], r.Call(i * 4)); | 1787 CHECK_EQ(memory[i], r.Call(i * 4)); |
1806 } | 1788 } |
1807 } | 1789 } |
1808 | 1790 |
1809 | 1791 |
1810 TEST(Run_Wasm_MemI32_Sum) { | 1792 TEST(Run_Wasm_MemI32_Sum) { |
1811 WasmRunner<uint32_t> r(MachineType::Int32()); | |
1812 const int kNumElems = 20; | 1793 const int kNumElems = 20; |
1813 const byte kSum = r.AllocateLocal(kAstI32); | |
1814 TestingModule module; | 1794 TestingModule module; |
1815 uint32_t* memory = module.AddMemoryElems<uint32_t>(kNumElems); | 1795 uint32_t* memory = module.AddMemoryElems<uint32_t>(kNumElems); |
1816 r.env()->module = &module; | 1796 WasmRunner<uint32_t> r(&module, MachineType::Int32()); |
| 1797 const byte kSum = r.AllocateLocal(kAstI32); |
1817 | 1798 |
1818 BUILD(r, WASM_BLOCK( | 1799 BUILD(r, WASM_BLOCK( |
1819 2, WASM_WHILE( | 1800 2, WASM_WHILE( |
1820 WASM_GET_LOCAL(0), | 1801 WASM_GET_LOCAL(0), |
1821 WASM_BLOCK( | 1802 WASM_BLOCK( |
1822 2, WASM_SET_LOCAL( | 1803 2, WASM_SET_LOCAL( |
1823 kSum, WASM_I32_ADD( | 1804 kSum, WASM_I32_ADD( |
1824 WASM_GET_LOCAL(kSum), | 1805 WASM_GET_LOCAL(kSum), |
1825 WASM_LOAD_MEM(MachineType::Int32(), | 1806 WASM_LOAD_MEM(MachineType::Int32(), |
1826 WASM_GET_LOCAL(0)))), | 1807 WASM_GET_LOCAL(0)))), |
1827 WASM_SET_LOCAL( | 1808 WASM_SET_LOCAL( |
1828 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), | 1809 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), |
1829 WASM_GET_LOCAL(1))); | 1810 WASM_GET_LOCAL(1))); |
1830 | 1811 |
1831 // Run 4 trials. | 1812 // Run 4 trials. |
1832 for (int i = 0; i < 3; i++) { | 1813 for (int i = 0; i < 3; i++) { |
1833 module.RandomizeMemory(i * 33); | 1814 module.RandomizeMemory(i * 33); |
1834 uint32_t expected = 0; | 1815 uint32_t expected = 0; |
1835 for (size_t j = kNumElems - 1; j > 0; j--) { | 1816 for (size_t j = kNumElems - 1; j > 0; j--) { |
1836 expected += memory[j]; | 1817 expected += memory[j]; |
1837 } | 1818 } |
1838 uint32_t result = r.Call(static_cast<int>(4 * (kNumElems - 1))); | 1819 uint32_t result = r.Call(static_cast<int>(4 * (kNumElems - 1))); |
1839 CHECK_EQ(expected, result); | 1820 CHECK_EQ(expected, result); |
1840 } | 1821 } |
1841 } | 1822 } |
1842 | 1823 |
1843 | 1824 |
1844 TEST(Run_Wasm_CheckMachIntsZero) { | 1825 TEST(Run_Wasm_CheckMachIntsZero) { |
1845 WasmRunner<uint32_t> r(MachineType::Int32()); | |
1846 const int kNumElems = 55; | 1826 const int kNumElems = 55; |
1847 TestingModule module; | 1827 TestingModule module; |
1848 module.AddMemoryElems<uint32_t>(kNumElems); | 1828 module.AddMemoryElems<uint32_t>(kNumElems); |
1849 r.env()->module = &module; | 1829 WasmRunner<uint32_t> r(&module, MachineType::Int32()); |
1850 | 1830 |
1851 BUILD(r, kExprBlock, 2, kExprLoop, 1, kExprIf, kExprGetLocal, 0, kExprBr, 0, | 1831 BUILD(r, kExprBlock, 2, kExprLoop, 1, kExprIf, kExprGetLocal, 0, kExprBr, 0, |
1852 kExprIfElse, kExprI32LoadMem, 0, kExprGetLocal, 0, kExprBr, 2, | 1832 kExprIfElse, kExprI32LoadMem, 0, kExprGetLocal, 0, kExprBr, 2, |
1853 kExprI8Const, 255, kExprSetLocal, 0, kExprI32Sub, kExprGetLocal, 0, | 1833 kExprI8Const, 255, kExprSetLocal, 0, kExprI32Sub, kExprGetLocal, 0, |
1854 kExprI8Const, 4, kExprI8Const, 0); | 1834 kExprI8Const, 4, kExprI8Const, 0); |
1855 | 1835 |
1856 module.BlankMemory(); | 1836 module.BlankMemory(); |
1857 CHECK_EQ(0, r.Call((kNumElems - 1) * 4)); | 1837 CHECK_EQ(0, r.Call((kNumElems - 1) * 4)); |
1858 } | 1838 } |
1859 | 1839 |
1860 | 1840 |
1861 TEST(Run_Wasm_MemF32_Sum) { | 1841 TEST(Run_Wasm_MemF32_Sum) { |
1862 WasmRunner<int32_t> r(MachineType::Int32()); | |
1863 const byte kSum = r.AllocateLocal(kAstF32); | |
1864 const int kSize = 5; | 1842 const int kSize = 5; |
1865 TestingModule module; | 1843 TestingModule module; |
1866 module.AddMemoryElems<float>(kSize); | 1844 module.AddMemoryElems<float>(kSize); |
1867 float* buffer = module.raw_mem_start<float>(); | 1845 float* buffer = module.raw_mem_start<float>(); |
1868 buffer[0] = -99.25; | 1846 buffer[0] = -99.25; |
1869 buffer[1] = -888.25; | 1847 buffer[1] = -888.25; |
1870 buffer[2] = -77.25; | 1848 buffer[2] = -77.25; |
1871 buffer[3] = 66666.25; | 1849 buffer[3] = 66666.25; |
1872 buffer[4] = 5555.25; | 1850 buffer[4] = 5555.25; |
1873 r.env()->module = &module; | 1851 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
| 1852 const byte kSum = r.AllocateLocal(kAstF32); |
1874 | 1853 |
1875 BUILD(r, WASM_BLOCK( | 1854 BUILD(r, WASM_BLOCK( |
1876 3, WASM_WHILE( | 1855 3, WASM_WHILE( |
1877 WASM_GET_LOCAL(0), | 1856 WASM_GET_LOCAL(0), |
1878 WASM_BLOCK( | 1857 WASM_BLOCK( |
1879 2, WASM_SET_LOCAL( | 1858 2, WASM_SET_LOCAL( |
1880 kSum, WASM_F32_ADD( | 1859 kSum, WASM_F32_ADD( |
1881 WASM_GET_LOCAL(kSum), | 1860 WASM_GET_LOCAL(kSum), |
1882 WASM_LOAD_MEM(MachineType::Float32(), | 1861 WASM_LOAD_MEM(MachineType::Float32(), |
1883 WASM_GET_LOCAL(0)))), | 1862 WASM_GET_LOCAL(0)))), |
1884 WASM_SET_LOCAL( | 1863 WASM_SET_LOCAL( |
1885 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), | 1864 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), |
1886 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, | 1865 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, |
1887 WASM_GET_LOCAL(kSum)), | 1866 WASM_GET_LOCAL(kSum)), |
1888 WASM_GET_LOCAL(0))); | 1867 WASM_GET_LOCAL(0))); |
1889 | 1868 |
1890 CHECK_EQ(0, r.Call(4 * (kSize - 1))); | 1869 CHECK_EQ(0, r.Call(4 * (kSize - 1))); |
1891 CHECK_NE(-99.25, buffer[0]); | 1870 CHECK_NE(-99.25, buffer[0]); |
1892 CHECK_EQ(71256.0f, buffer[0]); | 1871 CHECK_EQ(71256.0f, buffer[0]); |
1893 } | 1872 } |
1894 | 1873 |
1895 | 1874 |
1896 #if WASM_64 | 1875 #if WASM_64 |
1897 TEST(Run_Wasm_MemI64_Sum) { | 1876 TEST(Run_Wasm_MemI64_Sum) { |
1898 WasmRunner<uint64_t> r(MachineType::Int32()); | |
1899 const int kNumElems = 20; | 1877 const int kNumElems = 20; |
1900 const byte kSum = r.AllocateLocal(kAstI64); | |
1901 TestingModule module; | 1878 TestingModule module; |
1902 uint64_t* memory = module.AddMemoryElems<uint64_t>(kNumElems); | 1879 uint64_t* memory = module.AddMemoryElems<uint64_t>(kNumElems); |
1903 r.env()->module = &module; | 1880 WasmRunner<uint64_t> r(&module, MachineType::Int32()); |
| 1881 const byte kSum = r.AllocateLocal(kAstI64); |
1904 | 1882 |
1905 BUILD(r, WASM_BLOCK( | 1883 BUILD(r, WASM_BLOCK( |
1906 2, WASM_WHILE( | 1884 2, WASM_WHILE( |
1907 WASM_GET_LOCAL(0), | 1885 WASM_GET_LOCAL(0), |
1908 WASM_BLOCK( | 1886 WASM_BLOCK( |
1909 2, WASM_SET_LOCAL( | 1887 2, WASM_SET_LOCAL( |
1910 kSum, WASM_I64_ADD( | 1888 kSum, WASM_I64_ADD( |
1911 WASM_GET_LOCAL(kSum), | 1889 WASM_GET_LOCAL(kSum), |
1912 WASM_LOAD_MEM(MachineType::Int64(), | 1890 WASM_LOAD_MEM(MachineType::Int64(), |
1913 WASM_GET_LOCAL(0)))), | 1891 WASM_GET_LOCAL(0)))), |
(...skipping 11 matching lines...) Expand all Loading... |
1925 uint64_t result = r.Call(8 * (kNumElems - 1)); | 1903 uint64_t result = r.Call(8 * (kNumElems - 1)); |
1926 CHECK_EQ(expected, result); | 1904 CHECK_EQ(expected, result); |
1927 } | 1905 } |
1928 } | 1906 } |
1929 #endif | 1907 #endif |
1930 | 1908 |
1931 | 1909 |
1932 template <typename T> | 1910 template <typename T> |
1933 T GenerateAndRunFold(WasmOpcode binop, T* buffer, size_t size, | 1911 T GenerateAndRunFold(WasmOpcode binop, T* buffer, size_t size, |
1934 LocalType astType, MachineType memType) { | 1912 LocalType astType, MachineType memType) { |
1935 WasmRunner<int32_t> r(MachineType::Int32()); | |
1936 const byte kAccum = r.AllocateLocal(astType); | |
1937 TestingModule module; | 1913 TestingModule module; |
1938 module.AddMemoryElems<T>(size); | 1914 module.AddMemoryElems<T>(size); |
1939 for (size_t i = 0; i < size; i++) { | 1915 for (size_t i = 0; i < size; i++) { |
1940 module.raw_mem_start<T>()[i] = buffer[i]; | 1916 module.raw_mem_start<T>()[i] = buffer[i]; |
1941 } | 1917 } |
1942 r.env()->module = &module; | 1918 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
| 1919 const byte kAccum = r.AllocateLocal(astType); |
1943 | 1920 |
1944 BUILD( | 1921 BUILD( |
1945 r, | 1922 r, |
1946 WASM_BLOCK( | 1923 WASM_BLOCK( |
1947 4, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)), | 1924 4, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)), |
1948 WASM_WHILE( | 1925 WASM_WHILE( |
1949 WASM_GET_LOCAL(0), | 1926 WASM_GET_LOCAL(0), |
1950 WASM_BLOCK( | 1927 WASM_BLOCK( |
1951 2, WASM_SET_LOCAL( | 1928 2, WASM_SET_LOCAL( |
1952 kAccum, | 1929 kAccum, |
(...skipping 18 matching lines...) Expand all Loading... |
1971 | 1948 |
1972 | 1949 |
1973 TEST(Build_Wasm_Infinite_Loop) { | 1950 TEST(Build_Wasm_Infinite_Loop) { |
1974 WasmRunner<int32_t> r(MachineType::Int32()); | 1951 WasmRunner<int32_t> r(MachineType::Int32()); |
1975 // Only build the graph and compile, don't run. | 1952 // Only build the graph and compile, don't run. |
1976 BUILD(r, WASM_INFINITE_LOOP); | 1953 BUILD(r, WASM_INFINITE_LOOP); |
1977 } | 1954 } |
1978 | 1955 |
1979 | 1956 |
1980 TEST(Build_Wasm_Infinite_Loop_effect) { | 1957 TEST(Build_Wasm_Infinite_Loop_effect) { |
1981 WasmRunner<int32_t> r(MachineType::Int32()); | |
1982 TestingModule module; | 1958 TestingModule module; |
1983 module.AddMemoryElems<int8_t>(16); | 1959 module.AddMemoryElems<int8_t>(16); |
1984 r.env()->module = &module; | 1960 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1985 | 1961 |
1986 // Only build the graph and compile, don't run. | 1962 // Only build the graph and compile, don't run. |
1987 BUILD(r, WASM_LOOP(1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO))); | 1963 BUILD(r, WASM_LOOP(1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO))); |
1988 } | 1964 } |
1989 | 1965 |
1990 | 1966 |
1991 TEST(Run_Wasm_Unreachable0a) { | 1967 TEST(Run_Wasm_Unreachable0a) { |
1992 WasmRunner<int32_t> r(MachineType::Int32()); | 1968 WasmRunner<int32_t> r(MachineType::Int32()); |
1993 BUILD(r, | 1969 BUILD(r, |
1994 WASM_BLOCK(2, WASM_BRV(0, WASM_I8(9)), WASM_RETURN(WASM_GET_LOCAL(0)))); | 1970 WASM_BLOCK(2, WASM_BRV(0, WASM_I8(9)), WASM_RETURN(WASM_GET_LOCAL(0)))); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2111 #undef GRAPH_BUILD_TEST | 2087 #undef GRAPH_BUILD_TEST |
2112 } | 2088 } |
2113 | 2089 |
2114 | 2090 |
2115 TEST(Run_Wasm_Int32LoadInt8_signext) { | 2091 TEST(Run_Wasm_Int32LoadInt8_signext) { |
2116 TestingModule module; | 2092 TestingModule module; |
2117 const int kNumElems = 16; | 2093 const int kNumElems = 16; |
2118 int8_t* memory = module.AddMemoryElems<int8_t>(kNumElems); | 2094 int8_t* memory = module.AddMemoryElems<int8_t>(kNumElems); |
2119 module.RandomizeMemory(); | 2095 module.RandomizeMemory(); |
2120 memory[0] = -1; | 2096 memory[0] = -1; |
2121 WasmRunner<int32_t> r(MachineType::Int32()); | 2097 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2122 r.env()->module = &module; | |
2123 BUILD(r, WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0))); | 2098 BUILD(r, WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0))); |
2124 | 2099 |
2125 for (size_t i = 0; i < kNumElems; i++) { | 2100 for (size_t i = 0; i < kNumElems; i++) { |
2126 CHECK_EQ(memory[i], r.Call(static_cast<int>(i))); | 2101 CHECK_EQ(memory[i], r.Call(static_cast<int>(i))); |
2127 } | 2102 } |
2128 } | 2103 } |
2129 | 2104 |
2130 | 2105 |
2131 TEST(Run_Wasm_Int32LoadInt8_zeroext) { | 2106 TEST(Run_Wasm_Int32LoadInt8_zeroext) { |
2132 TestingModule module; | 2107 TestingModule module; |
2133 const int kNumElems = 16; | 2108 const int kNumElems = 16; |
2134 byte* memory = module.AddMemory(kNumElems); | 2109 byte* memory = module.AddMemory(kNumElems); |
2135 module.RandomizeMemory(77); | 2110 module.RandomizeMemory(77); |
2136 memory[0] = 255; | 2111 memory[0] = 255; |
2137 WasmRunner<int32_t> r(MachineType::Int32()); | 2112 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2138 r.env()->module = &module; | |
2139 BUILD(r, WASM_LOAD_MEM(MachineType::Uint8(), WASM_GET_LOCAL(0))); | 2113 BUILD(r, WASM_LOAD_MEM(MachineType::Uint8(), WASM_GET_LOCAL(0))); |
2140 | 2114 |
2141 for (size_t i = 0; i < kNumElems; i++) { | 2115 for (size_t i = 0; i < kNumElems; i++) { |
2142 CHECK_EQ(memory[i], r.Call(static_cast<int>(i))); | 2116 CHECK_EQ(memory[i], r.Call(static_cast<int>(i))); |
2143 } | 2117 } |
2144 } | 2118 } |
2145 | 2119 |
2146 | 2120 |
2147 TEST(Run_Wasm_Int32LoadInt16_signext) { | 2121 TEST(Run_Wasm_Int32LoadInt16_signext) { |
2148 TestingModule module; | 2122 TestingModule module; |
2149 const int kNumBytes = 16; | 2123 const int kNumBytes = 16; |
2150 byte* memory = module.AddMemory(kNumBytes); | 2124 byte* memory = module.AddMemory(kNumBytes); |
2151 module.RandomizeMemory(888); | 2125 module.RandomizeMemory(888); |
2152 memory[1] = 200; | 2126 memory[1] = 200; |
2153 WasmRunner<int32_t> r(MachineType::Int32()); | 2127 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2154 r.env()->module = &module; | |
2155 BUILD(r, WASM_LOAD_MEM(MachineType::Int16(), WASM_GET_LOCAL(0))); | 2128 BUILD(r, WASM_LOAD_MEM(MachineType::Int16(), WASM_GET_LOCAL(0))); |
2156 | 2129 |
2157 for (size_t i = 0; i < kNumBytes; i += 2) { | 2130 for (size_t i = 0; i < kNumBytes; i += 2) { |
2158 int32_t expected = memory[i] | (static_cast<int8_t>(memory[i + 1]) << 8); | 2131 int32_t expected = memory[i] | (static_cast<int8_t>(memory[i + 1]) << 8); |
2159 CHECK_EQ(expected, r.Call(static_cast<int>(i))); | 2132 CHECK_EQ(expected, r.Call(static_cast<int>(i))); |
2160 } | 2133 } |
2161 } | 2134 } |
2162 | 2135 |
2163 | 2136 |
2164 TEST(Run_Wasm_Int32LoadInt16_zeroext) { | 2137 TEST(Run_Wasm_Int32LoadInt16_zeroext) { |
2165 TestingModule module; | 2138 TestingModule module; |
2166 const int kNumBytes = 16; | 2139 const int kNumBytes = 16; |
2167 byte* memory = module.AddMemory(kNumBytes); | 2140 byte* memory = module.AddMemory(kNumBytes); |
2168 module.RandomizeMemory(9999); | 2141 module.RandomizeMemory(9999); |
2169 memory[1] = 204; | 2142 memory[1] = 204; |
2170 WasmRunner<int32_t> r(MachineType::Int32()); | 2143 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2171 r.env()->module = &module; | |
2172 BUILD(r, WASM_LOAD_MEM(MachineType::Uint16(), WASM_GET_LOCAL(0))); | 2144 BUILD(r, WASM_LOAD_MEM(MachineType::Uint16(), WASM_GET_LOCAL(0))); |
2173 | 2145 |
2174 for (size_t i = 0; i < kNumBytes; i += 2) { | 2146 for (size_t i = 0; i < kNumBytes; i += 2) { |
2175 int32_t expected = memory[i] | (memory[i + 1] << 8); | 2147 int32_t expected = memory[i] | (memory[i + 1] << 8); |
2176 CHECK_EQ(expected, r.Call(static_cast<int>(i))); | 2148 CHECK_EQ(expected, r.Call(static_cast<int>(i))); |
2177 } | 2149 } |
2178 } | 2150 } |
2179 | 2151 |
2180 | 2152 |
2181 TEST(Run_WasmInt32Global) { | 2153 TEST(Run_WasmInt32Global) { |
2182 TestingModule module; | 2154 TestingModule module; |
2183 int32_t* global = module.AddGlobal<int32_t>(MachineType::Int32()); | 2155 int32_t* global = module.AddGlobal<int32_t>(MachineType::Int32()); |
2184 WasmRunner<int32_t> r(MachineType::Int32()); | 2156 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2185 r.env()->module = &module; | |
2186 // global = global + p0 | 2157 // global = global + p0 |
2187 BUILD(r, WASM_STORE_GLOBAL( | 2158 BUILD(r, WASM_STORE_GLOBAL( |
2188 0, WASM_I32_ADD(WASM_LOAD_GLOBAL(0), WASM_GET_LOCAL(0)))); | 2159 0, WASM_I32_ADD(WASM_LOAD_GLOBAL(0), WASM_GET_LOCAL(0)))); |
2189 | 2160 |
2190 *global = 116; | 2161 *global = 116; |
2191 for (int i = 9; i < 444444; i += 111111) { | 2162 for (int i = 9; i < 444444; i += 111111) { |
2192 int32_t expected = *global + i; | 2163 int32_t expected = *global + i; |
2193 r.Call(i); | 2164 r.Call(i); |
2194 CHECK_EQ(expected, *global); | 2165 CHECK_EQ(expected, *global); |
2195 } | 2166 } |
2196 } | 2167 } |
2197 | 2168 |
2198 | 2169 |
2199 TEST(Run_WasmInt32Globals_DontAlias) { | 2170 TEST(Run_WasmInt32Globals_DontAlias) { |
2200 const int kNumGlobals = 3; | 2171 const int kNumGlobals = 3; |
2201 TestingModule module; | 2172 TestingModule module; |
2202 int32_t* globals[] = {module.AddGlobal<int32_t>(MachineType::Int32()), | 2173 int32_t* globals[] = {module.AddGlobal<int32_t>(MachineType::Int32()), |
2203 module.AddGlobal<int32_t>(MachineType::Int32()), | 2174 module.AddGlobal<int32_t>(MachineType::Int32()), |
2204 module.AddGlobal<int32_t>(MachineType::Int32())}; | 2175 module.AddGlobal<int32_t>(MachineType::Int32())}; |
2205 | 2176 |
2206 for (int g = 0; g < kNumGlobals; g++) { | 2177 for (int g = 0; g < kNumGlobals; g++) { |
2207 // global = global + p0 | 2178 // global = global + p0 |
2208 WasmRunner<int32_t> r(MachineType::Int32()); | 2179 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2209 r.env()->module = &module; | |
2210 BUILD(r, WASM_STORE_GLOBAL( | 2180 BUILD(r, WASM_STORE_GLOBAL( |
2211 g, WASM_I32_ADD(WASM_LOAD_GLOBAL(g), WASM_GET_LOCAL(0)))); | 2181 g, WASM_I32_ADD(WASM_LOAD_GLOBAL(g), WASM_GET_LOCAL(0)))); |
2212 | 2182 |
2213 // Check that reading/writing global number {g} doesn't alter the others. | 2183 // Check that reading/writing global number {g} doesn't alter the others. |
2214 *globals[g] = 116 * g; | 2184 *globals[g] = 116 * g; |
2215 int32_t before[kNumGlobals]; | 2185 int32_t before[kNumGlobals]; |
2216 for (int i = 9; i < 444444; i += 111113) { | 2186 for (int i = 9; i < 444444; i += 111113) { |
2217 int32_t sum = *globals[g] + i; | 2187 int32_t sum = *globals[g] + i; |
2218 for (int j = 0; j < kNumGlobals; j++) before[j] = *globals[j]; | 2188 for (int j = 0; j < kNumGlobals; j++) before[j] = *globals[j]; |
2219 r.Call(i); | 2189 r.Call(i); |
2220 for (int j = 0; j < kNumGlobals; j++) { | 2190 for (int j = 0; j < kNumGlobals; j++) { |
2221 int32_t expected = j == g ? sum : before[j]; | 2191 int32_t expected = j == g ? sum : before[j]; |
2222 CHECK_EQ(expected, *globals[j]); | 2192 CHECK_EQ(expected, *globals[j]); |
2223 } | 2193 } |
2224 } | 2194 } |
2225 } | 2195 } |
2226 } | 2196 } |
2227 | 2197 |
2228 | 2198 |
2229 #if WASM_64 | 2199 #if WASM_64 |
2230 TEST(Run_WasmInt64Global) { | 2200 TEST(Run_WasmInt64Global) { |
2231 TestingModule module; | 2201 TestingModule module; |
2232 int64_t* global = module.AddGlobal<int64_t>(MachineType::Int64()); | 2202 int64_t* global = module.AddGlobal<int64_t>(MachineType::Int64()); |
2233 WasmRunner<int32_t> r(MachineType::Int32()); | 2203 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2234 r.env()->module = &module; | |
2235 // global = global + p0 | 2204 // global = global + p0 |
2236 BUILD(r, WASM_BLOCK(2, WASM_STORE_GLOBAL( | 2205 BUILD(r, WASM_BLOCK(2, WASM_STORE_GLOBAL( |
2237 0, WASM_I64_ADD( | 2206 0, WASM_I64_ADD( |
2238 WASM_LOAD_GLOBAL(0), | 2207 WASM_LOAD_GLOBAL(0), |
2239 WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)))), | 2208 WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)))), |
2240 WASM_ZERO)); | 2209 WASM_ZERO)); |
2241 | 2210 |
2242 *global = 0xFFFFFFFFFFFFFFFFLL; | 2211 *global = 0xFFFFFFFFFFFFFFFFLL; |
2243 for (int i = 9; i < 444444; i += 111111) { | 2212 for (int i = 9; i < 444444; i += 111111) { |
2244 int64_t expected = *global + i; | 2213 int64_t expected = *global + i; |
2245 r.Call(i); | 2214 r.Call(i); |
2246 CHECK_EQ(expected, *global); | 2215 CHECK_EQ(expected, *global); |
2247 } | 2216 } |
2248 } | 2217 } |
2249 #endif | 2218 #endif |
2250 | 2219 |
2251 | 2220 |
2252 TEST(Run_WasmFloat32Global) { | 2221 TEST(Run_WasmFloat32Global) { |
2253 TestingModule module; | 2222 TestingModule module; |
2254 float* global = module.AddGlobal<float>(MachineType::Float32()); | 2223 float* global = module.AddGlobal<float>(MachineType::Float32()); |
2255 WasmRunner<int32_t> r(MachineType::Int32()); | 2224 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2256 r.env()->module = &module; | |
2257 // global = global + p0 | 2225 // global = global + p0 |
2258 BUILD(r, WASM_BLOCK(2, WASM_STORE_GLOBAL( | 2226 BUILD(r, WASM_BLOCK(2, WASM_STORE_GLOBAL( |
2259 0, WASM_F32_ADD( | 2227 0, WASM_F32_ADD( |
2260 WASM_LOAD_GLOBAL(0), | 2228 WASM_LOAD_GLOBAL(0), |
2261 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))), | 2229 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))), |
2262 WASM_ZERO)); | 2230 WASM_ZERO)); |
2263 | 2231 |
2264 *global = 1.25; | 2232 *global = 1.25; |
2265 for (int i = 9; i < 4444; i += 1111) { | 2233 for (int i = 9; i < 4444; i += 1111) { |
2266 volatile float expected = *global + i; | 2234 volatile float expected = *global + i; |
2267 r.Call(i); | 2235 r.Call(i); |
2268 CHECK_EQ(expected, *global); | 2236 CHECK_EQ(expected, *global); |
2269 } | 2237 } |
2270 } | 2238 } |
2271 | 2239 |
2272 | 2240 |
2273 TEST(Run_WasmFloat64Global) { | 2241 TEST(Run_WasmFloat64Global) { |
2274 TestingModule module; | 2242 TestingModule module; |
2275 double* global = module.AddGlobal<double>(MachineType::Float64()); | 2243 double* global = module.AddGlobal<double>(MachineType::Float64()); |
2276 WasmRunner<int32_t> r(MachineType::Int32()); | 2244 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2277 r.env()->module = &module; | |
2278 // global = global + p0 | 2245 // global = global + p0 |
2279 BUILD(r, WASM_BLOCK(2, WASM_STORE_GLOBAL( | 2246 BUILD(r, WASM_BLOCK(2, WASM_STORE_GLOBAL( |
2280 0, WASM_F64_ADD( | 2247 0, WASM_F64_ADD( |
2281 WASM_LOAD_GLOBAL(0), | 2248 WASM_LOAD_GLOBAL(0), |
2282 WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))), | 2249 WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))), |
2283 WASM_ZERO)); | 2250 WASM_ZERO)); |
2284 | 2251 |
2285 *global = 1.25; | 2252 *global = 1.25; |
2286 for (int i = 9; i < 4444; i += 1111) { | 2253 for (int i = 9; i < 4444; i += 1111) { |
2287 volatile double expected = *global + i; | 2254 volatile double expected = *global + i; |
(...skipping 10 matching lines...) Expand all Loading... |
2298 | 2265 |
2299 int8_t* var_int8 = module.AddGlobal<int8_t>(MachineType::Int8()); | 2266 int8_t* var_int8 = module.AddGlobal<int8_t>(MachineType::Int8()); |
2300 uint8_t* var_uint8 = module.AddGlobal<uint8_t>(MachineType::Uint8()); | 2267 uint8_t* var_uint8 = module.AddGlobal<uint8_t>(MachineType::Uint8()); |
2301 int16_t* var_int16 = module.AddGlobal<int16_t>(MachineType::Int16()); | 2268 int16_t* var_int16 = module.AddGlobal<int16_t>(MachineType::Int16()); |
2302 uint16_t* var_uint16 = module.AddGlobal<uint16_t>(MachineType::Uint16()); | 2269 uint16_t* var_uint16 = module.AddGlobal<uint16_t>(MachineType::Uint16()); |
2303 int32_t* var_int32 = module.AddGlobal<int32_t>(MachineType::Int32()); | 2270 int32_t* var_int32 = module.AddGlobal<int32_t>(MachineType::Int32()); |
2304 uint32_t* var_uint32 = module.AddGlobal<uint32_t>(MachineType::Uint32()); | 2271 uint32_t* var_uint32 = module.AddGlobal<uint32_t>(MachineType::Uint32()); |
2305 float* var_float = module.AddGlobal<float>(MachineType::Float32()); | 2272 float* var_float = module.AddGlobal<float>(MachineType::Float32()); |
2306 double* var_double = module.AddGlobal<double>(MachineType::Float64()); | 2273 double* var_double = module.AddGlobal<double>(MachineType::Float64()); |
2307 | 2274 |
2308 WasmRunner<int32_t> r(MachineType::Int32()); | 2275 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2309 r.env()->module = &module; | |
2310 | 2276 |
2311 BUILD( | 2277 BUILD( |
2312 r, | 2278 r, |
2313 WASM_BLOCK( | 2279 WASM_BLOCK( |
2314 9, | 2280 9, |
2315 WASM_STORE_GLOBAL(1, WASM_LOAD_MEM(MachineType::Int8(), WASM_ZERO)), | 2281 WASM_STORE_GLOBAL(1, WASM_LOAD_MEM(MachineType::Int8(), WASM_ZERO)), |
2316 WASM_STORE_GLOBAL(2, WASM_LOAD_MEM(MachineType::Uint8(), WASM_ZERO)), | 2282 WASM_STORE_GLOBAL(2, WASM_LOAD_MEM(MachineType::Uint8(), WASM_ZERO)), |
2317 WASM_STORE_GLOBAL(3, WASM_LOAD_MEM(MachineType::Int16(), WASM_ZERO)), | 2283 WASM_STORE_GLOBAL(3, WASM_LOAD_MEM(MachineType::Int16(), WASM_ZERO)), |
2318 WASM_STORE_GLOBAL(4, WASM_LOAD_MEM(MachineType::Uint16(), WASM_ZERO)), | 2284 WASM_STORE_GLOBAL(4, WASM_LOAD_MEM(MachineType::Uint16(), WASM_ZERO)), |
2319 WASM_STORE_GLOBAL(5, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), | 2285 WASM_STORE_GLOBAL(5, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2401 } | 2367 } |
2402 } | 2368 } |
2403 #endif | 2369 #endif |
2404 | 2370 |
2405 | 2371 |
2406 TEST(Run_WasmCallEmpty) { | 2372 TEST(Run_WasmCallEmpty) { |
2407 const int32_t kExpected = -414444; | 2373 const int32_t kExpected = -414444; |
2408 // Build the target function. | 2374 // Build the target function. |
2409 TestSignatures sigs; | 2375 TestSignatures sigs; |
2410 TestingModule module; | 2376 TestingModule module; |
2411 WasmFunctionCompiler t(sigs.i_v()); | 2377 WasmFunctionCompiler t(sigs.i_v(), &module); |
2412 BUILD(t, WASM_I32(kExpected)); | 2378 BUILD(t, WASM_I32(kExpected)); |
2413 uint32_t index = t.CompileAndAdd(&module); | 2379 uint32_t index = t.CompileAndAdd(); |
2414 | 2380 |
2415 // Build the calling function. | 2381 // Build the calling function. |
2416 WasmRunner<int32_t> r; | 2382 WasmRunner<int32_t> r(&module); |
2417 r.env()->module = &module; | |
2418 BUILD(r, WASM_CALL_FUNCTION0(index)); | 2383 BUILD(r, WASM_CALL_FUNCTION0(index)); |
2419 | 2384 |
2420 int32_t result = r.Call(); | 2385 int32_t result = r.Call(); |
2421 CHECK_EQ(kExpected, result); | 2386 CHECK_EQ(kExpected, result); |
2422 } | 2387 } |
2423 | 2388 |
2424 | 2389 |
2425 TEST(Run_WasmCallF32StackParameter) { | 2390 TEST(Run_WasmCallF32StackParameter) { |
2426 // Build the target function. | 2391 // Build the target function. |
2427 LocalType param_types[20]; | 2392 LocalType param_types[20]; |
2428 for (int i = 0; i < 20; i++) param_types[i] = kAstF32; | 2393 for (int i = 0; i < 20; i++) param_types[i] = kAstF32; |
2429 FunctionSig sig(1, 19, param_types); | 2394 FunctionSig sig(1, 19, param_types); |
2430 TestingModule module; | 2395 TestingModule module; |
2431 WasmFunctionCompiler t(&sig); | 2396 WasmFunctionCompiler t(&sig, &module); |
2432 BUILD(t, WASM_GET_LOCAL(17)); | 2397 BUILD(t, WASM_GET_LOCAL(17)); |
2433 uint32_t index = t.CompileAndAdd(&module); | 2398 uint32_t index = t.CompileAndAdd(); |
2434 | 2399 |
2435 // Build the calling function. | 2400 // Build the calling function. |
2436 WasmRunner<float> r; | 2401 WasmRunner<float> r(&module); |
2437 r.env()->module = &module; | |
2438 BUILD(r, WASM_CALL_FUNCTION( | 2402 BUILD(r, WASM_CALL_FUNCTION( |
2439 index, WASM_F32(1.0f), WASM_F32(2.0f), WASM_F32(4.0f), | 2403 index, WASM_F32(1.0f), WASM_F32(2.0f), WASM_F32(4.0f), |
2440 WASM_F32(8.0f), WASM_F32(16.0f), WASM_F32(32.0f), | 2404 WASM_F32(8.0f), WASM_F32(16.0f), WASM_F32(32.0f), |
2441 WASM_F32(64.0f), WASM_F32(128.0f), WASM_F32(256.0f), | 2405 WASM_F32(64.0f), WASM_F32(128.0f), WASM_F32(256.0f), |
2442 WASM_F32(1.5f), WASM_F32(2.5f), WASM_F32(4.5f), WASM_F32(8.5f), | 2406 WASM_F32(1.5f), WASM_F32(2.5f), WASM_F32(4.5f), WASM_F32(8.5f), |
2443 WASM_F32(16.5f), WASM_F32(32.5f), WASM_F32(64.5f), | 2407 WASM_F32(16.5f), WASM_F32(32.5f), WASM_F32(64.5f), |
2444 WASM_F32(128.5f), WASM_F32(256.5f), WASM_F32(512.5f))); | 2408 WASM_F32(128.5f), WASM_F32(256.5f), WASM_F32(512.5f))); |
2445 | 2409 |
2446 float result = r.Call(); | 2410 float result = r.Call(); |
2447 CHECK_EQ(256.5f, result); | 2411 CHECK_EQ(256.5f, result); |
2448 } | 2412 } |
2449 | 2413 |
2450 | 2414 |
2451 TEST(Run_WasmCallF64StackParameter) { | 2415 TEST(Run_WasmCallF64StackParameter) { |
2452 // Build the target function. | 2416 // Build the target function. |
2453 LocalType param_types[20]; | 2417 LocalType param_types[20]; |
2454 for (int i = 0; i < 20; i++) param_types[i] = kAstF64; | 2418 for (int i = 0; i < 20; i++) param_types[i] = kAstF64; |
2455 FunctionSig sig(1, 19, param_types); | 2419 FunctionSig sig(1, 19, param_types); |
2456 TestingModule module; | 2420 TestingModule module; |
2457 WasmFunctionCompiler t(&sig); | 2421 WasmFunctionCompiler t(&sig, &module); |
2458 BUILD(t, WASM_GET_LOCAL(17)); | 2422 BUILD(t, WASM_GET_LOCAL(17)); |
2459 uint32_t index = t.CompileAndAdd(&module); | 2423 uint32_t index = t.CompileAndAdd(); |
2460 | 2424 |
2461 // Build the calling function. | 2425 // Build the calling function. |
2462 WasmRunner<double> r; | 2426 WasmRunner<double> r(&module); |
2463 r.env()->module = &module; | |
2464 BUILD(r, WASM_CALL_FUNCTION(index, WASM_F64(1.0), WASM_F64(2.0), | 2427 BUILD(r, WASM_CALL_FUNCTION(index, WASM_F64(1.0), WASM_F64(2.0), |
2465 WASM_F64(4.0), WASM_F64(8.0), WASM_F64(16.0), | 2428 WASM_F64(4.0), WASM_F64(8.0), WASM_F64(16.0), |
2466 WASM_F64(32.0), WASM_F64(64.0), WASM_F64(128.0), | 2429 WASM_F64(32.0), WASM_F64(64.0), WASM_F64(128.0), |
2467 WASM_F64(256.0), WASM_F64(1.5), WASM_F64(2.5), | 2430 WASM_F64(256.0), WASM_F64(1.5), WASM_F64(2.5), |
2468 WASM_F64(4.5), WASM_F64(8.5), WASM_F64(16.5), | 2431 WASM_F64(4.5), WASM_F64(8.5), WASM_F64(16.5), |
2469 WASM_F64(32.5), WASM_F64(64.5), WASM_F64(128.5), | 2432 WASM_F64(32.5), WASM_F64(64.5), WASM_F64(128.5), |
2470 WASM_F64(256.5), WASM_F64(512.5))); | 2433 WASM_F64(256.5), WASM_F64(512.5))); |
2471 | 2434 |
2472 float result = r.Call(); | 2435 float result = r.Call(); |
2473 CHECK_EQ(256.5, result); | 2436 CHECK_EQ(256.5, result); |
2474 } | 2437 } |
2475 | 2438 |
2476 TEST(Run_WasmCallI64Parameter) { | 2439 TEST(Run_WasmCallI64Parameter) { |
2477 // Build the target function. | 2440 // Build the target function. |
2478 LocalType param_types[20]; | 2441 LocalType param_types[20]; |
2479 for (int i = 0; i < 20; i++) param_types[i] = kAstI64; | 2442 for (int i = 0; i < 20; i++) param_types[i] = kAstI64; |
2480 param_types[3] = kAstI32; | 2443 param_types[3] = kAstI32; |
2481 param_types[4] = kAstI32; | 2444 param_types[4] = kAstI32; |
2482 FunctionSig sig(1, 19, param_types); | 2445 FunctionSig sig(1, 19, param_types); |
2483 for (int i = 0; i < 19; i++) { | 2446 for (int i = 0; i < 19; i++) { |
2484 TestingModule module; | 2447 TestingModule module; |
2485 WasmFunctionCompiler t(&sig); | 2448 WasmFunctionCompiler t(&sig, &module); |
2486 if (i == 2 || i == 3) { | 2449 if (i == 2 || i == 3) { |
2487 continue; | 2450 continue; |
2488 } else { | 2451 } else { |
2489 BUILD(t, WASM_GET_LOCAL(i)); | 2452 BUILD(t, WASM_GET_LOCAL(i)); |
2490 } | 2453 } |
2491 uint32_t index = t.CompileAndAdd(&module); | 2454 uint32_t index = t.CompileAndAdd(); |
2492 | 2455 |
2493 // Build the calling function. | 2456 // Build the calling function. |
2494 WasmRunner<int32_t> r; | 2457 WasmRunner<int32_t> r; |
2495 r.env()->module = &module; | 2458 r.env()->module = &module; |
2496 BUILD(r, | 2459 BUILD(r, |
2497 WASM_I32_CONVERT_I64(WASM_CALL_FUNCTION( | 2460 WASM_I32_CONVERT_I64(WASM_CALL_FUNCTION( |
2498 index, WASM_I64(0xbcd12340000000b), WASM_I64(0xbcd12340000000c), | 2461 index, WASM_I64(0xbcd12340000000b), WASM_I64(0xbcd12340000000c), |
2499 WASM_I32(0xd), WASM_I32_CONVERT_I64(WASM_I64(0xbcd12340000000e)), | 2462 WASM_I32(0xd), WASM_I32_CONVERT_I64(WASM_I64(0xbcd12340000000e)), |
2500 WASM_I64(0xbcd12340000000f), WASM_I64(0xbcd1234000000010), | 2463 WASM_I64(0xbcd12340000000f), WASM_I64(0xbcd1234000000010), |
2501 WASM_I64(0xbcd1234000000011), WASM_I64(0xbcd1234000000012), | 2464 WASM_I64(0xbcd1234000000011), WASM_I64(0xbcd1234000000012), |
(...skipping 18 matching lines...) Expand all Loading... |
2520 | 2483 |
2521 TEST(Run_WasmCallVoid) { | 2484 TEST(Run_WasmCallVoid) { |
2522 const byte kMemOffset = 8; | 2485 const byte kMemOffset = 8; |
2523 const int32_t kElemNum = kMemOffset / sizeof(int32_t); | 2486 const int32_t kElemNum = kMemOffset / sizeof(int32_t); |
2524 const int32_t kExpected = -414444; | 2487 const int32_t kExpected = -414444; |
2525 // Build the target function. | 2488 // Build the target function. |
2526 TestSignatures sigs; | 2489 TestSignatures sigs; |
2527 TestingModule module; | 2490 TestingModule module; |
2528 module.AddMemory(16); | 2491 module.AddMemory(16); |
2529 module.RandomizeMemory(); | 2492 module.RandomizeMemory(); |
2530 WasmFunctionCompiler t(sigs.v_v()); | 2493 WasmFunctionCompiler t(sigs.v_v(), &module); |
2531 t.env.module = &module; | |
2532 BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(kMemOffset), | 2494 BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(kMemOffset), |
2533 WASM_I32(kExpected))); | 2495 WASM_I32(kExpected))); |
2534 uint32_t index = t.CompileAndAdd(&module); | 2496 uint32_t index = t.CompileAndAdd(); |
2535 | 2497 |
2536 // Build the calling function. | 2498 // Build the calling function. |
2537 WasmRunner<int32_t> r; | 2499 WasmRunner<int32_t> r(&module); |
2538 r.env()->module = &module; | |
2539 BUILD(r, WASM_CALL_FUNCTION0(index), | 2500 BUILD(r, WASM_CALL_FUNCTION0(index), |
2540 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kMemOffset))); | 2501 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kMemOffset))); |
2541 | 2502 |
2542 int32_t result = r.Call(); | 2503 int32_t result = r.Call(); |
2543 CHECK_EQ(kExpected, result); | 2504 CHECK_EQ(kExpected, result); |
2544 CHECK_EQ(kExpected, module.raw_mem_start<int32_t>()[kElemNum]); | 2505 CHECK_EQ(kExpected, module.raw_mem_start<int32_t>()[kElemNum]); |
2545 } | 2506 } |
2546 | 2507 |
2547 | 2508 |
2548 TEST(Run_WasmCall_Int32Add) { | 2509 TEST(Run_WasmCall_Int32Add) { |
2549 // Build the target function. | 2510 // Build the target function. |
2550 TestSignatures sigs; | 2511 TestSignatures sigs; |
2551 TestingModule module; | 2512 TestingModule module; |
2552 WasmFunctionCompiler t(sigs.i_ii()); | 2513 WasmFunctionCompiler t(sigs.i_ii(), &module); |
2553 BUILD(t, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2514 BUILD(t, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2554 uint32_t index = t.CompileAndAdd(&module); | 2515 uint32_t index = t.CompileAndAdd(); |
2555 | 2516 |
2556 // Build the caller function. | 2517 // Build the caller function. |
2557 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 2518 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32()); |
2558 r.env()->module = &module; | |
2559 BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2519 BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2560 | 2520 |
2561 FOR_INT32_INPUTS(i) { | 2521 FOR_INT32_INPUTS(i) { |
2562 FOR_INT32_INPUTS(j) { | 2522 FOR_INT32_INPUTS(j) { |
2563 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) + | 2523 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) + |
2564 static_cast<uint32_t>(*j)); | 2524 static_cast<uint32_t>(*j)); |
2565 CHECK_EQ(expected, r.Call(*i, *j)); | 2525 CHECK_EQ(expected, r.Call(*i, *j)); |
2566 } | 2526 } |
2567 } | 2527 } |
2568 } | 2528 } |
2569 | 2529 |
2570 | 2530 |
2571 #if WASM_64 | 2531 #if WASM_64 |
2572 TEST(Run_WasmCall_Int64Sub) { | 2532 TEST(Run_WasmCall_Int64Sub) { |
2573 // Build the target function. | 2533 // Build the target function. |
2574 TestSignatures sigs; | 2534 TestSignatures sigs; |
2575 TestingModule module; | 2535 TestingModule module; |
2576 WasmFunctionCompiler t(sigs.l_ll()); | 2536 WasmFunctionCompiler t(sigs.l_ll(), &module); |
2577 BUILD(t, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2537 BUILD(t, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2578 uint32_t index = t.CompileAndAdd(&module); | 2538 uint32_t index = t.CompileAndAdd(); |
2579 | 2539 |
2580 // Build the caller function. | 2540 // Build the caller function. |
2581 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); | 2541 WasmRunner<int64_t> r(&module, MachineType::Int64(), MachineType::Int64()); |
2582 r.env()->module = &module; | |
2583 BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2542 BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2584 | 2543 |
2585 FOR_INT32_INPUTS(i) { | 2544 FOR_INT32_INPUTS(i) { |
2586 FOR_INT32_INPUTS(j) { | 2545 FOR_INT32_INPUTS(j) { |
2587 int64_t a = static_cast<int64_t>(*i) << 32 | | 2546 int64_t a = static_cast<int64_t>(*i) << 32 | |
2588 (static_cast<int64_t>(*j) | 0xFFFFFFFF); | 2547 (static_cast<int64_t>(*j) | 0xFFFFFFFF); |
2589 int64_t b = static_cast<int64_t>(*j) << 32 | | 2548 int64_t b = static_cast<int64_t>(*j) << 32 | |
2590 (static_cast<int64_t>(*i) | 0xFFFFFFFF); | 2549 (static_cast<int64_t>(*i) | 0xFFFFFFFF); |
2591 | 2550 |
2592 int64_t expected = static_cast<int64_t>(static_cast<uint64_t>(a) - | 2551 int64_t expected = static_cast<int64_t>(static_cast<uint64_t>(a) - |
2593 static_cast<uint64_t>(b)); | 2552 static_cast<uint64_t>(b)); |
2594 CHECK_EQ(expected, r.Call(a, b)); | 2553 CHECK_EQ(expected, r.Call(a, b)); |
2595 } | 2554 } |
2596 } | 2555 } |
2597 } | 2556 } |
2598 #endif | 2557 #endif |
2599 | 2558 |
2600 | 2559 |
2601 TEST(Run_WasmCall_Float32Sub) { | 2560 TEST(Run_WasmCall_Float32Sub) { |
2602 TestSignatures sigs; | 2561 TestSignatures sigs; |
2603 WasmFunctionCompiler t(sigs.f_ff()); | 2562 TestingModule module; |
| 2563 WasmFunctionCompiler t(sigs.f_ff(), &module); |
2604 | 2564 |
2605 // Build the target function. | 2565 // Build the target function. |
2606 TestingModule module; | |
2607 BUILD(t, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2566 BUILD(t, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2608 uint32_t index = t.CompileAndAdd(&module); | 2567 uint32_t index = t.CompileAndAdd(); |
2609 | 2568 |
2610 // Builder the caller function. | 2569 // Builder the caller function. |
2611 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); | 2570 WasmRunner<float> r(&module, MachineType::Float32(), MachineType::Float32()); |
2612 r.env()->module = &module; | |
2613 BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2571 BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2614 | 2572 |
2615 FOR_FLOAT32_INPUTS(i) { | 2573 FOR_FLOAT32_INPUTS(i) { |
2616 FOR_FLOAT32_INPUTS(j) { | 2574 FOR_FLOAT32_INPUTS(j) { |
2617 volatile float expected = *i - *j; | 2575 volatile float expected = *i - *j; |
2618 CheckFloatEq(expected, r.Call(*i, *j)); | 2576 CheckFloatEq(expected, r.Call(*i, *j)); |
2619 } | 2577 } |
2620 } | 2578 } |
2621 } | 2579 } |
2622 | 2580 |
2623 | 2581 |
2624 TEST(Run_WasmCall_Float64Sub) { | 2582 TEST(Run_WasmCall_Float64Sub) { |
2625 WasmRunner<int32_t> r; | |
2626 TestingModule module; | 2583 TestingModule module; |
2627 double* memory = module.AddMemoryElems<double>(16); | 2584 double* memory = module.AddMemoryElems<double>(16); |
2628 r.env()->module = &module; | 2585 WasmRunner<int32_t> r(&module); |
2629 | 2586 |
2630 // TODO(titzer): convert to a binop test. | 2587 // TODO(titzer): convert to a binop test. |
2631 BUILD(r, WASM_BLOCK( | 2588 BUILD(r, WASM_BLOCK( |
2632 2, WASM_STORE_MEM( | 2589 2, WASM_STORE_MEM( |
2633 MachineType::Float64(), WASM_ZERO, | 2590 MachineType::Float64(), WASM_ZERO, |
2634 WASM_F64_SUB( | 2591 WASM_F64_SUB( |
2635 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO), | 2592 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO), |
2636 WASM_LOAD_MEM(MachineType::Float64(), WASM_I8(8)))), | 2593 WASM_LOAD_MEM(MachineType::Float64(), WASM_I8(8)))), |
2637 WASM_I8(107))); | 2594 WASM_I8(107))); |
2638 | 2595 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2688 | 2645 |
2689 // ========================================================================= | 2646 // ========================================================================= |
2690 // Build the selector function. | 2647 // Build the selector function. |
2691 // ========================================================================= | 2648 // ========================================================================= |
2692 uint32_t index; | 2649 uint32_t index; |
2693 FunctionSig::Builder b(&zone, 1, num_params); | 2650 FunctionSig::Builder b(&zone, 1, num_params); |
2694 b.AddReturn(WasmOpcodes::LocalTypeFor(result)); | 2651 b.AddReturn(WasmOpcodes::LocalTypeFor(result)); |
2695 for (int i = 0; i < num_params; i++) { | 2652 for (int i = 0; i < num_params; i++) { |
2696 b.AddParam(WasmOpcodes::LocalTypeFor(memtypes[i])); | 2653 b.AddParam(WasmOpcodes::LocalTypeFor(memtypes[i])); |
2697 } | 2654 } |
2698 WasmFunctionCompiler t(b.Build()); | 2655 WasmFunctionCompiler t(b.Build(), &module); |
2699 t.env.module = &module; | |
2700 BUILD(t, WASM_GET_LOCAL(which)); | 2656 BUILD(t, WASM_GET_LOCAL(which)); |
2701 index = t.CompileAndAdd(&module); | 2657 index = t.CompileAndAdd(); |
2702 | 2658 |
2703 // ========================================================================= | 2659 // ========================================================================= |
2704 // Build the calling function. | 2660 // Build the calling function. |
2705 // ========================================================================= | 2661 // ========================================================================= |
2706 WasmRunner<int32_t> r; | 2662 WasmRunner<int32_t> r(&module); |
2707 r.env()->module = &module; | |
2708 | 2663 |
2709 { | 2664 std::vector<byte> code; |
2710 std::vector<byte> code; | 2665 ADD_CODE(code, |
2711 ADD_CODE(code, | 2666 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(result, true)), |
2712 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(result, true)), | 2667 WasmOpcodes::LoadStoreAccessOf(false)); |
2713 WasmOpcodes::LoadStoreAccessOf(false)); | 2668 ADD_CODE(code, WASM_ZERO); |
2714 ADD_CODE(code, WASM_ZERO); | 2669 ADD_CODE(code, kExprCallFunction, static_cast<byte>(index)); |
2715 ADD_CODE(code, kExprCallFunction, static_cast<byte>(index)); | |
2716 | 2670 |
2717 for (int i = 0; i < num_params; i++) { | 2671 for (int i = 0; i < num_params; i++) { |
2718 int offset = (i + 1) * kElemSize; | 2672 int offset = (i + 1) * kElemSize; |
2719 ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset))); | 2673 ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset))); |
2720 } | 2674 } |
2721 | 2675 |
2722 ADD_CODE(code, WASM_I32(kExpected)); | 2676 ADD_CODE(code, WASM_I32(kExpected)); |
2723 size_t end = code.size(); | 2677 size_t end = code.size(); |
2724 code.push_back(0); | 2678 code.push_back(0); |
2725 r.Build(&code[0], &code[end]); | 2679 r.Build(&code[0], &code[end]); |
2726 } | |
2727 | 2680 |
2728 // Run the code. | 2681 // Run the code. |
2729 for (int t = 0; t < 10; t++) { | 2682 for (int t = 0; t < 10; t++) { |
2730 module.RandomizeMemory(); | 2683 module.RandomizeMemory(); |
2731 CHECK_EQ(kExpected, r.Call()); | 2684 CHECK_EQ(kExpected, r.Call()); |
2732 | 2685 |
2733 int size = WasmOpcodes::MemSize(result); | 2686 int size = WasmOpcodes::MemSize(result); |
2734 for (int i = 0; i < size; i++) { | 2687 for (int i = 0; i < size; i++) { |
2735 int base = (which + 1) * kElemSize; | 2688 int base = (which + 1) * kElemSize; |
2736 byte expected = module.raw_mem_at<byte>(base + i); | 2689 byte expected = module.raw_mem_at<byte>(base + i); |
2737 byte result = module.raw_mem_at<byte>(i); | 2690 byte result = module.raw_mem_at<byte>(i); |
2738 CHECK_EQ(expected, result); | 2691 CHECK_EQ(expected, result); |
2739 } | 2692 } |
2740 } | 2693 } |
2741 } | 2694 } |
2742 } | 2695 } |
2743 | 2696 |
2744 | 2697 |
2745 TEST(Run_WasmMixedCall_0) { Run_WasmMixedCall_N(0); } | 2698 TEST(Run_WasmMixedCall_0) { Run_WasmMixedCall_N(0); } |
2746 TEST(Run_WasmMixedCall_1) { Run_WasmMixedCall_N(1); } | 2699 TEST(Run_WasmMixedCall_1) { Run_WasmMixedCall_N(1); } |
2747 TEST(Run_WasmMixedCall_2) { Run_WasmMixedCall_N(2); } | 2700 TEST(Run_WasmMixedCall_2) { Run_WasmMixedCall_N(2); } |
2748 TEST(Run_WasmMixedCall_3) { Run_WasmMixedCall_N(3); } | 2701 TEST(Run_WasmMixedCall_3) { Run_WasmMixedCall_N(3); } |
2749 | 2702 |
| 2703 TEST(Run_Wasm_AddCall) { |
| 2704 TestSignatures sigs; |
| 2705 TestingModule module; |
| 2706 WasmFunctionCompiler t1(sigs.i_ii(), &module); |
| 2707 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
| 2708 t1.CompileAndAdd(); |
| 2709 |
| 2710 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
| 2711 byte local = r.AllocateLocal(kAstI32); |
| 2712 BUILD(r, |
| 2713 WASM_BLOCK(2, WASM_SET_LOCAL(local, WASM_I8(99)), |
| 2714 WASM_I32_ADD( |
| 2715 WASM_CALL_FUNCTION(t1.function_index_, WASM_GET_LOCAL(0), |
| 2716 WASM_GET_LOCAL(0)), |
| 2717 WASM_CALL_FUNCTION(t1.function_index_, WASM_GET_LOCAL(1), |
| 2718 WASM_GET_LOCAL(local))))); |
| 2719 |
| 2720 CHECK_EQ(198, r.Call(0)); |
| 2721 CHECK_EQ(200, r.Call(1)); |
| 2722 CHECK_EQ(100, r.Call(-49)); |
| 2723 } |
2750 | 2724 |
2751 TEST(Run_Wasm_CountDown_expr) { | 2725 TEST(Run_Wasm_CountDown_expr) { |
2752 WasmRunner<int32_t> r(MachineType::Int32()); | 2726 WasmRunner<int32_t> r(MachineType::Int32()); |
2753 BUILD(r, WASM_LOOP( | 2727 BUILD(r, WASM_LOOP( |
2754 3, WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), | 2728 3, WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), |
2755 WASM_BREAKV(0, WASM_GET_LOCAL(0))), | 2729 WASM_BREAKV(0, WASM_GET_LOCAL(0))), |
2756 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), | 2730 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), |
2757 WASM_CONTINUE(0))); | 2731 WASM_CONTINUE(0))); |
2758 CHECK_EQ(0, r.Call(1)); | 2732 CHECK_EQ(0, r.Call(1)); |
2759 CHECK_EQ(0, r.Call(10)); | 2733 CHECK_EQ(0, r.Call(10)); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2909 CHECK_EQ(14, r.Call(0, 0)); | 2883 CHECK_EQ(14, r.Call(0, 0)); |
2910 } | 2884 } |
2911 | 2885 |
2912 | 2886 |
2913 #if WASM_64 | 2887 #if WASM_64 |
2914 TEST(Run_Wasm_LoadStoreI64_sx) { | 2888 TEST(Run_Wasm_LoadStoreI64_sx) { |
2915 byte loads[] = {kExprI64LoadMem8S, kExprI64LoadMem16S, kExprI64LoadMem32S, | 2889 byte loads[] = {kExprI64LoadMem8S, kExprI64LoadMem16S, kExprI64LoadMem32S, |
2916 kExprI64LoadMem}; | 2890 kExprI64LoadMem}; |
2917 | 2891 |
2918 for (size_t m = 0; m < arraysize(loads); m++) { | 2892 for (size_t m = 0; m < arraysize(loads); m++) { |
2919 WasmRunner<int64_t> r; | |
2920 TestingModule module; | 2893 TestingModule module; |
2921 byte* memory = module.AddMemoryElems<byte>(16); | 2894 byte* memory = module.AddMemoryElems<byte>(16); |
2922 r.env()->module = &module; | 2895 WasmRunner<int64_t> r(&module); |
2923 | 2896 |
2924 byte code[] = {kExprI64StoreMem, 0, kExprI8Const, 8, | 2897 byte code[] = {kExprI64StoreMem, 0, kExprI8Const, 8, |
2925 loads[m], 0, kExprI8Const, 0}; | 2898 loads[m], 0, kExprI8Const, 0}; |
2926 | 2899 |
2927 r.Build(code, code + arraysize(code)); | 2900 r.Build(code, code + arraysize(code)); |
2928 | 2901 |
2929 // Try a bunch of different negative values. | 2902 // Try a bunch of different negative values. |
2930 for (int i = -1; i >= -128; i -= 11) { | 2903 for (int i = -1; i >= -128; i -= 11) { |
2931 int size = 1 << m; | 2904 int size = 1 << m; |
2932 module.BlankMemory(); | 2905 module.BlankMemory(); |
2933 memory[size - 1] = static_cast<byte>(i); // set the high order byte. | 2906 memory[size - 1] = static_cast<byte>(i); // set the high order byte. |
2934 | 2907 |
2935 int64_t expected = static_cast<int64_t>(i) << ((size - 1) * 8); | 2908 int64_t expected = static_cast<int64_t>(i) << ((size - 1) * 8); |
2936 | 2909 |
2937 CHECK_EQ(expected, r.Call()); | 2910 CHECK_EQ(expected, r.Call()); |
2938 CHECK_EQ(static_cast<byte>(i), memory[8 + size - 1]); | 2911 CHECK_EQ(static_cast<byte>(i), memory[8 + size - 1]); |
2939 for (int j = size; j < 8; j++) { | 2912 for (int j = size; j < 8; j++) { |
2940 CHECK_EQ(255, memory[8 + j]); | 2913 CHECK_EQ(255, memory[8 + j]); |
2941 } | 2914 } |
2942 } | 2915 } |
2943 } | 2916 } |
2944 } | 2917 } |
2945 | 2918 |
2946 | 2919 |
2947 #endif | 2920 #endif |
2948 | 2921 |
2949 | 2922 |
2950 TEST(Run_Wasm_SimpleCallIndirect) { | 2923 TEST(Run_Wasm_SimpleCallIndirect) { |
2951 WasmRunner<int32_t> r(MachineType::Int32()); | |
2952 TestSignatures sigs; | 2924 TestSignatures sigs; |
2953 TestingModule module; | 2925 TestingModule module; |
2954 r.env()->module = &module; | 2926 |
2955 WasmFunctionCompiler t1(sigs.i_ii()); | 2927 WasmFunctionCompiler t1(sigs.i_ii(), &module); |
2956 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2928 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2957 t1.CompileAndAdd(&module, /*sig_index*/ 1); | 2929 t1.CompileAndAdd(/*sig_index*/ 1); |
2958 | 2930 |
2959 WasmFunctionCompiler t2(sigs.i_ii()); | 2931 WasmFunctionCompiler t2(sigs.i_ii(), &module); |
2960 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2932 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2961 t2.CompileAndAdd(&module, /*sig_index*/ 1); | 2933 t2.CompileAndAdd(/*sig_index*/ 1); |
2962 | 2934 |
2963 // Signature table. | 2935 // Signature table. |
2964 module.AddSignature(sigs.f_ff()); | 2936 module.AddSignature(sigs.f_ff()); |
2965 module.AddSignature(sigs.i_ii()); | 2937 module.AddSignature(sigs.i_ii()); |
2966 module.AddSignature(sigs.d_dd()); | 2938 module.AddSignature(sigs.d_dd()); |
2967 | 2939 |
2968 // Function table. | 2940 // Function table. |
2969 int table[] = {0, 1}; | 2941 int table[] = {0, 1}; |
2970 module.AddIndirectFunctionTable(table, 2); | 2942 module.AddIndirectFunctionTable(table, 2); |
2971 module.PopulateIndirectFunctionTable(); | 2943 module.PopulateIndirectFunctionTable(); |
2972 | 2944 |
2973 // Builder the caller function. | 2945 // Builder the caller function. |
| 2946 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2974 BUILD(r, WASM_CALL_INDIRECT(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); | 2947 BUILD(r, WASM_CALL_INDIRECT(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); |
2975 | 2948 |
2976 CHECK_EQ(88, r.Call(0)); | 2949 CHECK_EQ(88, r.Call(0)); |
2977 CHECK_EQ(44, r.Call(1)); | 2950 CHECK_EQ(44, r.Call(1)); |
2978 CHECK_TRAP(r.Call(2)); | 2951 CHECK_TRAP(r.Call(2)); |
2979 } | 2952 } |
2980 | 2953 |
2981 | 2954 |
2982 TEST(Run_Wasm_MultipleCallIndirect) { | 2955 TEST(Run_Wasm_MultipleCallIndirect) { |
2983 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32(), | |
2984 MachineType::Int32()); | |
2985 TestSignatures sigs; | 2956 TestSignatures sigs; |
2986 TestingModule module; | 2957 TestingModule module; |
2987 r.env()->module = &module; | 2958 |
2988 WasmFunctionCompiler t1(sigs.i_ii()); | 2959 WasmFunctionCompiler t1(sigs.i_ii(), &module); |
2989 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2960 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2990 t1.CompileAndAdd(&module, /*sig_index*/ 1); | 2961 t1.CompileAndAdd(/*sig_index*/ 1); |
2991 | 2962 |
2992 WasmFunctionCompiler t2(sigs.i_ii()); | 2963 WasmFunctionCompiler t2(sigs.i_ii(), &module); |
2993 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2964 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2994 t2.CompileAndAdd(&module, /*sig_index*/ 1); | 2965 t2.CompileAndAdd(/*sig_index*/ 1); |
2995 | 2966 |
2996 // Signature table. | 2967 // Signature table. |
2997 module.AddSignature(sigs.f_ff()); | 2968 module.AddSignature(sigs.f_ff()); |
2998 module.AddSignature(sigs.i_ii()); | 2969 module.AddSignature(sigs.i_ii()); |
2999 module.AddSignature(sigs.d_dd()); | 2970 module.AddSignature(sigs.d_dd()); |
3000 | 2971 |
3001 // Function table. | 2972 // Function table. |
3002 int table[] = {0, 1}; | 2973 int table[] = {0, 1}; |
3003 module.AddIndirectFunctionTable(table, 2); | 2974 module.AddIndirectFunctionTable(table, 2); |
3004 module.PopulateIndirectFunctionTable(); | 2975 module.PopulateIndirectFunctionTable(); |
3005 | 2976 |
3006 // Builder the caller function. | 2977 // Builder the caller function. |
| 2978 WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32(), |
| 2979 MachineType::Int32()); |
3007 BUILD(r, | 2980 BUILD(r, |
3008 WASM_I32_ADD(WASM_CALL_INDIRECT(1, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), | 2981 WASM_I32_ADD(WASM_CALL_INDIRECT(1, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), |
3009 WASM_GET_LOCAL(2)), | 2982 WASM_GET_LOCAL(2)), |
3010 WASM_CALL_INDIRECT(1, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2), | 2983 WASM_CALL_INDIRECT(1, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2), |
3011 WASM_GET_LOCAL(0)))); | 2984 WASM_GET_LOCAL(0)))); |
3012 | 2985 |
3013 CHECK_EQ(5, r.Call(0, 1, 2)); | 2986 CHECK_EQ(5, r.Call(0, 1, 2)); |
3014 CHECK_EQ(19, r.Call(0, 1, 9)); | 2987 CHECK_EQ(19, r.Call(0, 1, 9)); |
3015 CHECK_EQ(1, r.Call(1, 0, 2)); | 2988 CHECK_EQ(1, r.Call(1, 0, 2)); |
3016 CHECK_EQ(1, r.Call(1, 0, 9)); | 2989 CHECK_EQ(1, r.Call(1, 0, 9)); |
3017 | 2990 |
3018 CHECK_TRAP(r.Call(0, 2, 1)); | 2991 CHECK_TRAP(r.Call(0, 2, 1)); |
3019 CHECK_TRAP(r.Call(1, 2, 0)); | 2992 CHECK_TRAP(r.Call(1, 2, 0)); |
3020 CHECK_TRAP(r.Call(2, 0, 1)); | 2993 CHECK_TRAP(r.Call(2, 0, 1)); |
3021 CHECK_TRAP(r.Call(2, 1, 0)); | 2994 CHECK_TRAP(r.Call(2, 1, 0)); |
3022 } | 2995 } |
3023 | 2996 |
3024 TEST(Run_Wasm_CallIndirect_NoTable) { | 2997 TEST(Run_Wasm_CallIndirect_NoTable) { |
3025 WasmRunner<int32_t> r(MachineType::Int32()); | |
3026 TestSignatures sigs; | 2998 TestSignatures sigs; |
3027 TestingModule module; | 2999 TestingModule module; |
3028 r.env()->module = &module; | 3000 |
3029 // One function. | 3001 // One function. |
3030 WasmFunctionCompiler t1(sigs.i_ii()); | 3002 WasmFunctionCompiler t1(sigs.i_ii(), &module); |
3031 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 3003 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
3032 t1.CompileAndAdd(&module, /*sig_index*/ 1); | 3004 t1.CompileAndAdd(/*sig_index*/ 1); |
3033 | 3005 |
3034 // Signature table. | 3006 // Signature table. |
3035 module.AddSignature(sigs.f_ff()); | 3007 module.AddSignature(sigs.f_ff()); |
3036 module.AddSignature(sigs.i_ii()); | 3008 module.AddSignature(sigs.i_ii()); |
3037 | 3009 |
3038 // Builder the caller function. | 3010 // Builder the caller function. |
| 3011 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
3039 BUILD(r, WASM_CALL_INDIRECT(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); | 3012 BUILD(r, WASM_CALL_INDIRECT(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); |
3040 | 3013 |
3041 CHECK_TRAP(r.Call(0)); | 3014 CHECK_TRAP(r.Call(0)); |
3042 CHECK_TRAP(r.Call(1)); | 3015 CHECK_TRAP(r.Call(1)); |
3043 CHECK_TRAP(r.Call(2)); | 3016 CHECK_TRAP(r.Call(2)); |
3044 } | 3017 } |
3045 | 3018 |
3046 TEST(Run_Wasm_F32Floor) { | 3019 TEST(Run_Wasm_F32Floor) { |
3047 WasmRunner<float> r(MachineType::Float32()); | 3020 WasmRunner<float> r(MachineType::Float32()); |
3048 BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0))); | 3021 BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0))); |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3451 for (byte num_params = 0; num_params < 40; num_params++) { | 3424 for (byte num_params = 0; num_params < 40; num_params++) { |
3452 Zone zone; | 3425 Zone zone; |
3453 HandleScope scope(CcTest::InitIsolateOnce()); | 3426 HandleScope scope(CcTest::InitIsolateOnce()); |
3454 TestingModule module; | 3427 TestingModule module; |
3455 FunctionSig* sig = sigs.many(&zone, kAstStmt, param, num_params); | 3428 FunctionSig* sig = sigs.many(&zone, kAstStmt, param, num_params); |
3456 | 3429 |
3457 module.AddSignature(sig); | 3430 module.AddSignature(sig); |
3458 module.AddSignature(sig); | 3431 module.AddSignature(sig); |
3459 module.AddIndirectFunctionTable(nullptr, 0); | 3432 module.AddIndirectFunctionTable(nullptr, 0); |
3460 | 3433 |
3461 WasmFunctionCompiler t(sig); | 3434 WasmFunctionCompiler t(sig, &module); |
3462 t.env.module = &module; | |
3463 | 3435 |
3464 std::vector<byte> code; | 3436 std::vector<byte> code; |
3465 ADD_CODE(code, kExprCallIndirect, 1); | 3437 ADD_CODE(code, kExprCallIndirect, 1); |
3466 ADD_CODE(code, kExprI8Const, 0); | 3438 ADD_CODE(code, kExprI8Const, 0); |
3467 for (byte p = 0; p < num_params; p++) { | 3439 for (byte p = 0; p < num_params; p++) { |
3468 ADD_CODE(code, kExprGetLocal, p); | 3440 ADD_CODE(code, kExprGetLocal, p); |
3469 } | 3441 } |
3470 | 3442 |
3471 t.Build(&code[0], &code[0] + code.size()); | 3443 t.Build(&code[0], &code[0] + code.size()); |
3472 t.Compile(&module); | 3444 t.Compile(); |
3473 } | 3445 } |
3474 } | 3446 } |
3475 | 3447 |
3476 | 3448 |
3477 TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kAstI32); } | 3449 TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kAstI32); } |
3478 | 3450 |
3479 | 3451 |
3480 #if WASM_64 | 3452 #if WASM_64 |
3481 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } | 3453 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } |
3482 #endif | 3454 #endif |
3483 | 3455 |
3484 | 3456 |
3485 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } | 3457 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } |
3486 | 3458 |
3487 | 3459 |
3488 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } | 3460 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } |
OLD | NEW |