| 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 a519375292e45dc875247350c526f249635b7545..ed2011fc41c2948b9a597bc599e1f7c36c31ecfd 100644
|
| --- a/test/cctest/wasm/test-run-wasm.cc
|
| +++ b/test/cctest/wasm/test-run-wasm.cc
|
| @@ -6,6 +6,8 @@
|
| #include <stdlib.h>
|
| #include <string.h>
|
|
|
| +#include "src/base/platform/elapsed-timer.h"
|
| +
|
| #include "src/wasm/wasm-macro-gen.h"
|
|
|
| #include "test/cctest/cctest.h"
|
| @@ -19,10 +21,10 @@ 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
|
| +#define B2(a, b) kExprBlock, a, b, kExprEnd
|
| +#define B1(a) kExprBlock, a, kExprEnd
|
| +#define RET(x) x, kExprReturn
|
| +#define RET_I8(x) kExprI8Const, x, kExprReturn
|
|
|
| TEST(Run_WasmInt8Const) {
|
| WasmRunner<int32_t> r;
|
| @@ -595,6 +597,25 @@ TEST(Run_Wasm_IfElse_P) {
|
| }
|
| }
|
|
|
| +TEST(Run_Wasm_If_chain) {
|
| + WasmRunner<int32_t> r(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));
|
| + FOR_INT32_INPUTS(i) { CHECK_EQ(15, r.Call(*i)); }
|
| +}
|
| +
|
| +TEST(Run_Wasm_If_chain_set) {
|
| + WasmRunner<int32_t> r(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))),
|
| + WASM_GET_LOCAL(1));
|
| + FOR_INT32_INPUTS(i) {
|
| + int32_t expected = *i ? 74 : *i;
|
| + CHECK_EQ(expected, r.Call(*i, *i));
|
| + }
|
| +}
|
|
|
| TEST(Run_Wasm_IfElse_Unreachable1) {
|
| WasmRunner<int32_t> r;
|
| @@ -1437,10 +1458,10 @@ TEST(Run_Wasm_CheckMachIntsZero) {
|
| module.AddMemoryElems<uint32_t>(kNumElems);
|
| WasmRunner<uint32_t> r(&module, MachineType::Int32());
|
|
|
| - BUILD(r, kExprBlock, 2, kExprLoop, 1, kExprIf, kExprGetLocal, 0, kExprBr, 0,
|
| - kExprIfElse, kExprI32LoadMem, ZERO_ALIGNMENT, ZERO_OFFSET,
|
| - kExprGetLocal, 0, kExprBr, 2, kExprI8Const, 255, kExprSetLocal, 0,
|
| - kExprI32Sub, kExprGetLocal, 0, kExprI8Const, 4, kExprI8Const, 0);
|
| + BUILD(r, kExprLoop, kExprGetLocal, 0, kExprIf, kExprGetLocal, 0,
|
| + kExprI32LoadMem, 0, 0, kExprIf, kExprI8Const, 255, kExprReturn,
|
| + kExprEnd, kExprGetLocal, 0, kExprI8Const, 4, kExprI32Sub, kExprSetLocal,
|
| + 0, kExprBr, 0, kExprEnd, kExprEnd, kExprI8Const, 0);
|
|
|
| module.BlankMemory();
|
| CHECK_EQ(0, r.Call((kNumElems - 1) * 4));
|
| @@ -1635,14 +1656,13 @@ static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) {
|
| FunctionSig* sig = WasmOpcodes::Signature(opcode);
|
|
|
| if (sig->parameter_count() == 1) {
|
| - byte code[] = {WASM_NO_LOCALS, static_cast<byte>(opcode), kExprGetLocal, 0};
|
| + byte code[] = {WASM_NO_LOCALS, kExprGetLocal, 0, static_cast<byte>(opcode)};
|
| TestBuildingGraph(&zone, &jsgraph, nullptr, sig, code,
|
| code + arraysize(code));
|
| } else {
|
| CHECK_EQ(2, sig->parameter_count());
|
| - byte code[] = {WASM_NO_LOCALS, static_cast<byte>(opcode),
|
| - kExprGetLocal, 0,
|
| - kExprGetLocal, 1};
|
| + byte code[] = {WASM_NO_LOCALS, kExprGetLocal, 0, kExprGetLocal, 1,
|
| + static_cast<byte>(opcode)};
|
| TestBuildingGraph(&zone, &jsgraph, nullptr, sig, code,
|
| code + arraysize(code));
|
| }
|
| @@ -2074,23 +2094,29 @@ static void Run_WasmMixedCall_N(int start) {
|
| // Build the calling function.
|
| // =========================================================================
|
| WasmRunner<int32_t> r(&module);
|
| -
|
| std::vector<byte> code;
|
| - ADD_CODE(code,
|
| - static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(result, true)),
|
| - ZERO_ALIGNMENT, ZERO_OFFSET);
|
| +
|
| + // Load the offset for the store.
|
| ADD_CODE(code, WASM_ZERO);
|
| - ADD_CODE(code, kExprCallFunction, static_cast<byte>(index));
|
|
|
| + // 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>(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));
|
| - size_t end = code.size();
|
| - code.push_back(0);
|
| - r.Build(&code[0], &code[end]);
|
| +
|
| + r.Build(&code[0], &code[0] + code.size());
|
|
|
| // Run the code.
|
| for (int t = 0; t < 10; t++) {
|
| @@ -2291,7 +2317,6 @@ TEST(Run_Wasm_ExprLoop_nested_ifs) {
|
| CHECK_EQ(14, r.Call(0, 0));
|
| }
|
|
|
| -
|
| TEST(Run_Wasm_SimpleCallIndirect) {
|
| TestSignatures sigs;
|
| TestingModule module;
|
| @@ -2713,11 +2738,11 @@ void CompileCallIndirectMany(LocalType param) {
|
| WasmFunctionCompiler t(sig, &module);
|
|
|
| std::vector<byte> code;
|
| - ADD_CODE(code, kExprCallIndirect, 1);
|
| ADD_CODE(code, kExprI8Const, 0);
|
| for (byte p = 0; p < num_params; p++) {
|
| ADD_CODE(code, kExprGetLocal, p);
|
| }
|
| + ADD_CODE(code, kExprCallIndirect, 1);
|
|
|
| t.Build(&code[0], &code[0] + code.size());
|
| t.Compile();
|
|
|