Merge V8 5.3.332.45. DO NOT MERGE
Test: Manual
FPIIM-449
Change-Id: Id3254828b068abdea3cb10442e0172a8c9a98e03
(cherry picked from commit 13e2dadd00298019ed862f2b2fc5068bba730bcf)
diff --git a/test/cctest/wasm/test-run-wasm-64.cc b/test/cctest/wasm/test-run-wasm-64.cc
index 333183a..af87498 100644
--- a/test/cctest/wasm/test-run-wasm-64.cc
+++ b/test/cctest/wasm/test-run-wasm-64.cc
@@ -14,6 +14,13 @@
#include "test/cctest/wasm/test-signatures.h"
#include "test/cctest/wasm/wasm-run-utils.h"
+// If the target architecture is 64-bit, enable all tests.
+#if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64
+#define WASM_64 1
+#else
+#define WASM_64 0
+#endif
+
#define CHECK_TRAP32(x) \
CHECK_EQ(0xdeadbeef, (bit_cast<uint32_t>(x)) & 0xFFFFFFFF)
#define CHECK_TRAP64(x) \
@@ -92,7 +99,7 @@
WASM_EXEC_TEST(I64Const) {
REQUIRE(I64Const);
- WasmRunner<int64_t> r;
+ WasmRunner<int64_t> r(execution_mode);
const int64_t kExpectedValue = 0x1122334455667788LL;
// return(kExpectedValue)
BUILD(r, WASM_I64V_9(kExpectedValue));
@@ -103,7 +110,7 @@
REQUIRE(I64Const);
int cntr = 0;
FOR_INT32_INPUTS(i) {
- WasmRunner<int64_t> r;
+ WasmRunner<int64_t> r(execution_mode);
const int64_t kExpectedValue = (static_cast<int64_t>(*i) << 32) | cntr;
// return(kExpectedValue)
BUILD(r, WASM_I64V(kExpectedValue));
@@ -114,7 +121,7 @@
WASM_EXEC_TEST(Return_I64) {
REQUIRE(I64Return);
- WasmRunner<int64_t> r(MachineType::Int64());
+ WasmRunner<int64_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_RETURN1(WASM_GET_LOCAL(0)));
@@ -123,7 +130,8 @@
WASM_EXEC_TEST(I64Add) {
REQUIRE(I64Add);
- WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)); }
@@ -132,7 +140,8 @@
WASM_EXEC_TEST(I64Sub) {
REQUIRE(I64Sub);
- WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)); }
@@ -141,7 +150,8 @@
WASM_EXEC_TEST(I64DivS) {
REQUIRE(I64DivS);
- WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ 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) {
@@ -158,7 +168,8 @@
WASM_EXEC_TEST(I64DivS_Trap) {
REQUIRE(I64DivS);
- WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)));
@@ -170,7 +181,7 @@
WASM_EXEC_TEST(I64DivS_Byzero_Const) {
REQUIRE(I64DivS);
for (int8_t denom = -2; denom < 8; denom++) {
- WasmRunner<int64_t> r(MachineType::Int64());
+ 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) {
@@ -184,7 +195,8 @@
WASM_EXEC_TEST(I64DivU) {
REQUIRE(I64DivU);
- WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64());
+ 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) {
@@ -199,7 +211,8 @@
WASM_EXEC_TEST(I64DivU_Trap) {
REQUIRE(I64DivU);
- WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64());
+ 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_TRAP64(r.Call(asu64(100), asu64(0)));
@@ -210,7 +223,7 @@
WASM_EXEC_TEST(I64DivU_Byzero_Const) {
REQUIRE(I64DivU);
for (uint64_t denom = 0xfffffffffffffffe; denom < 8; denom++) {
- WasmRunner<uint64_t> r(MachineType::Uint64());
+ 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++) {
@@ -225,7 +238,8 @@
WASM_EXEC_TEST(I64RemS) {
REQUIRE(I64RemS);
- WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ 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) {
@@ -240,7 +254,8 @@
WASM_EXEC_TEST(I64RemS_Trap) {
REQUIRE(I64RemS);
- WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)));
@@ -251,7 +266,8 @@
WASM_EXEC_TEST(I64RemU) {
REQUIRE(I64RemU);
- WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64());
+ 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) {
@@ -266,7 +282,8 @@
WASM_EXEC_TEST(I64RemU_Trap) {
REQUIRE(I64RemU);
- WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64());
+ 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_TRAP64(r.Call(asu64(100), asu64(0)));
@@ -276,7 +293,8 @@
WASM_EXEC_TEST(I64And) {
REQUIRE(I64And);
- WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)); }
@@ -285,7 +303,8 @@
WASM_EXEC_TEST(I64Ior) {
REQUIRE(I64Ior);
- WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)); }
@@ -294,7 +313,8 @@
WASM_EXEC_TEST(I64Xor) {
REQUIRE(I64Xor);
- WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)); }
@@ -304,7 +324,8 @@
WASM_EXEC_TEST(I64Shl) {
REQUIRE(I64Shl);
{
- WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64());
+ 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) {
@@ -315,22 +336,22 @@
}
}
{
- WasmRunner<int64_t> r(MachineType::Int64());
+ WasmRunner<int64_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<int64_t> r(MachineType::Int64());
+ WasmRunner<int64_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<int64_t> r(MachineType::Int64());
+ WasmRunner<int64_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<int64_t> r(MachineType::Int64());
+ WasmRunner<int64_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)); }
}
@@ -339,7 +360,8 @@
WASM_EXEC_TEST(I64ShrU) {
REQUIRE(I64ShrU);
{
- WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64());
+ 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) {
@@ -350,22 +372,22 @@
}
}
{
- WasmRunner<int64_t> r(MachineType::Int64());
+ WasmRunner<int64_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<int64_t> r(MachineType::Int64());
+ WasmRunner<int64_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<int64_t> r(MachineType::Int64());
+ WasmRunner<int64_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<int64_t> r(MachineType::Int64());
+ WasmRunner<int64_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)); }
}
@@ -374,7 +396,8 @@
WASM_EXEC_TEST(I64ShrS) {
REQUIRE(I64ShrS);
{
- WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ 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) {
@@ -385,22 +408,22 @@
}
}
{
- WasmRunner<int64_t> r(MachineType::Int64());
+ 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> r(MachineType::Int64());
+ 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> r(MachineType::Int64());
+ 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> r(MachineType::Int64());
+ 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)); }
}
@@ -408,7 +431,8 @@
WASM_EXEC_TEST(I64Eq) {
REQUIRE(I64Eq);
- WasmRunner<int32_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)); }
@@ -417,7 +441,8 @@
WASM_EXEC_TEST(I64Ne) {
REQUIRE(I64Ne);
- WasmRunner<int32_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)); }
@@ -426,7 +451,8 @@
WASM_EXEC_TEST(I64LtS) {
REQUIRE(I64LtS);
- WasmRunner<int32_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)); }
@@ -435,7 +461,8 @@
WASM_EXEC_TEST(I64LeS) {
REQUIRE(I64LeS);
- WasmRunner<int32_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)); }
@@ -444,7 +471,8 @@
WASM_EXEC_TEST(I64LtU) {
REQUIRE(I64LtU);
- WasmRunner<int32_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)); }
@@ -453,7 +481,8 @@
WASM_EXEC_TEST(I64LeU) {
REQUIRE(I64LeU);
- WasmRunner<int32_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)); }
@@ -462,7 +491,8 @@
WASM_EXEC_TEST(I64GtS) {
REQUIRE(I64GtS);
- WasmRunner<int32_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)); }
@@ -471,7 +501,8 @@
WASM_EXEC_TEST(I64GeS) {
REQUIRE(I64GeS);
- WasmRunner<int32_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)); }
@@ -480,7 +511,8 @@
WASM_EXEC_TEST(I64GtU) {
REQUIRE(I64GtU);
- WasmRunner<int32_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)); }
@@ -489,7 +521,8 @@
WASM_EXEC_TEST(I64GeU) {
REQUIRE(I64GeU);
- WasmRunner<int32_t> r(MachineType::Int64(), MachineType::Int64());
+ 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)); }
@@ -499,7 +532,7 @@
WASM_EXEC_TEST(I32ConvertI64) {
REQUIRE(I32ConvertI64);
FOR_INT64_INPUTS(i) {
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
BUILD(r, WASM_I32_CONVERT_I64(WASM_I64V(*i)));
CHECK_EQ(static_cast<int32_t>(*i), r.Call());
}
@@ -507,14 +540,14 @@
WASM_EXEC_TEST(I64SConvertI32) {
REQUIRE(I64SConvertI32);
- WasmRunner<int64_t> r(MachineType::Int32());
+ 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> r(MachineType::Uint32());
+ 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<uint64_t>(*i), r.Call(*i)); }
}
@@ -529,7 +562,7 @@
{26, 0x1123456782345678},
{38, 0xffedcba09edcba09}};
- WasmRunner<int64_t> r(MachineType::Uint64());
+ 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));
@@ -538,7 +571,7 @@
WASM_EXEC_TEST(F32SConvertI64) {
REQUIRE(F32SConvertI64);
- WasmRunner<float> r(MachineType::Int64());
+ 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)); }
}
@@ -624,7 +657,7 @@
{0x8000008000000001, 0x5f000001},
{0x8000000000000400, 0x5f000000},
{0x8000000000000401, 0x5f000000}};
- WasmRunner<float> r(MachineType::Uint64());
+ 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));
@@ -633,7 +666,7 @@
WASM_EXEC_TEST(F64SConvertI64) {
REQUIRE(F64SConvertI64);
- WasmRunner<double> r(MachineType::Int64());
+ 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)); }
}
@@ -718,7 +751,7 @@
{0x8000008000000001, 0x43e0000010000000},
{0x8000000000000400, 0x43e0000000000000},
{0x8000000000000401, 0x43e0000000000001}};
- WasmRunner<double> r(MachineType::Uint64());
+ 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));
@@ -726,7 +759,7 @@
}
WASM_EXEC_TEST(I64SConvertF32a) {
- WasmRunner<int64_t> r(MachineType::Float32());
+ WasmRunner<int64_t> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
@@ -740,7 +773,7 @@
}
WASM_EXEC_TEST(I64SConvertF64a) {
- WasmRunner<int64_t> r(MachineType::Float64());
+ WasmRunner<int64_t> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
@@ -754,7 +787,7 @@
}
WASM_EXEC_TEST(I64UConvertF32a) {
- WasmRunner<uint64_t> r(MachineType::Float32());
+ WasmRunner<uint64_t> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_I64_UCONVERT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
@@ -768,7 +801,7 @@
}
WASM_EXEC_TEST(I64UConvertF64a) {
- WasmRunner<uint64_t> r(MachineType::Float64());
+ WasmRunner<uint64_t> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_I64_UCONVERT_F64(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
@@ -789,7 +822,7 @@
param_types[4] = kAstI32;
FunctionSig sig(1, 19, param_types);
for (int i = 0; i < 19; i++) {
- TestingModule module;
+ TestingModule module(execution_mode);
WasmFunctionCompiler t(&sig, &module);
if (i == 2 || i == 3) {
continue;
@@ -819,40 +852,44 @@
}
}
-void TestI64Binop(WasmOpcode opcode, int64_t expected, int64_t a, int64_t b) {
+void TestI64Binop(WasmExecutionMode execution_mode, WasmOpcode opcode,
+ int64_t expected, int64_t a, int64_t b) {
{
- WasmRunner<int64_t> r;
+ WasmRunner<int64_t> r(execution_mode);
// return K op K
BUILD(r, WASM_BINOP(opcode, WASM_I64V(a), WASM_I64V(b)));
CHECK_EQ(expected, r.Call());
}
{
- WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ 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));
}
}
-void TestI64Cmp(WasmOpcode opcode, int64_t expected, int64_t a, int64_t b) {
+void TestI64Cmp(WasmExecutionMode execution_mode, WasmOpcode opcode,
+ int64_t expected, int64_t a, int64_t b) {
{
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
// return K op K
BUILD(r, WASM_BINOP(opcode, WASM_I64V(a), WASM_I64V(b)));
CHECK_EQ(expected, r.Call());
}
{
- WasmRunner<int32_t> r(MachineType::Int64(), MachineType::Int64());
+ 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));
}
}
-#define TEST_I64_BINOP(name, expected, a, b) \
- do { \
- if (WASM_64 || kSupported_##name) \
- TestI64Binop(kExpr##name, expected, a, b); \
+#define TEST_I64_BINOP(name, expected, a, b) \
+ do { \
+ if (WASM_64 || kSupported_##name) \
+ TestI64Binop(execution_mode, kExpr##name, expected, a, b); \
} while (false)
WASM_EXEC_TEST(I64Binops) {
@@ -887,9 +924,10 @@
TEST_I64_BINOP(I64Rol, 8728493013947314237, 0xe07af243ac4d219d, 15);
}
-#define TEST_I64_CMP(name, expected, a, b) \
- do { \
- if (WASM_64 || kSupported_##name) TestI64Cmp(kExpr##name, expected, a, b); \
+#define TEST_I64_CMP(name, expected, a, b) \
+ do { \
+ if (WASM_64 || kSupported_##name) \
+ TestI64Cmp(execution_mode, kExpr##name, expected, a, b); \
} while (false)
WASM_EXEC_TEST(I64Compare) {
@@ -944,7 +982,7 @@
{62, 0x0000000000000002}, {63, 0x0000000000000001},
{64, 0x0000000000000000}};
- WasmRunner<int64_t> r(MachineType::Uint64());
+ 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));
@@ -990,7 +1028,7 @@
{2, 0x000000009afdbc84}, {1, 0x000000009afdbc82},
{0, 0x000000009afdbc81}};
- WasmRunner<int64_t> r(MachineType::Uint64());
+ 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));
@@ -1008,7 +1046,7 @@
{26, 0x1123456782345678},
{38, 0xffedcba09edcba09}};
- WasmRunner<int64_t> r(MachineType::Uint64());
+ 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));
@@ -1017,29 +1055,30 @@
// Test the WasmRunner with an Int64 return value and different numbers of
// Int64 parameters.
-TEST(Run_TestI64WasmRunner) {
+WASM_EXEC_TEST(I64WasmRunner) {
REQUIRE(I64Param);
REQUIRE(I64Xor);
- {FOR_INT64_INPUTS(i){WasmRunner<int64_t> r;
+ {FOR_INT64_INPUTS(i){WasmRunner<int64_t> r(execution_mode);
BUILD(r, WASM_I64V(*i));
CHECK_EQ(*i, r.Call());
}
}
{
- WasmRunner<int64_t> r(MachineType::Int64());
+ 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> r(MachineType::Int64(), MachineType::Int64());
+ 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> r(MachineType::Int64(), MachineType::Int64(),
- MachineType::Int64());
+ 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) {
@@ -1051,8 +1090,9 @@
}
}
{
- WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64(),
- MachineType::Int64(), MachineType::Int64());
+ 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),
@@ -1072,7 +1112,7 @@
REQUIRE(I64Sub);
// Build the target function.
TestSignatures sigs;
- TestingModule module;
+ 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();
@@ -1102,7 +1142,7 @@
kExprI64LoadMem};
for (size_t m = 0; m < arraysize(loads); m++) {
- TestingModule module;
+ TestingModule module(execution_mode);
byte* memory = module.AddMemoryElems<byte>(16);
WasmRunner<int64_t> r(&module);
@@ -1138,7 +1178,7 @@
WASM_EXEC_TEST(I64SConvertF32b) {
REQUIRE(I64SConvertF32);
- WasmRunner<int64_t> r(MachineType::Float32());
+ WasmRunner<int64_t> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
@@ -1153,7 +1193,7 @@
WASM_EXEC_TEST(I64SConvertF64b) {
REQUIRE(I64SConvertF64);
- WasmRunner<int64_t> r(MachineType::Float64());
+ WasmRunner<int64_t> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
@@ -1168,7 +1208,7 @@
WASM_EXEC_TEST(I64UConvertF32b) {
REQUIRE(I64UConvertF32);
- WasmRunner<uint64_t> r(MachineType::Float32());
+ WasmRunner<uint64_t> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_I64_UCONVERT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
@@ -1182,7 +1222,7 @@
WASM_EXEC_TEST(I64UConvertF64b) {
REQUIRE(I64UConvertF64);
- WasmRunner<uint64_t> r(MachineType::Float64());
+ WasmRunner<uint64_t> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_I64_UCONVERT_F64(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
@@ -1196,7 +1236,7 @@
WASM_EXEC_TEST(I64ReinterpretF64) {
REQUIRE(I64ReinterpretF64);
- TestingModule module;
+ TestingModule module(execution_mode);
int64_t* memory = module.AddMemoryElems<int64_t>(8);
WasmRunner<int64_t> r(&module);
@@ -1212,7 +1252,7 @@
WASM_EXEC_TEST(F64ReinterpretI64) {
REQUIRE(F64ReinterpretI64);
- TestingModule module;
+ TestingModule module(execution_mode);
int64_t* memory = module.AddMemoryElems<int64_t>(8);
WasmRunner<int64_t> r(&module, MachineType::Int64());
@@ -1230,7 +1270,7 @@
WASM_EXEC_TEST(LoadMemI64) {
REQUIRE(I64LoadStore);
- TestingModule module;
+ TestingModule module(execution_mode);
int64_t* memory = module.AddMemoryElems<int64_t>(8);
module.RandomizeMemory(1111);
WasmRunner<int64_t> r(&module);
@@ -1247,13 +1287,35 @@
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++) {
+ module.RandomizeMemory(1111);
+ WasmRunner<int64_t> r(&module);
+
+ BUILD(r,
+ WASM_LOAD_MEM_ALIGNMENT(MachineType::Int64(), WASM_I8(0), alignment));
+
+ memory[0] = 0xaabbccdd00112233LL;
+ CHECK_EQ(0xaabbccdd00112233LL, r.Call());
+
+ memory[0] = 0x33aabbccdd001122LL;
+ CHECK_EQ(0x33aabbccdd001122LL, r.Call());
+
+ memory[0] = 77777777;
+ CHECK_EQ(77777777, r.Call());
+ }
+}
+
WASM_EXEC_TEST(MemI64_Sum) {
REQUIRE(I64LoadStore);
REQUIRE(I64Add);
REQUIRE(I64Sub);
REQUIRE(I64Phi);
const int kNumElems = 20;
- TestingModule module;
+ 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);
@@ -1283,12 +1345,29 @@
}
}
+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> r(&module, MachineType::Int64());
+ BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int64(), WASM_ZERO, i,
+ WASM_GET_LOCAL(0)));
+ module.RandomizeMemory(1111);
+ memory[0] = 0;
+
+ CHECK_EQ(kWritten, r.Call(kWritten));
+ CHECK_EQ(kWritten, memory[0]);
+ }
+}
+
WASM_EXEC_TEST(I64Global) {
REQUIRE(I64LoadStore);
REQUIRE(I64SConvertI32);
REQUIRE(I64And);
REQUIRE(DepthFirst);
- TestingModule module;
+ TestingModule module(execution_mode);
int64_t* global = module.AddGlobal<int64_t>(MachineType::Int64());
WasmRunner<int32_t> r(&module, MachineType::Int32());
// global = global + p0
@@ -1308,7 +1387,7 @@
WASM_EXEC_TEST(I64Eqz) {
REQUIRE(I64Eq);
- WasmRunner<int32_t> r(MachineType::Int64());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int64());
BUILD(r, WASM_I64_EQZ(WASM_GET_LOCAL(0)));
FOR_INT64_INPUTS(i) {
@@ -1319,7 +1398,8 @@
WASM_EXEC_TEST(I64Ror) {
REQUIRE(I64Ror);
- WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ 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) {
@@ -1332,7 +1412,8 @@
WASM_EXEC_TEST(I64Rol) {
REQUIRE(I64Rol);
- WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ 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) {
@@ -1342,3 +1423,153 @@
}
}
}
+
+WASM_EXEC_TEST(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(),
+ MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(),
+ MachineType::Float64()};
+
+ for (size_t m = 0; m < arraysize(machineTypes); 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)),
+ WASM_ZERO);
+
+ byte memsize = WasmOpcodes::MemSize(machineTypes[m]);
+ uint32_t boundary = 24 - memsize;
+ CHECK_EQ(0, r.Call(boundary)); // in bounds.
+ CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize));
+
+ for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) {
+ CHECK_TRAP(r.Call(offset)); // out of bounds.
+ }
+ }
+}
+
+#define ADD_CODE(vec, ...) \
+ do { \
+ byte __buf[] = {__VA_ARGS__}; \
+ for (size_t i = 0; i < sizeof(__buf); i++) vec.push_back(__buf[i]); \
+ } while (false)
+
+static void CompileCallIndirectMany(LocalType param) {
+ // Make sure we don't run out of registers when compiling indirect calls
+ // with many many parameters.
+ TestSignatures sigs;
+ for (byte num_params = 0; num_params < 40; num_params++) {
+ v8::base::AccountingAllocator allocator;
+ Zone zone(&allocator);
+ HandleScope scope(CcTest::InitIsolateOnce());
+ TestingModule module(kExecuteCompiled);
+ FunctionSig* sig = sigs.many(&zone, kAstStmt, param, num_params);
+
+ module.AddSignature(sig);
+ module.AddSignature(sig);
+ module.AddIndirectFunctionTable(nullptr, 0);
+
+ WasmFunctionCompiler t(sig, &module);
+
+ std::vector<byte> code;
+ ADD_CODE(code, kExprI8Const, 0);
+ for (byte p = 0; p < num_params; p++) {
+ ADD_CODE(code, kExprGetLocal, p);
+ }
+ ADD_CODE(code, kExprCallIndirect, static_cast<byte>(num_params), 1);
+
+ t.Build(&code[0], &code[0] + code.size());
+ t.Compile();
+ }
+}
+
+TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); }
+
+static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
+ const int kExpected = 6333;
+ const int kElemSize = 8;
+ TestSignatures sigs;
+
+ static MachineType mixed[] = {
+ MachineType::Int32(), MachineType::Float32(), MachineType::Int64(),
+ MachineType::Float64(), MachineType::Float32(), MachineType::Int64(),
+ MachineType::Int32(), MachineType::Float64(), MachineType::Float32(),
+ MachineType::Float64(), MachineType::Int32(), MachineType::Int64(),
+ MachineType::Int32(), MachineType::Int32()};
+
+ int num_params = static_cast<int>(arraysize(mixed)) - start;
+ for (int which = 0; which < num_params; which++) {
+ v8::base::AccountingAllocator allocator;
+ Zone zone(&allocator);
+ 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(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.
+ ADD_CODE(code, WASM_ZERO);
+
+ // Load the arguments.
+ for (int i = 0; i < num_params; i++) {
+ int offset = (i + 1) * kElemSize;
+ ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset)));
+ }
+
+ // Call the selector function.
+ ADD_CODE(code, kExprCallFunction, static_cast<byte>(num_params),
+ static_cast<byte>(index));
+
+ // Store the result in memory.
+ ADD_CODE(code,
+ static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(result, true)),
+ ZERO_ALIGNMENT, ZERO_OFFSET);
+
+ // Return the expected value.
+ ADD_CODE(code, WASM_I32V_2(kExpected));
+
+ r.Build(&code[0], &code[0] + code.size());
+
+ // Run the code.
+ for (int t = 0; t < 10; t++) {
+ 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 = module.raw_mem_at<byte>(base + i);
+ byte result = module.raw_mem_at<byte>(i);
+ CHECK_EQ(expected, result);
+ }
+ }
+ }
+}
+
+WASM_EXEC_TEST(MixedCall_i64_0) { Run_WasmMixedCall_N(execution_mode, 0); }
+WASM_EXEC_TEST(MixedCall_i64_1) { Run_WasmMixedCall_N(execution_mode, 1); }
+WASM_EXEC_TEST(MixedCall_i64_2) { Run_WasmMixedCall_N(execution_mode, 2); }
+WASM_EXEC_TEST(MixedCall_i64_3) { Run_WasmMixedCall_N(execution_mode, 3); }
diff --git a/test/cctest/wasm/test-run-wasm-asmjs.cc b/test/cctest/wasm/test-run-wasm-asmjs.cc
index c597fc8..4d39dd6 100644
--- a/test/cctest/wasm/test-run-wasm-asmjs.cc
+++ b/test/cctest/wasm/test-run-wasm-asmjs.cc
@@ -26,8 +26,20 @@
#define RET(x) x, kExprReturn, 1
#define RET_I8(x) kExprI8Const, x, kExprReturn, 1
+namespace {
+uint32_t GetMatchingRelocInfoCount(Handle<Code> code, RelocInfo::Mode rmode) {
+ int filter = 1 << rmode;
+ uint32_t ret = 0;
+ for (RelocIterator it(*code, filter); !it.done(); it.next()) {
+ ++ret;
+ }
+ return ret;
+}
+}
+
WASM_EXEC_TEST(Int32AsmjsDivS) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, 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));
@@ -38,7 +50,8 @@
}
WASM_EXEC_TEST(Int32AsmjsRemS) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, 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));
@@ -49,7 +62,8 @@
}
WASM_EXEC_TEST(Int32AsmjsDivU) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, 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));
@@ -60,7 +74,8 @@
}
WASM_EXEC_TEST(Int32AsmjsRemU) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, 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));
@@ -71,7 +86,7 @@
}
WASM_EXEC_TEST(I32AsmjsSConvertF32) {
- WasmRunner<int32_t> r(MachineType::Float32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_UNOP(kExprI32AsmjsSConvertF32, WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
@@ -81,7 +96,7 @@
}
WASM_EXEC_TEST(I32AsmjsSConvertF64) {
- WasmRunner<int32_t> r(MachineType::Float64());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_UNOP(kExprI32AsmjsSConvertF64, WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
@@ -91,7 +106,7 @@
}
WASM_EXEC_TEST(I32AsmjsUConvertF32) {
- WasmRunner<uint32_t> r(MachineType::Float32());
+ WasmRunner<uint32_t> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_UNOP(kExprI32AsmjsUConvertF32, WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
@@ -101,7 +116,7 @@
}
WASM_EXEC_TEST(I32AsmjsUConvertF64) {
- WasmRunner<uint32_t> r(MachineType::Float64());
+ WasmRunner<uint32_t> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_UNOP(kExprI32AsmjsUConvertF64, WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
@@ -111,7 +126,7 @@
}
WASM_EXEC_TEST(LoadMemI32_oob_asm) {
- TestingModule module;
+ TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module, MachineType::Uint32());
module.RandomizeMemory(1112);
@@ -131,7 +146,7 @@
}
WASM_EXEC_TEST(LoadMemF32_oob_asm) {
- TestingModule module;
+ TestingModule module(execution_mode);
float* memory = module.AddMemoryElems<float>(8);
WasmRunner<float> r(&module, MachineType::Uint32());
module.RandomizeMemory(1112);
@@ -151,7 +166,7 @@
}
WASM_EXEC_TEST(LoadMemF64_oob_asm) {
- TestingModule module;
+ TestingModule module(execution_mode);
double* memory = module.AddMemoryElems<double>(8);
WasmRunner<double> r(&module, MachineType::Uint32());
module.RandomizeMemory(1112);
@@ -173,7 +188,7 @@
}
WASM_EXEC_TEST(StoreMemI32_oob_asm) {
- TestingModule module;
+ TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module, MachineType::Uint32(), MachineType::Uint32());
module.RandomizeMemory(1112);
@@ -193,3 +208,90 @@
CHECK_EQ(7777, r.Call(offset, 7777));
}
}
+
+#define FOREACH_INT_CHECKED_LOAD_OP(TEST_BODY) \
+ TEST_BODY(kExprI32AsmjsLoadMem8S) \
+ TEST_BODY(kExprI32AsmjsLoadMem8U) \
+ TEST_BODY(kExprI32AsmjsLoadMem16S) \
+ TEST_BODY(kExprI32AsmjsLoadMem16U) \
+ TEST_BODY(kExprI32AsmjsLoadMem)
+
+#define FOREACH_INT_CHECKED_STORE_OP(TEST_BODY) \
+ TEST_BODY(kExprI32AsmjsStoreMem8) \
+ TEST_BODY(kExprI32AsmjsStoreMem16) \
+ TEST_BODY(kExprI32AsmjsStoreMem)
+
+#define INT_LOAD_TEST(OP_TYPE) \
+ TEST(RunWasm_AsmCheckedRelocInfo##OP_TYPE) { \
+ TestingModule module(kExecuteCompiled); \
+ WasmRunner<int32_t> r(&module, MachineType::Uint32()); \
+ BUILD(r, WASM_UNOP(OP_TYPE, WASM_GET_LOCAL(0))); \
+ CHECK_EQ(1, GetMatchingRelocInfoCount(module.instance->function_code[0], \
+ RelocInfo::WASM_MEMORY_REFERENCE)); \
+ CHECK_NE( \
+ 0, GetMatchingRelocInfoCount(module.instance->function_code[0], \
+ RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); \
+ }
+
+FOREACH_INT_CHECKED_LOAD_OP(INT_LOAD_TEST)
+
+#define INT_STORE_TEST(OP_TYPE) \
+ TEST(RunWasm_AsmCheckedRelocInfo##OP_TYPE) { \
+ TestingModule module(kExecuteCompiled); \
+ 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(module.instance->function_code[0], \
+ RelocInfo::WASM_MEMORY_REFERENCE)); \
+ CHECK_NE( \
+ 0, GetMatchingRelocInfoCount(module.instance->function_code[0], \
+ RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); \
+ }
+
+FOREACH_INT_CHECKED_STORE_OP(INT_STORE_TEST)
+
+TEST(RunWasm_AsmCheckedLoadFloat32RelocInfo) {
+ TestingModule module(kExecuteCompiled);
+ WasmRunner<float> r(&module, MachineType::Uint32());
+ BUILD(r, WASM_UNOP(kExprF32AsmjsLoadMem, WASM_GET_LOCAL(0)));
+
+ CHECK_EQ(1, GetMatchingRelocInfoCount(module.instance->function_code[0],
+ RelocInfo::WASM_MEMORY_REFERENCE));
+ CHECK_NE(0, GetMatchingRelocInfoCount(module.instance->function_code[0],
+ RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
+}
+
+TEST(RunWasm_AsmCheckedStoreFloat32RelocInfo) {
+ TestingModule module(kExecuteCompiled);
+ 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(module.instance->function_code[0],
+ RelocInfo::WASM_MEMORY_REFERENCE));
+ CHECK_NE(0, GetMatchingRelocInfoCount(module.instance->function_code[0],
+ RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
+}
+
+TEST(RunWasm_AsmCheckedLoadFloat64RelocInfo) {
+ TestingModule module(kExecuteCompiled);
+ WasmRunner<double> r(&module, MachineType::Uint32());
+ BUILD(r, WASM_UNOP(kExprF64AsmjsLoadMem, WASM_GET_LOCAL(0)));
+
+ CHECK_EQ(1, GetMatchingRelocInfoCount(module.instance->function_code[0],
+ RelocInfo::WASM_MEMORY_REFERENCE));
+ CHECK_NE(0, GetMatchingRelocInfoCount(module.instance->function_code[0],
+ RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
+}
+
+TEST(RunWasm_AsmCheckedStoreFloat64RelocInfo) {
+ TestingModule module(kExecuteCompiled);
+ 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(module.instance->function_code[0],
+ RelocInfo::WASM_MEMORY_REFERENCE));
+ CHECK_NE(0, GetMatchingRelocInfoCount(module.instance->function_code[0],
+ RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
+}
diff --git a/test/cctest/wasm/test-run-wasm-interpreter.cc b/test/cctest/wasm/test-run-wasm-interpreter.cc
new file mode 100644
index 0000000..42b0f88
--- /dev/null
+++ b/test/cctest/wasm/test-run-wasm-interpreter.cc
@@ -0,0 +1,289 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "src/wasm/wasm-macro-gen.h"
+
+#include "src/wasm/wasm-interpreter.h"
+
+#include "test/cctest/cctest.h"
+#include "test/cctest/compiler/value-helper.h"
+#include "test/cctest/wasm/test-signatures.h"
+#include "test/cctest/wasm/wasm-run-utils.h"
+
+using namespace v8::base;
+using namespace v8::internal;
+using namespace v8::internal::compiler;
+using namespace v8::internal::wasm;
+
+namespace v8 {
+namespace internal {
+namespace wasm {
+
+TEST(Run_WasmInt8Const_i) {
+ WasmRunner<int32_t> r(kExecuteInterpreted);
+ const byte kExpectedValue = 109;
+ // return(kExpectedValue)
+ BUILD(r, WASM_I8(kExpectedValue));
+ CHECK_EQ(kExpectedValue, r.Call());
+}
+
+TEST(Run_WasmIfElse) {
+ WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32());
+ BUILD(r, WASM_IF_ELSE(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> 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));
+}
+
+TEST(Run_WasmNopsN) {
+ const int kMaxNops = 10;
+ byte code[kMaxNops + 2];
+ for (int nops = 0; nops < kMaxNops; nops++) {
+ byte expected = static_cast<byte>(20 + nops);
+ memset(code, kExprNop, sizeof(code));
+ code[nops] = kExprI8Const;
+ code[nops + 1] = expected;
+
+ WasmRunner<int32_t> r(kExecuteInterpreted);
+ r.Build(code, code + nops + 2);
+ CHECK_EQ(expected, r.Call());
+ }
+}
+
+TEST(Run_WasmConstsN) {
+ const int kMaxConsts = 10;
+ byte code[kMaxConsts * 2];
+ for (int count = 1; count < kMaxConsts; count++) {
+ for (int i = 0; i < count; i++) {
+ code[i * 2] = kExprI8Const;
+ code[i * 2 + 1] = static_cast<byte>(count * 10 + i);
+ }
+ byte expected = static_cast<byte>(count * 11 - 1);
+
+ WasmRunner<int32_t> r(kExecuteInterpreted);
+ r.Build(code, code + (count * 2));
+ CHECK_EQ(expected, r.Call());
+ }
+}
+
+TEST(Run_WasmBlocksN) {
+ const int kMaxNops = 10;
+ const int kExtra = 4;
+ byte code[kMaxNops + kExtra];
+ for (int nops = 0; nops < kMaxNops; nops++) {
+ byte expected = static_cast<byte>(30 + nops);
+ memset(code, kExprNop, sizeof(code));
+ code[0] = kExprBlock;
+ code[1 + nops] = kExprI8Const;
+ code[1 + nops + 1] = expected;
+ code[1 + nops + 2] = kExprEnd;
+
+ WasmRunner<int32_t> r(kExecuteInterpreted);
+ r.Build(code, code + nops + kExtra);
+ CHECK_EQ(expected, r.Call());
+ }
+}
+
+TEST(Run_WasmBlockBreakN) {
+ const int kMaxNops = 10;
+ const int kExtra = 6;
+ byte code[kMaxNops + kExtra];
+ for (int nops = 0; nops < kMaxNops; nops++) {
+ // Place the break anywhere within the block.
+ for (int index = 0; index < nops; index++) {
+ memset(code, kExprNop, sizeof(code));
+ code[0] = kExprBlock;
+ code[sizeof(code) - 1] = kExprEnd;
+
+ int expected = nops * 11 + index;
+ code[1 + index + 0] = kExprI8Const;
+ code[1 + index + 1] = static_cast<byte>(expected);
+ code[1 + index + 2] = kExprBr;
+ code[1 + index + 3] = ARITY_1;
+ code[1 + index + 4] = 0;
+
+ WasmRunner<int32_t> r(kExecuteInterpreted);
+ r.Build(code, code + kMaxNops + kExtra);
+ CHECK_EQ(expected, r.Call());
+ }
+ }
+}
+
+TEST(Run_Wasm_nested_ifs_i) {
+ WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32(),
+ MachineType::Int32());
+
+ BUILD(r, WASM_IF_ELSE(
+ WASM_GET_LOCAL(0),
+ WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)),
+ WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14))));
+
+ CHECK_EQ(11, r.Call(1, 1));
+ CHECK_EQ(12, r.Call(1, 0));
+ CHECK_EQ(13, r.Call(0, 1));
+ CHECK_EQ(14, r.Call(0, 0));
+}
+
+// Make tests more robust by not hard-coding offsets of various operations.
+// The {Find} method finds the offsets for the given bytecodes, returning
+// the offsets in an array.
+SmartArrayPointer<int> Find(byte* code, size_t code_size, int n, ...) {
+ va_list vl;
+ va_start(vl, n);
+
+ SmartArrayPointer<int> offsets(new int[n]);
+
+ for (int i = 0; i < n; i++) {
+ offsets[i] = -1;
+ }
+
+ int pos = 0;
+ WasmOpcode current = static_cast<WasmOpcode>(va_arg(vl, int));
+ for (size_t i = 0; i < code_size; i++) {
+ if (code[i] == current) {
+ offsets[pos++] = static_cast<int>(i);
+ if (pos == n) break;
+ current = static_cast<WasmOpcode>(va_arg(vl, int));
+ }
+ }
+ va_end(vl);
+
+ return offsets;
+}
+
+TEST(Breakpoint_I32Add) {
+ static const int kLocalsDeclSize = 1;
+ static const int kNumBreakpoints = 3;
+ byte code[] = {WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
+ SmartArrayPointer<int> offsets =
+ Find(code, sizeof(code), kNumBreakpoints, kExprGetLocal, kExprGetLocal,
+ kExprI32Add);
+
+ WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
+ MachineType::Uint32());
+
+ r.Build(code, code + arraysize(code));
+
+ WasmInterpreter* interpreter = r.interpreter();
+ WasmInterpreter::Thread* thread = interpreter->GetThread(0);
+ for (int i = 0; i < kNumBreakpoints; i++) {
+ interpreter->SetBreakpoint(r.function(), kLocalsDeclSize + offsets[i],
+ true);
+ }
+
+ FOR_UINT32_INPUTS(a) {
+ for (uint32_t b = 11; b < 3000000000u; b += 1000000000u) {
+ thread->Reset();
+ WasmVal args[] = {WasmVal(*a), WasmVal(b)};
+ thread->PushFrame(r.function(), args);
+
+ for (int i = 0; i < kNumBreakpoints; i++) {
+ thread->Run(); // run to next breakpoint
+ // Check the thread stopped at the right pc.
+ CHECK_EQ(WasmInterpreter::PAUSED, thread->state());
+ CHECK_EQ(kLocalsDeclSize + offsets[i], thread->GetBreakpointPc());
+ }
+
+ thread->Run(); // run to completion
+
+ // Check the thread finished with the right value.
+ CHECK_EQ(WasmInterpreter::FINISHED, thread->state());
+ uint32_t expected = (*a) + (b);
+ CHECK_EQ(expected, thread->GetReturnValue().to<uint32_t>());
+ }
+ }
+}
+
+TEST(Step_I32Mul) {
+ static const int kTraceLength = 4;
+ byte code[] = {WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
+
+ WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
+ MachineType::Uint32());
+
+ r.Build(code, code + arraysize(code));
+
+ WasmInterpreter* interpreter = r.interpreter();
+ WasmInterpreter::Thread* thread = interpreter->GetThread(0);
+
+ FOR_UINT32_INPUTS(a) {
+ for (uint32_t b = 33; b < 3000000000u; b += 1000000000u) {
+ thread->Reset();
+ WasmVal args[] = {WasmVal(*a), WasmVal(b)};
+ thread->PushFrame(r.function(), args);
+
+ // Run instructions one by one.
+ for (int i = 0; i < kTraceLength - 1; i++) {
+ thread->Step();
+ // Check the thread stopped.
+ CHECK_EQ(WasmInterpreter::PAUSED, thread->state());
+ }
+
+ // Run last instruction.
+ thread->Step();
+
+ // Check the thread finished with the right value.
+ CHECK_EQ(WasmInterpreter::FINISHED, thread->state());
+ uint32_t expected = (*a) * (b);
+ CHECK_EQ(expected, thread->GetReturnValue().to<uint32_t>());
+ }
+ }
+}
+
+TEST(Breakpoint_I32And_disable) {
+ static const int kLocalsDeclSize = 1;
+ static const int kNumBreakpoints = 1;
+ byte code[] = {WASM_I32_AND(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
+ SmartArrayPointer<int> offsets =
+ Find(code, sizeof(code), kNumBreakpoints, kExprI32And);
+
+ WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
+ MachineType::Uint32());
+
+ r.Build(code, code + arraysize(code));
+
+ WasmInterpreter* interpreter = r.interpreter();
+ WasmInterpreter::Thread* thread = interpreter->GetThread(0);
+
+ FOR_UINT32_INPUTS(a) {
+ for (uint32_t b = 11; b < 3000000000u; b += 1000000000u) {
+ // Run with and without breakpoints.
+ for (int do_break = 0; do_break < 2; do_break++) {
+ interpreter->SetBreakpoint(r.function(), kLocalsDeclSize + offsets[0],
+ do_break);
+ thread->Reset();
+ WasmVal args[] = {WasmVal(*a), WasmVal(b)};
+ thread->PushFrame(r.function(), args);
+
+ if (do_break) {
+ thread->Run(); // run to next breakpoint
+ // Check the thread stopped at the right pc.
+ CHECK_EQ(WasmInterpreter::PAUSED, thread->state());
+ CHECK_EQ(kLocalsDeclSize + offsets[0], thread->GetBreakpointPc());
+ }
+
+ thread->Run(); // run to completion
+
+ // Check the thread finished with the right value.
+ CHECK_EQ(WasmInterpreter::FINISHED, thread->state());
+ uint32_t expected = (*a) & (b);
+ CHECK_EQ(expected, thread->GetReturnValue().to<uint32_t>());
+ }
+ }
+ }
+}
+
+} // namespace wasm
+} // namespace internal
+} // namespace v8
diff --git a/test/cctest/wasm/test-run-wasm-module.cc b/test/cctest/wasm/test-run-wasm-module.cc
index 05edd62..7a79d67 100644
--- a/test/cctest/wasm/test-run-wasm-module.cc
+++ b/test/cctest/wasm/test-run-wasm-module.cc
@@ -20,14 +20,24 @@
using namespace v8::internal::wasm;
namespace {
-void TestModule(WasmModuleIndex* module, int32_t expected_result) {
+void TestModule(Zone* zone, WasmModuleBuilder* builder,
+ int32_t expected_result) {
+ ZoneBuffer buffer(zone);
+ builder->WriteTo(buffer);
+
Isolate* isolate = CcTest::InitIsolateOnce();
HandleScope scope(isolate);
WasmJs::InstallWasmFunctionMap(isolate, isolate->native_context());
int32_t result =
- CompileAndRunWasmModule(isolate, module->Begin(), module->End());
+ testing::CompileAndRunWasmModule(isolate, buffer.begin(), buffer.end());
CHECK_EQ(expected_result, result);
}
+
+void ExportAsMain(WasmFunctionBuilder* f) {
+ static const char kMainName[] = "main";
+ f->SetExported();
+ f->SetName(kMainName, arraysize(kMainName) - 1);
+}
} // namespace
TEST(Run_WasmModule_Return114) {
@@ -40,11 +50,10 @@
uint16_t f_index = builder->AddFunction();
WasmFunctionBuilder* f = builder->FunctionAt(f_index);
f->SetSignature(sigs.i_v());
- f->Exported(1);
+ ExportAsMain(f);
byte code[] = {WASM_I8(kReturnValue)};
f->EmitCode(code, sizeof(code));
- WasmModuleWriter* writer = builder->Build(&zone);
- TestModule(writer->WriteTo(&zone), kReturnValue);
+ TestModule(&zone, builder, kReturnValue);
}
TEST(Run_WasmModule_CallAdd) {
@@ -66,11 +75,10 @@
f = builder->FunctionAt(f2_index);
f->SetSignature(sigs.i_v());
- f->Exported(1);
+ ExportAsMain(f);
byte code2[] = {WASM_CALL_FUNCTION2(f1_index, WASM_I8(77), WASM_I8(22))};
f->EmitCode(code2, sizeof(code2));
- WasmModuleWriter* writer = builder->Build(&zone);
- TestModule(writer->WriteTo(&zone), 99);
+ TestModule(&zone, builder, 99);
}
TEST(Run_WasmModule_ReadLoadedDataSegment) {
@@ -84,15 +92,14 @@
WasmFunctionBuilder* f = builder->FunctionAt(f_index);
f->SetSignature(sigs.i_v());
- f->Exported(1);
+ ExportAsMain(f);
byte code[] = {
WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kDataSegmentDest0))};
f->EmitCode(code, sizeof(code));
byte data[] = {0xaa, 0xbb, 0xcc, 0xdd};
builder->AddDataSegment(new (&zone) WasmDataSegmentEncoder(
&zone, data, sizeof(data), kDataSegmentDest0));
- WasmModuleWriter* writer = builder->Build(&zone);
- TestModule(writer->WriteTo(&zone), 0xddccbbaa);
+ TestModule(&zone, builder, 0xddccbbaa);
}
TEST(Run_WasmModule_CheckMemoryIsZero) {
@@ -107,7 +114,7 @@
f->SetSignature(sigs.i_v());
uint16_t localIndex = f->AddLocal(kAstI32);
- f->Exported(1);
+ ExportAsMain(f);
byte code[] = {WASM_BLOCK(
2,
WASM_WHILE(
@@ -117,8 +124,7 @@
WASM_BRV(2, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))),
WASM_I8(11))};
f->EmitCode(code, sizeof(code));
- WasmModuleWriter* writer = builder->Build(&zone);
- TestModule(writer->WriteTo(&zone), 11);
+ TestModule(&zone, builder, 11);
}
TEST(Run_WasmModule_CallMain_recursive) {
@@ -132,7 +138,7 @@
f->SetSignature(sigs.i_v());
uint16_t localIndex = f->AddLocal(kAstI32);
- f->Exported(1);
+ ExportAsMain(f);
byte code[] = {WASM_BLOCK(
2, WASM_SET_LOCAL(localIndex,
WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)),
@@ -142,8 +148,7 @@
WASM_BRV(1, WASM_CALL_FUNCTION0(0))),
WASM_BRV(0, WASM_I8(55))))};
f->EmitCode(code, sizeof(code));
- WasmModuleWriter* writer = builder->Build(&zone);
- TestModule(writer->WriteTo(&zone), 55);
+ TestModule(&zone, builder, 55);
}
TEST(Run_WasmModule_Global) {
@@ -163,11 +168,10 @@
uint16_t f2_index = builder->AddFunction();
f = builder->FunctionAt(f2_index);
f->SetSignature(sigs.i_v());
- f->Exported(1);
+ ExportAsMain(f);
byte code2[] = {WASM_STORE_GLOBAL(global1, WASM_I32V_1(56)),
WASM_STORE_GLOBAL(global2, WASM_I32V_1(41)),
WASM_RETURN1(WASM_CALL_FUNCTION0(f1_index))};
f->EmitCode(code2, sizeof(code2));
- WasmModuleWriter* writer = builder->Build(&zone);
- TestModule(writer->WriteTo(&zone), 97);
+ TestModule(&zone, builder, 97);
}
diff --git a/test/cctest/wasm/test-run-wasm-relocation.cc b/test/cctest/wasm/test-run-wasm-relocation.cc
new file mode 100644
index 0000000..6b1f643
--- /dev/null
+++ b/test/cctest/wasm/test-run-wasm-relocation.cc
@@ -0,0 +1,64 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdlib.h>
+
+#include "src/v8.h"
+
+#include "test/cctest/cctest.h"
+#include "test/cctest/compiler/c-signature.h"
+#include "test/cctest/wasm/wasm-run-utils.h"
+
+using namespace v8::internal;
+using namespace v8::internal::compiler;
+
+#define FOREACH_TYPE(TEST_BODY) \
+ TEST_BODY(int8_t, Int8, WASM_I32_ADD) \
+ TEST_BODY(uint8_t, Uint8, WASM_I32_ADD) \
+ TEST_BODY(int16_t, Int16, WASM_I32_ADD) \
+ TEST_BODY(uint16_t, Uint16, WASM_I32_ADD) \
+ TEST_BODY(int32_t, Int32, WASM_I32_ADD) \
+ TEST_BODY(uint32_t, Uint32, WASM_I32_ADD) \
+ TEST_BODY(float, Float32, WASM_F32_ADD) \
+ TEST_BODY(double, Float64, WASM_F64_ADD)
+
+#define LOAD_STORE_GLOBAL_TEST_BODY(C_TYPE, MACHINE_TYPE, ADD) \
+ TEST(WasmRelocateGlobal##MACHINE_TYPE) { \
+ TestingModule module(kExecuteCompiled); \
+ module.AddGlobal<int32_t>(MachineType::MACHINE_TYPE()); \
+ module.AddGlobal<int32_t>(MachineType::MACHINE_TYPE()); \
+ \
+ WasmRunner<C_TYPE> r(&module, MachineType::MACHINE_TYPE()); \
+ \
+ /* global = global + p0 */ \
+ BUILD(r, \
+ WASM_STORE_GLOBAL(1, ADD(WASM_LOAD_GLOBAL(0), WASM_GET_LOCAL(0)))); \
+ CHECK_EQ(1, module.instance->function_code.size()); \
+ \
+ int filter = 1 << RelocInfo::WASM_GLOBAL_REFERENCE; \
+ \
+ Handle<Code> code = module.instance->function_code[0]; \
+ \
+ Address old_start = module.instance->globals_start; \
+ Address new_start = old_start + 1; \
+ \
+ Address old_addresses[2]; \
+ uint32_t address_index = 0U; \
+ for (RelocIterator it(*code, filter); !it.done(); it.next()) { \
+ old_addresses[address_index] = it.rinfo()->wasm_global_reference(); \
+ it.rinfo()->update_wasm_global_reference(old_start, new_start); \
+ ++address_index; \
+ } \
+ CHECK_EQ(2U, address_index); \
+ \
+ address_index = 0U; \
+ for (RelocIterator it(*code, filter); !it.done(); it.next()) { \
+ CHECK_EQ(old_addresses[address_index] + 1, \
+ it.rinfo()->wasm_global_reference()); \
+ ++address_index; \
+ } \
+ CHECK_EQ(2U, address_index); \
+ }
+
+FOREACH_TYPE(LOAD_STORE_GLOBAL_TEST_BODY)
diff --git a/test/cctest/wasm/test-run-wasm.cc b/test/cctest/wasm/test-run-wasm.cc
index 236624f..ec7c5e7 100644
--- a/test/cctest/wasm/test-run-wasm.cc
+++ b/test/cctest/wasm/test-run-wasm.cc
@@ -27,7 +27,7 @@
#define RET_I8(x) kExprI8Const, x, kExprReturn, 1
WASM_EXEC_TEST(Int8Const) {
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
const byte kExpectedValue = 121;
// return(kExpectedValue)
BUILD(r, WASM_I8(kExpectedValue));
@@ -35,7 +35,7 @@
}
WASM_EXEC_TEST(Int8Const_fallthru1) {
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
const byte kExpectedValue = 122;
// kExpectedValue
BUILD(r, WASM_I8(kExpectedValue));
@@ -43,7 +43,7 @@
}
WASM_EXEC_TEST(Int8Const_fallthru2) {
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
const byte kExpectedValue = 123;
// -99 kExpectedValue
BUILD(r, WASM_I8(-99), WASM_I8(kExpectedValue));
@@ -51,8 +51,8 @@
}
WASM_EXEC_TEST(Int8Const_all) {
- for (int value = -128; value <= 127; value++) {
- WasmRunner<int32_t> r;
+ for (int value = -128; value <= 127; ++value) {
+ WasmRunner<int32_t> r(execution_mode);
// return(value)
BUILD(r, WASM_I8(value));
int32_t result = r.Call();
@@ -61,7 +61,7 @@
}
WASM_EXEC_TEST(Int32Const) {
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
const int32_t kExpectedValue = 0x11223344;
// return(kExpectedValue)
BUILD(r, WASM_I32V_5(kExpectedValue));
@@ -70,7 +70,7 @@
WASM_EXEC_TEST(Int32Const_many) {
FOR_INT32_INPUTS(i) {
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
const int32_t kExpectedValue = *i;
// return(kExpectedValue)
BUILD(r, WASM_I32V(kExpectedValue));
@@ -79,7 +79,7 @@
}
WASM_EXEC_TEST(MemorySize) {
- TestingModule module;
+ TestingModule module(execution_mode);
WasmRunner<int32_t> r(&module);
module.AddMemory(1024);
BUILD(r, kExprMemorySize);
@@ -87,49 +87,51 @@
}
WASM_EXEC_TEST(Int32Param0) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// return(local[0])
BUILD(r, WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Int32Param0_fallthru) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// local[0]
BUILD(r, WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Int32Param1) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
+ MachineType::Int32());
// local[1]
BUILD(r, WASM_GET_LOCAL(1));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(-111, *i)); }
}
WASM_EXEC_TEST(Int32Add) {
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
// 11 + 44
BUILD(r, WASM_I32_ADD(WASM_I8(11), WASM_I8(44)));
CHECK_EQ(55, r.Call());
}
WASM_EXEC_TEST(Int32Add_P) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// p0 + 13
BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); }
}
WASM_EXEC_TEST(Int32Add_P_fallthru) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// p0 + 13
BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); }
}
WASM_EXEC_TEST(Int32Add_P2) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
+ MachineType::Int32());
// p0 + p1
BUILD(r, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT32_INPUTS(i) {
@@ -142,7 +144,7 @@
}
WASM_EXEC_TEST(Float32Add) {
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
// int(11.5f + 44.5f)
BUILD(r,
WASM_I32_SCONVERT_F32(WASM_F32_ADD(WASM_F32(11.5f), WASM_F32(44.5f))));
@@ -150,21 +152,23 @@
}
WASM_EXEC_TEST(Float64Add) {
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
// return int(13.5d + 43.5d)
BUILD(r, WASM_I32_SCONVERT_F64(WASM_F64_ADD(WASM_F64(13.5), WASM_F64(43.5))));
CHECK_EQ(57, r.Call());
}
-void TestInt32Binop(WasmOpcode opcode, int32_t expected, int32_t a, int32_t b) {
+void TestInt32Binop(WasmExecutionMode execution_mode, WasmOpcode opcode,
+ int32_t expected, int32_t a, int32_t b) {
{
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
// K op K
BUILD(r, WASM_BINOP(opcode, WASM_I32V(a), WASM_I32V(b)));
CHECK_EQ(expected, r.Call());
}
{
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
+ MachineType::Int32());
// a op b
BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(expected, r.Call(a, b));
@@ -172,46 +176,48 @@
}
WASM_EXEC_TEST(Int32Binops) {
- TestInt32Binop(kExprI32Add, 88888888, 33333333, 55555555);
- TestInt32Binop(kExprI32Sub, -1111111, 7777777, 8888888);
- TestInt32Binop(kExprI32Mul, 65130756, 88734, 734);
- TestInt32Binop(kExprI32DivS, -66, -4777344, 72384);
- TestInt32Binop(kExprI32DivU, 805306368, 0xF0000000, 5);
- TestInt32Binop(kExprI32RemS, -3, -3003, 1000);
- TestInt32Binop(kExprI32RemU, 4, 4004, 1000);
- TestInt32Binop(kExprI32And, 0xEE, 0xFFEE, 0xFF0000FF);
- TestInt32Binop(kExprI32Ior, 0xF0FF00FF, 0xF0F000EE, 0x000F0011);
- TestInt32Binop(kExprI32Xor, 0xABCDEF01, 0xABCDEFFF, 0xFE);
- TestInt32Binop(kExprI32Shl, 0xA0000000, 0xA, 28);
- TestInt32Binop(kExprI32ShrU, 0x07000010, 0x70000100, 4);
- TestInt32Binop(kExprI32ShrS, 0xFF000000, 0x80000000, 7);
- TestInt32Binop(kExprI32Ror, 0x01000000, 0x80000000, 7);
- TestInt32Binop(kExprI32Ror, 0x01000000, 0x80000000, 39);
- TestInt32Binop(kExprI32Rol, 0x00000040, 0x80000000, 7);
- TestInt32Binop(kExprI32Rol, 0x00000040, 0x80000000, 39);
- TestInt32Binop(kExprI32Eq, 1, -99, -99);
- TestInt32Binop(kExprI32Ne, 0, -97, -97);
+ TestInt32Binop(execution_mode, kExprI32Add, 88888888, 33333333, 55555555);
+ TestInt32Binop(execution_mode, kExprI32Sub, -1111111, 7777777, 8888888);
+ TestInt32Binop(execution_mode, kExprI32Mul, 65130756, 88734, 734);
+ TestInt32Binop(execution_mode, kExprI32DivS, -66, -4777344, 72384);
+ TestInt32Binop(execution_mode, kExprI32DivU, 805306368, 0xF0000000, 5);
+ TestInt32Binop(execution_mode, kExprI32RemS, -3, -3003, 1000);
+ TestInt32Binop(execution_mode, kExprI32RemU, 4, 4004, 1000);
+ TestInt32Binop(execution_mode, kExprI32And, 0xEE, 0xFFEE, 0xFF0000FF);
+ TestInt32Binop(execution_mode, kExprI32Ior, 0xF0FF00FF, 0xF0F000EE,
+ 0x000F0011);
+ TestInt32Binop(execution_mode, kExprI32Xor, 0xABCDEF01, 0xABCDEFFF, 0xFE);
+ TestInt32Binop(execution_mode, kExprI32Shl, 0xA0000000, 0xA, 28);
+ TestInt32Binop(execution_mode, kExprI32ShrU, 0x07000010, 0x70000100, 4);
+ TestInt32Binop(execution_mode, kExprI32ShrS, 0xFF000000, 0x80000000, 7);
+ TestInt32Binop(execution_mode, kExprI32Ror, 0x01000000, 0x80000000, 7);
+ TestInt32Binop(execution_mode, kExprI32Ror, 0x01000000, 0x80000000, 39);
+ TestInt32Binop(execution_mode, kExprI32Rol, 0x00000040, 0x80000000, 7);
+ TestInt32Binop(execution_mode, kExprI32Rol, 0x00000040, 0x80000000, 39);
+ TestInt32Binop(execution_mode, kExprI32Eq, 1, -99, -99);
+ TestInt32Binop(execution_mode, kExprI32Ne, 0, -97, -97);
- TestInt32Binop(kExprI32LtS, 1, -4, 4);
- TestInt32Binop(kExprI32LeS, 0, -2, -3);
- TestInt32Binop(kExprI32LtU, 1, 0, -6);
- TestInt32Binop(kExprI32LeU, 1, 98978, 0xF0000000);
+ TestInt32Binop(execution_mode, kExprI32LtS, 1, -4, 4);
+ TestInt32Binop(execution_mode, kExprI32LeS, 0, -2, -3);
+ TestInt32Binop(execution_mode, kExprI32LtU, 1, 0, -6);
+ TestInt32Binop(execution_mode, kExprI32LeU, 1, 98978, 0xF0000000);
- TestInt32Binop(kExprI32GtS, 1, 4, -4);
- TestInt32Binop(kExprI32GeS, 0, -3, -2);
- TestInt32Binop(kExprI32GtU, 1, -6, 0);
- TestInt32Binop(kExprI32GeU, 1, 0xF0000000, 98978);
+ TestInt32Binop(execution_mode, kExprI32GtS, 1, 4, -4);
+ TestInt32Binop(execution_mode, kExprI32GeS, 0, -3, -2);
+ TestInt32Binop(execution_mode, kExprI32GtU, 1, -6, 0);
+ TestInt32Binop(execution_mode, kExprI32GeU, 1, 0xF0000000, 98978);
}
-void TestInt32Unop(WasmOpcode opcode, int32_t expected, int32_t a) {
+void TestInt32Unop(WasmExecutionMode execution_mode, WasmOpcode opcode,
+ int32_t expected, int32_t a) {
{
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
// return op K
BUILD(r, WASM_UNOP(opcode, WASM_I32V(a)));
CHECK_EQ(expected, r.Call());
}
{
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// return op a
BUILD(r, WASM_UNOP(opcode, WASM_GET_LOCAL(0)));
CHECK_EQ(expected, r.Call(a));
@@ -219,95 +225,96 @@
}
WASM_EXEC_TEST(Int32Clz) {
- TestInt32Unop(kExprI32Clz, 0, 0x80001000);
- TestInt32Unop(kExprI32Clz, 1, 0x40000500);
- TestInt32Unop(kExprI32Clz, 2, 0x20000300);
- TestInt32Unop(kExprI32Clz, 3, 0x10000003);
- TestInt32Unop(kExprI32Clz, 4, 0x08050000);
- TestInt32Unop(kExprI32Clz, 5, 0x04006000);
- TestInt32Unop(kExprI32Clz, 6, 0x02000000);
- TestInt32Unop(kExprI32Clz, 7, 0x010000a0);
- TestInt32Unop(kExprI32Clz, 8, 0x00800c00);
- TestInt32Unop(kExprI32Clz, 9, 0x00400000);
- TestInt32Unop(kExprI32Clz, 10, 0x0020000d);
- TestInt32Unop(kExprI32Clz, 11, 0x00100f00);
- TestInt32Unop(kExprI32Clz, 12, 0x00080000);
- TestInt32Unop(kExprI32Clz, 13, 0x00041000);
- TestInt32Unop(kExprI32Clz, 14, 0x00020020);
- TestInt32Unop(kExprI32Clz, 15, 0x00010300);
- TestInt32Unop(kExprI32Clz, 16, 0x00008040);
- TestInt32Unop(kExprI32Clz, 17, 0x00004005);
- TestInt32Unop(kExprI32Clz, 18, 0x00002050);
- TestInt32Unop(kExprI32Clz, 19, 0x00001700);
- TestInt32Unop(kExprI32Clz, 20, 0x00000870);
- TestInt32Unop(kExprI32Clz, 21, 0x00000405);
- TestInt32Unop(kExprI32Clz, 22, 0x00000203);
- TestInt32Unop(kExprI32Clz, 23, 0x00000101);
- TestInt32Unop(kExprI32Clz, 24, 0x00000089);
- TestInt32Unop(kExprI32Clz, 25, 0x00000041);
- TestInt32Unop(kExprI32Clz, 26, 0x00000022);
- TestInt32Unop(kExprI32Clz, 27, 0x00000013);
- TestInt32Unop(kExprI32Clz, 28, 0x00000008);
- TestInt32Unop(kExprI32Clz, 29, 0x00000004);
- TestInt32Unop(kExprI32Clz, 30, 0x00000002);
- TestInt32Unop(kExprI32Clz, 31, 0x00000001);
- TestInt32Unop(kExprI32Clz, 32, 0x00000000);
+ TestInt32Unop(execution_mode, kExprI32Clz, 0, 0x80001000);
+ TestInt32Unop(execution_mode, kExprI32Clz, 1, 0x40000500);
+ TestInt32Unop(execution_mode, kExprI32Clz, 2, 0x20000300);
+ TestInt32Unop(execution_mode, kExprI32Clz, 3, 0x10000003);
+ TestInt32Unop(execution_mode, kExprI32Clz, 4, 0x08050000);
+ TestInt32Unop(execution_mode, kExprI32Clz, 5, 0x04006000);
+ TestInt32Unop(execution_mode, kExprI32Clz, 6, 0x02000000);
+ TestInt32Unop(execution_mode, kExprI32Clz, 7, 0x010000a0);
+ TestInt32Unop(execution_mode, kExprI32Clz, 8, 0x00800c00);
+ TestInt32Unop(execution_mode, kExprI32Clz, 9, 0x00400000);
+ TestInt32Unop(execution_mode, kExprI32Clz, 10, 0x0020000d);
+ TestInt32Unop(execution_mode, kExprI32Clz, 11, 0x00100f00);
+ TestInt32Unop(execution_mode, kExprI32Clz, 12, 0x00080000);
+ TestInt32Unop(execution_mode, kExprI32Clz, 13, 0x00041000);
+ TestInt32Unop(execution_mode, kExprI32Clz, 14, 0x00020020);
+ TestInt32Unop(execution_mode, kExprI32Clz, 15, 0x00010300);
+ TestInt32Unop(execution_mode, kExprI32Clz, 16, 0x00008040);
+ TestInt32Unop(execution_mode, kExprI32Clz, 17, 0x00004005);
+ TestInt32Unop(execution_mode, kExprI32Clz, 18, 0x00002050);
+ TestInt32Unop(execution_mode, kExprI32Clz, 19, 0x00001700);
+ TestInt32Unop(execution_mode, kExprI32Clz, 20, 0x00000870);
+ TestInt32Unop(execution_mode, kExprI32Clz, 21, 0x00000405);
+ TestInt32Unop(execution_mode, kExprI32Clz, 22, 0x00000203);
+ TestInt32Unop(execution_mode, kExprI32Clz, 23, 0x00000101);
+ TestInt32Unop(execution_mode, kExprI32Clz, 24, 0x00000089);
+ TestInt32Unop(execution_mode, kExprI32Clz, 25, 0x00000041);
+ TestInt32Unop(execution_mode, kExprI32Clz, 26, 0x00000022);
+ TestInt32Unop(execution_mode, kExprI32Clz, 27, 0x00000013);
+ TestInt32Unop(execution_mode, kExprI32Clz, 28, 0x00000008);
+ TestInt32Unop(execution_mode, kExprI32Clz, 29, 0x00000004);
+ TestInt32Unop(execution_mode, kExprI32Clz, 30, 0x00000002);
+ TestInt32Unop(execution_mode, kExprI32Clz, 31, 0x00000001);
+ TestInt32Unop(execution_mode, kExprI32Clz, 32, 0x00000000);
}
WASM_EXEC_TEST(Int32Ctz) {
- TestInt32Unop(kExprI32Ctz, 32, 0x00000000);
- TestInt32Unop(kExprI32Ctz, 31, 0x80000000);
- TestInt32Unop(kExprI32Ctz, 30, 0x40000000);
- TestInt32Unop(kExprI32Ctz, 29, 0x20000000);
- TestInt32Unop(kExprI32Ctz, 28, 0x10000000);
- TestInt32Unop(kExprI32Ctz, 27, 0xa8000000);
- TestInt32Unop(kExprI32Ctz, 26, 0xf4000000);
- TestInt32Unop(kExprI32Ctz, 25, 0x62000000);
- TestInt32Unop(kExprI32Ctz, 24, 0x91000000);
- TestInt32Unop(kExprI32Ctz, 23, 0xcd800000);
- TestInt32Unop(kExprI32Ctz, 22, 0x09400000);
- TestInt32Unop(kExprI32Ctz, 21, 0xaf200000);
- TestInt32Unop(kExprI32Ctz, 20, 0xac100000);
- TestInt32Unop(kExprI32Ctz, 19, 0xe0b80000);
- TestInt32Unop(kExprI32Ctz, 18, 0x9ce40000);
- TestInt32Unop(kExprI32Ctz, 17, 0xc7920000);
- TestInt32Unop(kExprI32Ctz, 16, 0xb8f10000);
- TestInt32Unop(kExprI32Ctz, 15, 0x3b9f8000);
- TestInt32Unop(kExprI32Ctz, 14, 0xdb4c4000);
- TestInt32Unop(kExprI32Ctz, 13, 0xe9a32000);
- TestInt32Unop(kExprI32Ctz, 12, 0xfca61000);
- TestInt32Unop(kExprI32Ctz, 11, 0x6c8a7800);
- TestInt32Unop(kExprI32Ctz, 10, 0x8ce5a400);
- TestInt32Unop(kExprI32Ctz, 9, 0xcb7d0200);
- TestInt32Unop(kExprI32Ctz, 8, 0xcb4dc100);
- TestInt32Unop(kExprI32Ctz, 7, 0xdfbec580);
- TestInt32Unop(kExprI32Ctz, 6, 0x27a9db40);
- TestInt32Unop(kExprI32Ctz, 5, 0xde3bcb20);
- TestInt32Unop(kExprI32Ctz, 4, 0xd7e8a610);
- TestInt32Unop(kExprI32Ctz, 3, 0x9afdbc88);
- TestInt32Unop(kExprI32Ctz, 2, 0x9afdbc84);
- TestInt32Unop(kExprI32Ctz, 1, 0x9afdbc82);
- TestInt32Unop(kExprI32Ctz, 0, 0x9afdbc81);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 32, 0x00000000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 31, 0x80000000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 30, 0x40000000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 29, 0x20000000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 28, 0x10000000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 27, 0xa8000000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 26, 0xf4000000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 25, 0x62000000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 24, 0x91000000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 23, 0xcd800000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 22, 0x09400000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 21, 0xaf200000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 20, 0xac100000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 19, 0xe0b80000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 18, 0x9ce40000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 17, 0xc7920000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 16, 0xb8f10000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 15, 0x3b9f8000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 14, 0xdb4c4000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 13, 0xe9a32000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 12, 0xfca61000);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 11, 0x6c8a7800);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 10, 0x8ce5a400);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 9, 0xcb7d0200);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 8, 0xcb4dc100);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 7, 0xdfbec580);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 6, 0x27a9db40);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 5, 0xde3bcb20);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 4, 0xd7e8a610);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 3, 0x9afdbc88);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 2, 0x9afdbc84);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 1, 0x9afdbc82);
+ TestInt32Unop(execution_mode, kExprI32Ctz, 0, 0x9afdbc81);
}
WASM_EXEC_TEST(Int32Popcnt) {
- TestInt32Unop(kExprI32Popcnt, 32, 0xffffffff);
- TestInt32Unop(kExprI32Popcnt, 0, 0x00000000);
- TestInt32Unop(kExprI32Popcnt, 1, 0x00008000);
- TestInt32Unop(kExprI32Popcnt, 13, 0x12345678);
- TestInt32Unop(kExprI32Popcnt, 19, 0xfedcba09);
+ TestInt32Unop(execution_mode, kExprI32Popcnt, 32, 0xffffffff);
+ TestInt32Unop(execution_mode, kExprI32Popcnt, 0, 0x00000000);
+ TestInt32Unop(execution_mode, kExprI32Popcnt, 1, 0x00008000);
+ TestInt32Unop(execution_mode, kExprI32Popcnt, 13, 0x12345678);
+ TestInt32Unop(execution_mode, kExprI32Popcnt, 19, 0xfedcba09);
}
WASM_EXEC_TEST(I32Eqz) {
- TestInt32Unop(kExprI32Eqz, 0, 1);
- TestInt32Unop(kExprI32Eqz, 0, -1);
- TestInt32Unop(kExprI32Eqz, 0, -827343);
- TestInt32Unop(kExprI32Eqz, 0, 8888888);
- TestInt32Unop(kExprI32Eqz, 1, 0);
+ TestInt32Unop(execution_mode, kExprI32Eqz, 0, 1);
+ TestInt32Unop(execution_mode, kExprI32Eqz, 0, -1);
+ TestInt32Unop(execution_mode, kExprI32Eqz, 0, -827343);
+ TestInt32Unop(execution_mode, kExprI32Eqz, 0, 8888888);
+ TestInt32Unop(execution_mode, kExprI32Eqz, 1, 0);
}
WASM_EXEC_TEST(I32Shl) {
- WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32());
+ WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
+ MachineType::Uint32());
BUILD(r, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT32_INPUTS(i) {
@@ -319,7 +326,8 @@
}
WASM_EXEC_TEST(I32Shr) {
- WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32());
+ WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
+ MachineType::Uint32());
BUILD(r, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT32_INPUTS(i) {
@@ -331,7 +339,8 @@
}
WASM_EXEC_TEST(I32Sar) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
+ MachineType::Int32());
BUILD(r, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT32_INPUTS(i) {
@@ -343,7 +352,8 @@
}
WASM_EXEC_TEST(Int32DivS_trap) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
+ MachineType::Int32());
BUILD(r, WASM_I32_DIVS(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));
@@ -354,7 +364,8 @@
}
WASM_EXEC_TEST(Int32RemS_trap) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
+ MachineType::Int32());
BUILD(r, WASM_I32_REMS(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));
@@ -365,7 +376,8 @@
}
WASM_EXEC_TEST(Int32DivU_trap) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
+ MachineType::Int32());
BUILD(r, WASM_I32_DIVU(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));
@@ -376,7 +388,8 @@
}
WASM_EXEC_TEST(Int32RemU_trap) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
+ MachineType::Int32());
BUILD(r, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(17, r.Call(217, 100));
const int32_t kMin = std::numeric_limits<int32_t>::min();
@@ -387,10 +400,10 @@
}
WASM_EXEC_TEST(Int32DivS_byzero_const) {
- for (int8_t denom = -2; denom < 8; denom++) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ for (int8_t denom = -2; denom < 8; ++denom) {
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom)));
- for (int32_t val = -7; val < 8; val++) {
+ for (int32_t val = -7; val < 8; ++val) {
if (denom == 0) {
CHECK_TRAP(r.Call(val));
} else {
@@ -401,11 +414,11 @@
}
WASM_EXEC_TEST(Int32DivU_byzero_const) {
- for (uint32_t denom = 0xfffffffe; denom < 8; denom++) {
- WasmRunner<uint32_t> r(MachineType::Uint32());
+ for (uint32_t denom = 0xfffffffe; denom < 8; ++denom) {
+ WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32());
BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(denom)));
- for (uint32_t val = 0xfffffff0; val < 8; val++) {
+ for (uint32_t val = 0xfffffff0; val < 8; ++val) {
if (denom == 0) {
CHECK_TRAP(r.Call(val));
} else {
@@ -416,7 +429,7 @@
}
WASM_EXEC_TEST(Int32DivS_trap_effect) {
- TestingModule module;
+ TestingModule module(execution_mode);
module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
@@ -434,32 +447,36 @@
CHECK_TRAP(r.Call(0, 0));
}
-void TestFloat32Binop(WasmOpcode opcode, int32_t expected, float a, float b) {
+void TestFloat32Binop(WasmExecutionMode execution_mode, WasmOpcode opcode,
+ int32_t expected, float a, float b) {
{
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
// return K op K
BUILD(r, WASM_BINOP(opcode, WASM_F32(a), WASM_F32(b)));
CHECK_EQ(expected, r.Call());
}
{
- WasmRunner<int32_t> r(MachineType::Float32(), MachineType::Float32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Float32(),
+ MachineType::Float32());
// return a op b
BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(expected, r.Call(a, b));
}
}
-void TestFloat32BinopWithConvert(WasmOpcode opcode, int32_t expected, float a,
+void TestFloat32BinopWithConvert(WasmExecutionMode execution_mode,
+ WasmOpcode opcode, int32_t expected, float a,
float b) {
{
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
// return int(K op K)
BUILD(r,
WASM_I32_SCONVERT_F32(WASM_BINOP(opcode, WASM_F32(a), WASM_F32(b))));
CHECK_EQ(expected, r.Call());
}
{
- WasmRunner<int32_t> r(MachineType::Float32(), MachineType::Float32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Float32(),
+ MachineType::Float32());
// return int(a op b)
BUILD(r, WASM_I32_SCONVERT_F32(
WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
@@ -467,62 +484,68 @@
}
}
-void TestFloat32UnopWithConvert(WasmOpcode opcode, int32_t expected, float a) {
+void TestFloat32UnopWithConvert(WasmExecutionMode execution_mode,
+ WasmOpcode opcode, int32_t expected, float a) {
{
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
// return int(op(K))
BUILD(r, WASM_I32_SCONVERT_F32(WASM_UNOP(opcode, WASM_F32(a))));
CHECK_EQ(expected, r.Call());
}
{
- WasmRunner<int32_t> r(MachineType::Float32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Float32());
// return int(op(a))
BUILD(r, WASM_I32_SCONVERT_F32(WASM_UNOP(opcode, WASM_GET_LOCAL(0))));
CHECK_EQ(expected, r.Call(a));
}
}
-void TestFloat64Binop(WasmOpcode opcode, int32_t expected, double a, double b) {
+void TestFloat64Binop(WasmExecutionMode execution_mode, WasmOpcode opcode,
+ int32_t expected, double a, double b) {
{
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
// return K op K
BUILD(r, WASM_BINOP(opcode, WASM_F64(a), WASM_F64(b)));
CHECK_EQ(expected, r.Call());
}
{
- WasmRunner<int32_t> r(MachineType::Float64(), MachineType::Float64());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Float64(),
+ MachineType::Float64());
// return a op b
BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(expected, r.Call(a, b));
}
}
-void TestFloat64BinopWithConvert(WasmOpcode opcode, int32_t expected, double a,
+void TestFloat64BinopWithConvert(WasmExecutionMode execution_mode,
+ WasmOpcode opcode, int32_t expected, double a,
double b) {
{
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
// return int(K op K)
BUILD(r,
WASM_I32_SCONVERT_F64(WASM_BINOP(opcode, WASM_F64(a), WASM_F64(b))));
CHECK_EQ(expected, r.Call());
}
{
- WasmRunner<int32_t> r(MachineType::Float64(), MachineType::Float64());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Float64(),
+ MachineType::Float64());
BUILD(r, WASM_I32_SCONVERT_F64(
WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
CHECK_EQ(expected, r.Call(a, b));
}
}
-void TestFloat64UnopWithConvert(WasmOpcode opcode, int32_t expected, double a) {
+void TestFloat64UnopWithConvert(WasmExecutionMode execution_mode,
+ WasmOpcode opcode, int32_t expected, double a) {
{
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
// return int(op(K))
BUILD(r, WASM_I32_SCONVERT_F64(WASM_UNOP(opcode, WASM_F64(a))));
CHECK_EQ(expected, r.Call());
}
{
- WasmRunner<int32_t> r(MachineType::Float64());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Float64());
// return int(op(a))
BUILD(r, WASM_I32_SCONVERT_F64(WASM_UNOP(opcode, WASM_GET_LOCAL(0))));
CHECK_EQ(expected, r.Call(a));
@@ -530,49 +553,50 @@
}
WASM_EXEC_TEST(Float32Binops) {
- TestFloat32Binop(kExprF32Eq, 1, 8.125f, 8.125f);
- TestFloat32Binop(kExprF32Ne, 1, 8.125f, 8.127f);
- TestFloat32Binop(kExprF32Lt, 1, -9.5f, -9.0f);
- TestFloat32Binop(kExprF32Le, 1, -1111.0f, -1111.0f);
- TestFloat32Binop(kExprF32Gt, 1, -9.0f, -9.5f);
- TestFloat32Binop(kExprF32Ge, 1, -1111.0f, -1111.0f);
+ TestFloat32Binop(execution_mode, kExprF32Eq, 1, 8.125f, 8.125f);
+ TestFloat32Binop(execution_mode, kExprF32Ne, 1, 8.125f, 8.127f);
+ TestFloat32Binop(execution_mode, kExprF32Lt, 1, -9.5f, -9.0f);
+ TestFloat32Binop(execution_mode, kExprF32Le, 1, -1111.0f, -1111.0f);
+ TestFloat32Binop(execution_mode, kExprF32Gt, 1, -9.0f, -9.5f);
+ TestFloat32Binop(execution_mode, kExprF32Ge, 1, -1111.0f, -1111.0f);
- TestFloat32BinopWithConvert(kExprF32Add, 10, 3.5f, 6.5f);
- TestFloat32BinopWithConvert(kExprF32Sub, 2, 44.5f, 42.5f);
- TestFloat32BinopWithConvert(kExprF32Mul, -66, -132.1f, 0.5f);
- TestFloat32BinopWithConvert(kExprF32Div, 11, 22.1f, 2.0f);
+ TestFloat32BinopWithConvert(execution_mode, kExprF32Add, 10, 3.5f, 6.5f);
+ TestFloat32BinopWithConvert(execution_mode, kExprF32Sub, 2, 44.5f, 42.5f);
+ TestFloat32BinopWithConvert(execution_mode, kExprF32Mul, -66, -132.1f, 0.5f);
+ TestFloat32BinopWithConvert(execution_mode, kExprF32Div, 11, 22.1f, 2.0f);
}
WASM_EXEC_TEST(Float32Unops) {
- TestFloat32UnopWithConvert(kExprF32Abs, 8, 8.125f);
- TestFloat32UnopWithConvert(kExprF32Abs, 9, -9.125f);
- TestFloat32UnopWithConvert(kExprF32Neg, -213, 213.125f);
- TestFloat32UnopWithConvert(kExprF32Sqrt, 12, 144.4f);
+ TestFloat32UnopWithConvert(execution_mode, kExprF32Abs, 8, 8.125f);
+ TestFloat32UnopWithConvert(execution_mode, kExprF32Abs, 9, -9.125f);
+ TestFloat32UnopWithConvert(execution_mode, kExprF32Neg, -213, 213.125f);
+ TestFloat32UnopWithConvert(execution_mode, kExprF32Sqrt, 12, 144.4f);
}
WASM_EXEC_TEST(Float64Binops) {
- TestFloat64Binop(kExprF64Eq, 1, 16.25, 16.25);
- TestFloat64Binop(kExprF64Ne, 1, 16.25, 16.15);
- TestFloat64Binop(kExprF64Lt, 1, -32.4, 11.7);
- TestFloat64Binop(kExprF64Le, 1, -88.9, -88.9);
- TestFloat64Binop(kExprF64Gt, 1, 11.7, -32.4);
- TestFloat64Binop(kExprF64Ge, 1, -88.9, -88.9);
+ TestFloat64Binop(execution_mode, kExprF64Eq, 1, 16.25, 16.25);
+ TestFloat64Binop(execution_mode, kExprF64Ne, 1, 16.25, 16.15);
+ TestFloat64Binop(execution_mode, kExprF64Lt, 1, -32.4, 11.7);
+ TestFloat64Binop(execution_mode, kExprF64Le, 1, -88.9, -88.9);
+ TestFloat64Binop(execution_mode, kExprF64Gt, 1, 11.7, -32.4);
+ TestFloat64Binop(execution_mode, kExprF64Ge, 1, -88.9, -88.9);
- TestFloat64BinopWithConvert(kExprF64Add, 100, 43.5, 56.5);
- TestFloat64BinopWithConvert(kExprF64Sub, 200, 12200.1, 12000.1);
- TestFloat64BinopWithConvert(kExprF64Mul, -33, 134, -0.25);
- TestFloat64BinopWithConvert(kExprF64Div, -1111, -2222.3, 2);
+ TestFloat64BinopWithConvert(execution_mode, kExprF64Add, 100, 43.5, 56.5);
+ TestFloat64BinopWithConvert(execution_mode, kExprF64Sub, 200, 12200.1,
+ 12000.1);
+ TestFloat64BinopWithConvert(execution_mode, kExprF64Mul, -33, 134, -0.25);
+ TestFloat64BinopWithConvert(execution_mode, kExprF64Div, -1111, -2222.3, 2);
}
WASM_EXEC_TEST(Float64Unops) {
- TestFloat64UnopWithConvert(kExprF64Abs, 108, 108.125);
- TestFloat64UnopWithConvert(kExprF64Abs, 209, -209.125);
- TestFloat64UnopWithConvert(kExprF64Neg, -209, 209.125);
- TestFloat64UnopWithConvert(kExprF64Sqrt, 13, 169.4);
+ TestFloat64UnopWithConvert(execution_mode, kExprF64Abs, 108, 108.125);
+ TestFloat64UnopWithConvert(execution_mode, kExprF64Abs, 209, -209.125);
+ TestFloat64UnopWithConvert(execution_mode, kExprF64Neg, -209, 209.125);
+ TestFloat64UnopWithConvert(execution_mode, kExprF64Sqrt, 13, 169.4);
}
WASM_EXEC_TEST(Float32Neg) {
- WasmRunner<float> r(MachineType::Float32());
+ WasmRunner<float> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_F32_NEG(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
@@ -582,22 +606,47 @@
}
WASM_EXEC_TEST(Float32SubMinusZero) {
- WasmRunner<float> r(MachineType::Float32());
+ WasmRunner<float> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_F32_SUB(WASM_F32(-0.0), WASM_GET_LOCAL(0)));
- CHECK_EQ(0x7fe00000, bit_cast<uint32_t>(r.Call(bit_cast<float>(0x7fa00000))));
+ uint32_t sNanValue =
+ bit_cast<uint32_t>(std::numeric_limits<float>::signaling_NaN());
+ uint32_t qNanValue =
+ bit_cast<uint32_t>(std::numeric_limits<float>::quiet_NaN());
+ uint32_t payload = 0x00200000;
+
+ uint32_t expected = (qNanValue & 0xffc00000) | payload;
+ uint32_t operand = (sNanValue & 0xffc00000) | payload;
+ CHECK_EQ(expected, bit_cast<uint32_t>(r.Call(bit_cast<float>(operand))));
+
+ // Change the sign of the NaN.
+ expected |= 0x80000000;
+ operand |= 0x80000000;
+ CHECK_EQ(expected, bit_cast<uint32_t>(r.Call(bit_cast<float>(operand))));
}
WASM_EXEC_TEST(Float64SubMinusZero) {
- WasmRunner<double> r(MachineType::Float64());
+ WasmRunner<double> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_F64_SUB(WASM_F64(-0.0), WASM_GET_LOCAL(0)));
- CHECK_EQ(0x7ff8123456789abc,
- bit_cast<uint64_t>(r.Call(bit_cast<double>(0x7ff0123456789abc))));
+ uint64_t sNanValue =
+ bit_cast<uint64_t>(std::numeric_limits<double>::signaling_NaN());
+ uint64_t qNanValue =
+ bit_cast<uint64_t>(std::numeric_limits<double>::quiet_NaN());
+ uint64_t payload = 0x0000123456789abc;
+
+ uint64_t expected = (qNanValue & 0xfff8000000000000) | payload;
+ uint64_t operand = (sNanValue & 0xfff8000000000000) | payload;
+ CHECK_EQ(expected, bit_cast<uint64_t>(r.Call(bit_cast<double>(operand))));
+
+ // Change the sign of the NaN.
+ expected |= 0x8000000000000000;
+ operand |= 0x8000000000000000;
+ CHECK_EQ(expected, bit_cast<uint64_t>(r.Call(bit_cast<double>(operand))));
}
WASM_EXEC_TEST(Float64Neg) {
- WasmRunner<double> r(MachineType::Float64());
+ WasmRunner<double> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_F64_NEG(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
@@ -607,7 +656,7 @@
}
WASM_EXEC_TEST(IfElse_P) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// if (p0) return 11; else return 22;
BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
WASM_I8(11), // --
@@ -619,33 +668,37 @@
}
WASM_EXEC_TEST(If_empty1) {
- WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32());
+ WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
+ MachineType::Uint32());
BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprEnd, WASM_GET_LOCAL(1));
FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 9, *i)); }
}
WASM_EXEC_TEST(IfElse_empty1) {
- WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32());
+ WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
+ MachineType::Uint32());
BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprElse, kExprEnd, WASM_GET_LOCAL(1));
FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 8, *i)); }
}
WASM_EXEC_TEST(IfElse_empty2) {
- WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32());
+ WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
+ MachineType::Uint32());
BUILD(r, WASM_GET_LOCAL(0), kExprIf, WASM_ZERO, kExprElse, kExprEnd,
WASM_GET_LOCAL(1));
FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 7, *i)); }
}
WASM_EXEC_TEST(IfElse_empty3) {
- WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32());
+ WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
+ MachineType::Uint32());
BUILD(r, WASM_GET_LOCAL(0), kExprIf, kExprElse, WASM_ZERO, kExprEnd,
WASM_GET_LOCAL(1));
FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 6, *i)); }
}
WASM_EXEC_TEST(If_chain) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// if (p0) 13; if (p0) 14; 15
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_I8(13)),
WASM_IF(WASM_GET_LOCAL(0), WASM_I8(14)), WASM_I8(15));
@@ -653,7 +706,8 @@
}
WASM_EXEC_TEST(If_chain_set) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
+ MachineType::Int32());
// if (p0) p1 = 73; if (p0) p1 = 74; p1
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(73))),
WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(74))),
@@ -665,7 +719,7 @@
}
WASM_EXEC_TEST(IfElse_Unreachable1) {
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
// if (0) unreachable; else return 22;
BUILD(r, WASM_IF_ELSE(WASM_ZERO, // --
WASM_UNREACHABLE, // --
@@ -674,21 +728,21 @@
}
WASM_EXEC_TEST(Return12) {
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
BUILD(r, RET_I8(12));
CHECK_EQ(12, r.Call());
}
WASM_EXEC_TEST(Return17) {
- WasmRunner<int32_t> r;
+ WasmRunner<int32_t> r(execution_mode);
BUILD(r, B1(RET_I8(17)));
CHECK_EQ(17, r.Call());
}
WASM_EXEC_TEST(Return_I32) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, RET(WASM_GET_LOCAL(0)));
@@ -696,7 +750,7 @@
}
WASM_EXEC_TEST(Return_F32) {
- WasmRunner<float> r(MachineType::Float32());
+ WasmRunner<float> r(execution_mode, MachineType::Float32());
BUILD(r, RET(WASM_GET_LOCAL(0)));
@@ -712,7 +766,7 @@
}
WASM_EXEC_TEST(Return_F64) {
- WasmRunner<double> r(MachineType::Float64());
+ WasmRunner<double> r(execution_mode, MachineType::Float64());
BUILD(r, RET(WASM_GET_LOCAL(0)));
@@ -728,7 +782,7 @@
}
WASM_EXEC_TEST(Select) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// return select(11, 22, a);
BUILD(r, WASM_SELECT(WASM_I8(11), WASM_I8(22), WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) {
@@ -738,7 +792,7 @@
}
WASM_EXEC_TEST(Select_strict1) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// select(a=0, a=1, a=2); return a
BUILD(r, B2(WASM_SELECT(WASM_SET_LOCAL(0, WASM_I8(0)),
WASM_SET_LOCAL(0, WASM_I8(1)),
@@ -748,7 +802,7 @@
}
WASM_EXEC_TEST(Select_strict2) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
r.AllocateLocal(kAstI32);
r.AllocateLocal(kAstI32);
// select(b=5, c=6, a)
@@ -761,7 +815,7 @@
}
WASM_EXEC_TEST(Select_strict3) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
r.AllocateLocal(kAstI32);
r.AllocateLocal(kAstI32);
// select(b=5, c=6, a=b)
@@ -775,7 +829,7 @@
}
WASM_EXEC_TEST(BrIf_strict) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(
r,
B2(B1(WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(99)))),
@@ -785,14 +839,14 @@
}
WASM_EXEC_TEST(BrTable0a) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r,
B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), WASM_I8(91)));
FOR_INT32_INPUTS(i) { CHECK_EQ(91, r.Call(*i)); }
}
WASM_EXEC_TEST(BrTable0b) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r,
B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(0))),
WASM_I8(92)));
@@ -800,7 +854,7 @@
}
WASM_EXEC_TEST(BrTable0c) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(
r,
B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(1))),
@@ -813,13 +867,13 @@
}
WASM_EXEC_TEST(BrTable1) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), RET_I8(93));
FOR_INT32_INPUTS(i) { CHECK_EQ(93, r.Call(*i)); }
}
WASM_EXEC_TEST(BrTable_loop) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r,
B2(WASM_LOOP(1, WASM_BR_TABLE(WASM_INC_LOCAL_BY(0, 1), 2, BR_TARGET(2),
BR_TARGET(1), BR_TARGET(0))),
@@ -833,7 +887,7 @@
}
WASM_EXEC_TEST(BrTable_br) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r,
B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(1), BR_TARGET(0))),
RET_I8(91)),
@@ -845,7 +899,7 @@
}
WASM_EXEC_TEST(BrTable_br2) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B2(B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 3, BR_TARGET(1),
BR_TARGET(2), BR_TARGET(3), BR_TARGET(0))),
@@ -862,8 +916,8 @@
}
WASM_EXEC_TEST(BrTable4) {
- for (int i = 0; i < 4; i++) {
- for (int t = 0; t < 4; t++) {
+ for (int i = 0; i < 4; ++i) {
+ for (int t = 0; t < 4; ++t) {
uint32_t cases[] = {0, 1, 2, 3};
cases[i] = t;
byte code[] = {B2(B2(B2(B2(B1(WASM_BR_TABLE(
@@ -876,10 +930,10 @@
RET_I8(73)),
WASM_I8(75)};
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
r.Build(code, code + arraysize(code));
- for (int x = -3; x < 50; x++) {
+ for (int x = -3; x < 50; ++x) {
int index = (x > 3 || x < 0) ? 3 : x;
int32_t expected = 70 + cases[index];
CHECK_EQ(expected, r.Call(x));
@@ -889,11 +943,11 @@
}
WASM_EXEC_TEST(BrTable4x4) {
- for (byte a = 0; a < 4; a++) {
- for (byte b = 0; b < 4; b++) {
- for (byte c = 0; c < 4; c++) {
- for (byte d = 0; d < 4; d++) {
- for (int i = 0; i < 4; i++) {
+ for (byte a = 0; a < 4; ++a) {
+ for (byte b = 0; b < 4; ++b) {
+ for (byte c = 0; c < 4; ++c) {
+ for (byte d = 0; d < 4; ++d) {
+ for (int i = 0; i < 4; ++i) {
uint32_t cases[] = {a, b, c, d};
byte code[] = {
B2(B2(B2(B2(B1(WASM_BR_TABLE(
@@ -906,10 +960,10 @@
RET_I8(53)),
WASM_I8(55)};
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
r.Build(code, code + arraysize(code));
- for (int x = -6; x < 47; x++) {
+ for (int x = -6; x < 47; ++x) {
int index = (x > 3 || x < 0) ? 3 : x;
int32_t expected = 50 + cases[index];
CHECK_EQ(expected, r.Call(x));
@@ -931,7 +985,8 @@
WASM_INC_LOCAL_BY(1, 8)),
WASM_GET_LOCAL(1)};
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
+ MachineType::Int32());
r.Build(code, code + arraysize(code));
CHECK_EQ(15, r.Call(0, 0));
@@ -948,7 +1003,7 @@
}
WASM_EXEC_TEST(F32ReinterpretI32) {
- TestingModule module;
+ TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module);
@@ -963,7 +1018,7 @@
}
WASM_EXEC_TEST(I32ReinterpretF32) {
- TestingModule module;
+ TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module, MachineType::Int32());
@@ -980,7 +1035,7 @@
}
WASM_EXEC_TEST(ReturnStore) {
- TestingModule module;
+ TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module);
@@ -999,7 +1054,7 @@
// Build the test function.
TestSignatures sigs;
- TestingModule module;
+ TestingModule module(execution_mode);
WasmFunctionCompiler t(sigs.v_v(), &module);
BUILD(t, kExprNop);
uint32_t index = t.CompileAndAdd();
@@ -1017,7 +1072,7 @@
// We use a wrapper function because WasmRunner<void> does not exist.
// Build the test function.
TestSignatures sigs;
- TestingModule module;
+ TestingModule module(execution_mode);
WasmFunctionCompiler t(sigs.v_v(), &module);
BUILD(t, WASM_RETURN0);
uint32_t index = t.CompileAndAdd();
@@ -1032,37 +1087,38 @@
}
WASM_EXEC_TEST(Block_empty) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, kExprBlock, kExprEnd, WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Block_empty_br1) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B1(WASM_BR(0)), WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Block_empty_brif1) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B1(WASM_BR_IF(0, WASM_ZERO)), WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Block_empty_brif2) {
- WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32());
+ WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
+ MachineType::Uint32());
BUILD(r, B1(WASM_BR_IF(0, WASM_GET_LOCAL(1))), WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); }
}
WASM_EXEC_TEST(Block_br2) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B1(WASM_BRV(0, WASM_GET_LOCAL(0))));
FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Block_If_P) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// { if (p0) return 51; return 52; }
BUILD(r, B2( // --
WASM_IF(WASM_GET_LOCAL(0), // --
@@ -1075,31 +1131,32 @@
}
WASM_EXEC_TEST(Loop_empty) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, kExprLoop, kExprEnd, WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Loop_empty_br1) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, WASM_LOOP(1, WASM_BR(1)), WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Loop_empty_brif1) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, WASM_LOOP(1, WASM_BR_IF(1, WASM_ZERO)), WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Loop_empty_brif2) {
- WasmRunner<uint32_t> r(MachineType::Uint32(), MachineType::Uint32());
+ WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
+ MachineType::Uint32());
BUILD(r, WASM_LOOP(1, WASM_BR_IF(1, WASM_GET_LOCAL(1))), WASM_GET_LOCAL(0));
FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); }
}
WASM_EXEC_TEST(Block_BrIf_P) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(51), WASM_GET_LOCAL(0)), WASM_I8(52)));
FOR_INT32_INPUTS(i) {
int32_t expected = *i ? 51 : 52;
@@ -1108,7 +1165,7 @@
}
WASM_EXEC_TEST(Block_IfElse_P_assign) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// { if (p0) p0 = 71; else p0 = 72; return p0; }
BUILD(r, B2( // --
WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
@@ -1122,7 +1179,7 @@
}
WASM_EXEC_TEST(Block_IfElse_P_return) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// if (p0) return 81; else return 82;
BUILD(r, // --
WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
@@ -1135,7 +1192,7 @@
}
WASM_EXEC_TEST(Block_If_P_assign) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// { if (p0) p0 = 61; p0; }
BUILD(r, WASM_BLOCK(
2, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(61))),
@@ -1147,14 +1204,14 @@
}
WASM_EXEC_TEST(DanglingAssign) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// { return 0; p0 = 0; }
BUILD(r, B2(RET_I8(99), WASM_SET_LOCAL(0, WASM_ZERO)));
CHECK_EQ(99, r.Call(1));
}
WASM_EXEC_TEST(ExprIf_P) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// p0 ? 11 : 22;
BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
WASM_I8(11), // --
@@ -1166,7 +1223,7 @@
}
WASM_EXEC_TEST(ExprIf_P_fallthru) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// p0 ? 11 : 22;
BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
WASM_I8(11), // --
@@ -1178,7 +1235,7 @@
}
WASM_EXEC_TEST(CountDown) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r,
WASM_BLOCK(
2, WASM_LOOP(
@@ -1193,7 +1250,7 @@
}
WASM_EXEC_TEST(CountDown_fallthru) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r,
WASM_BLOCK(
2, WASM_LOOP(3, WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), WASM_BREAK(1)),
@@ -1207,7 +1264,7 @@
}
WASM_EXEC_TEST(WhileCountDown) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, WASM_BLOCK(
2, WASM_WHILE(WASM_GET_LOCAL(0),
WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0),
@@ -1219,7 +1276,7 @@
}
WASM_EXEC_TEST(Loop_if_break1) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B2(WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(1)),
WASM_SET_LOCAL(0, WASM_I8(99))),
WASM_GET_LOCAL(0)));
@@ -1230,7 +1287,7 @@
}
WASM_EXEC_TEST(Loop_if_break2) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B2(WASM_LOOP(2, WASM_BR_IF(1, WASM_GET_LOCAL(0)),
WASM_SET_LOCAL(0, WASM_I8(99))),
WASM_GET_LOCAL(0)));
@@ -1241,7 +1298,7 @@
}
WASM_EXEC_TEST(Loop_if_break_fallthru) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B1(WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(1)),
WASM_SET_LOCAL(0, WASM_I8(93)))),
WASM_GET_LOCAL(0));
@@ -1252,7 +1309,7 @@
}
WASM_EXEC_TEST(IfBreak1) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), WASM_UNREACHABLE)),
WASM_I8(91));
CHECK_EQ(91, r.Call(0));
@@ -1261,7 +1318,7 @@
}
WASM_EXEC_TEST(IfBreak2) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), RET_I8(77))),
WASM_I8(81));
CHECK_EQ(81, r.Call(0));
@@ -1270,7 +1327,7 @@
}
WASM_EXEC_TEST(LoadMemI32) {
- TestingModule module;
+ TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module, MachineType::Int32());
module.RandomizeMemory(1111);
@@ -1287,8 +1344,29 @@
CHECK_EQ(77777777, r.Call(0));
}
+WASM_EXEC_TEST(LoadMemI32_alignment) {
+ TestingModule module(execution_mode);
+ int32_t* memory = module.AddMemoryElems<int32_t>(8);
+ for (byte alignment = 0; alignment <= 2; ++alignment) {
+ WasmRunner<int32_t> r(&module, MachineType::Int32());
+ module.RandomizeMemory(1111);
+
+ BUILD(r,
+ WASM_LOAD_MEM_ALIGNMENT(MachineType::Int32(), WASM_I8(0), alignment));
+
+ memory[0] = 0x1a2b3c4d;
+ CHECK_EQ(0x1a2b3c4d, r.Call(0));
+
+ memory[0] = 0x5e6f7a8b;
+ CHECK_EQ(0x5e6f7a8b, r.Call(0));
+
+ memory[0] = 0x9ca0b1c2;
+ CHECK_EQ(0x9ca0b1c2, r.Call(0));
+ }
+}
+
WASM_EXEC_TEST(LoadMemI32_oob) {
- TestingModule module;
+ TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module, MachineType::Uint32());
module.RandomizeMemory(1111);
@@ -1297,17 +1375,17 @@
memory[0] = 88888888;
CHECK_EQ(88888888, r.Call(0u));
- for (uint32_t offset = 29; offset < 40; offset++) {
+ for (uint32_t offset = 29; offset < 40; ++offset) {
CHECK_TRAP(r.Call(offset));
}
- for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) {
+ for (uint32_t offset = 0x80000000; offset < 0x80000010; ++offset) {
CHECK_TRAP(r.Call(offset));
}
}
WASM_EXEC_TEST(LoadMem_offset_oob) {
- TestingModule module;
+ TestingModule module(execution_mode);
module.AddMemoryElems<int32_t>(8);
static const MachineType machineTypes[] = {
@@ -1316,7 +1394,7 @@
MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(),
MachineType::Float64()};
- for (size_t m = 0; m < arraysize(machineTypes); m++) {
+ for (size_t m = 0; m < arraysize(machineTypes); ++m) {
module.RandomizeMemory(1116 + static_cast<int>(m));
WasmRunner<int32_t> r(&module, MachineType::Uint32());
uint32_t boundary = 24 - WasmOpcodes::MemSize(machineTypes[m]);
@@ -1326,14 +1404,14 @@
CHECK_EQ(0, r.Call(boundary)); // in bounds.
- for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) {
+ for (uint32_t offset = boundary + 1; offset < boundary + 19; ++offset) {
CHECK_TRAP(r.Call(offset)); // out of bounds.
}
}
}
WASM_EXEC_TEST(LoadMemI32_offset) {
- TestingModule module;
+ TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(4);
WasmRunner<int32_t> r(&module, MachineType::Int32());
module.RandomizeMemory(1111);
@@ -1357,14 +1435,12 @@
CHECK_EQ(44444444, r.Call(8));
}
-#if !V8_TARGET_ARCH_MIPS && !V8_TARGET_ARCH_MIPS64
-
WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) {
const int kMemSize = 12;
// TODO(titzer): Fix misaligned accesses on MIPS and re-enable.
- for (int offset = 0; offset < kMemSize + 5; offset++) {
- for (int index = 0; index < kMemSize + 5; index++) {
- TestingModule module;
+ for (int offset = 0; offset < kMemSize + 5; ++offset) {
+ for (int index = 0; index < kMemSize + 5; ++index) {
+ TestingModule module(execution_mode);
module.AddMemoryElems<byte>(kMemSize);
WasmRunner<int32_t> r(&module);
@@ -1382,13 +1458,11 @@
}
}
-#endif
-
WASM_EXEC_TEST(LoadMemI32_const_oob) {
const int kMemSize = 24;
for (int offset = 0; offset < kMemSize + 5; offset += 4) {
for (int index = 0; index < kMemSize + 5; index += 4) {
- TestingModule module;
+ TestingModule module(execution_mode);
module.AddMemoryElems<byte>(kMemSize);
WasmRunner<int32_t> r(&module);
@@ -1406,8 +1480,25 @@
}
}
+WASM_EXEC_TEST(StoreMemI32_alignment) {
+ TestingModule module(execution_mode);
+ int32_t* memory = module.AddMemoryElems<int32_t>(4);
+ const int32_t kWritten = 0x12345678;
+
+ for (byte i = 0; i <= 2; ++i) {
+ WasmRunner<int32_t> r(&module, MachineType::Int32());
+ BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int32(), WASM_ZERO, i,
+ WASM_GET_LOCAL(0)));
+ module.RandomizeMemory(1111);
+ memory[0] = 0;
+
+ CHECK_EQ(kWritten, r.Call(kWritten));
+ CHECK_EQ(kWritten, memory[0]);
+ }
+}
+
WASM_EXEC_TEST(StoreMemI32_offset) {
- TestingModule module;
+ TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(4);
WasmRunner<int32_t> r(&module, MachineType::Int32());
const int32_t kWritten = 0xaabbccdd;
@@ -1415,7 +1506,7 @@
BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0),
WASM_I32V_5(kWritten)));
- for (int i = 0; i < 2; i++) {
+ for (int i = 0; i < 2; ++i) {
module.RandomizeMemory(1111);
memory[0] = 66666666;
memory[1] = 77777777;
@@ -1430,23 +1521,16 @@
}
WASM_EXEC_TEST(StoreMem_offset_oob) {
- TestingModule module;
+ TestingModule module(execution_mode);
byte* memory = module.AddMemoryElems<byte>(32);
-#if WASM_64
- static const MachineType machineTypes[] = {
- MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
- MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
- MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(),
- MachineType::Float64()};
-#else
+ // 64-bit cases are handled in test-run-wasm-64.cc
static const MachineType machineTypes[] = {
MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
MachineType::Float32(), MachineType::Float64()};
-#endif
- for (size_t m = 0; m < arraysize(machineTypes); m++) {
+ for (size_t m = 0; m < arraysize(machineTypes); ++m) {
module.RandomizeMemory(1119 + static_cast<int>(m));
WasmRunner<int32_t> r(&module, MachineType::Uint32());
@@ -1459,7 +1543,7 @@
CHECK_EQ(0, r.Call(boundary)); // in bounds.
CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize));
- for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) {
+ for (uint32_t offset = boundary + 1; offset < boundary + 19; ++offset) {
CHECK_TRAP(r.Call(offset)); // out of bounds.
}
}
@@ -1467,21 +1551,21 @@
WASM_EXEC_TEST(LoadMemI32_P) {
const int kNumElems = 8;
- TestingModule module;
+ TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(kNumElems);
WasmRunner<int32_t> r(&module, MachineType::Int32());
module.RandomizeMemory(2222);
BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0)));
- for (int i = 0; i < kNumElems; i++) {
+ for (int i = 0; i < kNumElems; ++i) {
CHECK_EQ(memory[i], r.Call(i * 4));
}
}
WASM_EXEC_TEST(MemI32_Sum) {
const int kNumElems = 20;
- TestingModule module;
+ TestingModule module(execution_mode);
uint32_t* memory = module.AddMemoryElems<uint32_t>(kNumElems);
WasmRunner<uint32_t> r(&module, MachineType::Int32());
const byte kSum = r.AllocateLocal(kAstI32);
@@ -1500,20 +1584,20 @@
WASM_GET_LOCAL(1)));
// Run 4 trials.
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < 3; ++i) {
module.RandomizeMemory(i * 33);
uint32_t expected = 0;
- for (size_t j = kNumElems - 1; j > 0; j--) {
+ for (size_t j = kNumElems - 1; j > 0; --j) {
expected += memory[j];
}
- uint32_t result = r.Call(static_cast<int>(4 * (kNumElems - 1)));
+ uint32_t result = r.Call(4 * (kNumElems - 1));
CHECK_EQ(expected, result);
}
}
WASM_EXEC_TEST(CheckMachIntsZero) {
const int kNumElems = 55;
- TestingModule module;
+ TestingModule module(execution_mode);
module.AddMemoryElems<uint32_t>(kNumElems);
WasmRunner<uint32_t> r(&module, MachineType::Int32());
@@ -1528,7 +1612,7 @@
WASM_EXEC_TEST(MemF32_Sum) {
const int kSize = 5;
- TestingModule module;
+ TestingModule module(execution_mode);
module.AddMemoryElems<float>(kSize);
float* buffer = module.raw_mem_start<float>();
buffer[0] = -99.25;
@@ -1560,11 +1644,12 @@
}
template <typename T>
-T GenerateAndRunFold(WasmOpcode binop, T* buffer, size_t size,
- LocalType astType, MachineType memType) {
- TestingModule module;
+T GenerateAndRunFold(WasmExecutionMode execution_mode, WasmOpcode binop,
+ T* buffer, uint32_t size, LocalType astType,
+ MachineType memType) {
+ TestingModule module(execution_mode);
module.AddMemoryElems<T>(size);
- for (size_t i = 0; i < size; i++) {
+ for (uint32_t i = 0; i < size; ++i) {
module.raw_mem_start<T>()[i] = buffer[i];
}
WasmRunner<int32_t> r(&module, MachineType::Int32());
@@ -1592,19 +1677,20 @@
WASM_EXEC_TEST(MemF64_Mul) {
const size_t kSize = 6;
double buffer[kSize] = {1, 2, 2, 2, 2, 2};
- double result = GenerateAndRunFold<double>(kExprF64Mul, buffer, kSize,
- kAstF64, MachineType::Float64());
+ double result =
+ GenerateAndRunFold<double>(execution_mode, kExprF64Mul, buffer, kSize,
+ kAstF64, MachineType::Float64());
CHECK_EQ(32, result);
}
-TEST(Build_Wasm_Infinite_Loop) {
- WasmRunner<int32_t> r(MachineType::Int32());
+WASM_EXEC_TEST(Build_Wasm_Infinite_Loop) {
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
// Only build the graph and compile, don't run.
BUILD(r, WASM_INFINITE_LOOP);
}
-TEST(Build_Wasm_Infinite_Loop_effect) {
- TestingModule module;
+WASM_EXEC_TEST(Build_Wasm_Infinite_Loop_effect) {
+ TestingModule module(execution_mode);
module.AddMemoryElems<int8_t>(16);
WasmRunner<int32_t> r(&module, MachineType::Int32());
@@ -1613,47 +1699,47 @@
}
WASM_EXEC_TEST(Unreachable0a) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B2(WASM_BRV(0, WASM_I8(9)), RET(WASM_GET_LOCAL(0))));
CHECK_EQ(9, r.Call(0));
CHECK_EQ(9, r.Call(1));
}
WASM_EXEC_TEST(Unreachable0b) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B2(WASM_BRV(0, WASM_I8(7)), WASM_UNREACHABLE));
CHECK_EQ(7, r.Call(0));
CHECK_EQ(7, r.Call(1));
}
TEST(Build_Wasm_Unreachable1) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
BUILD(r, WASM_UNREACHABLE);
}
TEST(Build_Wasm_Unreachable2) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
BUILD(r, WASM_UNREACHABLE, WASM_UNREACHABLE);
}
TEST(Build_Wasm_Unreachable3) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
BUILD(r, WASM_UNREACHABLE, WASM_UNREACHABLE, WASM_UNREACHABLE);
}
TEST(Build_Wasm_UnreachableIf1) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
BUILD(r, WASM_UNREACHABLE, WASM_IF(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
}
TEST(Build_Wasm_UnreachableIf2) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
BUILD(r, WASM_UNREACHABLE,
WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE));
}
WASM_EXEC_TEST(Unreachable_Load) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B2(WASM_BRV(0, WASM_GET_LOCAL(0)),
WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0))));
CHECK_EQ(11, r.Call(11));
@@ -1661,14 +1747,14 @@
}
WASM_EXEC_TEST(Infinite_Loop_not_taken1) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I8(45)));
// Run the code, but don't go into the infinite loop.
CHECK_EQ(45, r.Call(0));
}
WASM_EXEC_TEST(Infinite_Loop_not_taken2) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(45)),
WASM_INFINITE_LOOP)));
// Run the code, but don't go into the infinite loop.
@@ -1676,7 +1762,7 @@
}
WASM_EXEC_TEST(Infinite_Loop_not_taken2_brif) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r,
B2(WASM_BRV_IF(0, WASM_I8(45), WASM_GET_LOCAL(0)), WASM_INFINITE_LOOP));
// Run the code, but don't go into the infinite loop.
@@ -1719,7 +1805,7 @@
}
WASM_EXEC_TEST(Int32LoadInt8_signext) {
- TestingModule module;
+ TestingModule module(execution_mode);
const int kNumElems = 16;
int8_t* memory = module.AddMemoryElems<int8_t>(kNumElems);
module.RandomizeMemory();
@@ -1727,13 +1813,13 @@
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0)));
- for (size_t i = 0; i < kNumElems; i++) {
- CHECK_EQ(memory[i], r.Call(static_cast<int>(i)));
+ for (int i = 0; i < kNumElems; ++i) {
+ CHECK_EQ(memory[i], r.Call(i));
}
}
WASM_EXEC_TEST(Int32LoadInt8_zeroext) {
- TestingModule module;
+ TestingModule module(execution_mode);
const int kNumElems = 16;
byte* memory = module.AddMemory(kNumElems);
module.RandomizeMemory(77);
@@ -1741,13 +1827,13 @@
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_LOAD_MEM(MachineType::Uint8(), WASM_GET_LOCAL(0)));
- for (size_t i = 0; i < kNumElems; i++) {
- CHECK_EQ(memory[i], r.Call(static_cast<int>(i)));
+ for (int i = 0; i < kNumElems; ++i) {
+ CHECK_EQ(memory[i], r.Call(i));
}
}
WASM_EXEC_TEST(Int32LoadInt16_signext) {
- TestingModule module;
+ TestingModule module(execution_mode);
const int kNumBytes = 16;
byte* memory = module.AddMemory(kNumBytes);
module.RandomizeMemory(888);
@@ -1755,14 +1841,14 @@
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_LOAD_MEM(MachineType::Int16(), WASM_GET_LOCAL(0)));
- for (size_t i = 0; i < kNumBytes; i += 2) {
+ for (int i = 0; i < kNumBytes; i += 2) {
int32_t expected = memory[i] | (static_cast<int8_t>(memory[i + 1]) << 8);
- CHECK_EQ(expected, r.Call(static_cast<int>(i)));
+ CHECK_EQ(expected, r.Call(i));
}
}
WASM_EXEC_TEST(Int32LoadInt16_zeroext) {
- TestingModule module;
+ TestingModule module(execution_mode);
const int kNumBytes = 16;
byte* memory = module.AddMemory(kNumBytes);
module.RandomizeMemory(9999);
@@ -1770,14 +1856,14 @@
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_LOAD_MEM(MachineType::Uint16(), WASM_GET_LOCAL(0)));
- for (size_t i = 0; i < kNumBytes; i += 2) {
+ for (int i = 0; i < kNumBytes; i += 2) {
int32_t expected = memory[i] | (memory[i + 1] << 8);
- CHECK_EQ(expected, r.Call(static_cast<int>(i)));
+ CHECK_EQ(expected, r.Call(i));
}
}
WASM_EXEC_TEST(Int32Global) {
- TestingModule module;
+ TestingModule module(execution_mode);
int32_t* global = module.AddGlobal<int32_t>(MachineType::Int32());
WasmRunner<int32_t> r(&module, MachineType::Int32());
// global = global + p0
@@ -1794,12 +1880,12 @@
WASM_EXEC_TEST(Int32Globals_DontAlias) {
const int kNumGlobals = 3;
- TestingModule module;
+ TestingModule module(execution_mode);
int32_t* globals[] = {module.AddGlobal<int32_t>(MachineType::Int32()),
module.AddGlobal<int32_t>(MachineType::Int32()),
module.AddGlobal<int32_t>(MachineType::Int32())};
- for (int g = 0; g < kNumGlobals; g++) {
+ for (int g = 0; g < kNumGlobals; ++g) {
// global = global + p0
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_STORE_GLOBAL(
@@ -1810,9 +1896,9 @@
int32_t before[kNumGlobals];
for (int i = 9; i < 444444; i += 111113) {
int32_t sum = *globals[g] + i;
- for (int j = 0; j < kNumGlobals; j++) before[j] = *globals[j];
+ for (int j = 0; j < kNumGlobals; ++j) before[j] = *globals[j];
r.Call(i);
- for (int j = 0; j < kNumGlobals; j++) {
+ for (int j = 0; j < kNumGlobals; ++j) {
int32_t expected = j == g ? sum : before[j];
CHECK_EQ(expected, *globals[j]);
}
@@ -1821,7 +1907,7 @@
}
WASM_EXEC_TEST(Float32Global) {
- TestingModule module;
+ TestingModule module(execution_mode);
float* global = module.AddGlobal<float>(MachineType::Float32());
WasmRunner<int32_t> r(&module, MachineType::Int32());
// global = global + p0
@@ -1839,7 +1925,7 @@
}
WASM_EXEC_TEST(Float64Global) {
- TestingModule module;
+ TestingModule module(execution_mode);
double* global = module.AddGlobal<double>(MachineType::Float64());
WasmRunner<int32_t> r(&module, MachineType::Int32());
// global = global + p0
@@ -1857,7 +1943,7 @@
}
WASM_EXEC_TEST(MixedGlobals) {
- TestingModule module;
+ TestingModule module(execution_mode);
int32_t* unused = module.AddGlobal<int32_t>(MachineType::Int32());
byte* memory = module.AddMemory(32);
@@ -1914,7 +2000,7 @@
const int32_t kExpected = -414444;
// Build the target function.
TestSignatures sigs;
- TestingModule module;
+ TestingModule module(execution_mode);
WasmFunctionCompiler t(sigs.i_v(), &module);
BUILD(t, WASM_I32V_3(kExpected));
uint32_t index = t.CompileAndAdd();
@@ -1930,9 +2016,9 @@
WASM_EXEC_TEST(CallF32StackParameter) {
// Build the target function.
LocalType param_types[20];
- for (int i = 0; i < 20; i++) param_types[i] = kAstF32;
+ for (int i = 0; i < 20; ++i) param_types[i] = kAstF32;
FunctionSig sig(1, 19, param_types);
- TestingModule module;
+ TestingModule module(execution_mode);
WasmFunctionCompiler t(&sig, &module);
BUILD(t, WASM_GET_LOCAL(17));
uint32_t index = t.CompileAndAdd();
@@ -1954,9 +2040,9 @@
WASM_EXEC_TEST(CallF64StackParameter) {
// Build the target function.
LocalType param_types[20];
- for (int i = 0; i < 20; i++) param_types[i] = kAstF64;
+ for (int i = 0; i < 20; ++i) param_types[i] = kAstF64;
FunctionSig sig(1, 19, param_types);
- TestingModule module;
+ TestingModule module(execution_mode);
WasmFunctionCompiler t(&sig, &module);
BUILD(t, WASM_GET_LOCAL(17));
uint32_t index = t.CompileAndAdd();
@@ -1981,7 +2067,7 @@
const int32_t kExpected = -414444;
// Build the target function.
TestSignatures sigs;
- TestingModule module;
+ TestingModule module(execution_mode);
module.AddMemory(16);
module.RandomizeMemory();
WasmFunctionCompiler t(sigs.v_v(), &module);
@@ -2002,7 +2088,7 @@
WASM_EXEC_TEST(Call_Int32Add) {
// Build the target function.
TestSignatures sigs;
- TestingModule module;
+ TestingModule module(execution_mode);
WasmFunctionCompiler t(sigs.i_ii(), &module);
BUILD(t, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
uint32_t index = t.CompileAndAdd();
@@ -2022,7 +2108,7 @@
WASM_EXEC_TEST(Call_Float32Sub) {
TestSignatures sigs;
- TestingModule module;
+ TestingModule module(execution_mode);
WasmFunctionCompiler t(sigs.f_ff(), &module);
// Build the target function.
@@ -2039,7 +2125,7 @@
}
WASM_EXEC_TEST(Call_Float64Sub) {
- TestingModule module;
+ TestingModule module(execution_mode);
double* memory = module.AddMemoryElems<double>(16);
WasmRunner<int32_t> r(&module);
@@ -2069,34 +2155,26 @@
#define ADD_CODE(vec, ...) \
do { \
byte __buf[] = {__VA_ARGS__}; \
- for (size_t i = 0; i < sizeof(__buf); i++) vec.push_back(__buf[i]); \
+ for (size_t i = 0; i < sizeof(__buf); ++i) vec.push_back(__buf[i]); \
} while (false)
-static void Run_WasmMixedCall_N(int start) {
+static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
const int kExpected = 6333;
const int kElemSize = 8;
TestSignatures sigs;
-#if WASM_64
- static MachineType mixed[] = {
- MachineType::Int32(), MachineType::Float32(), MachineType::Int64(),
- MachineType::Float64(), MachineType::Float32(), MachineType::Int64(),
- MachineType::Int32(), MachineType::Float64(), MachineType::Float32(),
- MachineType::Float64(), MachineType::Int32(), MachineType::Int64(),
- MachineType::Int32(), MachineType::Int32()};
-#else
+ // 64-bit cases handled in test-run-wasm-64.cc.
static MachineType mixed[] = {
MachineType::Int32(), MachineType::Float32(), MachineType::Float64(),
MachineType::Float32(), MachineType::Int32(), MachineType::Float64(),
MachineType::Float32(), MachineType::Float64(), MachineType::Int32(),
MachineType::Int32(), MachineType::Int32()};
-#endif
int num_params = static_cast<int>(arraysize(mixed)) - start;
- for (int which = 0; which < num_params; which++) {
+ for (int which = 0; which < num_params; ++which) {
v8::base::AccountingAllocator allocator;
Zone zone(&allocator);
- TestingModule module;
+ TestingModule module(execution_mode);
module.AddMemory(1024);
MachineType* memtypes = &mixed[start];
MachineType result = memtypes[which];
@@ -2107,7 +2185,7 @@
uint32_t index;
FunctionSig::Builder b(&zone, 1, num_params);
b.AddReturn(WasmOpcodes::LocalTypeFor(result));
- for (int i = 0; i < num_params; i++) {
+ for (int i = 0; i < num_params; ++i) {
b.AddParam(WasmOpcodes::LocalTypeFor(memtypes[i]));
}
WasmFunctionCompiler t(b.Build(), &module);
@@ -2124,7 +2202,7 @@
ADD_CODE(code, WASM_ZERO);
// Load the arguments.
- for (int i = 0; i < num_params; i++) {
+ for (int i = 0; i < num_params; ++i) {
int offset = (i + 1) * kElemSize;
ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset)));
}
@@ -2144,12 +2222,12 @@
r.Build(&code[0], &code[0] + code.size());
// Run the code.
- for (int t = 0; t < 10; t++) {
+ for (int t = 0; t < 10; ++t) {
module.RandomizeMemory();
CHECK_EQ(kExpected, r.Call());
int size = WasmOpcodes::MemSize(result);
- for (int i = 0; i < size; i++) {
+ for (int i = 0; i < size; ++i) {
int base = (which + 1) * kElemSize;
byte expected = module.raw_mem_at<byte>(base + i);
byte result = module.raw_mem_at<byte>(i);
@@ -2159,14 +2237,14 @@
}
}
-WASM_EXEC_TEST(MixedCall_0) { Run_WasmMixedCall_N(0); }
-WASM_EXEC_TEST(MixedCall_1) { Run_WasmMixedCall_N(1); }
-WASM_EXEC_TEST(MixedCall_2) { Run_WasmMixedCall_N(2); }
-WASM_EXEC_TEST(MixedCall_3) { Run_WasmMixedCall_N(3); }
+WASM_EXEC_TEST(MixedCall_0) { Run_WasmMixedCall_N(execution_mode, 0); }
+WASM_EXEC_TEST(MixedCall_1) { Run_WasmMixedCall_N(execution_mode, 1); }
+WASM_EXEC_TEST(MixedCall_2) { Run_WasmMixedCall_N(execution_mode, 2); }
+WASM_EXEC_TEST(MixedCall_3) { Run_WasmMixedCall_N(execution_mode, 3); }
WASM_EXEC_TEST(AddCall) {
TestSignatures sigs;
- TestingModule module;
+ TestingModule module(execution_mode);
WasmFunctionCompiler t1(sigs.i_ii(), &module);
BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
t1.CompileAndAdd();
@@ -2175,9 +2253,9 @@
byte local = r.AllocateLocal(kAstI32);
BUILD(r, B2(WASM_SET_LOCAL(local, WASM_I8(99)),
WASM_I32_ADD(
- WASM_CALL_FUNCTION2(t1.function_index_, WASM_GET_LOCAL(0),
+ WASM_CALL_FUNCTION2(t1.function_index(), WASM_GET_LOCAL(0),
WASM_GET_LOCAL(0)),
- WASM_CALL_FUNCTION2(t1.function_index_, WASM_GET_LOCAL(1),
+ WASM_CALL_FUNCTION2(t1.function_index(), WASM_GET_LOCAL(1),
WASM_GET_LOCAL(local)))));
CHECK_EQ(198, r.Call(0));
@@ -2186,7 +2264,7 @@
}
WASM_EXEC_TEST(CountDown_expr) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, WASM_LOOP(
3, WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)),
WASM_BREAKV(1, WASM_GET_LOCAL(0))),
@@ -2198,35 +2276,35 @@
}
WASM_EXEC_TEST(ExprBlock2a) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), WASM_I8(1)));
CHECK_EQ(1, r.Call(0));
CHECK_EQ(1, r.Call(1));
}
WASM_EXEC_TEST(ExprBlock2b) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), WASM_I8(2)));
CHECK_EQ(2, r.Call(0));
CHECK_EQ(1, r.Call(1));
}
WASM_EXEC_TEST(ExprBlock2c) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), WASM_I8(1)));
CHECK_EQ(1, r.Call(0));
CHECK_EQ(1, r.Call(1));
}
WASM_EXEC_TEST(ExprBlock2d) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B2(WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)), WASM_I8(2)));
CHECK_EQ(2, r.Call(0));
CHECK_EQ(1, r.Call(1));
}
WASM_EXEC_TEST(ExprBlock_ManualSwitch) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, WASM_BLOCK(6, WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1)),
WASM_BRV(1, WASM_I8(11))),
WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2)),
@@ -2248,7 +2326,7 @@
}
WASM_EXEC_TEST(ExprBlock_ManualSwitch_brif) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r,
WASM_BLOCK(6, WASM_BRV_IF(0, WASM_I8(11),
WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1))),
@@ -2271,7 +2349,8 @@
}
WASM_EXEC_TEST(nested_ifs) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
+ MachineType::Int32());
BUILD(r, WASM_IF_ELSE(
WASM_GET_LOCAL(0),
@@ -2285,7 +2364,7 @@
}
WASM_EXEC_TEST(ExprBlock_if) {
- WasmRunner<int32_t> r(MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(11)),
WASM_BRV(1, WASM_I8(14)))));
@@ -2295,7 +2374,8 @@
}
WASM_EXEC_TEST(ExprBlock_nested_ifs) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
+ MachineType::Int32());
BUILD(r, WASM_BLOCK(
1, WASM_IF_ELSE(
@@ -2312,7 +2392,8 @@
}
WASM_EXEC_TEST(ExprLoop_nested_ifs) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
+ MachineType::Int32());
BUILD(r, WASM_LOOP(
1, WASM_IF_ELSE(
@@ -2330,7 +2411,7 @@
WASM_EXEC_TEST(SimpleCallIndirect) {
TestSignatures sigs;
- TestingModule module;
+ TestingModule module(execution_mode);
WasmFunctionCompiler t1(sigs.i_ii(), &module);
BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
@@ -2361,7 +2442,7 @@
WASM_EXEC_TEST(MultipleCallIndirect) {
TestSignatures sigs;
- TestingModule module;
+ TestingModule module(execution_mode);
WasmFunctionCompiler t1(sigs.i_ii(), &module);
BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
@@ -2403,7 +2484,7 @@
WASM_EXEC_TEST(CallIndirect_NoTable) {
TestSignatures sigs;
- TestingModule module;
+ TestingModule module(execution_mode);
// One function.
WasmFunctionCompiler t1(sigs.i_ii(), &module);
@@ -2424,63 +2505,64 @@
}
WASM_EXEC_TEST(F32Floor) {
- WasmRunner<float> r(MachineType::Float32());
+ WasmRunner<float> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(floorf(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F32Ceil) {
- WasmRunner<float> r(MachineType::Float32());
+ WasmRunner<float> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_F32_CEIL(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(ceilf(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F32Trunc) {
- WasmRunner<float> r(MachineType::Float32());
+ WasmRunner<float> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_F32_TRUNC(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(truncf(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F32NearestInt) {
- WasmRunner<float> r(MachineType::Float32());
+ WasmRunner<float> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_F32_NEARESTINT(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(nearbyintf(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F64Floor) {
- WasmRunner<double> r(MachineType::Float64());
+ WasmRunner<double> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_F64_FLOOR(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(floor(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F64Ceil) {
- WasmRunner<double> r(MachineType::Float64());
+ WasmRunner<double> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_F64_CEIL(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(ceil(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F64Trunc) {
- WasmRunner<double> r(MachineType::Float64());
+ WasmRunner<double> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_F64_TRUNC(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(trunc(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F64NearestInt) {
- WasmRunner<double> r(MachineType::Float64());
+ WasmRunner<double> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_F64_NEARESTINT(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(nearbyint(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F32Min) {
- WasmRunner<float> r(MachineType::Float32(), MachineType::Float32());
+ WasmRunner<float> r(execution_mode, MachineType::Float32(),
+ MachineType::Float32());
BUILD(r, WASM_F32_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_FLOAT32_INPUTS(i) {
@@ -2503,7 +2585,8 @@
}
WASM_EXEC_TEST(F64Min) {
- WasmRunner<double> r(MachineType::Float64(), MachineType::Float64());
+ WasmRunner<double> r(execution_mode, MachineType::Float64(),
+ MachineType::Float64());
BUILD(r, WASM_F64_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_FLOAT64_INPUTS(i) {
@@ -2526,7 +2609,8 @@
}
WASM_EXEC_TEST(F32Max) {
- WasmRunner<float> r(MachineType::Float32(), MachineType::Float32());
+ WasmRunner<float> r(execution_mode, MachineType::Float32(),
+ MachineType::Float32());
BUILD(r, WASM_F32_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_FLOAT32_INPUTS(i) {
@@ -2549,7 +2633,8 @@
}
WASM_EXEC_TEST(F64Max) {
- WasmRunner<double> r(MachineType::Float64(), MachineType::Float64());
+ WasmRunner<double> r(execution_mode, MachineType::Float64(),
+ MachineType::Float64());
BUILD(r, WASM_F64_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_FLOAT64_INPUTS(i) {
@@ -2577,13 +2662,13 @@
WASM_EXEC_TEST(F32Min_Snan) {
// Test that the instruction does not return a signalling NaN.
{
- WasmRunner<float> r;
+ WasmRunner<float> r(execution_mode);
BUILD(r,
WASM_F32_MIN(WASM_F32(bit_cast<float>(0xff80f1e2)), WASM_F32(57.67)));
CHECK_EQ(0xffc0f1e2, bit_cast<uint32_t>(r.Call()));
}
{
- WasmRunner<float> r;
+ WasmRunner<float> r(execution_mode);
BUILD(r,
WASM_F32_MIN(WASM_F32(45.73), WASM_F32(bit_cast<float>(0x7f80f1e2))));
CHECK_EQ(0x7fc0f1e2, bit_cast<uint32_t>(r.Call()));
@@ -2593,13 +2678,13 @@
WASM_EXEC_TEST(F32Max_Snan) {
// Test that the instruction does not return a signalling NaN.
{
- WasmRunner<float> r;
+ WasmRunner<float> r(execution_mode);
BUILD(r,
WASM_F32_MAX(WASM_F32(bit_cast<float>(0xff80f1e2)), WASM_F32(57.67)));
CHECK_EQ(0xffc0f1e2, bit_cast<uint32_t>(r.Call()));
}
{
- WasmRunner<float> r;
+ WasmRunner<float> r(execution_mode);
BUILD(r,
WASM_F32_MAX(WASM_F32(45.73), WASM_F32(bit_cast<float>(0x7f80f1e2))));
CHECK_EQ(0x7fc0f1e2, bit_cast<uint32_t>(r.Call()));
@@ -2609,13 +2694,13 @@
WASM_EXEC_TEST(F64Min_Snan) {
// Test that the instruction does not return a signalling NaN.
{
- WasmRunner<double> r;
+ WasmRunner<double> r(execution_mode);
BUILD(r, WASM_F64_MIN(WASM_F64(bit_cast<double>(0xfff000000000f1e2)),
WASM_F64(57.67)));
CHECK_EQ(0xfff800000000f1e2, bit_cast<uint64_t>(r.Call()));
}
{
- WasmRunner<double> r;
+ WasmRunner<double> r(execution_mode);
BUILD(r, WASM_F64_MIN(WASM_F64(45.73),
WASM_F64(bit_cast<double>(0x7ff000000000f1e2))));
CHECK_EQ(0x7ff800000000f1e2, bit_cast<uint64_t>(r.Call()));
@@ -2625,13 +2710,13 @@
WASM_EXEC_TEST(F64Max_Snan) {
// Test that the instruction does not return a signalling NaN.
{
- WasmRunner<double> r;
+ WasmRunner<double> r(execution_mode);
BUILD(r, WASM_F64_MAX(WASM_F64(bit_cast<double>(0xfff000000000f1e2)),
WASM_F64(57.67)));
CHECK_EQ(0xfff800000000f1e2, bit_cast<uint64_t>(r.Call()));
}
{
- WasmRunner<double> r;
+ WasmRunner<double> r(execution_mode);
BUILD(r, WASM_F64_MAX(WASM_F64(45.73),
WASM_F64(bit_cast<double>(0x7ff000000000f1e2))));
CHECK_EQ(0x7ff800000000f1e2, bit_cast<uint64_t>(r.Call()));
@@ -2641,7 +2726,7 @@
#endif
WASM_EXEC_TEST(I32SConvertF32) {
- WasmRunner<int32_t> r(MachineType::Float32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_I32_SCONVERT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
@@ -2655,7 +2740,7 @@
}
WASM_EXEC_TEST(I32SConvertF64) {
- WasmRunner<int32_t> r(MachineType::Float64());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_I32_SCONVERT_F64(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
@@ -2669,7 +2754,7 @@
}
WASM_EXEC_TEST(I32UConvertF32) {
- WasmRunner<uint32_t> r(MachineType::Float32());
+ WasmRunner<uint32_t> r(execution_mode, MachineType::Float32());
BUILD(r, WASM_I32_UCONVERT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
@@ -2682,7 +2767,7 @@
}
WASM_EXEC_TEST(I32UConvertF64) {
- WasmRunner<uint32_t> r(MachineType::Float64());
+ WasmRunner<uint32_t> r(execution_mode, MachineType::Float64());
BUILD(r, WASM_I32_UCONVERT_F64(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
@@ -2695,7 +2780,8 @@
}
WASM_EXEC_TEST(F64CopySign) {
- WasmRunner<double> r(MachineType::Float64(), MachineType::Float64());
+ WasmRunner<double> r(execution_mode, MachineType::Float64(),
+ MachineType::Float64());
BUILD(r, WASM_F64_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_FLOAT64_INPUTS(i) {
@@ -2704,7 +2790,8 @@
}
WASM_EXEC_TEST(F32CopySign) {
- WasmRunner<float> r(MachineType::Float32(), MachineType::Float32());
+ WasmRunner<float> r(execution_mode, MachineType::Float32(),
+ MachineType::Float32());
BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_FLOAT32_INPUTS(i) {
@@ -2712,15 +2799,15 @@
}
}
-void CompileCallIndirectMany(LocalType param) {
+static void CompileCallIndirectMany(LocalType param) {
// Make sure we don't run out of registers when compiling indirect calls
// with many many parameters.
TestSignatures sigs;
- for (byte num_params = 0; num_params < 40; num_params++) {
+ for (byte num_params = 0; num_params < 40; ++num_params) {
v8::base::AccountingAllocator allocator;
Zone zone(&allocator);
HandleScope scope(CcTest::InitIsolateOnce());
- TestingModule module;
+ TestingModule module(kExecuteCompiled);
FunctionSig* sig = sigs.many(&zone, kAstStmt, param, num_params);
module.AddSignature(sig);
@@ -2731,7 +2818,7 @@
std::vector<byte> code;
ADD_CODE(code, kExprI8Const, 0);
- for (byte p = 0; p < num_params; p++) {
+ for (byte p = 0; p < num_params; ++p) {
ADD_CODE(code, kExprGetLocal, p);
}
ADD_CODE(code, kExprCallIndirect, static_cast<byte>(num_params), 1);
@@ -2743,16 +2830,13 @@
TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kAstI32); }
-#if WASM_64
-TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); }
-#endif
-
TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); }
TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); }
WASM_EXEC_TEST(Int32RemS_dead) {
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
+ WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
+ MachineType::Int32());
BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO);
const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(0, r.Call(133, 100));
diff --git a/test/cctest/wasm/test-wasm-function-name-table.cc b/test/cctest/wasm/test-wasm-function-name-table.cc
index 2f1e251..1ae78dc 100644
--- a/test/cctest/wasm/test-wasm-function-name-table.cc
+++ b/test/cctest/wasm/test-wasm-function-name-table.cc
@@ -30,17 +30,20 @@
WasmModule module;
std::vector<char> all_names;
+ // No name should have offset 0, because that encodes unnamed functions.
+ // In real wasm binary, offset 0 is impossible anyway.
+ all_names.push_back('\0');
uint32_t func_index = 0;
for (Vector<const char> name : names) {
- size_t name_offset = all_names.size();
+ size_t name_offset = name.start() ? all_names.size() : 0;
all_names.insert(all_names.end(), name.start(),
name.start() + name.length());
// Make every second function name null-terminated.
if (func_index % 2) all_names.push_back('\0');
- module.functions.push_back(
- {nullptr, 0, 0, static_cast<uint32_t>(name_offset),
- static_cast<uint32_t>(name.length()), 0, 0, false});
+ module.functions.push_back({nullptr, 0, 0,
+ static_cast<uint32_t>(name_offset),
+ static_cast<uint32_t>(name.length()), 0, 0});
++func_index;
}
@@ -53,19 +56,21 @@
func_index = 0;
for (Vector<const char> name : names) {
- Handle<Object> string_obj = GetWasmFunctionNameFromTable(
+ MaybeHandle<String> string = GetWasmFunctionNameFromTable(
Handle<ByteArray>::cast(wasm_function_name_table), func_index);
- CHECK(!string_obj.is_null());
- CHECK(string_obj->IsString());
- Handle<String> string = Handle<String>::cast(string_obj);
- CHECK(string->IsUtf8EqualTo(name));
+ if (name.start()) {
+ CHECK(string.ToHandleChecked()->IsUtf8EqualTo(name));
+ } else {
+ CHECK(string.is_null());
+ }
++func_index;
}
}
void testFunctionNameTable(Vector<const char *> names) {
std::vector<Vector<const char>> names_vec;
- for (const char *name : names) names_vec.push_back(CStrVector(name));
+ for (const char *name : names)
+ names_vec.push_back(name ? CStrVector(name) : Vector<const char>());
testFunctionNameTable(Vector<Vector<const char>>(
names_vec.data(), static_cast<int>(names_vec.size())));
}
@@ -108,3 +113,8 @@
const char *names[] = {"↱fun↰", "↺", "alpha:α beta:β"};
testFunctionNameTable(ArrayVector(names));
}
+
+TEST(UnnamedVsEmptyNames) {
+ const char *names[] = {"", nullptr, nullptr, ""};
+ testFunctionNameTable(ArrayVector(names));
+}
diff --git a/test/cctest/wasm/test-wasm-stack.cc b/test/cctest/wasm/test-wasm-stack.cc
index b6cd674..f2a8481 100644
--- a/test/cctest/wasm/test-wasm-stack.cc
+++ b/test/cctest/wasm/test-wasm-stack.cc
@@ -51,10 +51,10 @@
};
template <int N>
-void CheckExceptionInfos(Isolate* isolate, Handle<Object> exc,
+void CheckExceptionInfos(Handle<Object> exc,
const ExceptionInfo (&excInfos)[N]) {
// Check that it's indeed an Error object.
- CHECK(Object::IsErrorObject(isolate, exc));
+ CHECK(exc->IsJSError());
// Extract stack frame from the exception.
Local<v8::Value> localExc = Utils::ToLocal(exc);
@@ -110,16 +110,15 @@
Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
CHECK(returnObjMaybe.is_null());
- // Line number is 1-based, with 0 == kNoLineNumberInfo.
+ // The column is 1-based, so add 1 to the actual byte offset.
ExceptionInfo expected_exceptions[] = {
- {"a", 3, 8}, // -
- {"js", 4, 2}, // -
- {"<WASM>", static_cast<int>(wasm_index), 2}, // -
- {"<WASM>", static_cast<int>(wasm_index_2), 1}, // -
- {"callFn", 1, 24} // -
+ {"a", 3, 8}, // -
+ {"js", 4, 2}, // -
+ {"<WASM UNNAMED>", static_cast<int>(wasm_index), 3}, // -
+ {"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 2}, // -
+ {"callFn", 1, 24} // -
};
- CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
- expected_exceptions);
+ CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
}
// Trigger a trap in WASM, stack should be JS -> WASM -> WASM.
@@ -155,12 +154,11 @@
Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
CHECK(maybe_return_obj.is_null());
- // Line number is 1-based, with 0 == kNoLineNumberInfo.
+ // The column is 1-based, so add 1 to the actual byte offset.
ExceptionInfo expected_exceptions[] = {
- {"<WASM>", static_cast<int>(wasm_index), 1}, // -
- {"<WASM>", static_cast<int>(wasm_index_2), 1}, // -
- {"callFn", 1, 24} //-
+ {"<WASM UNNAMED>", static_cast<int>(wasm_index), 2}, // -
+ {"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 2}, // -
+ {"callFn", 1, 24} //-
};
- CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
- expected_exceptions);
+ CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
}
diff --git a/test/cctest/wasm/test-wasm-trap-position.cc b/test/cctest/wasm/test-wasm-trap-position.cc
index 13f2929..30f5d48 100644
--- a/test/cctest/wasm/test-wasm-trap-position.cc
+++ b/test/cctest/wasm/test-wasm-trap-position.cc
@@ -38,10 +38,10 @@
};
template <int N>
-void CheckExceptionInfos(Isolate* isolate, Handle<Object> exc,
+void CheckExceptionInfos(Handle<Object> exc,
const ExceptionInfo (&excInfos)[N]) {
// Check that it's indeed an Error object.
- CHECK(Object::IsErrorObject(isolate, exc));
+ CHECK(exc->IsJSError());
// Extract stack frame from the exception.
Local<v8::Value> localExc = Utils::ToLocal(exc);
@@ -88,12 +88,12 @@
Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
CHECK(returnObjMaybe.is_null());
+ // The column is 1-based, so add 1 to the actual byte offset.
ExceptionInfo expected_exceptions[] = {
- {"<WASM>", static_cast<int>(wasm_index), 1}, // --
- {"callFn", 1, 24} // --
+ {"<WASM UNNAMED>", static_cast<int>(wasm_index), 2}, // --
+ {"callFn", 1, 24} // --
};
- CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
- expected_exceptions);
+ CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
}
// Trigger a trap for loading from out-of-bounds.
@@ -129,12 +129,11 @@
Execution::TryCall(isolate, js_trampoline, global, 1, args, &maybe_exc);
CHECK(returnObjMaybe.is_null());
- // Line number is 1-based, with 0 == kNoLineNumberInfo.
+ // The column is 1-based, so add 1 to the actual byte offset.
ExceptionInfo expected_exceptions[] = {
- {"<WASM>", static_cast<int>(wasm_index), 6}, // --
- {"<WASM>", static_cast<int>(wasm_index_2), 2}, // --
- {"callFn", 1, 24} // --
+ {"<WASM UNNAMED>", static_cast<int>(wasm_index), 7}, // --
+ {"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 3}, // --
+ {"callFn", 1, 24} // --
};
- CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
- expected_exceptions);
+ CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
}
diff --git a/test/cctest/wasm/wasm-run-utils.h b/test/cctest/wasm/wasm-run-utils.h
index a92c9ff..1f758bb 100644
--- a/test/cctest/wasm/wasm-run-utils.h
+++ b/test/cctest/wasm/wasm-run-utils.h
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>
+#include "src/base/accounting-allocator.h"
#include "src/base/utils/random-number-generator.h"
#include "src/compiler/graph-visualizer.h"
@@ -20,6 +21,7 @@
#include "src/compiler/zone-pool.h"
#include "src/wasm/ast-decoder.h"
+#include "src/wasm/wasm-interpreter.h"
#include "src/wasm/wasm-js.h"
#include "src/wasm/wasm-macro-gen.h"
#include "src/wasm/wasm-module.h"
@@ -31,15 +33,10 @@
#include "test/cctest/compiler/call-tester.h"
#include "test/cctest/compiler/graph-builder-tester.h"
-// TODO(titzer): pull WASM_64 up to a common header.
-#if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64
-#define WASM_64 1
-#else
-#define WASM_64 0
-#endif
-
static const uint32_t kMaxFunctions = 10;
+enum WasmExecutionMode { kExecuteInterpreted, kExecuteCompiled };
+
// TODO(titzer): check traps more robustly in tests.
// Currently, in tests, we just return 0xdeadbeef from the function in which
// the trap occurs if the runtime context is not available to throw a JavaScript
@@ -72,16 +69,21 @@
// {WasmModuleInstance}.
class TestingModule : public ModuleEnv {
public:
- TestingModule() : instance_(&module_), global_offset(0) {
- module_.shared_isolate = CcTest::InitIsolateOnce();
+ explicit TestingModule(WasmExecutionMode mode = kExecuteCompiled)
+ : execution_mode_(mode),
+ instance_(&module_),
+ isolate_(CcTest::InitIsolateOnce()),
+ global_offset(0),
+ interpreter_(mode == kExecuteInterpreted
+ ? new WasmInterpreter(&instance_, &allocator_)
+ : nullptr) {
module = &module_;
instance = &instance_;
instance->module = &module_;
instance->globals_start = global_data;
- instance->globals_size = kMaxGlobalsSize;
+ module_.globals_size = kMaxGlobalsSize;
instance->mem_start = nullptr;
instance->mem_size = 0;
- linker = nullptr;
origin = kWasmOrigin;
memset(global_data, 0, sizeof(global_data));
}
@@ -90,9 +92,10 @@
if (instance->mem_start) {
free(instance->mem_start);
}
+ if (interpreter_) delete interpreter_;
}
- byte* AddMemory(size_t size) {
+ byte* AddMemory(uint32_t size) {
CHECK_NULL(instance->mem_start);
CHECK_EQ(0, instance->mem_size);
instance->mem_start = reinterpret_cast<byte*>(malloc(size));
@@ -103,19 +106,19 @@
}
template <typename T>
- T* AddMemoryElems(size_t count) {
+ T* AddMemoryElems(uint32_t count) {
AddMemory(count * sizeof(T));
return raw_mem_start<T>();
}
template <typename T>
T* AddGlobal(MachineType mem_type) {
- WasmGlobal* global = AddGlobal(mem_type);
+ const WasmGlobal* global = AddGlobal(mem_type);
return reinterpret_cast<T*>(instance->globals_start + global->offset);
}
byte AddSignature(FunctionSig* sig) {
- module->signatures.push_back(sig);
+ module_.signatures.push_back(sig);
size_t size = module->signatures.size();
CHECK(size < 127);
return static_cast<byte>(size - 1);
@@ -165,11 +168,16 @@
if (module->functions.size() == 0) {
// TODO(titzer): Reserving space here to avoid the underlying WasmFunction
// structs from moving.
- module->functions.reserve(kMaxFunctions);
+ module_.functions.reserve(kMaxFunctions);
}
uint32_t index = static_cast<uint32_t>(module->functions.size());
- module->functions.push_back({sig, index, 0, 0, 0, 0, 0, false});
+ module_.functions.push_back({sig, index, 0, 0, 0, 0, 0});
instance->function_code.push_back(code);
+ if (interpreter_) {
+ const WasmFunction* function = &module->functions.back();
+ int interpreter_index = interpreter_->AddFunctionForTesting(function);
+ CHECK_EQ(index, static_cast<uint32_t>(interpreter_index));
+ }
DCHECK_LT(index, kMaxFunctions); // limited for testing.
return index;
}
@@ -178,23 +186,21 @@
Handle<JSFunction> jsfunc = Handle<JSFunction>::cast(v8::Utils::OpenHandle(
*v8::Local<v8::Function>::Cast(CompileRun(source))));
uint32_t index = AddFunction(sig, Handle<Code>::null());
- Isolate* isolate = module->shared_isolate;
WasmName module_name = ArrayVector("test");
WasmName function_name;
- Handle<Code> code = CompileWasmToJSWrapper(isolate, this, jsfunc, sig,
+ Handle<Code> code = CompileWasmToJSWrapper(isolate_, jsfunc, sig,
module_name, function_name);
instance->function_code[index] = code;
return index;
}
Handle<JSFunction> WrapCode(uint32_t index) {
- Isolate* isolate = module->shared_isolate;
// Wrap the code so it can be called as a JS function.
- Handle<String> name = isolate->factory()->NewStringFromStaticChars("main");
- Handle<JSObject> module_object = Handle<JSObject>(0, isolate);
+ Handle<String> name = isolate_->factory()->NewStringFromStaticChars("main");
+ Handle<JSObject> module_object = Handle<JSObject>(0, isolate_);
Handle<Code> code = instance->function_code[index];
- WasmJs::InstallWasmFunctionMap(isolate, isolate->native_context());
- return compiler::CompileJSToWasmWrapper(isolate, this, name, code,
+ WasmJs::InstallWasmFunctionMap(isolate_, isolate_->native_context());
+ return compiler::CompileJSToWasmWrapper(isolate_, this, name, code,
module_object, index);
}
@@ -203,13 +209,12 @@
}
void AddIndirectFunctionTable(int* functions, int table_size) {
- Isolate* isolate = module->shared_isolate;
Handle<FixedArray> fixed =
- isolate->factory()->NewFixedArray(2 * table_size);
+ isolate_->factory()->NewFixedArray(2 * table_size);
instance->function_table = fixed;
DCHECK_EQ(0u, module->function_table.size());
for (int i = 0; i < table_size; i++) {
- module->function_table.push_back(functions[i]);
+ module_.function_table.push_back(functions[i]);
}
}
@@ -218,23 +223,31 @@
int table_size = static_cast<int>(module->function_table.size());
for (int i = 0; i < table_size; i++) {
int function_index = module->function_table[i];
- WasmFunction* function = &module->functions[function_index];
+ const WasmFunction* function = &module->functions[function_index];
instance->function_table->set(i, Smi::FromInt(function->sig_index));
instance->function_table->set(i + table_size,
*instance->function_code[function_index]);
}
}
+ WasmFunction* GetFunctionAt(int index) { return &module_.functions[index]; }
+
+ WasmInterpreter* interpreter() { return interpreter_; }
+ WasmExecutionMode execution_mode() { return execution_mode_; }
private:
+ WasmExecutionMode execution_mode_;
WasmModule module_;
WasmModuleInstance instance_;
+ Isolate* isolate_;
+ v8::base::AccountingAllocator allocator_;
uint32_t global_offset;
V8_ALIGNED(8) byte global_data[kMaxGlobalsSize]; // preallocated global data.
+ WasmInterpreter* interpreter_;
- WasmGlobal* AddGlobal(MachineType mem_type) {
+ const WasmGlobal* AddGlobal(MachineType mem_type) {
byte size = WasmOpcodes::MemSize(mem_type);
global_offset = (global_offset + size - 1) & ~(size - 1); // align
- module->globals.push_back({0, 0, mem_type, global_offset, false});
+ module_.globals.push_back({0, 0, mem_type, global_offset, false});
global_offset += size;
// limit number of globals.
CHECK_LT(global_offset, kMaxGlobalsSize);
@@ -408,14 +421,41 @@
// 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, later, interpretation.
+// TurboFan graph) and interpretation (by adding to the interpreter manually).
class WasmFunctionCompiler : public HandleAndZoneScope,
private GraphAndBuilders {
public:
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) {
+ interpreter_ = new WasmInterpreter(nullptr, 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),
@@ -423,23 +463,20 @@
testing_module_(module),
debug_name_(debug_name),
local_decls(main_zone(), sig),
- source_position_table_(this->graph()) {
- if (module) {
- // Get a new function from the testing module.
- function_ = nullptr;
- function_index_ = module->AddFunction(sig, Handle<Code>::null());
- } else {
- // Create our own function.
- function_ = new WasmFunction();
- function_->sig = sig;
- function_index_ = 0;
- }
+ 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 (function_) delete function_;
+ 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.
@@ -447,9 +484,9 @@
TestingModule* testing_module_;
Vector<const char> debug_name_;
WasmFunction* function_;
- int function_index_;
LocalDeclEncoder local_decls;
SourcePositionTable source_position_table_;
+ WasmInterpreter* interpreter_;
Isolate* isolate() { return main_isolate(); }
Graph* graph() const { return main_graph_; }
@@ -462,13 +499,17 @@
}
}
CallDescriptor* descriptor() { return descriptor_; }
+ uint32_t function_index() { return function_->func_index; }
void Build(const byte* start, const byte* end) {
// Build the TurboFan graph.
- local_decls.Prepend(&start, &end);
+ local_decls.Prepend(main_zone(), &start, &end);
TestBuildingGraph(main_zone(), &jsgraph, testing_module_, sig,
&source_position_table_, start, end);
- delete[] start;
+ if (interpreter_) {
+ // Add the code to the interpreter.
+ CHECK(interpreter_->SetFunctionCodeForTesting(function_, start, end));
+ }
}
byte AllocateLocal(LocalType type) {
@@ -494,13 +535,13 @@
Handle<Code> code = info.code();
- // Length is always 2, since usually <wasm_obj, func_index> is stored in the
- // deopt data. Here, we only store the function index.
+ // Length is always 2, since usually <wasm_obj, func_index> is stored in
+ // the deopt data. Here, we only store the function index.
DCHECK(code->deoptimization_data() == nullptr ||
code->deoptimization_data()->length() == 0);
Handle<FixedArray> deopt_data =
isolate()->factory()->NewFixedArray(2, TENURED);
- deopt_data->set(1, Smi::FromInt(function_index_));
+ deopt_data->set(1, Smi::FromInt(static_cast<int>(function_index())));
deopt_data->set_length(2);
code->set_deoptimization_data(*deopt_data);
@@ -516,15 +557,10 @@
uint32_t CompileAndAdd(uint16_t sig_index = 0) {
CHECK(testing_module_);
- function()->sig_index = sig_index;
+ function_->sig_index = sig_index;
Handle<Code> code = Compile();
- testing_module_->SetFunctionCode(function_index_, code);
- return static_cast<uint32_t>(function_index_);
- }
-
- WasmFunction* function() {
- if (function_) return function_;
- return &testing_module_->module->functions[function_index_];
+ testing_module_->SetFunctionCode(function_index(), code);
+ return function_index();
}
// Set the context, such that e.g. runtime functions can be called.
@@ -543,7 +579,8 @@
template <typename ReturnType>
class WasmRunner {
public:
- WasmRunner(MachineType p0 = MachineType::None(),
+ WasmRunner(WasmExecutionMode execution_mode,
+ MachineType p0 = MachineType::None(),
MachineType p1 = MachineType::None(),
MachineType p2 = MachineType::None(),
MachineType p3 = MachineType::None())
@@ -551,7 +588,7 @@
compiled_(false),
signature_(MachineTypeForC<ReturnType>() == MachineType::None() ? 0 : 1,
GetParameterCount(p0, p1, p2, p3), storage_),
- compiler_(&signature_, nullptr) {
+ compiler_(&signature_, execution_mode) {
InitSigStorage(p0, p1, p2, p3);
}
@@ -594,51 +631,102 @@
void Build(const byte* start, const byte* end) {
CHECK(!compiled_);
compiled_ = true;
-
- // Build the TF graph within the compiler.
compiler_.Build(start, end);
- // Generate code.
- Handle<Code> code = compiler_.Compile();
- if (compiler_.testing_module_) {
- // Update the table of function code in the module.
- compiler_.testing_module_->SetFunctionCode(compiler_.function_index_,
- code);
+ if (!interpret()) {
+ // 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);
}
-
- wrapper_.SetInnerCode(code);
}
- ReturnType Call() { return Call(0, 0, 0, 0); }
+ ReturnType Call() {
+ if (interpret()) {
+ return CallInterpreter(Vector<WasmVal>(nullptr, 0));
+ } else {
+ return Call(0, 0, 0, 0);
+ }
+ }
template <typename P0>
ReturnType Call(P0 p0) {
- return Call(p0, 0, 0, 0);
+ 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) {
- return Call(p0, p1, 0, 0);
+ 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) {
- return Call(p0, p1, p2, 0);
+ if (interpret()) {
+ WasmVal args[] = {WasmVal(p0), WasmVal(p1), WasmVal(p2)};
+ return CallInterpreter(ArrayVector(args));
+ } else {
+ return Call(p0, p1, p2, 0);
+ }
}
template <typename P0, typename P1, typename P2, typename P3>
ReturnType Call(P0 p0, P1 p1, P2 p2, P3 p3) {
- CodeRunner<int32_t> runner(CcTest::InitIsolateOnce(),
- wrapper_.GetWrapperCode(), wrapper_.signature());
- ReturnType return_value;
- int32_t result = runner.Call<void*, void*, void*, void*, void*>(
- &p0, &p1, &p2, &p3, &return_value);
- CHECK_EQ(WASM_WRAPPER_RETURN_VALUE, result);
- return return_value;
+ if (interpret()) {
+ WasmVal args[] = {WasmVal(p0), WasmVal(p1), WasmVal(p2), WasmVal(p3)};
+ return CallInterpreter(ArrayVector(args));
+ } else {
+ CodeRunner<int32_t> runner(CcTest::InitIsolateOnce(),
+ wrapper_.GetWrapperCode(),
+ wrapper_.signature());
+ ReturnType return_value;
+ int32_t result = runner.Call<void*, void*, void*, void*, void*>(
+ &p0, &p1, &p2, &p3, &return_value);
+ CHECK_EQ(WASM_WRAPPER_RETURN_VALUE, result);
+ return return_value;
+ }
+ }
+
+ 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();
+ thread->PushFrame(compiler_.function_, args.start());
+ if (thread->Run() == WasmInterpreter::FINISHED) {
+ WasmVal val = thread->GetReturnValue();
+ return val.to<ReturnType>();
+ } else if (thread->state() == WasmInterpreter::TRAPPED) {
+ // TODO(titzer): return the correct trap code
+ int64_t result = 0xdeadbeefdeadbeef;
+ return static_cast<ReturnType>(result);
+ } else {
+ // TODO(titzer): falling off end
+ ReturnType val = 0;
+ return val;
+ }
}
byte AllocateLocal(LocalType type) { return compiler_.AllocateLocal(type); }
+ WasmFunction* function() { return compiler_.function_; }
+ WasmInterpreter* interpreter() { return compiler_.interpreter_; }
+
protected:
v8::base::AccountingAllocator allocator_;
Zone zone;
@@ -648,6 +736,8 @@
WasmFunctionCompiler compiler_;
WasmFunctionWrapper<ReturnType> wrapper_;
+ 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;
@@ -662,10 +752,11 @@
// Currently only supports compiled tests, but a future
// RunWasmInterpreted_##name version will allow each test to also run in the
// interpreter.
-#define WASM_EXEC_TEST(name) \
- void RunWasm_##name(); \
- TEST(RunWasmCompiled_##name) { RunWasm_##name(); } \
- void RunWasm_##name()
+#define WASM_EXEC_TEST(name) \
+ void RunWasm_##name(WasmExecutionMode execution_mode); \
+ TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \
+ TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \
+ void RunWasm_##name(WasmExecutionMode execution_mode)
} // namespace