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

Unified Diff: test/cctest/wasm/test-run-wasm.cc

Issue 1764723002: [wasm] Remove TableSwitch and replace with br_table. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/wasm-opcodes.h ('k') | test/unittests/wasm/ast-decoder-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/wasm/test-run-wasm.cc
diff --git a/test/cctest/wasm/test-run-wasm.cc b/test/cctest/wasm/test-run-wasm.cc
index 7df2e5739bdfd73715f4602edc3008967072c1f4..c29c52cdb63e1b1402f8f49c0602b700041b0d43 100644
--- a/test/cctest/wasm/test-run-wasm.cc
+++ b/test/cctest/wasm/test-run-wasm.cc
@@ -18,6 +18,12 @@ using namespace v8::internal;
using namespace v8::internal::compiler;
using namespace v8::internal::wasm;
+// for even shorter tests.
+#define B2(a, b) kExprBlock, 2, a, b
+#define B1(a) kExprBlock, 1, a
+#define RET(x) kExprReturn, x
+#define RET_I8(x) kExprReturn, kExprI8Const, x
+
TEST(Run_WasmInt8Const) {
WasmRunner<int32_t> r;
const byte kExpectedValue = 121;
@@ -876,7 +882,7 @@ TEST(Run_Wasm_IfElse_Unreachable1) {
TEST(Run_Wasm_Return12) {
WasmRunner<int32_t> r;
- BUILD(r, WASM_RETURN(WASM_I8(12)));
+ BUILD(r, RET_I8(12));
CHECK_EQ(12, r.Call());
}
@@ -884,7 +890,7 @@ TEST(Run_Wasm_Return12) {
TEST(Run_Wasm_Return17) {
WasmRunner<int32_t> r;
- BUILD(r, WASM_BLOCK(1, WASM_RETURN(WASM_I8(17))));
+ BUILD(r, B1(RET_I8(17)));
CHECK_EQ(17, r.Call());
}
@@ -892,7 +898,7 @@ TEST(Run_Wasm_Return17) {
TEST(Run_Wasm_Return_I32) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_RETURN(WASM_GET_LOCAL(0)));
+ BUILD(r, RET(WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
@@ -902,7 +908,7 @@ TEST(Run_Wasm_Return_I32) {
TEST(Run_Wasm_Return_I64) {
WasmRunner<int64_t> r(MachineType::Int64());
- BUILD(r, WASM_RETURN(WASM_GET_LOCAL(0)));
+ BUILD(r, RET(WASM_GET_LOCAL(0)));
FOR_INT64_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
@@ -912,7 +918,7 @@ TEST(Run_Wasm_Return_I64) {
TEST(Run_Wasm_Return_F32) {
WasmRunner<float> r(MachineType::Float32());
- BUILD(r, WASM_RETURN(WASM_GET_LOCAL(0)));
+ BUILD(r, RET(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
float expect = *i;
@@ -929,7 +935,7 @@ TEST(Run_Wasm_Return_F32) {
TEST(Run_Wasm_Return_F64) {
WasmRunner<double> r(MachineType::Float64());
- BUILD(r, WASM_RETURN(WASM_GET_LOCAL(0)));
+ BUILD(r, RET(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
double expect = *i;
@@ -957,10 +963,10 @@ TEST(Run_Wasm_Select) {
TEST(Run_Wasm_Select_strict1) {
WasmRunner<int32_t> r(MachineType::Int32());
// select(a=0, a=1, a=2); return a
- BUILD(r, WASM_BLOCK(2, WASM_SELECT(WASM_SET_LOCAL(0, WASM_I8(0)),
- WASM_SET_LOCAL(0, WASM_I8(1)),
- WASM_SET_LOCAL(0, WASM_I8(2))),
- WASM_GET_LOCAL(0)));
+ BUILD(r, B2(WASM_SELECT(WASM_SET_LOCAL(0, WASM_I8(0)),
+ WASM_SET_LOCAL(0, WASM_I8(1)),
+ WASM_SET_LOCAL(0, WASM_I8(2))),
+ WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); }
}
@@ -993,55 +999,67 @@ TEST(Run_Wasm_Select_strict3) {
TEST(Run_Wasm_BrIf_strict) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(
- 2, WASM_BLOCK(1, WASM_BRV_IF(0, WASM_GET_LOCAL(0),
- WASM_SET_LOCAL(0, WASM_I8(99)))),
- WASM_GET_LOCAL(0)));
+ BUILD(
+ r,
+ B2(B1(WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(99)))),
+ WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(99, r.Call(*i)); }
}
-TEST(Run_Wasm_TableSwitch0a) {
+TEST(Run_Wasm_BrTable0a) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(2, WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(0)),
- WASM_TABLESWITCH_BODY0(WASM_GET_LOCAL(0)), WASM_I8(91)));
+ 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)); }
}
-TEST(Run_Wasm_TableSwitch0b) {
+TEST(Run_Wasm_BrTable0b) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(
- 2, WASM_TABLESWITCH_OP(0, 2, WASM_CASE_BR(0), WASM_CASE_BR(0)),
- WASM_TABLESWITCH_BODY0(WASM_GET_LOCAL(0)), WASM_I8(92)));
+ BUILD(r,
+ B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(0))),
+ WASM_I8(92)));
FOR_INT32_INPUTS(i) { CHECK_EQ(92, r.Call(*i)); }
}
-TEST(Run_Wasm_TableSwitch0c) {
+TEST(Run_Wasm_BrTable0c) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r,
- WASM_BLOCK(2, WASM_BLOCK(2, WASM_TABLESWITCH_OP(0, 2, WASM_CASE_BR(0),
- WASM_CASE_BR(1)),
- WASM_TABLESWITCH_BODY0(WASM_GET_LOCAL(0)),
- WASM_RETURN(WASM_I8(76))),
- WASM_I8(77)));
+ BUILD(
+ r,
+ B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(1))),
+ RET_I8(76)),
+ WASM_I8(77)));
FOR_INT32_INPUTS(i) {
int32_t expected = *i == 0 ? 76 : 77;
CHECK_EQ(expected, r.Call(*i));
}
}
-TEST(Run_Wasm_TableSwitch1) {
+TEST(Run_Wasm_BrTable1) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
- WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_RETURN(WASM_I8(93))));
+ 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)); }
}
+TEST(Run_Wasm_BrTable_loop) {
+ WasmRunner<int32_t> r(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))),
+ RET_I8(99)),
+ WASM_I8(98));
+ CHECK_EQ(99, r.Call(0));
+ CHECK_EQ(98, r.Call(-1));
+ CHECK_EQ(98, r.Call(-2));
+ CHECK_EQ(98, r.Call(-3));
+ CHECK_EQ(98, r.Call(-100));
+}
-TEST(Run_Wasm_TableSwitch_br) {
+TEST(Run_Wasm_BrTable_br) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_TABLESWITCH_OP(1, 2, WASM_CASE_BR(0), WASM_CASE(0)),
- WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_RETURN(WASM_I8(91))),
+ BUILD(r,
+ B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(1), BR_TARGET(0))),
+ RET_I8(91)),
WASM_I8(99));
CHECK_EQ(99, r.Call(0));
CHECK_EQ(91, r.Call(1));
@@ -1049,17 +1067,14 @@ TEST(Run_Wasm_TableSwitch_br) {
CHECK_EQ(91, r.Call(3));
}
-
-TEST(Run_Wasm_TableSwitch_br2) {
+TEST(Run_Wasm_BrTable_br2) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(
- 2, WASM_BLOCK(2, WASM_TABLESWITCH_OP(
- 1, 4, WASM_CASE_BR(0), WASM_CASE_BR(1),
- WASM_CASE_BR(2), WASM_CASE(0)),
- WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0),
- WASM_RETURN(WASM_I8(85))),
- WASM_RETURN(WASM_I8(86))),
- WASM_RETURN(WASM_I8(87))),
+
+ 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))),
+ RET_I8(85)),
+ RET_I8(86)),
+ RET_I8(87)),
WASM_I8(88));
CHECK_EQ(86, r.Call(0));
CHECK_EQ(87, r.Call(1));
@@ -1069,95 +1084,74 @@ TEST(Run_Wasm_TableSwitch_br2) {
CHECK_EQ(85, r.Call(5));
}
-
-TEST(Run_Wasm_TableSwitch2) {
- WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)),
- WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_RETURN(WASM_I8(91)),
- WASM_RETURN(WASM_I8(92))));
- FOR_INT32_INPUTS(i) {
- int32_t expected = *i == 0 ? 91 : 92;
- CHECK_EQ(expected, r.Call(*i));
- }
-}
-
-
-TEST(Run_Wasm_TableSwitch2b) {
- WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(1), WASM_CASE(0)),
- WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_RETURN(WASM_I8(81)),
- WASM_RETURN(WASM_I8(82))));
- FOR_INT32_INPUTS(i) {
- int32_t expected = *i == 0 ? 82 : 81;
- CHECK_EQ(expected, r.Call(*i));
- }
-}
-
-
-TEST(Run_Wasm_TableSwitch4) {
+TEST(Run_Wasm_BrTable4) {
for (int i = 0; i < 4; i++) {
- const uint16_t br = 0x8000u;
- uint16_t c = 0;
- uint16_t cases[] = {i == 0 ? br : c++, i == 1 ? br : c++, i == 2 ? br : c++,
- i == 3 ? br : c++};
- byte code[] = {
- WASM_BLOCK(1, WASM_TABLESWITCH_OP(
- 3, 4, WASM_CASE(cases[0]), WASM_CASE(cases[1]),
- WASM_CASE(cases[2]), WASM_CASE(cases[3])),
- WASM_TABLESWITCH_BODY(
- WASM_GET_LOCAL(0), WASM_RETURN(WASM_I8(71)),
- WASM_RETURN(WASM_I8(72)), WASM_RETURN(WASM_I8(73)))),
- WASM_RETURN(WASM_I8(74))};
-
- WasmRunner<int32_t> r(MachineType::Int32());
- r.Build(code, code + arraysize(code));
-
- FOR_INT32_INPUTS(i) {
- int index = (*i < 0 || *i > 3) ? 3 : *i;
- int32_t expected = 71 + cases[index];
- if (expected >= 0x8000) expected = 74;
- CHECK_EQ(expected, r.Call(*i));
+ for (int t = 0; t < 4; t++) {
+ uint16_t cases[] = {0, 1, 2, 3};
+ cases[i] = t;
+ byte code[] = {B2(B2(B2(B2(B1(WASM_BR_TABLE(
+ WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]),
+ BR_TARGET(cases[1]), BR_TARGET(cases[2]),
+ BR_TARGET(cases[3]))),
+ RET_I8(70)),
+ RET_I8(71)),
+ RET_I8(72)),
+ RET_I8(73)),
+ WASM_I8(75)};
+
+ WasmRunner<int32_t> r(MachineType::Int32());
+ r.Build(code, code + arraysize(code));
+
+ 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));
+ }
}
}
}
-
-TEST(Run_Wasm_TableSwitch4b) {
- for (int a = 0; a < 2; a++) {
- for (int b = 0; b < 2; b++) {
- for (int c = 0; c < 2; c++) {
- for (int d = 0; d < 2; d++) {
- if (a + b + c + d == 0) continue;
- if (a + b + c + d == 4) continue;
-
- byte code[] = {
- WASM_TABLESWITCH_OP(2, 4, WASM_CASE(a), WASM_CASE(b),
- WASM_CASE(c), WASM_CASE(d)),
- WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_RETURN(WASM_I8(61)),
- WASM_RETURN(WASM_I8(62)))};
-
- WasmRunner<int32_t> r(MachineType::Int32());
- r.Build(code, code + arraysize(code));
-
- CHECK_EQ(61 + a, r.Call(0));
- CHECK_EQ(61 + b, r.Call(1));
- CHECK_EQ(61 + c, r.Call(2));
- CHECK_EQ(61 + d, r.Call(3));
- CHECK_EQ(61 + d, r.Call(4));
+TEST(Run_Wasm_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++) {
+ uint16_t cases[] = {a, b, c, d};
+ byte code[] = {
+ B2(B2(B2(B2(B1(WASM_BR_TABLE(
+ WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]),
+ BR_TARGET(cases[1]), BR_TARGET(cases[2]),
+ BR_TARGET(cases[3]))),
+ RET_I8(50)),
+ RET_I8(51)),
+ RET_I8(52)),
+ RET_I8(53)),
+ WASM_I8(55)};
+
+ WasmRunner<int32_t> r(MachineType::Int32());
+ r.Build(code, code + arraysize(code));
+
+ 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));
+ }
+ }
}
}
}
}
}
-
-TEST(Run_Wasm_TableSwitch4_fallthru) {
+TEST(Run_Wasm_BrTable4_fallthru) {
byte code[] = {
- WASM_TABLESWITCH_OP(4, 4, WASM_CASE(0), WASM_CASE(1), WASM_CASE(2),
- WASM_CASE(3)),
- WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_INC_LOCAL_BY(1, 1),
- WASM_INC_LOCAL_BY(1, 2), WASM_INC_LOCAL_BY(1, 4),
- WASM_INC_LOCAL_BY(1, 8)),
+ B2(B2(B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 3, BR_TARGET(0),
+ BR_TARGET(1), BR_TARGET(2), BR_TARGET(3))),
+ WASM_INC_LOCAL_BY(1, 1)),
+ WASM_INC_LOCAL_BY(1, 2)),
+ WASM_INC_LOCAL_BY(1, 4)),
+ WASM_INC_LOCAL_BY(1, 8)),
WASM_GET_LOCAL(1)};
WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
@@ -1176,34 +1170,6 @@ TEST(Run_Wasm_TableSwitch4_fallthru) {
CHECK_EQ(108, r.Call(4, 100));
}
-
-TEST(Run_Wasm_TableSwitch4_fallthru_br) {
- byte code[] = {
- WASM_TABLESWITCH_OP(4, 4, WASM_CASE(0), WASM_CASE(1), WASM_CASE(2),
- WASM_CASE(3)),
- WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_INC_LOCAL_BY(1, 1),
- WASM_BRV(0, WASM_INC_LOCAL_BY(1, 2)),
- WASM_INC_LOCAL_BY(1, 4),
- WASM_BRV(0, WASM_INC_LOCAL_BY(1, 8))),
- WASM_GET_LOCAL(1)};
-
- WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
- r.Build(code, code + arraysize(code));
-
- CHECK_EQ(3, r.Call(0, 0));
- CHECK_EQ(2, r.Call(1, 0));
- CHECK_EQ(12, r.Call(2, 0));
- CHECK_EQ(8, r.Call(3, 0));
- CHECK_EQ(8, r.Call(4, 0));
-
- CHECK_EQ(203, r.Call(0, 200));
- CHECK_EQ(202, r.Call(1, 200));
- CHECK_EQ(212, r.Call(2, 200));
- CHECK_EQ(208, r.Call(3, 200));
- CHECK_EQ(208, r.Call(4, 200));
-}
-
-
TEST(Run_Wasm_F32ReinterpretI32) {
TestingModule module;
int32_t* memory = module.AddMemoryElems<int32_t>(8);
@@ -1268,7 +1234,7 @@ TEST(Run_Wasm_VoidReturn1) {
// Build the calling function.
WasmRunner<int32_t> r;
r.env()->module = &module;
- BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected)));
+ BUILD(r, B2(WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected)));
int32_t result = r.Call();
CHECK_EQ(kExpected, result);
@@ -1288,7 +1254,7 @@ TEST(Run_Wasm_VoidReturn2) {
// Build the calling function.
WasmRunner<int32_t> r;
r.env()->module = &module;
- BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected)));
+ BUILD(r, B2(WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected)));
int32_t result = r.Call();
CHECK_EQ(kExpected, result);
@@ -1298,10 +1264,10 @@ TEST(Run_Wasm_VoidReturn2) {
TEST(Run_Wasm_Block_If_P) {
WasmRunner<int32_t> r(MachineType::Int32());
// { if (p0) return 51; return 52; }
- BUILD(r, WASM_BLOCK(2, // --
- WASM_IF(WASM_GET_LOCAL(0), // --
- WASM_BRV(0, WASM_I8(51))), // --
- WASM_I8(52))); // --
+ BUILD(r, B2( // --
+ WASM_IF(WASM_GET_LOCAL(0), // --
+ WASM_BRV(0, WASM_I8(51))), // --
+ WASM_I8(52))); // --
FOR_INT32_INPUTS(i) {
int32_t expected = *i ? 51 : 52;
CHECK_EQ(expected, r.Call(*i));
@@ -1311,8 +1277,7 @@ TEST(Run_Wasm_Block_If_P) {
TEST(Run_Wasm_Block_BrIf_P) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(2, WASM_BRV_IF(0, WASM_I8(51), WASM_GET_LOCAL(0)),
- WASM_I8(52)));
+ 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;
CHECK_EQ(expected, r.Call(*i));
@@ -1323,11 +1288,11 @@ TEST(Run_Wasm_Block_BrIf_P) {
TEST(Run_Wasm_Block_IfElse_P_assign) {
WasmRunner<int32_t> r(MachineType::Int32());
// { if (p0) p0 = 71; else p0 = 72; return p0; }
- BUILD(r, WASM_BLOCK(2, // --
- WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
- WASM_SET_LOCAL(0, WASM_I8(71)), // --
- WASM_SET_LOCAL(0, WASM_I8(72))), // --
- WASM_GET_LOCAL(0)));
+ BUILD(r, B2( // --
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
+ WASM_SET_LOCAL(0, WASM_I8(71)), // --
+ WASM_SET_LOCAL(0, WASM_I8(72))), // --
+ WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) {
int32_t expected = *i ? 71 : 72;
CHECK_EQ(expected, r.Call(*i));
@@ -1338,10 +1303,10 @@ TEST(Run_Wasm_Block_IfElse_P_assign) {
TEST(Run_Wasm_Block_IfElse_P_return) {
WasmRunner<int32_t> r(MachineType::Int32());
// if (p0) return 81; else return 82;
- BUILD(r, // --
- WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
- WASM_RETURN(WASM_I8(81)), // --
- WASM_RETURN(WASM_I8(82)))); // --
+ BUILD(r, // --
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
+ RET_I8(81), // --
+ RET_I8(82))); // --
FOR_INT32_INPUTS(i) {
int32_t expected = *i ? 81 : 82;
CHECK_EQ(expected, r.Call(*i));
@@ -1365,8 +1330,7 @@ TEST(Run_Wasm_Block_If_P_assign) {
TEST(Run_Wasm_DanglingAssign) {
WasmRunner<int32_t> r(MachineType::Int32());
// { return 0; p0 = 0; }
- BUILD(r,
- WASM_BLOCK(2, WASM_RETURN(WASM_I8(99)), WASM_SET_LOCAL(0, WASM_ZERO)));
+ BUILD(r, B2(RET_I8(99), WASM_SET_LOCAL(0, WASM_ZERO)));
CHECK_EQ(99, r.Call(1));
}
@@ -1443,9 +1407,9 @@ TEST(Run_Wasm_WhileCountDown) {
TEST(Run_Wasm_Loop_if_break1) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(2, WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(0)),
- WASM_SET_LOCAL(0, WASM_I8(99))),
- WASM_GET_LOCAL(0)));
+ BUILD(r, B2(WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(0)),
+ WASM_SET_LOCAL(0, WASM_I8(99))),
+ WASM_GET_LOCAL(0)));
CHECK_EQ(99, r.Call(0));
CHECK_EQ(3, r.Call(3));
CHECK_EQ(10000, r.Call(10000));
@@ -1455,9 +1419,9 @@ TEST(Run_Wasm_Loop_if_break1) {
TEST(Run_Wasm_Loop_if_break2) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(2, WASM_LOOP(2, WASM_BR_IF(1, WASM_GET_LOCAL(0)),
- WASM_SET_LOCAL(0, WASM_I8(99))),
- WASM_GET_LOCAL(0)));
+ 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)));
CHECK_EQ(99, r.Call(0));
CHECK_EQ(3, r.Call(3));
CHECK_EQ(10000, r.Call(10000));
@@ -1467,8 +1431,8 @@ TEST(Run_Wasm_Loop_if_break2) {
TEST(Run_Wasm_Loop_if_break_fallthru) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(1, WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(1)),
- WASM_SET_LOCAL(0, WASM_I8(93)))),
+ 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));
CHECK_EQ(93, r.Call(0));
CHECK_EQ(3, r.Call(3));
@@ -1950,8 +1914,7 @@ TEST(Build_Wasm_Infinite_Loop_effect) {
TEST(Run_Wasm_Unreachable0a) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r,
- WASM_BLOCK(2, WASM_BRV(0, WASM_I8(9)), WASM_RETURN(WASM_GET_LOCAL(0))));
+ 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));
}
@@ -1959,7 +1922,7 @@ TEST(Run_Wasm_Unreachable0a) {
TEST(Run_Wasm_Unreachable0b) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(2, WASM_BRV(0, WASM_I8(7)), WASM_UNREACHABLE));
+ BUILD(r, B2(WASM_BRV(0, WASM_I8(7)), WASM_UNREACHABLE));
CHECK_EQ(7, r.Call(0));
CHECK_EQ(7, r.Call(1));
}
@@ -1998,8 +1961,8 @@ TEST(Build_Wasm_UnreachableIf2) {
TEST(Run_Wasm_Unreachable_Load) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(2, WASM_BRV(0, WASM_GET_LOCAL(0)),
- WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0))));
+ 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));
CHECK_EQ(21, r.Call(21));
}
@@ -2007,8 +1970,7 @@ TEST(Run_Wasm_Unreachable_Load) {
TEST(Run_Wasm_Infinite_Loop_not_taken1) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(2, WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP),
- WASM_I8(45)));
+ 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));
}
@@ -2016,9 +1978,8 @@ TEST(Run_Wasm_Infinite_Loop_not_taken1) {
TEST(Run_Wasm_Infinite_Loop_not_taken2) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r,
- WASM_BLOCK(1, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(45)),
- WASM_INFINITE_LOOP)));
+ BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(45)),
+ WASM_INFINITE_LOOP)));
// Run the code, but don't go into the infinite loop.
CHECK_EQ(45, r.Call(1));
}
@@ -2026,8 +1987,8 @@ TEST(Run_Wasm_Infinite_Loop_not_taken2) {
TEST(Run_Wasm_Infinite_Loop_not_taken2_brif) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(2, WASM_BRV_IF(0, WASM_I8(45), WASM_GET_LOCAL(0)),
- WASM_INFINITE_LOOP));
+ 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.
CHECK_EQ(45, r.Call(1));
}
@@ -2186,11 +2147,10 @@ TEST(Run_WasmInt64Global) {
int64_t* global = module.AddGlobal<int64_t>(MachineType::Int64());
WasmRunner<int32_t> r(&module, MachineType::Int32());
// global = global + p0
- BUILD(r, WASM_BLOCK(2, WASM_STORE_GLOBAL(
- 0, WASM_I64_ADD(
- WASM_LOAD_GLOBAL(0),
- WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)))),
- WASM_ZERO));
+ BUILD(r, B2(WASM_STORE_GLOBAL(
+ 0, WASM_I64_ADD(WASM_LOAD_GLOBAL(0),
+ WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)))),
+ WASM_ZERO));
*global = 0xFFFFFFFFFFFFFFFFLL;
for (int i = 9; i < 444444; i += 111111) {
@@ -2207,11 +2167,10 @@ TEST(Run_WasmFloat32Global) {
float* global = module.AddGlobal<float>(MachineType::Float32());
WasmRunner<int32_t> r(&module, MachineType::Int32());
// global = global + p0
- BUILD(r, WASM_BLOCK(2, WASM_STORE_GLOBAL(
- 0, WASM_F32_ADD(
- WASM_LOAD_GLOBAL(0),
- WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))),
- WASM_ZERO));
+ BUILD(r, B2(WASM_STORE_GLOBAL(
+ 0, WASM_F32_ADD(WASM_LOAD_GLOBAL(0),
+ WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))),
+ WASM_ZERO));
*global = 1.25;
for (int i = 9; i < 4444; i += 1111) {
@@ -2227,11 +2186,10 @@ TEST(Run_WasmFloat64Global) {
double* global = module.AddGlobal<double>(MachineType::Float64());
WasmRunner<int32_t> r(&module, MachineType::Int32());
// global = global + p0
- BUILD(r, WASM_BLOCK(2, WASM_STORE_GLOBAL(
- 0, WASM_F64_ADD(
- WASM_LOAD_GLOBAL(0),
- WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))),
- WASM_ZERO));
+ BUILD(r, B2(WASM_STORE_GLOBAL(
+ 0, WASM_F64_ADD(WASM_LOAD_GLOBAL(0),
+ WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))),
+ WASM_ZERO));
*global = 1.25;
for (int i = 9; i < 4444; i += 1111) {
@@ -2647,13 +2605,12 @@ TEST(Run_Wasm_AddCall) {
WasmRunner<int32_t> r(&module, MachineType::Int32());
byte local = r.AllocateLocal(kAstI32);
- BUILD(r,
- WASM_BLOCK(2, WASM_SET_LOCAL(local, WASM_I8(99)),
- WASM_I32_ADD(
- WASM_CALL_FUNCTION(t1.function_index_, WASM_GET_LOCAL(0),
- WASM_GET_LOCAL(0)),
- WASM_CALL_FUNCTION(t1.function_index_, WASM_GET_LOCAL(1),
- WASM_GET_LOCAL(local)))));
+ BUILD(r, B2(WASM_SET_LOCAL(local, WASM_I8(99)),
+ WASM_I32_ADD(
+ WASM_CALL_FUNCTION(t1.function_index_, WASM_GET_LOCAL(0),
+ WASM_GET_LOCAL(0)),
+ WASM_CALL_FUNCTION(t1.function_index_, WASM_GET_LOCAL(1),
+ WASM_GET_LOCAL(local)))));
CHECK_EQ(198, r.Call(0));
CHECK_EQ(200, r.Call(1));
@@ -2675,8 +2632,7 @@ TEST(Run_Wasm_CountDown_expr) {
TEST(Run_Wasm_ExprBlock2a) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(1))),
- WASM_I8(1)));
+ BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(1))), WASM_I8(1)));
CHECK_EQ(1, r.Call(0));
CHECK_EQ(1, r.Call(1));
}
@@ -2684,8 +2640,7 @@ TEST(Run_Wasm_ExprBlock2a) {
TEST(Run_Wasm_ExprBlock2b) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(1))),
- WASM_I8(2)));
+ BUILD(r, B2(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(1))), WASM_I8(2)));
CHECK_EQ(2, r.Call(0));
CHECK_EQ(1, r.Call(1));
}
@@ -2693,8 +2648,7 @@ TEST(Run_Wasm_ExprBlock2b) {
TEST(Run_Wasm_ExprBlock2c) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(2, WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)),
- WASM_I8(1)));
+ 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));
}
@@ -2702,8 +2656,7 @@ TEST(Run_Wasm_ExprBlock2c) {
TEST(Run_Wasm_ExprBlock2d) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r, WASM_BLOCK(2, WASM_BRV_IF(0, WASM_I8(1), WASM_GET_LOCAL(0)),
- WASM_I8(2)));
+ 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));
}
@@ -2775,9 +2728,8 @@ TEST(Run_Wasm_nested_ifs) {
TEST(Run_Wasm_ExprBlock_if) {
WasmRunner<int32_t> r(MachineType::Int32());
- BUILD(r,
- WASM_BLOCK(1, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(11)),
- WASM_BRV(0, WASM_I8(14)))));
+ BUILD(r, B1(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(11)),
+ WASM_BRV(0, WASM_I8(14)))));
CHECK_EQ(11, r.Call(1));
CHECK_EQ(14, r.Call(0));
« no previous file with comments | « src/wasm/wasm-opcodes.h ('k') | test/unittests/wasm/ast-decoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698