Commit 07b21f64 authored by Zhi An Ng's avatar Zhi An Ng Committed by Commit Bot

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

This relands commit 61b56d16

The fix is to capture variables used in the lambda.

Original change's description:
> [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/+/2487880
> Reviewed-by: Bill Budge <bbudge@chromium.org>
> Commit-Queue: Zhi An Ng <zhin@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#70693}

Bug: v8:10713
Change-Id: Ib8fa58c6600d85a37fc0b6647ddbdb991f3b1c04
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2497382Reviewed-by: 's avatarBill Budge <bbudge@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70769}
parent 421ea59c
......@@ -3704,21 +3704,53 @@ 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).
WasmRunner<int32_t> r(execution_tier, lower_simd);
S* memory = r.builder().AddMemoryElems<S>(kWasmPageSize / sizeof(S));
S* global = r.builder().AddGlobal<S>(kWasmS128);
BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_LOAD_OP(op, WASM_I32V(mem_index))),
WASM_ONE);
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);
std::tie(memory, global) = initialize_builder(&r);
S sentinel = S{-1};
r.builder().WriteMemory(&memory[lanes_s], sentinel);
r.Call();
BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_LOAD_OP(op, WASM_I32V(mem_index))),
WASM_ONE);
r.Call();
// 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]));
}
}
// 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.
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]));
}
}
// 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