| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
| 10 #include "src/wasm/wasm-macro-gen.h" | 10 #include "src/wasm/wasm-macro-gen.h" |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 if (*i < static_cast<float>(std::numeric_limits<uint64_t>::max()) && | 862 if (*i < static_cast<float>(std::numeric_limits<uint64_t>::max()) && |
| 863 *i > -1) { | 863 *i > -1) { |
| 864 CHECK_EQ(static_cast<uint64_t>(*i), r.Call(*i)); | 864 CHECK_EQ(static_cast<uint64_t>(*i), r.Call(*i)); |
| 865 } else { | 865 } else { |
| 866 CHECK_TRAP64(r.Call(*i)); | 866 CHECK_TRAP64(r.Call(*i)); |
| 867 } | 867 } |
| 868 } | 868 } |
| 869 } | 869 } |
| 870 | 870 |
| 871 WASM_EXEC_TEST(CallI64Parameter) { | 871 WASM_EXEC_TEST(CallI64Parameter) { |
| 872 LocalType param_types[20]; | 872 ValueType param_types[20]; |
| 873 for (int i = 0; i < 20; i++) param_types[i] = kAstI64; | 873 for (int i = 0; i < 20; i++) param_types[i] = kWasmI64; |
| 874 param_types[3] = kAstI32; | 874 param_types[3] = kWasmI32; |
| 875 param_types[4] = kAstI32; | 875 param_types[4] = kWasmI32; |
| 876 FunctionSig sig(1, 19, param_types); | 876 FunctionSig sig(1, 19, param_types); |
| 877 for (int i = 0; i < 19; i++) { | 877 for (int i = 0; i < 19; i++) { |
| 878 if (i == 2 || i == 3) continue; | 878 if (i == 2 || i == 3) continue; |
| 879 WasmRunner<int32_t> r(execution_mode); | 879 WasmRunner<int32_t> r(execution_mode); |
| 880 // Build the target function. | 880 // Build the target function. |
| 881 WasmFunctionCompiler& t = r.NewFunction(&sig); | 881 WasmFunctionCompiler& t = r.NewFunction(&sig); |
| 882 BUILD(t, WASM_GET_LOCAL(i)); | 882 BUILD(t, WASM_GET_LOCAL(i)); |
| 883 | 883 |
| 884 // Build the calling function. | 884 // Build the calling function. |
| 885 BUILD( | 885 BUILD( |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 } | 1350 } |
| 1351 | 1351 |
| 1352 WASM_EXEC_TEST(MemI64_Sum) { | 1352 WASM_EXEC_TEST(MemI64_Sum) { |
| 1353 REQUIRE(I64LoadStore); | 1353 REQUIRE(I64LoadStore); |
| 1354 REQUIRE(I64Add); | 1354 REQUIRE(I64Add); |
| 1355 REQUIRE(I64Sub); | 1355 REQUIRE(I64Sub); |
| 1356 REQUIRE(I64Phi); | 1356 REQUIRE(I64Phi); |
| 1357 const int kNumElems = 20; | 1357 const int kNumElems = 20; |
| 1358 WasmRunner<uint64_t, int32_t> r(execution_mode); | 1358 WasmRunner<uint64_t, int32_t> r(execution_mode); |
| 1359 uint64_t* memory = r.module().AddMemoryElems<uint64_t>(kNumElems); | 1359 uint64_t* memory = r.module().AddMemoryElems<uint64_t>(kNumElems); |
| 1360 const byte kSum = r.AllocateLocal(kAstI64); | 1360 const byte kSum = r.AllocateLocal(kWasmI64); |
| 1361 | 1361 |
| 1362 BUILD( | 1362 BUILD( |
| 1363 r, | 1363 r, |
| 1364 WASM_WHILE( | 1364 WASM_WHILE( |
| 1365 WASM_GET_LOCAL(0), | 1365 WASM_GET_LOCAL(0), |
| 1366 WASM_BLOCK( | 1366 WASM_BLOCK( |
| 1367 WASM_SET_LOCAL(kSum, | 1367 WASM_SET_LOCAL(kSum, |
| 1368 WASM_I64_ADD(WASM_GET_LOCAL(kSum), | 1368 WASM_I64_ADD(WASM_GET_LOCAL(kSum), |
| 1369 WASM_LOAD_MEM(MachineType::Int64(), | 1369 WASM_LOAD_MEM(MachineType::Int64(), |
| 1370 WASM_GET_LOCAL(0)))), | 1370 WASM_GET_LOCAL(0)))), |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1485 } | 1485 } |
| 1486 } | 1486 } |
| 1487 } | 1487 } |
| 1488 | 1488 |
| 1489 #define ADD_CODE(vec, ...) \ | 1489 #define ADD_CODE(vec, ...) \ |
| 1490 do { \ | 1490 do { \ |
| 1491 byte __buf[] = {__VA_ARGS__}; \ | 1491 byte __buf[] = {__VA_ARGS__}; \ |
| 1492 for (size_t i = 0; i < sizeof(__buf); i++) vec.push_back(__buf[i]); \ | 1492 for (size_t i = 0; i < sizeof(__buf); i++) vec.push_back(__buf[i]); \ |
| 1493 } while (false) | 1493 } while (false) |
| 1494 | 1494 |
| 1495 static void CompileCallIndirectMany(LocalType param) { | 1495 static void CompileCallIndirectMany(ValueType param) { |
| 1496 // Make sure we don't run out of registers when compiling indirect calls | 1496 // Make sure we don't run out of registers when compiling indirect calls |
| 1497 // with many many parameters. | 1497 // with many many parameters. |
| 1498 TestSignatures sigs; | 1498 TestSignatures sigs; |
| 1499 for (byte num_params = 0; num_params < 40; num_params++) { | 1499 for (byte num_params = 0; num_params < 40; num_params++) { |
| 1500 WasmRunner<void> r(kExecuteCompiled); | 1500 WasmRunner<void> r(kExecuteCompiled); |
| 1501 FunctionSig* sig = sigs.many(r.zone(), kAstStmt, param, num_params); | 1501 FunctionSig* sig = sigs.many(r.zone(), kWasmStmt, param, num_params); |
| 1502 | 1502 |
| 1503 r.module().AddSignature(sig); | 1503 r.module().AddSignature(sig); |
| 1504 r.module().AddSignature(sig); | 1504 r.module().AddSignature(sig); |
| 1505 r.module().AddIndirectFunctionTable(nullptr, 0); | 1505 r.module().AddIndirectFunctionTable(nullptr, 0); |
| 1506 | 1506 |
| 1507 WasmFunctionCompiler& t = r.NewFunction(sig); | 1507 WasmFunctionCompiler& t = r.NewFunction(sig); |
| 1508 | 1508 |
| 1509 std::vector<byte> code; | 1509 std::vector<byte> code; |
| 1510 for (byte p = 0; p < num_params; p++) { | 1510 for (byte p = 0; p < num_params; p++) { |
| 1511 ADD_CODE(code, kExprGetLocal, p); | 1511 ADD_CODE(code, kExprGetLocal, p); |
| 1512 } | 1512 } |
| 1513 ADD_CODE(code, kExprI8Const, 0); | 1513 ADD_CODE(code, kExprI8Const, 0); |
| 1514 ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO); | 1514 ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO); |
| 1515 | 1515 |
| 1516 t.Build(&code[0], &code[0] + code.size()); | 1516 t.Build(&code[0], &code[0] + code.size()); |
| 1517 } | 1517 } |
| 1518 } | 1518 } |
| 1519 | 1519 |
| 1520 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } | 1520 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kWasmI64); } |
| 1521 | 1521 |
| 1522 static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) { | 1522 static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) { |
| 1523 const int kExpected = 6333; | 1523 const int kExpected = 6333; |
| 1524 const int kElemSize = 8; | 1524 const int kElemSize = 8; |
| 1525 TestSignatures sigs; | 1525 TestSignatures sigs; |
| 1526 | 1526 |
| 1527 static MachineType mixed[] = { | 1527 static MachineType mixed[] = { |
| 1528 MachineType::Int32(), MachineType::Float32(), MachineType::Int64(), | 1528 MachineType::Int32(), MachineType::Float32(), MachineType::Int64(), |
| 1529 MachineType::Float64(), MachineType::Float32(), MachineType::Int64(), | 1529 MachineType::Float64(), MachineType::Float32(), MachineType::Int64(), |
| 1530 MachineType::Int32(), MachineType::Float64(), MachineType::Float32(), | 1530 MachineType::Int32(), MachineType::Float64(), MachineType::Float32(), |
| 1531 MachineType::Float64(), MachineType::Int32(), MachineType::Int64(), | 1531 MachineType::Float64(), MachineType::Int32(), MachineType::Int64(), |
| 1532 MachineType::Int32(), MachineType::Int32()}; | 1532 MachineType::Int32(), MachineType::Int32()}; |
| 1533 | 1533 |
| 1534 int num_params = static_cast<int>(arraysize(mixed)) - start; | 1534 int num_params = static_cast<int>(arraysize(mixed)) - start; |
| 1535 for (int which = 0; which < num_params; which++) { | 1535 for (int which = 0; which < num_params; which++) { |
| 1536 v8::internal::AccountingAllocator allocator; | 1536 v8::internal::AccountingAllocator allocator; |
| 1537 Zone zone(&allocator, ZONE_NAME); | 1537 Zone zone(&allocator, ZONE_NAME); |
| 1538 WasmRunner<int32_t> r(execution_mode); | 1538 WasmRunner<int32_t> r(execution_mode); |
| 1539 r.module().AddMemory(1024); | 1539 r.module().AddMemory(1024); |
| 1540 MachineType* memtypes = &mixed[start]; | 1540 MachineType* memtypes = &mixed[start]; |
| 1541 MachineType result = memtypes[which]; | 1541 MachineType result = memtypes[which]; |
| 1542 | 1542 |
| 1543 // ========================================================================= | 1543 // ========================================================================= |
| 1544 // Build the selector function. | 1544 // Build the selector function. |
| 1545 // ========================================================================= | 1545 // ========================================================================= |
| 1546 FunctionSig::Builder b(&zone, 1, num_params); | 1546 FunctionSig::Builder b(&zone, 1, num_params); |
| 1547 b.AddReturn(WasmOpcodes::LocalTypeFor(result)); | 1547 b.AddReturn(WasmOpcodes::ValueTypeFor(result)); |
| 1548 for (int i = 0; i < num_params; i++) { | 1548 for (int i = 0; i < num_params; i++) { |
| 1549 b.AddParam(WasmOpcodes::LocalTypeFor(memtypes[i])); | 1549 b.AddParam(WasmOpcodes::ValueTypeFor(memtypes[i])); |
| 1550 } | 1550 } |
| 1551 WasmFunctionCompiler& t = r.NewFunction(b.Build()); | 1551 WasmFunctionCompiler& t = r.NewFunction(b.Build()); |
| 1552 BUILD(t, WASM_GET_LOCAL(which)); | 1552 BUILD(t, WASM_GET_LOCAL(which)); |
| 1553 | 1553 |
| 1554 // ========================================================================= | 1554 // ========================================================================= |
| 1555 // Build the calling function. | 1555 // Build the calling function. |
| 1556 // ========================================================================= | 1556 // ========================================================================= |
| 1557 std::vector<byte> code; | 1557 std::vector<byte> code; |
| 1558 | 1558 |
| 1559 // Load the offset for the store. | 1559 // Load the offset for the store. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1591 CHECK_EQ(expected, result); | 1591 CHECK_EQ(expected, result); |
| 1592 } | 1592 } |
| 1593 } | 1593 } |
| 1594 } | 1594 } |
| 1595 } | 1595 } |
| 1596 | 1596 |
| 1597 WASM_EXEC_TEST(MixedCall_i64_0) { Run_WasmMixedCall_N(execution_mode, 0); } | 1597 WASM_EXEC_TEST(MixedCall_i64_0) { Run_WasmMixedCall_N(execution_mode, 0); } |
| 1598 WASM_EXEC_TEST(MixedCall_i64_1) { Run_WasmMixedCall_N(execution_mode, 1); } | 1598 WASM_EXEC_TEST(MixedCall_i64_1) { Run_WasmMixedCall_N(execution_mode, 1); } |
| 1599 WASM_EXEC_TEST(MixedCall_i64_2) { Run_WasmMixedCall_N(execution_mode, 2); } | 1599 WASM_EXEC_TEST(MixedCall_i64_2) { Run_WasmMixedCall_N(execution_mode, 2); } |
| 1600 WASM_EXEC_TEST(MixedCall_i64_3) { Run_WasmMixedCall_N(execution_mode, 3); } | 1600 WASM_EXEC_TEST(MixedCall_i64_3) { Run_WasmMixedCall_N(execution_mode, 3); } |
| OLD | NEW |