Commit c7928e55 authored by Ng Zhi An's avatar Ng Zhi An Committed by Commit Bot

[wasm-simd] Fix max alignment for load extends

Load extends always load 64-bits. Previously, we were setting the max
alignment to be the size_log_2 of the load_type. For LoadExtends the
load_type indicates what the lane size to be extended is, *NOT* the size
to be loaded.

Bug: chromium:1082848
Change-Id: I0c4115ea6ec916211b03afdb83376ccc05c0c244
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2202721Reviewed-by: 's avatarBill Budge <bbudge@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67815}
parent c9662124
......@@ -2819,8 +2819,11 @@ class WasmFullDecoder : public WasmDecoder<validate> {
int DecodeLoadTransformMem(LoadType type, LoadTransformationKind transform,
uint32_t opcode_length) {
if (!CheckHasMemory()) return 0;
// Load extends always load 64-bits.
uint32_t max_alignment =
transform == LoadTransformationKind::kExtend ? 3 : type.size_log_2();
MemoryAccessImmediate<validate> imm(this, this->pc_ + opcode_length,
type.size_log_2());
max_alignment);
auto index = Pop(0, kWasmI32);
auto* result = Push(kWasmS128);
CALL_INTERFACE_IF_REACHABLE(LoadTransform, type, transform, imm, index,
......
......@@ -3430,20 +3430,25 @@ void RunLoadExtendTest(ExecutionTier execution_tier, LowerSimd lower_simd,
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).
WasmRunner<int32_t> r(execution_tier, lower_simd);
S* memory = r.builder().AddMemoryElems<S>(kWasmPageSize / sizeof(S));
T* global = r.builder().AddGlobal<T>(kWasmS128);
BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_LOAD_EXTEND(op, WASM_I32V(mem_index))),
WASM_ONE);
// Load extends always load 64 bits, so alignment values can be from 0 to 3.
for (byte alignment = 0; alignment <= 3; alignment++) {
WasmRunner<int32_t> r(execution_tier, lower_simd);
S* memory = r.builder().AddMemoryElems<S>(kWasmPageSize / sizeof(S));
T* global = r.builder().AddGlobal<T>(kWasmS128);
BUILD(r,
WASM_SET_GLOBAL(0, WASM_SIMD_LOAD_EXTEND_ALIGNMENT(
op, WASM_I32V(mem_index), alignment)),
WASM_ONE);
for (S x : compiler::ValueHelper::GetVector<S>()) {
for (int i = 0; i < lanes_s; i++) {
// 16-th byte in memory is lanes-th element (size T) of memory.
r.builder().WriteMemory(&memory[lanes_s + i], x);
}
r.Call();
for (int i = 0; i < lanes_t; i++) {
CHECK_EQ(static_cast<T>(x), ReadLittleEndianValue<T>(&global[i]));
for (S x : compiler::ValueHelper::GetVector<S>()) {
for (int i = 0; i < lanes_s; i++) {
// 16-th byte in memory is lanes-th element (size T) of memory.
r.builder().WriteMemory(&memory[lanes_s + i], x);
}
r.Call();
for (int i = 0; i < lanes_t; i++) {
CHECK_EQ(static_cast<T>(x), ReadLittleEndianValue<T>(&global[i]));
}
}
}
}
......
......@@ -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_ALIGNMENT(opcode, index, alignment) \
index, WASM_SIMD_OP(opcode), alignment, ZERO_OFFSET
//------------------------------------------------------------------------------
// Compilation Hints.
......
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