Commit 9deed409 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] [cleanup] Always use macros for memory operations

The only users of the LoadStoreOpcodeOf function were a number of
macros in wasm-macro-gen.h, and three test functions using it directly.
This CL refactors those functions to also use the macros.
In one case, this requires storing the value in a local variable first.

R=ahaas@chromium.org

Change-Id: Ia2fbf67a3831fafc9345e155eb240cf1bf6feb5d
Reviewed-on: https://chromium-review.googlesource.com/486842Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44885}
parent 2e23a0ec
...@@ -1614,9 +1614,6 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) { ...@@ -1614,9 +1614,6 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
// ========================================================================= // =========================================================================
std::vector<byte> code; std::vector<byte> code;
// Load the offset for the store.
ADD_CODE(code, WASM_ZERO);
// Load the arguments. // Load the arguments.
for (int i = 0; i < num_params; i++) { for (int i = 0; i < num_params; i++) {
int offset = (i + 1) * kElemSize; int offset = (i + 1) * kElemSize;
...@@ -1626,9 +1623,13 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) { ...@@ -1626,9 +1623,13 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
// Call the selector function. // Call the selector function.
ADD_CODE(code, WASM_CALL_FUNCTION0(t.function_index())); ADD_CODE(code, WASM_CALL_FUNCTION0(t.function_index()));
// Store the result in a local.
byte local_index = r.AllocateLocal(WasmOpcodes::ValueTypeFor(result));
ADD_CODE(code, kExprSetLocal, local_index);
// Store the result in memory. // Store the result in memory.
ADD_CODE(code, static_cast<byte>(LoadStoreOpcodeOf(result, true)), ADD_CODE(code,
ZERO_ALIGNMENT, ZERO_OFFSET); WASM_STORE_MEM(result, WASM_ZERO, WASM_GET_LOCAL(local_index)));
// Return the expected value. // Return the expected value.
ADD_CODE(code, WASM_I32V_2(kExpected)); ADD_CODE(code, WASM_I32V_2(kExpected));
......
...@@ -1082,11 +1082,9 @@ WASM_EXEC_TEST(LoadMaxUint32Offset) { ...@@ -1082,11 +1082,9 @@ WASM_EXEC_TEST(LoadMaxUint32Offset) {
WasmRunner<int32_t> r(execution_mode); WasmRunner<int32_t> r(execution_mode);
r.module().AddMemoryElems<int32_t>(8); r.module().AddMemoryElems<int32_t>(8);
BUILD(r, kExprI32Const, 0, // index BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), // type
static_cast<byte>( U32V_5(0xffffffff), // offset
LoadStoreOpcodeOf(MachineType::Int32(), false)), // load opcode WASM_ZERO)); // index
0, // alignment
U32V_5(0xffffffff)); // offset
CHECK_TRAP32(r.Call()); CHECK_TRAP32(r.Call());
} }
...@@ -1593,10 +1591,10 @@ WASM_EXEC_TEST(LoadMemI32_offset) { ...@@ -1593,10 +1591,10 @@ WASM_EXEC_TEST(LoadMemI32_offset) {
WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) { WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) {
// TODO(eholk): Fix this test for the trap handler. // TODO(eholk): Fix this test for the trap handler.
if (trap_handler::UseTrapHandler()) return; if (trap_handler::UseTrapHandler()) return;
const int kMemSize = 12; constexpr byte kMemSize = 12;
// TODO(titzer): Fix misaligned accesses on MIPS and re-enable. // TODO(titzer): Fix misaligned accesses on MIPS and re-enable.
for (int offset = 0; offset < kMemSize + 5; ++offset) { for (byte offset = 0; offset < kMemSize + 5; ++offset) {
for (int index = 0; index < kMemSize + 5; ++index) { for (byte index = 0; index < kMemSize + 5; ++index) {
WasmRunner<int32_t> r(execution_mode); WasmRunner<int32_t> r(execution_mode);
r.module().AddMemoryElems<byte>(kMemSize); r.module().AddMemoryElems<byte>(kMemSize);
r.module().RandomizeMemory(); r.module().RandomizeMemory();
...@@ -1604,7 +1602,7 @@ WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) { ...@@ -1604,7 +1602,7 @@ WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) {
BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset,
WASM_I32V_2(index))); WASM_I32V_2(index)));
if ((offset + index) <= static_cast<int>((kMemSize - sizeof(int32_t)))) { if (offset + index <= (kMemSize - sizeof(int32_t))) {
CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call()); CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call());
} else { } else {
CHECK_TRAP(r.Call()); CHECK_TRAP(r.Call());
...@@ -1616,9 +1614,9 @@ WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) { ...@@ -1616,9 +1614,9 @@ WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) {
WASM_EXEC_TEST(LoadMemI32_const_oob) { WASM_EXEC_TEST(LoadMemI32_const_oob) {
// TODO(eholk): Fix this test for the trap handler. // TODO(eholk): Fix this test for the trap handler.
if (trap_handler::UseTrapHandler()) return; if (trap_handler::UseTrapHandler()) return;
const int kMemSize = 24; constexpr byte kMemSize = 24;
for (int offset = 0; offset < kMemSize + 5; offset += 4) { for (byte offset = 0; offset < kMemSize + 5; offset += 4) {
for (int index = 0; index < kMemSize + 5; index += 4) { for (byte index = 0; index < kMemSize + 5; index += 4) {
WasmRunner<int32_t> r(execution_mode); WasmRunner<int32_t> r(execution_mode);
r.module().AddMemoryElems<byte>(kMemSize); r.module().AddMemoryElems<byte>(kMemSize);
r.module().RandomizeMemory(); r.module().RandomizeMemory();
...@@ -1626,7 +1624,7 @@ WASM_EXEC_TEST(LoadMemI32_const_oob) { ...@@ -1626,7 +1624,7 @@ WASM_EXEC_TEST(LoadMemI32_const_oob) {
BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset,
WASM_I32V_2(index))); WASM_I32V_2(index)));
if ((offset + index) <= static_cast<int>((kMemSize - sizeof(int32_t)))) { if (offset + index <= (kMemSize - sizeof(int32_t))) {
CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call()); CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call());
} else { } else {
CHECK_TRAP(r.Call()); CHECK_TRAP(r.Call());
...@@ -2339,9 +2337,6 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) { ...@@ -2339,9 +2337,6 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
// ========================================================================= // =========================================================================
std::vector<byte> code; std::vector<byte> code;
// Load the offset for the store.
ADD_CODE(code, WASM_ZERO);
// Load the arguments. // Load the arguments.
for (int i = 0; i < num_params; ++i) { for (int i = 0; i < num_params; ++i) {
int offset = (i + 1) * kElemSize; int offset = (i + 1) * kElemSize;
...@@ -2351,9 +2346,13 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) { ...@@ -2351,9 +2346,13 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
// Call the selector function. // Call the selector function.
ADD_CODE(code, WASM_CALL_FUNCTION0(t.function_index())); ADD_CODE(code, WASM_CALL_FUNCTION0(t.function_index()));
// Store the result in a local.
byte local_index = r.AllocateLocal(WasmOpcodes::ValueTypeFor(result));
ADD_CODE(code, kExprSetLocal, local_index);
// Store the result in memory. // Store the result in memory.
ADD_CODE(code, static_cast<byte>(LoadStoreOpcodeOf(result, true)), ADD_CODE(code,
ZERO_ALIGNMENT, ZERO_OFFSET); WASM_STORE_MEM(result, WASM_ZERO, WASM_GET_LOCAL(local_index)));
// Return the expected value. // Return the expected value.
ADD_CODE(code, WASM_I32V_2(kExpected)); ADD_CODE(code, WASM_I32V_2(kExpected));
......
...@@ -340,11 +340,11 @@ inline WasmOpcode LoadStoreOpcodeOf(MachineType type, bool store) { ...@@ -340,11 +340,11 @@ inline WasmOpcode LoadStoreOpcodeOf(MachineType type, bool store) {
#define WASM_LOAD_MEM_OFFSET(type, offset, index) \ #define WASM_LOAD_MEM_OFFSET(type, offset, index) \
index, \ index, \
static_cast<byte>(v8::internal::wasm::LoadStoreOpcodeOf(type, false)), \ static_cast<byte>(v8::internal::wasm::LoadStoreOpcodeOf(type, false)), \
ZERO_ALIGNMENT, static_cast<byte>(offset) ZERO_ALIGNMENT, offset
#define WASM_STORE_MEM_OFFSET(type, offset, index, val) \ #define WASM_STORE_MEM_OFFSET(type, offset, index, val) \
index, val, \ index, val, \
static_cast<byte>(v8::internal::wasm::LoadStoreOpcodeOf(type, true)), \ static_cast<byte>(v8::internal::wasm::LoadStoreOpcodeOf(type, true)), \
ZERO_ALIGNMENT, static_cast<byte>(offset) ZERO_ALIGNMENT, offset
#define WASM_LOAD_MEM_ALIGNMENT(type, index, alignment) \ #define WASM_LOAD_MEM_ALIGNMENT(type, index, alignment) \
index, \ index, \
static_cast<byte>(v8::internal::wasm::LoadStoreOpcodeOf(type, false)), \ static_cast<byte>(v8::internal::wasm::LoadStoreOpcodeOf(type, false)), \
......
...@@ -1295,7 +1295,7 @@ TEST_F(FunctionBodyDecoderTest, StoreMemOffset) { ...@@ -1295,7 +1295,7 @@ TEST_F(FunctionBodyDecoderTest, StoreMemOffset) {
TestModuleEnv module_env; TestModuleEnv module_env;
module = &module_env; module = &module_env;
module_env.InitializeMemory(); module_env.InitializeMemory();
for (int offset = 0; offset < 128; offset += 7) { for (byte offset = 0; offset < 128; offset += 7) {
byte code[] = {WASM_STORE_MEM_OFFSET(MachineType::Int32(), offset, byte code[] = {WASM_STORE_MEM_OFFSET(MachineType::Int32(), offset,
WASM_ZERO, WASM_ZERO)}; WASM_ZERO, WASM_ZERO)};
EXPECT_VERIFIES_C(v_i, code); EXPECT_VERIFIES_C(v_i, code);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment