Commit 671c2fda authored by Ng Zhi An's avatar Ng Zhi An Committed by Commit Bot

[wasm-simd] Test for offsets in load extend tests

Bug: v8:9886
Change-Id: I22af3c19ef6371d31f0f95c58730ceb3e7effafa
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2207653Reviewed-by: 's avatarDeepti Gandluri <gdeepti@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67877}
parent 1f0befca
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <limits>
#include <type_traits>
#include "src/base/bits.h"
......@@ -3427,6 +3428,8 @@ WASM_SIMD_TEST_NO_LOWERING(S64x2LoadSplat) {
template <typename S, typename T>
void RunLoadExtendTest(ExecutionTier execution_tier, LowerSimd lower_simd,
WasmOpcode op) {
static_assert(sizeof(S) < sizeof(T),
"load extend should go from smaller to larger type");
constexpr int lanes_s = 16 / sizeof(S);
constexpr int lanes_t = 16 / sizeof(T);
constexpr int mem_index = 16; // Load from mem index 16 (bytes).
......@@ -3451,6 +3454,35 @@ void RunLoadExtendTest(ExecutionTier execution_tier, LowerSimd lower_simd,
}
}
}
// Test for offset.
{
WasmRunner<int32_t> r(execution_tier, lower_simd);
S* memory = r.builder().AddMemoryElems<S>(kWasmPageSize / sizeof(S));
T* global = r.builder().AddGlobal<T>(kWasmS128);
constexpr byte offset = sizeof(S);
BUILD(
r,
WASM_SET_GLOBAL(0, WASM_SIMD_LOAD_EXTEND_OFFSET(op, WASM_ZERO, offset)),
WASM_ONE);
// Let max_s be the max_s value for type S, we set up the memory as such:
// memory = [max_s, max_s - 1, ... max_s - (lane_s - 1)].
constexpr S max_s = std::numeric_limits<S>::max();
for (int i = 0; i < lanes_s; i++) {
// Integer promotion due to -, static_cast to narrow.
r.builder().WriteMemory(&memory[i], static_cast<S>(max_s - i));
}
r.Call();
// Loads will be offset by sizeof(S), so will always start from (max_s - 1).
for (int i = 0; i < lanes_t; i++) {
// Integer promotion due to -, static_cast to narrow.
T expected = static_cast<T>(max_s - i - 1);
CHECK_EQ(expected, ReadLittleEndianValue<T>(&global[i]));
}
}
}
WASM_SIMD_TEST(I16x8Load8x8U) {
......
......@@ -815,6 +815,8 @@ inline WasmOpcode LoadStoreOpcodeOf(MachineType type, bool store) {
index, WASM_SIMD_OP(opcode), ZERO_ALIGNMENT, offset
#define WASM_SIMD_LOAD_EXTEND(opcode, index) \
index, WASM_SIMD_OP(opcode), ZERO_ALIGNMENT, ZERO_OFFSET
#define WASM_SIMD_LOAD_EXTEND_OFFSET(opcode, index, offset) \
index, WASM_SIMD_OP(opcode), ZERO_ALIGNMENT, offset
#define WASM_SIMD_LOAD_EXTEND_ALIGNMENT(opcode, index, alignment) \
index, WASM_SIMD_OP(opcode), alignment, ZERO_OFFSET
......
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