Commit 61b56d16 authored by Ng Zhi An's avatar Ng Zhi An Committed by Commit Bot

[wasm-simd] Add more tests for v128 load zero

Add tests for all valid alignments, and using memarg immediate offset
instead of i32 index.

Also randomize the memory to help catch cases where we are loading more
than we should, and accidentally get correct values with zero-ed memory.

Bug: v8:10713
Change-Id: I443c2799ba0d539bf23c63760c08e18c4d36607f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2487880Reviewed-by: 's avatarBill Budge <bbudge@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70693}
parent 81d168d0
......@@ -3704,14 +3704,45 @@ void RunLoadZeroTest(TestExecutionTier execution_tier, LowerSimd lower_simd,
FLAG_SCOPE(wasm_simd_post_mvp);
constexpr int lanes_s = kSimd128Size / sizeof(S);
constexpr int mem_index = 16; // Load from mem index 16 (bytes).
constexpr S sentinel = S{-1};
S* memory;
S* global;
auto initialize_builder = [](WasmRunner<int32_t>* r) -> std::tuple<S*, S*> {
S* memory = r->builder().AddMemoryElems<S>(kWasmPageSize / sizeof(S));
S* global = r->builder().AddGlobal<S>(kWasmS128);
r->builder().RandomizeMemory();
r->builder().WriteMemory(&memory[lanes_s], sentinel);
return std::make_tuple(memory, global);
};
// Check all supported alignments.
constexpr int max_alignment = base::bits::CountTrailingZeros(sizeof(S));
for (byte alignment = 0; alignment <= max_alignment; alignment++) {
WasmRunner<int32_t> r(execution_tier, lower_simd);
S* memory = r.builder().AddMemoryElems<S>(kWasmPageSize / sizeof(S));
S* global = r.builder().AddGlobal<S>(kWasmS128);
std::tie(memory, global) = initialize_builder(&r);
BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_LOAD_OP(op, WASM_I32V(mem_index))),
WASM_ONE);
r.Call();
S sentinel = S{-1};
r.builder().WriteMemory(&memory[lanes_s], sentinel);
// Only first lane is set to sentinel.
CHECK_EQ(sentinel, ReadLittleEndianValue<S>(&global[0]));
// The other lanes are zero.
for (int i = 1; i < lanes_s; i++) {
CHECK_EQ(S{0}, ReadLittleEndianValue<S>(&global[i]));
}
}
{
// Use memarg to specific offset.
WasmRunner<int32_t> r(execution_tier, lower_simd);
std::tie(memory, global) = initialize_builder(&r);
BUILD(
r,
WASM_SET_GLOBAL(0, WASM_SIMD_LOAD_OP_OFFSET(op, WASM_ZERO, mem_index)),
WASM_ONE);
r.Call();
// Only first lane is set to sentinel.
......@@ -3720,6 +3751,7 @@ void RunLoadZeroTest(TestExecutionTier execution_tier, LowerSimd lower_simd,
for (int i = 1; i < lanes_s; i++) {
CHECK_EQ(S{0}, ReadLittleEndianValue<S>(&global[i]));
}
}
// Test for OOB.
{
......
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