Revert of [wasm] Make WasmRunner the central test structure (patchset #5 id:80001 of https://codereview.chromium.org/2551043002/ )

Reason for revert:
Win64 dbg failures

Original issue's description:
> [wasm] Make WasmRunner the central test structure
>
> The WasmRunner now always holds a TestingModule, and allows to add
> several functions to it. The prepares a change to always run wasm code
> with a full module behind it, removing the special handling for "no wasm
> instance" at runtime (http://crrev.com/2551053002).
> This CL here also templatizes the WasmRunner such that the Call method must
> be called with the same signature specified for the WasmRunner. This
> already catched several mismatches there.
>
> R=titzer@chromium.org, ahaas@chromium.org
> BUG=v8:5620
>
> Review-Url: https://codereview.chromium.org/2551043002
> Cr-Commit-Position: refs/heads/master@{#41728}
> Committed: 2ff5906231

TBR=ahaas@chromium.org,titzer@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:5620

Review-Url: https://codereview.chromium.org/2583543002
Cr-Commit-Position: refs/heads/master@{#41732}
This commit is contained in:
clemensh 2016-12-15 08:51:11 -08:00 committed by Commit bot
parent 7ca7229283
commit 5993a1161b
11 changed files with 1353 additions and 1013 deletions

View File

@ -120,7 +120,7 @@ WASM_EXEC_TEST(I64Const_many) {
WASM_EXEC_TEST(Return_I64) {
REQUIRE(I64Return);
WasmRunner<int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_RETURN1(WASM_GET_LOCAL(0)));
@ -129,7 +129,8 @@ WASM_EXEC_TEST(Return_I64) {
WASM_EXEC_TEST(I64Add) {
REQUIRE(I64Add);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i + *j, r.Call(*i, *j)); }
@ -138,7 +139,8 @@ WASM_EXEC_TEST(I64Add) {
WASM_EXEC_TEST(I64Sub) {
REQUIRE(I64Sub);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i - *j, r.Call(*i, *j)); }
@ -148,7 +150,8 @@ WASM_EXEC_TEST(I64Sub) {
WASM_EXEC_TEST(I64AddUseOnlyLowWord) {
REQUIRE(I64Add);
REQUIRE(I32ConvertI64);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I32_CONVERT_I64(
WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
FOR_INT64_INPUTS(i) {
@ -161,7 +164,8 @@ WASM_EXEC_TEST(I64AddUseOnlyLowWord) {
WASM_EXEC_TEST(I64SubUseOnlyLowWord) {
REQUIRE(I64Sub);
REQUIRE(I32ConvertI64);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I32_CONVERT_I64(
WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
FOR_INT64_INPUTS(i) {
@ -174,7 +178,8 @@ WASM_EXEC_TEST(I64SubUseOnlyLowWord) {
WASM_EXEC_TEST(I64MulUseOnlyLowWord) {
REQUIRE(I64Mul);
REQUIRE(I32ConvertI64);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I32_CONVERT_I64(
WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
FOR_INT64_INPUTS(i) {
@ -187,7 +192,8 @@ WASM_EXEC_TEST(I64MulUseOnlyLowWord) {
WASM_EXEC_TEST(I64ShlUseOnlyLowWord) {
REQUIRE(I64Shl);
REQUIRE(I32ConvertI64);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I32_CONVERT_I64(
WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
FOR_INT64_INPUTS(i) {
@ -201,7 +207,8 @@ WASM_EXEC_TEST(I64ShlUseOnlyLowWord) {
WASM_EXEC_TEST(I64ShrUseOnlyLowWord) {
REQUIRE(I64ShrU);
REQUIRE(I32ConvertI64);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I32_CONVERT_I64(
WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
FOR_UINT64_INPUTS(i) {
@ -215,7 +222,8 @@ WASM_EXEC_TEST(I64ShrUseOnlyLowWord) {
WASM_EXEC_TEST(I64SarUseOnlyLowWord) {
REQUIRE(I64ShrS);
REQUIRE(I32ConvertI64);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I32_CONVERT_I64(
WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
FOR_INT64_INPUTS(i) {
@ -228,7 +236,8 @@ WASM_EXEC_TEST(I64SarUseOnlyLowWord) {
WASM_EXEC_TEST_WITH_TRAP(I64DivS) {
REQUIRE(I64DivS);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) {
@ -245,7 +254,8 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivS) {
WASM_EXEC_TEST_WITH_TRAP(I64DivS_Trap) {
REQUIRE(I64DivS);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(0, r.Call(asi64(0), asi64(100)));
CHECK_TRAP64(r.Call(asi64(100), asi64(0)));
@ -257,7 +267,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivS_Trap) {
WASM_EXEC_TEST_WITH_TRAP(I64DivS_Byzero_Const) {
REQUIRE(I64DivS);
for (int8_t denom = -2; denom < 8; denom++) {
WasmRunner<int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(denom)));
for (int64_t val = -7; val < 8; val++) {
if (denom == 0) {
@ -271,7 +281,8 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivS_Byzero_Const) {
WASM_EXEC_TEST_WITH_TRAP(I64DivU) {
REQUIRE(I64DivU);
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(),
MachineType::Uint64());
BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
FOR_UINT64_INPUTS(j) {
@ -286,9 +297,10 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivU) {
WASM_EXEC_TEST_WITH_TRAP(I64DivU_Trap) {
REQUIRE(I64DivU);
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(),
MachineType::Uint64());
BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(0, r.Call(asu64(0), asu64(100)));
CHECK_EQ(0u, r.Call(asu64(0), asu64(100)));
CHECK_TRAP64(r.Call(asu64(100), asu64(0)));
CHECK_TRAP64(r.Call(asu64(1001), asu64(0)));
CHECK_TRAP64(r.Call(std::numeric_limits<uint64_t>::max(), asu64(0)));
@ -297,7 +309,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivU_Trap) {
WASM_EXEC_TEST_WITH_TRAP(I64DivU_Byzero_Const) {
REQUIRE(I64DivU);
for (uint64_t denom = 0xfffffffffffffffe; denom < 8; denom++) {
WasmRunner<uint64_t, uint64_t> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64());
BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(denom)));
for (uint64_t val = 0xfffffffffffffff0; val < 8; val++) {
@ -312,7 +324,8 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivU_Byzero_Const) {
WASM_EXEC_TEST_WITH_TRAP(I64RemS) {
REQUIRE(I64RemS);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) {
@ -327,7 +340,8 @@ WASM_EXEC_TEST_WITH_TRAP(I64RemS) {
WASM_EXEC_TEST_WITH_TRAP(I64RemS_Trap) {
REQUIRE(I64RemS);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(33, r.Call(asi64(133), asi64(100)));
CHECK_EQ(0, r.Call(std::numeric_limits<int64_t>::min(), asi64(-1)));
@ -338,7 +352,8 @@ WASM_EXEC_TEST_WITH_TRAP(I64RemS_Trap) {
WASM_EXEC_TEST_WITH_TRAP(I64RemU) {
REQUIRE(I64RemU);
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(),
MachineType::Uint64());
BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
FOR_UINT64_INPUTS(j) {
@ -353,9 +368,10 @@ WASM_EXEC_TEST_WITH_TRAP(I64RemU) {
WASM_EXEC_TEST_WITH_TRAP(I64RemU_Trap) {
REQUIRE(I64RemU);
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(),
MachineType::Uint64());
BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(17, r.Call(asu64(217), asu64(100)));
CHECK_EQ(17u, r.Call(asu64(217), asu64(100)));
CHECK_TRAP64(r.Call(asu64(100), asu64(0)));
CHECK_TRAP64(r.Call(asu64(1001), asu64(0)));
CHECK_TRAP64(r.Call(std::numeric_limits<uint64_t>::max(), asu64(0)));
@ -363,7 +379,8 @@ WASM_EXEC_TEST_WITH_TRAP(I64RemU_Trap) {
WASM_EXEC_TEST(I64And) {
REQUIRE(I64And);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_AND(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ((*i) & (*j), r.Call(*i, *j)); }
@ -372,7 +389,8 @@ WASM_EXEC_TEST(I64And) {
WASM_EXEC_TEST(I64Ior) {
REQUIRE(I64Ior);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ((*i) | (*j), r.Call(*i, *j)); }
@ -381,7 +399,8 @@ WASM_EXEC_TEST(I64Ior) {
WASM_EXEC_TEST(I64Xor) {
REQUIRE(I64Xor);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ((*i) ^ (*j), r.Call(*i, *j)); }
@ -391,7 +410,8 @@ WASM_EXEC_TEST(I64Xor) {
WASM_EXEC_TEST(I64Shl) {
REQUIRE(I64Shl);
{
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(),
MachineType::Uint64());
BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
@ -402,22 +422,22 @@ WASM_EXEC_TEST(I64Shl) {
}
}
{
WasmRunner<uint64_t, int64_t> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(0)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 0, r.Call(*i)); }
}
{
WasmRunner<uint64_t, int64_t> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(32)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 32, r.Call(*i)); }
}
{
WasmRunner<uint64_t, int64_t> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(20)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 20, r.Call(*i)); }
}
{
WasmRunner<uint64_t, int64_t> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(40)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 40, r.Call(*i)); }
}
@ -426,7 +446,8 @@ WASM_EXEC_TEST(I64Shl) {
WASM_EXEC_TEST(I64ShrU) {
REQUIRE(I64ShrU);
{
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(),
MachineType::Uint64());
BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
@ -437,22 +458,22 @@ WASM_EXEC_TEST(I64ShrU) {
}
}
{
WasmRunner<uint64_t, int64_t> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(0)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 0, r.Call(*i)); }
}
{
WasmRunner<uint64_t, int64_t> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(32)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 32, r.Call(*i)); }
}
{
WasmRunner<uint64_t, int64_t> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(20)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 20, r.Call(*i)); }
}
{
WasmRunner<uint64_t, int64_t> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(40)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 40, r.Call(*i)); }
}
@ -461,7 +482,8 @@ WASM_EXEC_TEST(I64ShrU) {
WASM_EXEC_TEST(I64ShrS) {
REQUIRE(I64ShrS);
{
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
@ -472,22 +494,22 @@ WASM_EXEC_TEST(I64ShrS) {
}
}
{
WasmRunner<int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(0)));
FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 0, r.Call(*i)); }
}
{
WasmRunner<int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(32)));
FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 32, r.Call(*i)); }
}
{
WasmRunner<int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(20)));
FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 20, r.Call(*i)); }
}
{
WasmRunner<int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(40)));
FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 40, r.Call(*i)); }
}
@ -495,7 +517,8 @@ WASM_EXEC_TEST(I64ShrS) {
WASM_EXEC_TEST(I64Eq) {
REQUIRE(I64Eq);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i == *j ? 1 : 0, r.Call(*i, *j)); }
@ -504,7 +527,8 @@ WASM_EXEC_TEST(I64Eq) {
WASM_EXEC_TEST(I64Ne) {
REQUIRE(I64Ne);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_NE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i != *j ? 1 : 0, r.Call(*i, *j)); }
@ -513,7 +537,8 @@ WASM_EXEC_TEST(I64Ne) {
WASM_EXEC_TEST(I64LtS) {
REQUIRE(I64LtS);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i < *j ? 1 : 0, r.Call(*i, *j)); }
@ -522,7 +547,8 @@ WASM_EXEC_TEST(I64LtS) {
WASM_EXEC_TEST(I64LeS) {
REQUIRE(I64LeS);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_LES(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i <= *j ? 1 : 0, r.Call(*i, *j)); }
@ -531,7 +557,8 @@ WASM_EXEC_TEST(I64LeS) {
WASM_EXEC_TEST(I64LtU) {
REQUIRE(I64LtU);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
FOR_UINT64_INPUTS(j) { CHECK_EQ(*i < *j ? 1 : 0, r.Call(*i, *j)); }
@ -540,7 +567,8 @@ WASM_EXEC_TEST(I64LtU) {
WASM_EXEC_TEST(I64LeU) {
REQUIRE(I64LeU);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
FOR_UINT64_INPUTS(j) { CHECK_EQ(*i <= *j ? 1 : 0, r.Call(*i, *j)); }
@ -549,7 +577,8 @@ WASM_EXEC_TEST(I64LeU) {
WASM_EXEC_TEST(I64GtS) {
REQUIRE(I64GtS);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i > *j ? 1 : 0, r.Call(*i, *j)); }
@ -558,7 +587,8 @@ WASM_EXEC_TEST(I64GtS) {
WASM_EXEC_TEST(I64GeS) {
REQUIRE(I64GeS);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_GES(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i >= *j ? 1 : 0, r.Call(*i, *j)); }
@ -567,7 +597,8 @@ WASM_EXEC_TEST(I64GeS) {
WASM_EXEC_TEST(I64GtU) {
REQUIRE(I64GtU);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
FOR_UINT64_INPUTS(j) { CHECK_EQ(*i > *j ? 1 : 0, r.Call(*i, *j)); }
@ -576,7 +607,8 @@ WASM_EXEC_TEST(I64GtU) {
WASM_EXEC_TEST(I64GeU) {
REQUIRE(I64GeU);
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
FOR_UINT64_INPUTS(j) { CHECK_EQ(*i >= *j ? 1 : 0, r.Call(*i, *j)); }
@ -594,14 +626,14 @@ WASM_EXEC_TEST(I32ConvertI64) {
WASM_EXEC_TEST(I64SConvertI32) {
REQUIRE(I64SConvertI32);
WasmRunner<int64_t, int32_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int32());
BUILD(r, WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(I64UConvertI32) {
REQUIRE(I64UConvertI32);
WasmRunner<int64_t, uint32_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Uint32());
BUILD(r, WASM_I64_UCONVERT_I32(WASM_GET_LOCAL(0)));
FOR_UINT32_INPUTS(i) { CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); }
}
@ -616,7 +648,7 @@ WASM_EXEC_TEST(I64Popcnt) {
{26, 0x1123456782345678},
{38, 0xffedcba09edcba09}};
WasmRunner<int64_t, uint64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Uint64());
BUILD(r, WASM_I64_POPCNT(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(values[i].expected, r.Call(values[i].input));
@ -625,7 +657,7 @@ WASM_EXEC_TEST(I64Popcnt) {
WASM_EXEC_TEST(F32SConvertI64) {
REQUIRE(F32SConvertI64);
WasmRunner<float, int64_t> r(execution_mode);
WasmRunner<float> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_F32_SCONVERT_I64(WASM_GET_LOCAL(0)));
FOR_INT64_INPUTS(i) { CHECK_FLOAT_EQ(static_cast<float>(*i), r.Call(*i)); }
}
@ -711,7 +743,7 @@ WASM_EXEC_TEST(F32UConvertI64) {
{0x8000008000000001, 0x5f000001},
{0x8000000000000400, 0x5f000000},
{0x8000000000000401, 0x5f000000}};
WasmRunner<float, uint64_t> r(execution_mode);
WasmRunner<float> r(execution_mode, MachineType::Uint64());
BUILD(r, WASM_F32_UCONVERT_I64(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(bit_cast<float>(values[i].expected), r.Call(values[i].input));
@ -720,7 +752,7 @@ WASM_EXEC_TEST(F32UConvertI64) {
WASM_EXEC_TEST(F64SConvertI64) {
REQUIRE(F64SConvertI64);
WasmRunner<double, int64_t> r(execution_mode);
WasmRunner<double> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_F64_SCONVERT_I64(WASM_GET_LOCAL(0)));
FOR_INT64_INPUTS(i) { CHECK_DOUBLE_EQ(static_cast<double>(*i), r.Call(*i)); }
}
@ -805,7 +837,7 @@ WASM_EXEC_TEST(F64UConvertI64) {
{0x8000008000000001, 0x43e0000010000000},
{0x8000000000000400, 0x43e0000000000000},
{0x8000000000000401, 0x43e0000000000001}};
WasmRunner<double, uint64_t> r(execution_mode);
WasmRunner<double> r(execution_mode, MachineType::Uint64());
BUILD(r, WASM_F64_UCONVERT_I64(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(bit_cast<double>(values[i].expected), r.Call(values[i].input));
@ -813,7 +845,7 @@ WASM_EXEC_TEST(F64UConvertI64) {
}
WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32a) {
WasmRunner<int64_t, float> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
@ -827,7 +859,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32a) {
}
WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64a) {
WasmRunner<int64_t, double> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
@ -841,7 +873,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64a) {
}
WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32a) {
WasmRunner<uint64_t, float> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_I64_UCONVERT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
@ -855,7 +887,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32a) {
}
WASM_EXEC_TEST_WITH_TRAP(I64UConvertF64a) {
WasmRunner<uint64_t, double> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_I64_UCONVERT_F64(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
@ -869,23 +901,28 @@ WASM_EXEC_TEST_WITH_TRAP(I64UConvertF64a) {
}
WASM_EXEC_TEST(CallI64Parameter) {
// Build the target function.
LocalType param_types[20];
for (int i = 0; i < 20; i++) param_types[i] = kAstI64;
param_types[3] = kAstI32;
param_types[4] = kAstI32;
FunctionSig sig(1, 19, param_types);
for (int i = 0; i < 19; i++) {
if (i == 2 || i == 3) continue;
WasmRunner<int32_t> r(execution_mode);
// Build the target function.
WasmFunctionCompiler& t = r.NewFunction(&sig);
TestingModule module(execution_mode);
WasmFunctionCompiler t(&sig, &module);
if (i == 2 || i == 3) {
continue;
} else {
BUILD(t, WASM_GET_LOCAL(i));
}
uint32_t index = t.CompileAndAdd();
// Build the calling function.
WasmRunner<int32_t> r(&module);
BUILD(
r,
WASM_I32_CONVERT_I64(WASM_CALL_FUNCTION(
t.function_index(), WASM_I64V_9(0xbcd12340000000b),
index, WASM_I64V_9(0xbcd12340000000b),
WASM_I64V_9(0xbcd12340000000c), WASM_I32V_1(0xd),
WASM_I32_CONVERT_I64(WASM_I64V_9(0xbcd12340000000e)),
WASM_I64V_9(0xbcd12340000000f), WASM_I64V_10(0xbcd1234000000010),
@ -910,7 +947,8 @@ void TestI64Binop(WasmExecutionMode execution_mode, WasmOpcode opcode,
CHECK_EQ(expected, r.Call());
}
{
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
// return a op b
BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(expected, r.Call(a, b));
@ -926,7 +964,8 @@ void TestI64Cmp(WasmExecutionMode execution_mode, WasmOpcode opcode,
CHECK_EQ(expected, r.Call());
}
{
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
// return a op b
BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(expected, r.Call(a, b));
@ -1029,7 +1068,7 @@ WASM_EXEC_TEST(I64Clz) {
{62, 0x0000000000000002}, {63, 0x0000000000000001},
{64, 0x0000000000000000}};
WasmRunner<int64_t, uint64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Uint64());
BUILD(r, WASM_I64_CLZ(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(values[i].expected, r.Call(values[i].input));
@ -1075,7 +1114,7 @@ WASM_EXEC_TEST(I64Ctz) {
{2, 0x000000009afdbc84}, {1, 0x000000009afdbc82},
{0, 0x000000009afdbc81}};
WasmRunner<int64_t, uint64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Uint64());
BUILD(r, WASM_I64_CTZ(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(values[i].expected, r.Call(values[i].input));
@ -1093,7 +1132,7 @@ WASM_EXEC_TEST(I64Popcnt2) {
{26, 0x1123456782345678},
{38, 0xffedcba09edcba09}};
WasmRunner<int64_t, uint64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Uint64());
BUILD(r, WASM_I64_POPCNT(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(values[i].expected, r.Call(values[i].input));
@ -1111,19 +1150,21 @@ WASM_EXEC_TEST(I64WasmRunner) {
}
}
{
WasmRunner<int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_GET_LOCAL(0));
FOR_INT64_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
{
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i ^ *j, r.Call(*i, *j)); }
}
}
{
WasmRunner<int64_t, int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64(), MachineType::Int64());
BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0),
WASM_I64_XOR(WASM_GET_LOCAL(1), WASM_GET_LOCAL(2))));
FOR_INT64_INPUTS(i) {
@ -1135,7 +1176,9 @@ WASM_EXEC_TEST(I64WasmRunner) {
}
}
{
WasmRunner<int64_t, int64_t, int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64(), MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0),
WASM_I64_XOR(WASM_GET_LOCAL(1),
WASM_I64_XOR(WASM_GET_LOCAL(2),
@ -1153,15 +1196,16 @@ WASM_EXEC_TEST(I64WasmRunner) {
WASM_EXEC_TEST(Call_Int64Sub) {
REQUIRE(I64Sub);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
// Build the target function.
TestSignatures sigs;
WasmFunctionCompiler& t = r.NewFunction(sigs.l_ll());
TestingModule module(execution_mode);
WasmFunctionCompiler t(sigs.l_ll(), &module);
BUILD(t, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
uint32_t index = t.CompileAndAdd();
// Build the caller function.
BUILD(r, WASM_CALL_FUNCTION(t.function_index(), WASM_GET_LOCAL(0),
WASM_GET_LOCAL(1)));
WasmRunner<int64_t> r(&module, MachineType::Int64(), MachineType::Int64());
BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT32_INPUTS(i) {
FOR_INT32_INPUTS(j) {
@ -1184,8 +1228,9 @@ WASM_EXEC_TEST(LoadStoreI64_sx) {
kExprI64LoadMem};
for (size_t m = 0; m < arraysize(loads); m++) {
WasmRunner<int64_t> r(execution_mode);
byte* memory = r.module().AddMemoryElems<byte>(16);
TestingModule module(execution_mode);
byte* memory = module.AddMemoryElems<byte>(16);
WasmRunner<int64_t> r(&module);
byte code[] = {
kExprI8Const, 8, // --
@ -1207,7 +1252,7 @@ WASM_EXEC_TEST(LoadStoreI64_sx) {
// Try a bunch of different negative values.
for (int i = -1; i >= -128; i -= 11) {
int size = 1 << m;
r.module().BlankMemory();
module.BlankMemory();
memory[size - 1] = static_cast<byte>(i); // set the high order byte.
int64_t expected = static_cast<int64_t>(i) << ((size - 1) * 8);
@ -1223,7 +1268,7 @@ WASM_EXEC_TEST(LoadStoreI64_sx) {
WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32b) {
REQUIRE(I64SConvertF32);
WasmRunner<int64_t, float> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
@ -1238,7 +1283,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32b) {
WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64b) {
REQUIRE(I64SConvertF64);
WasmRunner<int64_t, double> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
@ -1253,7 +1298,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64b) {
WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32b) {
REQUIRE(I64UConvertF32);
WasmRunner<uint64_t, float> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_I64_UCONVERT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
@ -1267,7 +1312,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32b) {
WASM_EXEC_TEST_WITH_TRAP(I64UConvertF64b) {
REQUIRE(I64UConvertF64);
WasmRunner<uint64_t, double> r(execution_mode);
WasmRunner<uint64_t> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_I64_UCONVERT_F64(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
@ -1281,23 +1326,25 @@ WASM_EXEC_TEST_WITH_TRAP(I64UConvertF64b) {
WASM_EXEC_TEST(I64ReinterpretF64) {
REQUIRE(I64ReinterpretF64);
WasmRunner<int64_t> r(execution_mode);
int64_t* memory = r.module().AddMemoryElems<int64_t>(8);
TestingModule module(execution_mode);
int64_t* memory = module.AddMemoryElems<int64_t>(8);
WasmRunner<int64_t> r(&module);
BUILD(r, WASM_I64_REINTERPRET_F64(
WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)));
FOR_INT32_INPUTS(i) {
int64_t expected = static_cast<int64_t>(*i) * 0x300010001;
r.module().WriteMemory(&memory[0], expected);
module.WriteMemory(&memory[0], expected);
CHECK_EQ(expected, r.Call());
}
}
WASM_EXEC_TEST(F64ReinterpretI64) {
REQUIRE(F64ReinterpretI64);
WasmRunner<int64_t, int64_t> r(execution_mode);
int64_t* memory = r.module().AddMemoryElems<int64_t>(8);
TestingModule module(execution_mode);
int64_t* memory = module.AddMemoryElems<int64_t>(8);
WasmRunner<int64_t> r(&module, MachineType::Int64());
BUILD(r, WASM_STORE_MEM(MachineType::Float64(), WASM_ZERO,
WASM_F64_REINTERPRET_I64(WASM_GET_LOCAL(0))),
@ -1306,45 +1353,47 @@ WASM_EXEC_TEST(F64ReinterpretI64) {
FOR_INT32_INPUTS(i) {
int64_t expected = static_cast<int64_t>(*i) * 0x300010001;
CHECK_EQ(expected, r.Call(expected));
CHECK_EQ(expected, r.module().ReadMemory<int64_t>(&memory[0]));
CHECK_EQ(expected, module.ReadMemory<int64_t>(&memory[0]));
}
}
WASM_EXEC_TEST(LoadMemI64) {
REQUIRE(I64LoadStore);
WasmRunner<int64_t> r(execution_mode);
int64_t* memory = r.module().AddMemoryElems<int64_t>(8);
r.module().RandomizeMemory(1111);
TestingModule module(execution_mode);
int64_t* memory = module.AddMemoryElems<int64_t>(8);
module.RandomizeMemory(1111);
WasmRunner<int64_t> r(&module);
BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_I8(0)));
r.module().WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL);
module.WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL);
CHECK_EQ(0x1abbccdd00112233LL, r.Call());
r.module().WriteMemory<int64_t>(&memory[0], 0x33aabbccdd001122LL);
module.WriteMemory<int64_t>(&memory[0], 0x33aabbccdd001122LL);
CHECK_EQ(0x33aabbccdd001122LL, r.Call());
r.module().WriteMemory<int64_t>(&memory[0], 77777777);
module.WriteMemory<int64_t>(&memory[0], 77777777);
CHECK_EQ(77777777, r.Call());
}
WASM_EXEC_TEST(LoadMemI64_alignment) {
REQUIRE(I64LoadStore);
TestingModule module(execution_mode);
int64_t* memory = module.AddMemoryElems<int64_t>(8);
for (byte alignment = 0; alignment <= 3; alignment++) {
WasmRunner<int64_t> r(execution_mode);
int64_t* memory = r.module().AddMemoryElems<int64_t>(8);
r.module().RandomizeMemory(1111);
module.RandomizeMemory(1111);
WasmRunner<int64_t> r(&module);
BUILD(r,
WASM_LOAD_MEM_ALIGNMENT(MachineType::Int64(), WASM_I8(0), alignment));
r.module().WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL);
module.WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL);
CHECK_EQ(0x1abbccdd00112233LL, r.Call());
r.module().WriteMemory<int64_t>(&memory[0], 0x33aabbccdd001122LL);
module.WriteMemory<int64_t>(&memory[0], 0x33aabbccdd001122LL);
CHECK_EQ(0x33aabbccdd001122LL, r.Call());
r.module().WriteMemory<int64_t>(&memory[0], 77777777);
module.WriteMemory<int64_t>(&memory[0], 77777777);
CHECK_EQ(77777777, r.Call());
}
}
@ -1355,8 +1404,9 @@ WASM_EXEC_TEST(MemI64_Sum) {
REQUIRE(I64Sub);
REQUIRE(I64Phi);
const int kNumElems = 20;
WasmRunner<uint64_t, int32_t> r(execution_mode);
uint64_t* memory = r.module().AddMemoryElems<uint64_t>(kNumElems);
TestingModule module(execution_mode);
uint64_t* memory = module.AddMemoryElems<uint64_t>(kNumElems);
WasmRunner<uint64_t> r(&module, MachineType::Int32());
const byte kSum = r.AllocateLocal(kAstI64);
BUILD(
@ -1373,10 +1423,10 @@ WASM_EXEC_TEST(MemI64_Sum) {
// Run 4 trials.
for (int i = 0; i < 3; i++) {
r.module().RandomizeMemory(i * 33);
module.RandomizeMemory(i * 33);
uint64_t expected = 0;
for (size_t j = kNumElems - 1; j > 0; j--) {
expected += r.module().ReadMemory(&memory[j]);
expected += module.ReadMemory(&memory[j]);
}
uint64_t result = r.Call(8 * (kNumElems - 1));
CHECK_EQ(expected, result);
@ -1384,19 +1434,20 @@ WASM_EXEC_TEST(MemI64_Sum) {
}
WASM_EXEC_TEST(StoreMemI64_alignment) {
TestingModule module(execution_mode);
int64_t* memory = module.AddMemoryElems<int64_t>(4);
const int64_t kWritten = 0x12345678abcd0011ll;
for (byte i = 0; i <= 3; i++) {
WasmRunner<int64_t, int64_t> r(execution_mode);
int64_t* memory = r.module().AddMemoryElems<int64_t>(4);
WasmRunner<int64_t> r(&module, MachineType::Int64());
BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int64(), WASM_ZERO, i,
WASM_GET_LOCAL(0)),
WASM_GET_LOCAL(0));
r.module().RandomizeMemory(1111);
r.module().WriteMemory<int64_t>(&memory[0], 0);
module.RandomizeMemory(1111);
module.WriteMemory<int64_t>(&memory[0], 0);
CHECK_EQ(kWritten, r.Call(kWritten));
CHECK_EQ(kWritten, r.module().ReadMemory(&memory[0]));
CHECK_EQ(kWritten, module.ReadMemory(&memory[0]));
}
}
@ -1405,15 +1456,16 @@ WASM_EXEC_TEST(I64Global) {
REQUIRE(I64SConvertI32);
REQUIRE(I64And);
REQUIRE(DepthFirst);
WasmRunner<int32_t, int32_t> r(execution_mode);
int64_t* global = r.module().AddGlobal<int64_t>();
TestingModule module(execution_mode);
int64_t* global = module.AddGlobal<int64_t>(kAstI64);
WasmRunner<int32_t> r(&module, MachineType::Int32());
// global = global + p0
BUILD(r, WASM_SET_GLOBAL(
0, WASM_I64_AND(WASM_GET_GLOBAL(0),
WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)))),
WASM_ZERO);
r.module().WriteMemory<int64_t>(global, 0xFFFFFFFFFFFFFFFFLL);
module.WriteMemory<int64_t>(global, 0xFFFFFFFFFFFFFFFFLL);
for (int i = 9; i < 444444; i += 111111) {
int64_t expected = *global & i;
r.Call(i);
@ -1424,7 +1476,7 @@ WASM_EXEC_TEST(I64Global) {
WASM_EXEC_TEST(I64Eqz) {
REQUIRE(I64Eq);
WasmRunner<int32_t, int64_t> r(execution_mode);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_I64_EQZ(WASM_GET_LOCAL(0)));
FOR_INT64_INPUTS(i) {
@ -1435,7 +1487,8 @@ WASM_EXEC_TEST(I64Eqz) {
WASM_EXEC_TEST(I64Ror) {
REQUIRE(I64Ror);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
@ -1448,7 +1501,8 @@ WASM_EXEC_TEST(I64Ror) {
WASM_EXEC_TEST(I64Rol) {
REQUIRE(I64Rol);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
BUILD(r, WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
@ -1460,6 +1514,9 @@ WASM_EXEC_TEST(I64Rol) {
}
WASM_EXEC_TEST_WITH_TRAP(StoreMem_offset_oob_i64) {
TestingModule module(execution_mode);
byte* memory = module.AddMemoryElems<byte>(32);
static const MachineType machineTypes[] = {
MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
@ -1467,9 +1524,8 @@ WASM_EXEC_TEST_WITH_TRAP(StoreMem_offset_oob_i64) {
MachineType::Float64()};
for (size_t m = 0; m < arraysize(machineTypes); m++) {
WasmRunner<int32_t, uint32_t> r(execution_mode);
byte* memory = r.module().AddMemoryElems<byte>(32);
r.module().RandomizeMemory(1119 + static_cast<int>(m));
module.RandomizeMemory(1119 + static_cast<int>(m));
WasmRunner<int32_t> r(&module, MachineType::Uint32());
BUILD(r, WASM_STORE_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0),
WASM_LOAD_MEM(machineTypes[m], WASM_ZERO)),
@ -1497,14 +1553,17 @@ static void CompileCallIndirectMany(LocalType param) {
// with many many parameters.
TestSignatures sigs;
for (byte num_params = 0; num_params < 40; num_params++) {
WasmRunner<void> r(kExecuteCompiled);
FunctionSig* sig = sigs.many(r.zone(), kAstStmt, param, num_params);
v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
HandleScope scope(CcTest::InitIsolateOnce());
TestingModule module(kExecuteCompiled);
FunctionSig* sig = sigs.many(&zone, kAstStmt, param, num_params);
r.module().AddSignature(sig);
r.module().AddSignature(sig);
r.module().AddIndirectFunctionTable(nullptr, 0);
module.AddSignature(sig);
module.AddSignature(sig);
module.AddIndirectFunctionTable(nullptr, 0);
WasmFunctionCompiler& t = r.NewFunction(sig);
WasmFunctionCompiler t(sig, &module);
std::vector<byte> code;
for (byte p = 0; p < num_params; p++) {
@ -1514,6 +1573,7 @@ static void CompileCallIndirectMany(LocalType param) {
ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO);
t.Build(&code[0], &code[0] + code.size());
t.Compile();
}
}
@ -1535,25 +1595,28 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
for (int which = 0; which < num_params; which++) {
v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
WasmRunner<int32_t> r(execution_mode);
r.module().AddMemory(1024);
TestingModule module(execution_mode);
module.AddMemory(1024);
MachineType* memtypes = &mixed[start];
MachineType result = memtypes[which];
// =========================================================================
// Build the selector function.
// =========================================================================
uint32_t index;
FunctionSig::Builder b(&zone, 1, num_params);
b.AddReturn(WasmOpcodes::LocalTypeFor(result));
for (int i = 0; i < num_params; i++) {
b.AddParam(WasmOpcodes::LocalTypeFor(memtypes[i]));
}
WasmFunctionCompiler& t = r.NewFunction(b.Build());
WasmFunctionCompiler t(b.Build(), &module);
BUILD(t, WASM_GET_LOCAL(which));
index = t.CompileAndAdd();
// =========================================================================
// Build the calling function.
// =========================================================================
WasmRunner<int32_t> r(&module);
std::vector<byte> code;
// Load the offset for the store.
@ -1566,7 +1629,7 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
}
// Call the selector function.
ADD_CODE(code, WASM_CALL_FUNCTION0(t.function_index()));
ADD_CODE(code, kExprCallFunction, static_cast<byte>(index));
// Store the result in memory.
ADD_CODE(code,
@ -1580,14 +1643,14 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
// Run the code.
for (int t = 0; t < 10; t++) {
r.module().RandomizeMemory();
module.RandomizeMemory();
CHECK_EQ(kExpected, r.Call());
int size = WasmOpcodes::MemSize(result);
for (int i = 0; i < size; i++) {
int base = (which + 1) * kElemSize;
byte expected = r.module().raw_mem_at<byte>(base + i);
byte result = r.module().raw_mem_at<byte>(i);
byte expected = module.raw_mem_at<byte>(base + i);
byte result = module.raw_mem_at<byte>(i);
CHECK_EQ(expected, result);
}
}

View File

@ -38,8 +38,9 @@ uint32_t GetMatchingRelocInfoCount(Handle<Code> code, RelocInfo::Mode rmode) {
}
WASM_EXEC_TEST(Int32AsmjsDivS) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
BUILD(r, WASM_BINOP(kExprI32AsmjsDivS, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(0, r.Call(0, 100));
@ -50,8 +51,9 @@ WASM_EXEC_TEST(Int32AsmjsDivS) {
}
WASM_EXEC_TEST(Int32AsmjsRemS) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
BUILD(r, WASM_BINOP(kExprI32AsmjsRemS, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(33, r.Call(133, 100));
@ -62,8 +64,9 @@ WASM_EXEC_TEST(Int32AsmjsRemS) {
}
WASM_EXEC_TEST(Int32AsmjsDivU) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
BUILD(r, WASM_BINOP(kExprI32AsmjsDivU, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(0, r.Call(0, 100));
@ -74,8 +77,9 @@ WASM_EXEC_TEST(Int32AsmjsDivU) {
}
WASM_EXEC_TEST(Int32AsmjsRemU) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
BUILD(r, WASM_BINOP(kExprI32AsmjsRemU, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(17, r.Call(217, 100));
@ -86,8 +90,9 @@ WASM_EXEC_TEST(Int32AsmjsRemU) {
}
WASM_EXEC_TEST(I32AsmjsSConvertF32) {
WasmRunner<int32_t, float> r(execution_mode);
r.module().ChangeOriginToAsmjs();
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<int32_t> r(&module, MachineType::Float32());
BUILD(r, WASM_UNOP(kExprI32AsmjsSConvertF32, WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
@ -97,8 +102,9 @@ WASM_EXEC_TEST(I32AsmjsSConvertF32) {
}
WASM_EXEC_TEST(I32AsmjsSConvertF64) {
WasmRunner<int32_t, double> r(execution_mode);
r.module().ChangeOriginToAsmjs();
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<int32_t> r(&module, MachineType::Float64());
BUILD(r, WASM_UNOP(kExprI32AsmjsSConvertF64, WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
@ -108,8 +114,9 @@ WASM_EXEC_TEST(I32AsmjsSConvertF64) {
}
WASM_EXEC_TEST(I32AsmjsUConvertF32) {
WasmRunner<uint32_t, float> r(execution_mode);
r.module().ChangeOriginToAsmjs();
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<uint32_t> r(&module, MachineType::Float32());
BUILD(r, WASM_UNOP(kExprI32AsmjsUConvertF32, WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
@ -119,8 +126,9 @@ WASM_EXEC_TEST(I32AsmjsUConvertF32) {
}
WASM_EXEC_TEST(I32AsmjsUConvertF64) {
WasmRunner<uint32_t, double> r(execution_mode);
r.module().ChangeOriginToAsmjs();
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<uint32_t> r(&module, MachineType::Float64());
BUILD(r, WASM_UNOP(kExprI32AsmjsUConvertF64, WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
@ -130,10 +138,11 @@ WASM_EXEC_TEST(I32AsmjsUConvertF64) {
}
WASM_EXEC_TEST(LoadMemI32_oob_asm) {
WasmRunner<int32_t, uint32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
int32_t* memory = r.module().AddMemoryElems<int32_t>(8);
r.module().RandomizeMemory(1112);
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module, MachineType::Uint32());
module.RandomizeMemory(1112);
BUILD(r, WASM_UNOP(kExprI32AsmjsLoadMem, WASM_GET_LOCAL(0)));
@ -150,10 +159,11 @@ WASM_EXEC_TEST(LoadMemI32_oob_asm) {
}
WASM_EXEC_TEST(LoadMemF32_oob_asm) {
WasmRunner<float, uint32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
float* memory = r.module().AddMemoryElems<float>(8);
r.module().RandomizeMemory(1112);
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
float* memory = module.AddMemoryElems<float>(8);
WasmRunner<float> r(&module, MachineType::Uint32());
module.RandomizeMemory(1112);
BUILD(r, WASM_UNOP(kExprF32AsmjsLoadMem, WASM_GET_LOCAL(0)));
@ -170,10 +180,11 @@ WASM_EXEC_TEST(LoadMemF32_oob_asm) {
}
WASM_EXEC_TEST(LoadMemF64_oob_asm) {
WasmRunner<double, uint32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
double* memory = r.module().AddMemoryElems<double>(8);
r.module().RandomizeMemory(1112);
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
double* memory = module.AddMemoryElems<double>(8);
WasmRunner<double> r(&module, MachineType::Uint32());
module.RandomizeMemory(1112);
BUILD(r, WASM_UNOP(kExprF64AsmjsLoadMem, WASM_GET_LOCAL(0)));
@ -192,10 +203,11 @@ WASM_EXEC_TEST(LoadMemF64_oob_asm) {
}
WASM_EXEC_TEST(StoreMemI32_oob_asm) {
WasmRunner<int32_t, uint32_t, uint32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
int32_t* memory = r.module().AddMemoryElems<int32_t>(8);
r.module().RandomizeMemory(1112);
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module, MachineType::Uint32(), MachineType::Uint32());
module.RandomizeMemory(1112);
BUILD(r, WASM_BINOP(kExprI32AsmjsStoreMem, WASM_GET_LOCAL(0),
WASM_GET_LOCAL(1)));
@ -227,14 +239,14 @@ WASM_EXEC_TEST(StoreMemI32_oob_asm) {
#define INT_LOAD_TEST(OP_TYPE) \
TEST(RunWasm_AsmCheckedRelocInfo##OP_TYPE) { \
WasmRunner<int32_t, uint32_t> r(kExecuteCompiled); \
r.module().ChangeOriginToAsmjs(); \
TestingModule module(kExecuteCompiled); \
module.ChangeOriginToAsmjs(); \
WasmRunner<int32_t> r(&module, MachineType::Uint32()); \
BUILD(r, WASM_UNOP(OP_TYPE, WASM_GET_LOCAL(0))); \
CHECK_EQ(1, \
GetMatchingRelocInfoCount(r.module().instance->function_code[0], \
CHECK_EQ(1u, GetMatchingRelocInfoCount(module.instance->function_code[0], \
RelocInfo::WASM_MEMORY_REFERENCE)); \
CHECK_NE( \
0, GetMatchingRelocInfoCount(r.module().instance->function_code[0], \
0u, GetMatchingRelocInfoCount(module.instance->function_code[0], \
RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); \
}
@ -242,61 +254,70 @@ FOREACH_INT_CHECKED_LOAD_OP(INT_LOAD_TEST)
#define INT_STORE_TEST(OP_TYPE) \
TEST(RunWasm_AsmCheckedRelocInfo##OP_TYPE) { \
WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteCompiled); \
r.module().ChangeOriginToAsmjs(); \
TestingModule module(kExecuteCompiled); \
module.ChangeOriginToAsmjs(); \
WasmRunner<int32_t> r(&module, MachineType::Uint32(), \
MachineType::Uint32()); \
BUILD(r, WASM_BINOP(OP_TYPE, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); \
CHECK_EQ(1, \
GetMatchingRelocInfoCount(r.module().instance->function_code[0], \
CHECK_EQ(1u, GetMatchingRelocInfoCount(module.instance->function_code[0], \
RelocInfo::WASM_MEMORY_REFERENCE)); \
CHECK_NE( \
0, GetMatchingRelocInfoCount(r.module().instance->function_code[0], \
0u, GetMatchingRelocInfoCount(module.instance->function_code[0], \
RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); \
}
FOREACH_INT_CHECKED_STORE_OP(INT_STORE_TEST)
TEST(RunWasm_AsmCheckedLoadFloat32RelocInfo) {
WasmRunner<float, uint32_t> r(kExecuteCompiled);
r.module().ChangeOriginToAsmjs();
TestingModule module(kExecuteCompiled);
module.ChangeOriginToAsmjs();
WasmRunner<float> r(&module, MachineType::Uint32());
BUILD(r, WASM_UNOP(kExprF32AsmjsLoadMem, WASM_GET_LOCAL(0)));
CHECK_EQ(1, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
CHECK_EQ(1u, GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_REFERENCE));
CHECK_NE(0, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
CHECK_NE(0u,
GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
}
TEST(RunWasm_AsmCheckedStoreFloat32RelocInfo) {
WasmRunner<float, uint32_t, float> r(kExecuteCompiled);
r.module().ChangeOriginToAsmjs();
TestingModule module(kExecuteCompiled);
module.ChangeOriginToAsmjs();
WasmRunner<float> r(&module, MachineType::Uint32(), MachineType::Float32());
BUILD(r, WASM_BINOP(kExprF32AsmjsStoreMem, WASM_GET_LOCAL(0),
WASM_GET_LOCAL(1)));
CHECK_EQ(1, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
CHECK_EQ(1u, GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_REFERENCE));
CHECK_NE(0, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
CHECK_NE(0u,
GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
}
TEST(RunWasm_AsmCheckedLoadFloat64RelocInfo) {
WasmRunner<double, uint32_t> r(kExecuteCompiled);
r.module().ChangeOriginToAsmjs();
TestingModule module(kExecuteCompiled);
module.ChangeOriginToAsmjs();
WasmRunner<double> r(&module, MachineType::Uint32());
BUILD(r, WASM_UNOP(kExprF64AsmjsLoadMem, WASM_GET_LOCAL(0)));
CHECK_EQ(1, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
CHECK_EQ(1u, GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_REFERENCE));
CHECK_NE(0, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
CHECK_NE(0u,
GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
}
TEST(RunWasm_AsmCheckedStoreFloat64RelocInfo) {
WasmRunner<double, uint32_t, double> r(kExecuteCompiled);
r.module().ChangeOriginToAsmjs();
TestingModule module(kExecuteCompiled);
module.ChangeOriginToAsmjs();
WasmRunner<double> r(&module, MachineType::Uint32(), MachineType::Float64());
BUILD(r, WASM_BINOP(kExprF64AsmjsStoreMem, WASM_GET_LOCAL(0),
WASM_GET_LOCAL(1)));
CHECK_EQ(1, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
CHECK_EQ(1u, GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_REFERENCE));
CHECK_NE(0, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
CHECK_NE(0u,
GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
}

View File

@ -35,14 +35,14 @@ TEST(Run_WasmInt8Const_i) {
}
TEST(Run_WasmIfElse) {
WasmRunner<int32_t, int32_t> r(kExecuteInterpreted);
WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32());
BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(10)));
CHECK_EQ(10, r.Call(0));
CHECK_EQ(9, r.Call(1));
}
TEST(Run_WasmIfReturn) {
WasmRunner<int32_t, int32_t> r(kExecuteInterpreted);
WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32());
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I8(77))), WASM_I8(65));
CHECK_EQ(65, r.Call(0));
CHECK_EQ(77, r.Call(1));
@ -131,7 +131,8 @@ TEST(Run_WasmBlockBreakN) {
}
TEST(Run_Wasm_nested_ifs_i) {
WasmRunner<int32_t, int32_t, int32_t> r(kExecuteInterpreted);
WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32(),
MachineType::Int32());
BUILD(r, WASM_IF_ELSE_I(
WASM_GET_LOCAL(0),
@ -179,7 +180,8 @@ TEST(Breakpoint_I32Add) {
Find(code, sizeof(code), kNumBreakpoints, kExprGetLocal, kExprGetLocal,
kExprI32Add);
WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteInterpreted);
WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
MachineType::Uint32());
r.Build(code, code + arraysize(code));
@ -218,7 +220,8 @@ TEST(Step_I32Mul) {
static const int kTraceLength = 4;
byte code[] = {WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteInterpreted);
WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
MachineType::Uint32());
r.Build(code, code + arraysize(code));
@ -256,7 +259,8 @@ TEST(Breakpoint_I32And_disable) {
std::unique_ptr<int[]> offsets =
Find(code, sizeof(code), kNumBreakpoints, kExprI32And);
WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteInterpreted);
WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
MachineType::Uint32());
r.Build(code, code + arraysize(code));
@ -293,8 +297,9 @@ TEST(Breakpoint_I32And_disable) {
}
TEST(GrowMemory) {
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted);
r.module().AddMemory(WasmModule::kPageSize);
TestingModule module(kExecuteInterpreted);
WasmRunner<int32_t> r(&module, MachineType::Uint32());
module.AddMemory(WasmModule::kPageSize);
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
CHECK_EQ(1, r.Call(1));
}
@ -302,8 +307,9 @@ TEST(GrowMemory) {
TEST(GrowMemoryPreservesData) {
int32_t index = 16;
int32_t value = 2335;
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted);
r.module().AddMemory(WasmModule::kPageSize);
TestingModule module(kExecuteInterpreted);
WasmRunner<int32_t> r(&module, MachineType::Uint32());
module.AddMemory(WasmModule::kPageSize);
BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index),
WASM_I32V(value)),
WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), WASM_DROP,
@ -314,14 +320,16 @@ TEST(GrowMemoryPreservesData) {
TEST(GrowMemoryInvalidSize) {
{
// Grow memory by an invalid amount without initial memory.
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted);
TestingModule module(kExecuteInterpreted);
WasmRunner<int32_t> r(&module, MachineType::Uint32());
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
CHECK_EQ(-1, r.Call(1048575));
}
{
// Grow memory by an invalid amount without initial memory.
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted);
r.module().AddMemory(WasmModule::kPageSize);
TestingModule module(kExecuteInterpreted);
WasmRunner<int32_t> r(&module, MachineType::Uint32());
module.AddMemory(WasmModule::kPageSize);
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
CHECK_EQ(-1, r.Call(1048575));
}
@ -330,7 +338,9 @@ TEST(GrowMemoryInvalidSize) {
TEST(TestPossibleNondeterminism) {
{
// F32Div may produced NaN
WasmRunner<float, float, float> r(kExecuteInterpreted);
TestingModule module(kExecuteInterpreted);
WasmRunner<float> r(&module, MachineType::Float32(),
MachineType::Float32());
BUILD(r, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
r.Call(1048575.5f, 2.5f);
CHECK(!r.possible_nondeterminism());
@ -339,7 +349,8 @@ TEST(TestPossibleNondeterminism) {
}
{
// F32Sqrt may produced NaN
WasmRunner<float, float> r(kExecuteInterpreted);
TestingModule module(kExecuteInterpreted);
WasmRunner<float> r(&module, MachineType::Float32());
BUILD(r, WASM_F32_SQRT(WASM_GET_LOCAL(0)));
r.Call(16.0f);
CHECK(!r.possible_nondeterminism());
@ -348,7 +359,9 @@ TEST(TestPossibleNondeterminism) {
}
{
// F32Mul may produced NaN
WasmRunner<float, float, float> r(kExecuteInterpreted);
TestingModule module(kExecuteInterpreted);
WasmRunner<float> r(&module, MachineType::Float32(),
MachineType::Float32());
BUILD(r, WASM_F32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
r.Call(1048575.5f, 2.5f);
CHECK(!r.possible_nondeterminism());
@ -357,7 +370,9 @@ TEST(TestPossibleNondeterminism) {
}
{
// F64Div may produced NaN
WasmRunner<double, double, double> r(kExecuteInterpreted);
TestingModule module(kExecuteInterpreted);
WasmRunner<double> r(&module, MachineType::Float64(),
MachineType::Float64());
BUILD(r, WASM_F64_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
r.Call(1048575.5, 2.5);
CHECK(!r.possible_nondeterminism());
@ -366,7 +381,8 @@ TEST(TestPossibleNondeterminism) {
}
{
// F64Sqrt may produced NaN
WasmRunner<double, double> r(kExecuteInterpreted);
TestingModule module(kExecuteInterpreted);
WasmRunner<double> r(&module, MachineType::Float64());
BUILD(r, WASM_F64_SQRT(WASM_GET_LOCAL(0)));
r.Call(1048575.5);
CHECK(!r.possible_nondeterminism());
@ -375,7 +391,9 @@ TEST(TestPossibleNondeterminism) {
}
{
// F64Mul may produced NaN
WasmRunner<double, double, double> r(kExecuteInterpreted);
TestingModule module(kExecuteInterpreted);
WasmRunner<double> r(&module, MachineType::Float64(),
MachineType::Float64());
BUILD(r, WASM_F64_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
r.Call(1048575.5, 2.5);
CHECK(!r.possible_nondeterminism());

View File

@ -97,36 +97,48 @@ void EXPECT_CALL(double expected, Handle<JSFunction> jsfunc, double a,
} // namespace
TEST(Run_Int32Sub_jswrapped) {
WasmRunner<int, int, int> r(kExecuteCompiled);
BUILD(r, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index);
CcTest::InitializeVM();
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler t(sigs.i_ii(), &module);
BUILD(t, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
EXPECT_CALL(33, jsfunc, 44, 11);
EXPECT_CALL(-8723487, jsfunc, -8000000, 723487);
}
TEST(Run_Float32Div_jswrapped) {
WasmRunner<float, float, float> r(kExecuteCompiled);
BUILD(r, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index);
CcTest::InitializeVM();
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler t(sigs.f_ff(), &module);
BUILD(t, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
EXPECT_CALL(92, jsfunc, 46, 0.5);
EXPECT_CALL(64, jsfunc, -16, -0.25);
}
TEST(Run_Float64Add_jswrapped) {
WasmRunner<double, double, double> r(kExecuteCompiled);
BUILD(r, WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index);
CcTest::InitializeVM();
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler t(sigs.d_dd(), &module);
BUILD(t, WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
EXPECT_CALL(3, jsfunc, 2, 1);
EXPECT_CALL(-5.5, jsfunc, -5.25, -0.25);
}
TEST(Run_I32Popcount_jswrapped) {
WasmRunner<int, int> r(kExecuteCompiled);
BUILD(r, WASM_I32_POPCNT(WASM_GET_LOCAL(0)));
Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index);
CcTest::InitializeVM();
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler t(sigs.i_i(), &module);
BUILD(t, WASM_I32_POPCNT(WASM_GET_LOCAL(0)));
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
EXPECT_CALL(2, jsfunc, 9, 0);
EXPECT_CALL(3, jsfunc, 11, 0);
@ -134,13 +146,15 @@ TEST(Run_I32Popcount_jswrapped) {
}
TEST(Run_CallJS_Add_jswrapped) {
WasmRunner<int, int> r(kExecuteCompiled);
CcTest::InitializeVM();
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler t(sigs.i_i(), &module);
uint32_t js_index =
r.module().AddJsFunction(sigs.i_i(), "(function(a) { return a + 99; })");
BUILD(r, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0)));
module.AddJsFunction(sigs.i_i(), "(function(a) { return a + 99; })");
BUILD(t, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0)));
Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index);
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
EXPECT_CALL(101, jsfunc, 2, -8);
EXPECT_CALL(199, jsfunc, 100, -1);
@ -157,9 +171,9 @@ void RunJSSelectTest(int which) {
HandleScope scope(CcTest::InitIsolateOnce());
FunctionSig sig(1, num_params, types);
WasmRunner<void> r(kExecuteCompiled);
uint32_t js_index = AddJSSelector(&r.module(), &sig, which);
WasmFunctionCompiler& t = r.NewFunction(&sig);
TestingModule module;
uint32_t js_index = AddJSSelector(&module, &sig, which);
WasmFunctionCompiler t(&sig, &module);
{
std::vector<byte> code;
@ -175,7 +189,7 @@ void RunJSSelectTest(int which) {
t.Build(&code[0], &code[end]);
}
Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index());
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
double expected = inputs.arg_d(which);
EXPECT_CALL(expected, jsfunc, 0.0, 0.0);
}
@ -231,10 +245,10 @@ void RunWASMSelectTest(int which) {
type, type, type, type};
FunctionSig sig(1, num_params, types);
WasmRunner<void> r(kExecuteCompiled);
WasmFunctionCompiler& t = r.NewFunction(&sig);
TestingModule module;
WasmFunctionCompiler t(&sig, &module);
BUILD(t, WASM_GET_LOCAL(which));
Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index());
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
Handle<Object> args[] = {
isolate->factory()->NewNumber(inputs.arg_d(0)),
@ -303,10 +317,10 @@ void RunWASMSelectAlignTest(int num_args, int num_params) {
FunctionSig sig(1, num_params, types);
for (int which = 0; which < num_params; which++) {
WasmRunner<void> r(kExecuteCompiled);
WasmFunctionCompiler& t = r.NewFunction(&sig);
TestingModule module;
WasmFunctionCompiler t(&sig, &module);
BUILD(t, WASM_GET_LOCAL(which));
Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index());
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
Handle<Object> args[] = {isolate->factory()->NewNumber(inputs.arg_d(0)),
isolate->factory()->NewNumber(inputs.arg_d(1)),
@ -397,8 +411,6 @@ void RunJSSelectAlignTest(int num_args, int num_params) {
LocalType types[kMaxParams + 1] = {type, type, type, type, type, type,
type, type, type, type, type};
FunctionSig sig(1, num_params, types);
i::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
// Build the calling code.
std::vector<byte> code;
@ -407,21 +419,21 @@ void RunJSSelectAlignTest(int num_args, int num_params) {
ADD_CODE(code, WASM_GET_LOCAL(i));
}
uint8_t predicted_js_index = 1;
ADD_CODE(code, kExprCallFunction, predicted_js_index);
ADD_CODE(code, kExprCallFunction, 0);
size_t end = code.size();
code.push_back(0);
// Call different select JS functions.
for (int which = 0; which < num_params; which++) {
WasmRunner<void> r(kExecuteCompiled);
uint32_t js_index = AddJSSelector(&r.module(), &sig, which);
CHECK_EQ(predicted_js_index, js_index);
WasmFunctionCompiler& t = r.NewFunction(&sig);
HandleScope scope(isolate);
TestingModule module;
uint32_t js_index = AddJSSelector(&module, &sig, which);
CHECK_EQ(0u, js_index);
WasmFunctionCompiler t(&sig, &module);
t.Build(&code[0], &code[end]);
Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index());
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
Handle<Object> args[] = {
factory->NewNumber(inputs.arg_d(0)),

View File

@ -14,28 +14,30 @@ using namespace v8::internal;
using namespace v8::internal::compiler;
#define FOREACH_TYPE(TEST_BODY) \
TEST_BODY(int32_t, WASM_I32_ADD) \
TEST_BODY(int64_t, WASM_I64_ADD) \
TEST_BODY(float, WASM_F32_ADD) \
TEST_BODY(double, WASM_F64_ADD)
TEST_BODY(int32_t, I32, WASM_I32_ADD) \
TEST_BODY(int64_t, I64, WASM_I64_ADD) \
TEST_BODY(float, F32, WASM_F32_ADD) \
TEST_BODY(double, F64, WASM_F64_ADD)
#define LOAD_SET_GLOBAL_TEST_BODY(C_TYPE, ADD) \
TEST(WasmRelocateGlobal_##C_TYPE) { \
WasmRunner<C_TYPE, C_TYPE> r(kExecuteCompiled); \
#define LOAD_SET_GLOBAL_TEST_BODY(C_TYPE, MACHINE_TYPE, ADD) \
TEST(WasmRelocateGlobal##MACHINE_TYPE) { \
TestingModule module(kExecuteCompiled); \
module.AddGlobal<C_TYPE>(kAst##MACHINE_TYPE); \
module.AddGlobal<C_TYPE>(kAst##MACHINE_TYPE); \
\
r.module().AddGlobal<C_TYPE>(); \
r.module().AddGlobal<C_TYPE>(); \
WasmRunner<C_TYPE> r(&module, \
WasmOpcodes::MachineTypeFor(kAst##MACHINE_TYPE)); \
\
/* global = global + p0 */ \
BUILD(r, WASM_SET_GLOBAL(1, ADD(WASM_GET_GLOBAL(0), WASM_GET_LOCAL(0))), \
WASM_GET_GLOBAL(0)); \
CHECK_EQ(1, r.module().instance->function_code.size()); \
CHECK_EQ(1u, module.instance->function_code.size()); \
\
int filter = 1 << RelocInfo::WASM_GLOBAL_REFERENCE; \
\
Handle<Code> code = r.module().instance->function_code[0]; \
Handle<Code> code = module.instance->function_code[0]; \
\
Address old_start = r.module().instance->globals_start; \
Address old_start = module.instance->globals_start; \
Address new_start = old_start + 1; \
\
Address old_addresses[4]; \

View File

@ -17,7 +17,7 @@ using namespace v8::internal::wasm;
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Splat) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
BUILD(r,
WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(5))));
FOR_INT32_INPUTS(i) { CHECK_EQ(5, r.Call()); }
@ -25,7 +25,7 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Splat) {
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Add) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
BUILD(r, WASM_SIMD_I32x4_EXTRACT_LANE(
0, WASM_SIMD_I32x4_ADD(WASM_SIMD_I32x4_SPLAT(WASM_I32V(5)),
WASM_SIMD_I32x4_SPLAT(WASM_I32V(6)))));
@ -34,7 +34,7 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Add) {
WASM_EXEC_COMPILED_TEST(Simd_F32x4_Splat) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
BUILD(r,
WASM_IF_ELSE(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
0, WASM_SIMD_F32x4_SPLAT(WASM_F32(9.5))),
@ -45,7 +45,7 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Splat) {
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Extract_With_F32x4) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
BUILD(r,
WASM_IF_ELSE(WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE(
0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))),
@ -56,7 +56,7 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Extract_With_F32x4) {
WASM_EXEC_COMPILED_TEST(Simd_F32x4_Extract_With_I32x4) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
BUILD(r,
WASM_IF_ELSE(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(15))),
@ -67,7 +67,7 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Extract_With_I32x4) {
WASM_EXEC_COMPILED_TEST(Simd_F32x4_Add_With_I32x4) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
BUILD(r,
WASM_IF_ELSE(
WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
@ -82,7 +82,7 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Add_With_I32x4) {
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Add_With_F32x4) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
BUILD(r,
WASM_IF_ELSE(
WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE(
@ -97,39 +97,39 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Add_With_F32x4) {
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Local) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
r.AllocateLocal(kAstS128);
BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_RETURN1(
WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(0)))));
WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)))));
FOR_INT32_INPUTS(i) { CHECK_EQ(31, r.Call()); }
}
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Replace_Lane) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
r.AllocateLocal(kAstS128);
BUILD(r,
WASM_BLOCK(
WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_SET_LOCAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(0),
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(1),
WASM_I32V(53))),
WASM_RETURN1(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(0)))));
WASM_RETURN1(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(1)))));
FOR_INT32_INPUTS(i) { CHECK_EQ(53, r.Call()); }
}
WASM_EXEC_COMPILED_TEST(Simd_F32x4_Replace_Lane) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
r.AllocateLocal(kAstF32);
r.AllocateLocal(kAstS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_SPLAT(WASM_F32(23.5))),
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_REPLACE_LANE(
3, WASM_GET_LOCAL(1), WASM_F32(65.25))),
WASM_SET_LOCAL(2, WASM_SIMD_F32x4_SPLAT(WASM_F32(23.5))),
WASM_SET_LOCAL(2, WASM_SIMD_F32x4_REPLACE_LANE(
3, WASM_GET_LOCAL(2), WASM_F32(65.25))),
WASM_SET_LOCAL(
0, WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1))),
WASM_IF(WASM_F32_EQ(WASM_GET_LOCAL(0), WASM_F32(65.25)),
1, WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(2))),
WASM_IF(WASM_F32_EQ(WASM_GET_LOCAL(1), WASM_F32(65.25)),
WASM_RETURN1(WASM_I32V(1))),
WASM_RETURN1(WASM_I32V(0))));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
@ -137,26 +137,27 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Replace_Lane) {
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Splat_From_Extract) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
r.AllocateLocal(kAstI32);
r.AllocateLocal(kAstS128);
BUILD(r,
WASM_BLOCK(
WASM_SET_LOCAL(0, WASM_SIMD_I32x4_EXTRACT_LANE(
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_EXTRACT_LANE(
0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(76)))),
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0))),
WASM_RETURN1(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1)))));
WASM_SET_LOCAL(2, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(1))),
WASM_RETURN1(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(2)))));
FOR_INT32_INPUTS(i) { CHECK_EQ(76, r.Call()); }
}
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Get_Global) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
int32_t* global = r.module().AddGlobal<int32_t>(kAstS128);
TestingModule module(kExecuteCompiled);
int32_t* global = module.AddGlobal<int32_t>(kAstS128);
*(global) = 0;
*(global + 1) = 1;
*(global + 2) = 2;
*(global + 3) = 3;
WasmRunner<int32_t> r(&module, MachineType::Int32());
r.AllocateLocal(kAstI32);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(1, WASM_I32V(1)),
@ -178,8 +179,9 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Get_Global) {
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Set_Global) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
int32_t* global = r.module().AddGlobal<int32_t>(kAstS128);
TestingModule module(kExecuteCompiled);
int32_t* global = module.AddGlobal<int32_t>(kAstS128);
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_BLOCK(
WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(23))),
WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(
@ -198,12 +200,13 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Set_Global) {
WASM_EXEC_COMPILED_TEST(Simd_F32x4_Get_Global) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
float* global = r.module().AddGlobal<float>(kAstS128);
TestingModule module(kExecuteCompiled);
float* global = module.AddGlobal<float>(kAstS128);
*(global) = 0.0;
*(global + 1) = 1.5;
*(global + 2) = 2.25;
*(global + 3) = 3.5;
WasmRunner<int32_t> r(&module, MachineType::Int32());
r.AllocateLocal(kAstI32);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(1, WASM_I32V(1)),
@ -225,8 +228,9 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Get_Global) {
WASM_EXEC_COMPILED_TEST(Simd_F32x4_Set_Global) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
float* global = r.module().AddGlobal<float>(kAstS128);
TestingModule module(kExecuteCompiled);
float* global = module.AddGlobal<float>(kAstS128);
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_BLOCK(
WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_SPLAT(WASM_F32(13.5))),
WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(
@ -245,69 +249,69 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Set_Global) {
WASM_EXEC_COMPILED_TEST(Simd_I32x4_For) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
r.AllocateLocal(kAstI32);
r.AllocateLocal(kAstS128);
BUILD(
r,
WASM_BLOCK(
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(1),
WASM_SET_LOCAL(2, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_SET_LOCAL(2, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(2),
WASM_I32V(53))),
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(1),
WASM_SET_LOCAL(2, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(2),
WASM_I32V(23))),
WASM_SET_LOCAL(0, WASM_I32V(0)),
WASM_LOOP(WASM_SET_LOCAL(1, WASM_SIMD_I32x4_ADD(
WASM_GET_LOCAL(1),
WASM_SET_LOCAL(1, WASM_I32V(0)),
WASM_LOOP(WASM_SET_LOCAL(2, WASM_SIMD_I32x4_ADD(
WASM_GET_LOCAL(2),
WASM_SIMD_I32x4_SPLAT(WASM_I32V(1)))),
WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(5)),
WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(1), WASM_I32V(5)),
WASM_BR(1))),
WASM_SET_LOCAL(0, WASM_I32V(1)),
WASM_SET_LOCAL(1, WASM_I32V(1)),
WASM_IF(
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)),
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(2)),
WASM_I32V(36)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1)),
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(2)),
WASM_I32V(58)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(1)),
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(2)),
WASM_I32V(28)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)),
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(2)),
WASM_I32V(36)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_RETURN1(WASM_GET_LOCAL(0))));
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_RETURN1(WASM_GET_LOCAL(1))));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
}
WASM_EXEC_COMPILED_TEST(Simd_F32x4_For) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
r.AllocateLocal(kAstI32);
r.AllocateLocal(kAstS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25))),
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_REPLACE_LANE(
3, WASM_GET_LOCAL(1), WASM_F32(19.5))),
WASM_SET_LOCAL(0, WASM_I32V(0)),
WASM_SET_LOCAL(2, WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25))),
WASM_SET_LOCAL(2, WASM_SIMD_F32x4_REPLACE_LANE(
3, WASM_GET_LOCAL(2), WASM_F32(19.5))),
WASM_SET_LOCAL(1, WASM_I32V(0)),
WASM_LOOP(
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_ADD(
WASM_GET_LOCAL(1),
WASM_SET_LOCAL(2, WASM_SIMD_F32x4_ADD(
WASM_GET_LOCAL(2),
WASM_SIMD_F32x4_SPLAT(WASM_F32(2.0)))),
WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(3)),
WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(1), WASM_I32V(3)),
WASM_BR(1))),
WASM_SET_LOCAL(0, WASM_I32V(1)),
WASM_SET_LOCAL(1, WASM_I32V(1)),
WASM_IF(WASM_F32_NE(
WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)),
WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(2)),
WASM_F32(27.25)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_IF(WASM_F32_NE(
WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)),
WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(2)),
WASM_F32(25.5)),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_RETURN1(WASM_GET_LOCAL(0))));
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_RETURN1(WASM_GET_LOCAL(1))));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
}

View File

@ -45,7 +45,7 @@ WASM_EXEC_TEST(I32x4Splat) {
// return 0
//
// return 1
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
byte lane_val = 0;
byte simd = r.AllocateLocal(kAstS128);
BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(
@ -58,7 +58,8 @@ WASM_EXEC_TEST(I32x4Splat) {
WASM_EXEC_TEST(I32x4ReplaceLane) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(),
MachineType::Int32());
byte old_val = 0;
byte new_val = 1;
byte simd = r.AllocateLocal(kAstS128);
@ -91,7 +92,8 @@ WASM_EXEC_TEST(I32x4ReplaceLane) {
WASM_EXEC_TEST(I32x4Add) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(),
MachineType::Int32(), MachineType::Int32());
byte a = 0;
byte b = 1;
byte expected = 2;
@ -113,7 +115,8 @@ WASM_EXEC_TEST(I32x4Add) {
WASM_EXEC_TEST(I32x4Sub) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled);
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(),
MachineType::Int32(), MachineType::Int32());
byte a = 0;
byte b = 1;
byte expected = 2;

File diff suppressed because it is too large Load Diff

View File

@ -76,22 +76,25 @@ void CheckExceptionInfos(Handle<Object> exc,
// Call from JS to WASM to JS and throw an Error from JS.
TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
WasmRunner<void> r(kExecuteCompiled);
TestSignatures sigs;
TestingModule module;
uint32_t js_throwing_index = r.module().AddJsFunction(
// Initialize WasmFunctionCompiler first, since it sets up the HandleScope.
WasmFunctionCompiler comp1(sigs.v_v(), &module);
uint32_t js_throwing_index = module.AddJsFunction(
sigs.v_v(),
"(function js() {\n function a() {\n throw new Error(); };\n a(); })");
// Add a nop such that we don't always get position 1.
BUILD(r, WASM_NOP, WASM_CALL_FUNCTION0(js_throwing_index));
uint32_t wasm_index_1 = r.function()->func_index;
BUILD(comp1, WASM_NOP, WASM_CALL_FUNCTION0(js_throwing_index));
uint32_t wasm_index = comp1.CompileAndAdd();
WasmFunctionCompiler& f2 = r.NewFunction<void>();
BUILD(f2, WASM_CALL_FUNCTION0(wasm_index_1));
uint32_t wasm_index_2 = f2.function_index();
WasmFunctionCompiler comp2(sigs.v_v(), &module);
BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index));
uint32_t wasm_index_2 = comp2.CompileAndAdd();
Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2);
Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2);
Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
@ -111,7 +114,7 @@ TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
ExceptionInfo expected_exceptions[] = {
{"a", 3, 8}, // -
{"js", 4, 2}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 3}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 3}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // -
{"callFn", 1, 24} // -
};
@ -121,18 +124,21 @@ TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
// Trigger a trap in WASM, stack should be JS -> WASM -> WASM.
TEST(CollectDetailedWasmStack_WasmError) {
TestSignatures sigs;
WasmRunner<int> r(kExecuteCompiled);
TestingModule module;
WasmFunctionCompiler comp1(sigs.i_v(), &module,
ArrayVector("exec_unreachable"));
// Set the execution context, such that a runtime error can be thrown.
r.SetModuleContext();
comp1.SetModuleContext();
BUILD(comp1, WASM_UNREACHABLE);
uint32_t wasm_index = comp1.CompileAndAdd();
BUILD(r, WASM_UNREACHABLE);
uint32_t wasm_index_1 = r.function()->func_index;
WasmFunctionCompiler comp2(sigs.i_v(), &module,
ArrayVector("call_exec_unreachable"));
BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index));
uint32_t wasm_index_2 = comp2.CompileAndAdd();
WasmFunctionCompiler& f2 = r.NewFunction<int>();
BUILD(f2, WASM_CALL_FUNCTION0(0));
uint32_t wasm_index_2 = f2.function_index();
Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2);
Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2);
Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
@ -150,7 +156,7 @@ TEST(CollectDetailedWasmStack_WasmError) {
// Line and column are 1-based, so add 1 for the expected wasm output.
ExceptionInfo expected_exceptions[] = {
{"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 2}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 2}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // -
{"callFn", 1, 24} //-
};

View File

@ -62,15 +62,17 @@ void CheckExceptionInfos(Handle<Object> exc,
// Trigger a trap for executing unreachable.
TEST(Unreachable) {
WasmRunner<void> r(kExecuteCompiled);
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler comp1(sigs.v_v(), &module,
ArrayVector("exec_unreachable"));
// Set the execution context, such that a runtime error can be thrown.
r.SetModuleContext();
comp1.SetModuleContext();
BUILD(comp1, WASM_UNREACHABLE);
uint32_t wasm_index = comp1.CompileAndAdd();
BUILD(r, WASM_UNREACHABLE);
uint32_t wasm_index = r.function()->func_index;
Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index);
Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index);
Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
@ -96,22 +98,23 @@ TEST(Unreachable) {
// Trigger a trap for loading from out-of-bounds.
TEST(IllegalLoad) {
WasmRunner<void> r(kExecuteCompiled);
TestSignatures sigs;
// Set the execution context, such that a runtime error can be thrown.
r.SetModuleContext();
TestingModule module;
BUILD(r, WASM_IF(WASM_ONE, WASM_SEQ(WASM_LOAD_MEM(MachineType::Int32(),
WasmFunctionCompiler comp1(sigs.v_v(), &module, ArrayVector("mem_oob"));
// Set the execution context, such that a runtime error can be thrown.
comp1.SetModuleContext();
BUILD(comp1, WASM_IF(WASM_ONE, WASM_SEQ(WASM_LOAD_MEM(MachineType::Int32(),
WASM_I32V_1(-3)),
WASM_DROP)));
uint32_t wasm_index_1 = r.function()->func_index;
uint32_t wasm_index = comp1.CompileAndAdd();
WasmFunctionCompiler& f2 = r.NewFunction<void>();
WasmFunctionCompiler comp2(sigs.v_v(), &module, ArrayVector("call_mem_oob"));
// Insert a NOP such that the position of the call is not one.
BUILD(f2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index_1));
uint32_t wasm_index_2 = f2.function_index();
BUILD(comp2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index));
uint32_t wasm_index_2 = comp2.CompileAndAdd();
Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2);
Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2);
Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
@ -129,7 +132,7 @@ TEST(IllegalLoad) {
// Line and column are 1-based, so add 1 for the expected wasm output.
ExceptionInfo expected_exceptions[] = {
{"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 8}, // --
{"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 8}, // --
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 3}, // --
{"callFn", 1, 24} // --
};

View File

@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <array>
#include <memory>
#include "src/base/utils/random-number-generator.h"
@ -52,6 +51,7 @@ enum WasmExecutionMode { kExecuteInterpreted, kExecuteCompiled };
CHECK_EQ(0xdeadbeefdeadbeef, (bit_cast<uint64_t>(x)) & 0xFFFFFFFFFFFFFFFF)
#define CHECK_TRAP(x) CHECK_TRAP32(x)
#define WASM_RUNNER_MAX_NUM_PARAMETERS 4
#define WASM_WRAPPER_RETURN_VALUE 8754
#define BUILD(r, ...) \
@ -73,7 +73,7 @@ const uint32_t kMaxGlobalsSize = 128;
// {WasmInstance}.
class TestingModule : public ModuleEnv {
public:
explicit TestingModule(Zone* zone, WasmExecutionMode mode = kExecuteCompiled)
explicit TestingModule(WasmExecutionMode mode = kExecuteCompiled)
: ModuleEnv(&module_, &instance_),
execution_mode_(mode),
instance_(&module_),
@ -83,7 +83,7 @@ class TestingModule : public ModuleEnv {
? new WasmInterpreter(
ModuleBytesEnv(&module_, &instance_,
Vector<const byte>::empty()),
zone->allocator())
&allocator_)
: nullptr) {
instance->module = &module_;
instance->globals_start = global_data;
@ -104,7 +104,7 @@ class TestingModule : public ModuleEnv {
byte* AddMemory(uint32_t size) {
CHECK_NULL(instance->mem_start);
CHECK_EQ(0, instance->mem_size);
CHECK_EQ(0u, instance->mem_size);
instance->mem_start = reinterpret_cast<byte*>(malloc(size));
CHECK(instance->mem_start);
memset(instance->mem_start, 0, size);
@ -119,8 +119,7 @@ class TestingModule : public ModuleEnv {
}
template <typename T>
T* AddGlobal(
LocalType type = WasmOpcodes::LocalTypeFor(MachineTypeForC<T>())) {
T* AddGlobal(LocalType type) {
const WasmGlobal* global = AddGlobal(type);
return reinterpret_cast<T*>(instance->globals_start + global->offset);
}
@ -245,7 +244,6 @@ class TestingModule : public ModuleEnv {
}
void PopulateIndirectFunctionTable() {
if (execution_mode_ == kExecuteInterpreted) return;
// Initialize the fixed arrays in instance->function_tables.
for (uint32_t i = 0; i < instance->function_tables.size(); i++) {
WasmIndirectFunctionTable& table = module_.function_tables[i];
@ -264,13 +262,13 @@ class TestingModule : public ModuleEnv {
WasmInterpreter* interpreter() { return interpreter_; }
WasmExecutionMode execution_mode() { return execution_mode_; }
Isolate* isolate() { return isolate_; }
private:
WasmExecutionMode execution_mode_;
WasmModule module_;
WasmInstance instance_;
Isolate* isolate_;
v8::internal::AccountingAllocator allocator_;
uint32_t global_offset;
V8_ALIGNED(8) byte global_data[kMaxGlobalsSize]; // preallocated global data.
WasmInterpreter* interpreter_;
@ -316,29 +314,36 @@ inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module,
}
}
class WasmFunctionWrapper : private GraphAndBuilders {
template <typename ReturnType>
class WasmFunctionWrapper : public HandleAndZoneScope,
private GraphAndBuilders {
public:
explicit WasmFunctionWrapper(Zone* zone, int num_params)
: GraphAndBuilders(zone), inner_code_node_(nullptr), signature_(nullptr) {
WasmFunctionWrapper()
: GraphAndBuilders(main_zone()),
inner_code_node_(nullptr),
signature_(nullptr) {
// One additional parameter for the pointer to the return value memory.
Signature<MachineType>::Builder sig_builder(zone, 1, num_params + 1);
Signature<MachineType>::Builder sig_builder(
zone(), 1, WASM_RUNNER_MAX_NUM_PARAMETERS + 1);
sig_builder.AddReturn(MachineType::Int32());
for (int i = 0; i < num_params + 1; i++) {
for (int i = 0; i < WASM_RUNNER_MAX_NUM_PARAMETERS + 1; i++) {
sig_builder.AddParam(MachineType::Pointer());
}
signature_ = sig_builder.Build();
}
void Init(CallDescriptor* descriptor, MachineType return_type,
Vector<MachineType> param_types) {
DCHECK_NOT_NULL(descriptor);
DCHECK_EQ(signature_->parameter_count(), param_types.length() + 1);
// Create the TF graph for the wrapper.
void Init(CallDescriptor* descriptor, MachineType p0 = MachineType::None(),
MachineType p1 = MachineType::None(),
MachineType p2 = MachineType::None(),
MachineType p3 = MachineType::None()) {
// Create the TF graph for the wrapper. The wrapper always takes four
// pointers as parameters, but may not pass the values of all pointers to
// the actual test function.
// Function, effect, and control.
Node** parameters = zone()->NewArray<Node*>(param_types.length() + 3);
Node** parameters =
zone()->template NewArray<Node*>(WASM_RUNNER_MAX_NUM_PARAMETERS + 3);
graph()->SetStart(graph()->NewNode(common()->Start(6)));
Node* effect = graph()->start();
int parameter_count = 0;
@ -347,12 +352,34 @@ class WasmFunctionWrapper : private GraphAndBuilders {
inner_code_node_ = graph()->NewNode(common()->Int32Constant(0));
parameters[parameter_count++] = inner_code_node_;
int param_idx = 0;
for (MachineType t : param_types) {
DCHECK_NE(MachineType::None(), t);
if (p0 != MachineType::None()) {
parameters[parameter_count] = graph()->NewNode(
machine()->Load(t),
graph()->NewNode(common()->Parameter(param_idx++), graph()->start()),
machine()->Load(p0),
graph()->NewNode(common()->Parameter(0), graph()->start()),
graph()->NewNode(common()->Int32Constant(0)), effect,
graph()->start());
effect = parameters[parameter_count++];
}
if (p1 != MachineType::None()) {
parameters[parameter_count] = graph()->NewNode(
machine()->Load(p1),
graph()->NewNode(common()->Parameter(1), graph()->start()),
graph()->NewNode(common()->Int32Constant(0)), effect,
graph()->start());
effect = parameters[parameter_count++];
}
if (p2 != MachineType::None()) {
parameters[parameter_count] = graph()->NewNode(
machine()->Load(p2),
graph()->NewNode(common()->Parameter(2), graph()->start()),
graph()->NewNode(common()->Int32Constant(0)), effect,
graph()->start());
effect = parameters[parameter_count++];
}
if (p3 != MachineType::None()) {
parameters[parameter_count] = graph()->NewNode(
machine()->Load(p3),
graph()->NewNode(common()->Parameter(3), graph()->start()),
graph()->NewNode(common()->Int32Constant(0)), effect,
graph()->start());
effect = parameters[parameter_count++];
@ -363,15 +390,14 @@ class WasmFunctionWrapper : private GraphAndBuilders {
Node* call = graph()->NewNode(common()->Call(descriptor), parameter_count,
parameters);
if (!return_type.IsNone()) {
effect = graph()->NewNode(
machine()->Store(StoreRepresentation(
return_type.representation(), WriteBarrierKind::kNoWriteBarrier)),
graph()->NewNode(common()->Parameter(param_types.length()),
machine()->Store(
StoreRepresentation(MachineTypeForC<ReturnType>().representation(),
WriteBarrierKind::kNoWriteBarrier)),
graph()->NewNode(common()->Parameter(WASM_RUNNER_MAX_NUM_PARAMETERS),
graph()->start()),
graph()->NewNode(common()->Int32Constant(0)), call, effect,
graph()->start());
}
Node* zero = graph()->NewNode(common()->Int32Constant(0));
Node* r = graph()->NewNode(
common()->Return(), zero,
@ -380,15 +406,6 @@ class WasmFunctionWrapper : private GraphAndBuilders {
graph()->SetEnd(graph()->NewNode(common()->End(2), r, graph()->start()));
}
template <typename ReturnType, typename... ParamTypes>
void Init(CallDescriptor* descriptor) {
std::array<MachineType, sizeof...(ParamTypes)> param_machine_types{
{MachineTypeForC<ParamTypes>()...}};
Vector<MachineType> param_vec(param_machine_types.data(),
param_machine_types.size());
Init(descriptor, MachineTypeForC<ReturnType>(), param_vec);
}
void SetInnerCode(Handle<Code> code_handle) {
NodeProperties::ChangeOp(inner_code_node_,
common()->HeapConstant(code_handle));
@ -402,13 +419,12 @@ class WasmFunctionWrapper : private GraphAndBuilders {
Linkage::GetSimplifiedCDescriptor(zone(), signature_, true);
if (kPointerSize == 4) {
size_t num_params = signature_->parameter_count();
// One additional parameter for the pointer of the return value.
Signature<MachineRepresentation>::Builder rep_builder(zone(), 1,
num_params + 1);
Signature<MachineRepresentation>::Builder rep_builder(
zone(), 1, WASM_RUNNER_MAX_NUM_PARAMETERS + 1);
rep_builder.AddReturn(MachineRepresentation::kWord32);
for (size_t i = 0; i < num_params + 1; i++) {
for (int i = 0; i < WASM_RUNNER_MAX_NUM_PARAMETERS + 1; i++) {
rep_builder.AddParam(MachineRepresentation::kWord32);
}
Int64Lowering r(graph(), machine(), common(), zone(),
@ -440,37 +456,99 @@ class WasmFunctionWrapper : private GraphAndBuilders {
Signature<MachineType>* signature_;
};
// A helper for compiling WASM functions for testing.
// It contains the internal state for compilation (i.e. TurboFan graph) and
// interpretation (by adding to the interpreter manually).
class WasmFunctionCompiler : private GraphAndBuilders {
// A helper for compiling WASM functions for testing. This class can create a
// standalone function if {module} is NULL or a function within a
// {TestingModule}. It contains the internal state for compilation (i.e.
// TurboFan graph) and interpretation (by adding to the interpreter manually).
class WasmFunctionCompiler : public HandleAndZoneScope,
private GraphAndBuilders {
public:
Isolate* isolate() { return testing_module_->isolate(); }
explicit WasmFunctionCompiler(
FunctionSig* sig, WasmExecutionMode mode,
Vector<const char> debug_name = ArrayVector("<WASM UNNAMED>"))
: GraphAndBuilders(main_zone()),
execution_mode_(mode),
jsgraph(this->isolate(), this->graph(), this->common(), nullptr,
nullptr, this->machine()),
sig(sig),
descriptor_(nullptr),
testing_module_(nullptr),
debug_name_(debug_name),
local_decls(main_zone(), sig),
source_position_table_(this->graph()),
interpreter_(nullptr) {
// Create our own function.
function_ = new WasmFunction();
function_->sig = sig;
function_->func_index = 0;
function_->sig_index = 0;
if (mode == kExecuteInterpreted) {
ModuleBytesEnv empty_env(nullptr, nullptr, Vector<const byte>::empty());
interpreter_ = new WasmInterpreter(empty_env, zone()->allocator());
int index = interpreter_->AddFunctionForTesting(function_);
CHECK_EQ(0, index);
}
}
explicit WasmFunctionCompiler(
FunctionSig* sig, TestingModule* module,
Vector<const char> debug_name = ArrayVector("<WASM UNNAMED>"))
: GraphAndBuilders(main_zone()),
execution_mode_(module->execution_mode()),
jsgraph(this->isolate(), this->graph(), this->common(), nullptr,
nullptr, this->machine()),
sig(sig),
descriptor_(nullptr),
testing_module_(module),
debug_name_(debug_name),
local_decls(main_zone(), sig),
source_position_table_(this->graph()),
interpreter_(module->interpreter()) {
// Get a new function from the testing module.
int index = module->AddFunction(sig, Handle<Code>::null());
function_ = testing_module_->GetFunctionAt(index);
}
~WasmFunctionCompiler() {
if (testing_module_) return; // testing module owns the below things.
delete function_;
if (interpreter_) delete interpreter_;
}
WasmExecutionMode execution_mode_;
JSGraph jsgraph;
FunctionSig* sig;
// The call descriptor is initialized when the function is compiled.
CallDescriptor* descriptor_;
TestingModule* testing_module_;
Vector<const char> debug_name_;
WasmFunction* function_;
LocalDeclEncoder local_decls;
SourcePositionTable source_position_table_;
WasmInterpreter* interpreter_;
Isolate* isolate() { return main_isolate(); }
Graph* graph() const { return main_graph_; }
Zone* zone() const { return graph()->zone(); }
CommonOperatorBuilder* common() { return &main_common_; }
MachineOperatorBuilder* machine() { return &main_machine_; }
CallDescriptor* descriptor() {
void InitializeDescriptor() {
if (descriptor_ == nullptr) {
descriptor_ = testing_module_->GetWasmCallDescriptor(zone(), sig);
descriptor_ = testing_module_->GetWasmCallDescriptor(main_zone(), sig);
}
return descriptor_;
}
CallDescriptor* descriptor() { return descriptor_; }
uint32_t function_index() { return function_->func_index; }
void Build(const byte* start, const byte* end) {
local_decls.Prepend(zone(), &start, &end);
// Build the TurboFan graph.
local_decls.Prepend(main_zone(), &start, &end);
TestBuildingGraph(main_zone(), &jsgraph, testing_module_, sig,
&source_position_table_, start, end);
if (interpreter_) {
// Add the code to the interpreter.
CHECK(interpreter_->SetFunctionCodeForTesting(function_, start, end));
return;
}
// Build the TurboFan graph.
TestBuildingGraph(zone(), &jsgraph, testing_module_, sig,
&source_position_table_, start, end);
Handle<Code> code = Compile();
testing_module_->SetFunctionCode(function_index(), code);
}
byte AllocateLocal(LocalType type) {
@ -480,33 +558,13 @@ class WasmFunctionCompiler : private GraphAndBuilders {
return result;
}
void SetSigIndex(int sig_index) { function_->sig_index = sig_index; }
private:
friend class WasmRunnerBase;
explicit WasmFunctionCompiler(Zone* zone, FunctionSig* sig,
TestingModule* module)
: GraphAndBuilders(zone),
jsgraph(module->isolate(), this->graph(), this->common(), nullptr,
nullptr, this->machine()),
sig(sig),
descriptor_(nullptr),
testing_module_(module),
local_decls(zone, sig),
source_position_table_(this->graph()),
interpreter_(module->interpreter()) {
// Get a new function from the testing module.
int index = module->AddFunction(sig, Handle<Code>::null());
function_ = testing_module_->GetFunctionAt(index);
}
Handle<Code> Compile() {
CallDescriptor* desc = descriptor();
InitializeDescriptor();
CallDescriptor* desc = descriptor_;
if (kPointerSize == 4) {
desc = testing_module_->GetI32WasmCallDescriptor(this->zone(), desc);
}
CompilationInfo info(CStrVector("wasm"), this->isolate(), this->zone(),
CompilationInfo info(debug_name_, this->isolate(), this->zone(),
Code::ComputeFlags(Code::WASM_FUNCTION));
std::unique_ptr<CompilationJob> job(Pipeline::NewWasmCompilationJob(
&info, &jsgraph, desc, &source_position_table_, nullptr));
@ -536,26 +594,82 @@ class WasmFunctionCompiler : private GraphAndBuilders {
return code;
}
JSGraph jsgraph;
FunctionSig* sig;
// The call descriptor is initialized when the function is compiled.
CallDescriptor* descriptor_;
TestingModule* testing_module_;
Vector<const char> debug_name_;
WasmFunction* function_;
LocalDeclEncoder local_decls;
SourcePositionTable source_position_table_;
WasmInterpreter* interpreter_;
uint32_t CompileAndAdd(uint16_t sig_index = 0) {
CHECK(testing_module_);
function_->sig_index = sig_index;
Handle<Code> code = Compile();
testing_module_->SetFunctionCode(function_index(), code);
return function_index();
}
// Set the context, such that e.g. runtime functions can be called.
void SetModuleContext() {
if (!testing_module_->instance->context.is_null()) {
CHECK(testing_module_->instance->context.is_identical_to(
main_isolate()->native_context()));
return;
}
testing_module_->instance->context = main_isolate()->native_context();
}
};
// A helper class to build a module around Wasm bytecode, generate machine
template <typename ReturnType>
union ReturnTypeUnion {
ReturnType value;
uint64_t trap;
};
// A helper class to build graphs from Wasm bytecode, generate machine
// code, and run that code.
class WasmRunnerBase : public HandleAndZoneScope {
template <typename ReturnType>
class WasmRunner {
public:
explicit WasmRunnerBase(WasmExecutionMode execution_mode, int num_params)
: zone_(&allocator_, ZONE_NAME),
module_(&zone_, execution_mode),
wrapper_(&zone_, num_params) {}
WasmRunner(WasmExecutionMode execution_mode,
MachineType p0 = MachineType::None(),
MachineType p1 = MachineType::None(),
MachineType p2 = MachineType::None(),
MachineType p3 = MachineType::None())
: zone(&allocator_, ZONE_NAME),
compiled_(false),
signature_(MachineTypeForC<ReturnType>() == MachineType::None() ? 0 : 1,
GetParameterCount(p0, p1, p2, p3), storage_),
compiler_(&signature_, execution_mode) {
InitSigStorage(p0, p1, p2, p3);
}
WasmRunner(TestingModule* module, MachineType p0 = MachineType::None(),
MachineType p1 = MachineType::None(),
MachineType p2 = MachineType::None(),
MachineType p3 = MachineType::None())
: zone(&allocator_, ZONE_NAME),
compiled_(false),
signature_(MachineTypeForC<ReturnType>() == MachineType::None() ? 0 : 1,
GetParameterCount(p0, p1, p2, p3), storage_),
compiler_(&signature_, module),
possible_nondeterminism_(false) {
DCHECK(module);
InitSigStorage(p0, p1, p2, p3);
}
void InitSigStorage(MachineType p0, MachineType p1, MachineType p2,
MachineType p3) {
int index = 0;
MachineType ret = MachineTypeForC<ReturnType>();
if (ret != MachineType::None()) {
storage_[index++] = WasmOpcodes::LocalTypeFor(ret);
}
if (p0 != MachineType::None())
storage_[index++] = WasmOpcodes::LocalTypeFor(p0);
if (p1 != MachineType::None())
storage_[index++] = WasmOpcodes::LocalTypeFor(p1);
if (p2 != MachineType::None())
storage_[index++] = WasmOpcodes::LocalTypeFor(p2);
if (p3 != MachineType::None())
storage_[index++] = WasmOpcodes::LocalTypeFor(p3);
compiler_.InitializeDescriptor();
wrapper_.Init(compiler_.descriptor(), p0, p1, p2, p3);
}
// Builds a graph from the given Wasm code and generates the machine
// code and call wrapper for that graph. This method must not be called
@ -563,118 +677,102 @@ class WasmRunnerBase : public HandleAndZoneScope {
void Build(const byte* start, const byte* end) {
CHECK(!compiled_);
compiled_ = true;
functions_[0]->Build(start, end);
}
compiler_.Build(start, end);
// Resets the state for building the next function.
// The main function called will always be the first function.
template <typename ReturnType, typename... ParamTypes>
WasmFunctionCompiler& NewFunction() {
return NewFunction(CreateSig<ReturnType, ParamTypes...>());
}
// Resets the state for building the next function.
// The main function called will be the last generated function.
// Returns the index of the previously built function.
WasmFunctionCompiler& NewFunction(FunctionSig* sig) {
functions_.emplace_back(new WasmFunctionCompiler(&zone_, sig, &module_));
return *functions_.back();
}
byte AllocateLocal(LocalType type) {
return functions_[0]->AllocateLocal(type);
}
WasmFunction* function() { return functions_[0]->function_; }
WasmInterpreter* interpreter() { return functions_[0]->interpreter_; }
bool possible_nondeterminism() { return possible_nondeterminism_; }
TestingModule& module() { return module_; }
Zone* zone() { return &zone_; }
// Set the context, such that e.g. runtime functions can be called.
void SetModuleContext() {
if (!module_.instance->context.is_null()) {
CHECK(module_.instance->context.is_identical_to(
main_isolate()->native_context()));
return;
}
module_.instance->context = main_isolate()->native_context();
}
private:
FunctionSig* CreateSig(MachineType return_type,
Vector<MachineType> param_types) {
int return_count = return_type.IsNone() ? 0 : 1;
int param_count = param_types.length();
// Allocate storage array in zone.
LocalType* sig_types =
zone_.NewArray<LocalType>(return_count + param_count);
// Convert machine types to local types, and check that there are no
// MachineType::None()'s in the parameters.
int idx = 0;
if (return_count) sig_types[idx++] = WasmOpcodes::LocalTypeFor(return_type);
for (MachineType param : param_types) {
CHECK_NE(MachineType::None(), param);
sig_types[idx++] = WasmOpcodes::LocalTypeFor(param);
}
return new (&zone_) FunctionSig(return_count, param_count, sig_types);
}
template <typename ReturnType, typename... ParamTypes>
FunctionSig* CreateSig() {
std::array<MachineType, sizeof...(ParamTypes)> param_machine_types{
{MachineTypeForC<ParamTypes>()...}};
Vector<MachineType> param_vec(param_machine_types.data(),
param_machine_types.size());
return CreateSig(MachineTypeForC<ReturnType>(), param_vec);
}
protected:
v8::internal::AccountingAllocator allocator_;
Zone zone_;
TestingModule module_;
std::vector<std::unique_ptr<WasmFunctionCompiler>> functions_;
WasmFunctionWrapper wrapper_;
bool compiled_ = false;
bool possible_nondeterminism_ = false;
bool interpret() { return module_.execution_mode() == kExecuteInterpreted; }
public:
// This field has to be static. Otherwise, gcc complains about the using in
// the lambda context below.
static jmp_buf jump_buffer;
};
template <typename ReturnType, typename... ParamTypes>
class WasmRunner : public WasmRunnerBase {
public:
explicit WasmRunner(WasmExecutionMode execution_mode)
: WasmRunnerBase(execution_mode, sizeof...(ParamTypes)) {
NewFunction<ReturnType, ParamTypes...>();
if (!interpret()) {
wrapper_.Init<ReturnType, ParamTypes...>(functions_[0]->descriptor());
// Compile machine code and install it into the module.
Handle<Code> code = compiler_.Compile();
if (compiler_.testing_module_) {
// Update the table of function code in the module.
compiler_.testing_module_->SetFunctionCode(
compiler_.function_->func_index, code);
}
wrapper_.SetInnerCode(code);
}
}
ReturnType Call(ParamTypes... p) {
DCHECK(compiled_);
if (interpret()) return CallInterpreter(p...);
ReturnType Call() {
if (interpret()) {
return CallInterpreter(Vector<WasmVal>(nullptr, 0));
} else {
return Call(0, 0, 0, 0);
}
}
template <typename P0>
ReturnType Call(P0 p0) {
if (interpret()) {
WasmVal args[] = {WasmVal(p0)};
return CallInterpreter(ArrayVector(args));
} else {
return Call(p0, 0, 0, 0);
}
}
template <typename P0, typename P1>
ReturnType Call(P0 p0, P1 p1) {
if (interpret()) {
WasmVal args[] = {WasmVal(p0), WasmVal(p1)};
return CallInterpreter(ArrayVector(args));
} else {
return Call(p0, p1, 0, 0);
}
}
template <typename P0, typename P1, typename P2>
ReturnType Call(P0 p0, P1 p1, P2 p2) {
if (interpret()) {
WasmVal args[] = {WasmVal(p0), WasmVal(p1), WasmVal(p2)};
return CallInterpreter(ArrayVector(args));
} else {
return Call(p0, p1, p2, 0);
}
}
static jmp_buf jump_buffer;
static int jump_value;
static ReturnTypeUnion<ReturnType> return_value;
template <typename P0, typename P1, typename P2, typename P3>
void DoCall(P0 p0, P1 p1, P2 p2, P3 p3) {
auto trap_callback = []() {
WasmRunner<ReturnType>::return_value.trap = 0xdeadbeefdeadbeef;
longjmp(WasmRunner<ReturnType>::jump_buffer, 1);
};
set_trap_callback_for_testing(trap_callback);
CodeRunner<int32_t> runner(CcTest::InitIsolateOnce(),
wrapper_.GetWrapperCode(), wrapper_.signature());
int32_t result = runner.Call<void*, void*, void*, void*, void*>(
&p0, &p1, &p2, &p3, &WasmRunner<ReturnType>::return_value.value);
CHECK_EQ(WASM_WRAPPER_RETURN_VALUE, result);
}
template <typename P0, typename P1, typename P2, typename P3>
ReturnType Call(P0 p0, P1 p1, P2 p2, P3 p3) {
if (interpret()) {
WasmVal args[] = {WasmVal(p0), WasmVal(p1), WasmVal(p2), WasmVal(p3)};
return CallInterpreter(ArrayVector(args));
} else {
// Use setjmp/longjmp to deal with traps in WebAssembly code.
int jump_value = setjmp(WasmRunnerBase::jump_buffer);
// jump_value == 0 --> first return; jump_value == 1 --> longjmp happened.
return jump_value ? static_cast<ReturnType>(0xdeadbeefdeadbeef)
: DoCall(p...);
WasmRunner<ReturnType>::jump_value =
setjmp(WasmRunner<ReturnType>::jump_buffer);
if (!WasmRunner<ReturnType>::jump_value) {
DoCall(p0, p1, p2, p3);
}
set_trap_callback_for_testing(nullptr);
return WasmRunner<ReturnType>::return_value.value;
}
}
ReturnType CallInterpreter(ParamTypes... p) {
ReturnType CallInterpreter(Vector<WasmVal> args) {
CHECK_EQ(args.length(),
static_cast<int>(compiler_.function_->sig->parameter_count()));
WasmInterpreter::Thread* thread = interpreter()->GetThread(0);
thread->Reset();
std::array<WasmVal, sizeof...(p)> args{{WasmVal(p)...}};
thread->PushFrame(function(), args.data());
thread->PushFrame(compiler_.function_, args.start());
if (thread->Run() == WasmInterpreter::FINISHED) {
WasmVal val = thread->GetReturnValue();
possible_nondeterminism_ |= thread->PossibleNondeterminism();
@ -685,33 +783,45 @@ class WasmRunner : public WasmRunnerBase {
return static_cast<ReturnType>(result);
} else {
// TODO(titzer): falling off end
return ReturnType{0};
ReturnType val = 0;
return val;
}
}
private:
ReturnType DoCall(ParamTypes... p) {
auto trap_callback = []() -> void {
set_trap_callback_for_testing(nullptr);
longjmp(WasmRunnerBase::jump_buffer, 1);
};
set_trap_callback_for_testing(trap_callback);
byte AllocateLocal(LocalType type) { return compiler_.AllocateLocal(type); }
wrapper_.SetInnerCode(
module_.GetFunctionCode(functions_[0]->function_index()));
CodeRunner<int32_t> runner(CcTest::InitIsolateOnce(),
wrapper_.GetWrapperCode(), wrapper_.signature());
ReturnType return_value;
int32_t result = runner.Call(static_cast<void*>(&p)...,
static_cast<void*>(&return_value));
// If we arrive here, no trap happened.
CHECK_EQ(WASM_WRAPPER_RETURN_VALUE, result);
return return_value;
WasmFunction* function() { return compiler_.function_; }
WasmInterpreter* interpreter() { return compiler_.interpreter_; }
bool possible_nondeterminism() { return possible_nondeterminism_; }
protected:
v8::internal::AccountingAllocator allocator_;
Zone zone;
bool compiled_;
LocalType storage_[WASM_RUNNER_MAX_NUM_PARAMETERS];
FunctionSig signature_;
WasmFunctionCompiler compiler_;
WasmFunctionWrapper<ReturnType> wrapper_;
bool possible_nondeterminism_;
bool interpret() { return compiler_.execution_mode_ == kExecuteInterpreted; }
static size_t GetParameterCount(MachineType p0, MachineType p1,
MachineType p2, MachineType p3) {
if (p0 == MachineType::None()) return 0;
if (p1 == MachineType::None()) return 1;
if (p2 == MachineType::None()) return 2;
if (p3 == MachineType::None()) return 3;
return 4;
}
};
// Declare static variable.
jmp_buf WasmRunnerBase::jump_buffer;
template <typename ReturnType>
jmp_buf WasmRunner<ReturnType>::jump_buffer;
template <typename ReturnType>
int WasmRunner<ReturnType>::jump_value;
template <typename ReturnType>
ReturnTypeUnion<ReturnType> WasmRunner<ReturnType>::return_value;
// A macro to define tests that run in different engine configurations.
#define WASM_EXEC_TEST(name) \