From 61b56d165059fdc9ad9ed6abc3f5ca3444a627c7 Mon Sep 17 00:00:00 2001 From: Ng Zhi An Date: Wed, 21 Oct 2020 10:28:04 -0700 Subject: [PATCH] [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 Commit-Queue: Zhi An Ng Cr-Commit-Position: refs/heads/master@{#70693} --- test/cctest/wasm/test-run-wasm-simd.cc | 58 ++++++++++++++++++++------ 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/test/cctest/wasm/test-run-wasm-simd.cc b/test/cctest/wasm/test-run-wasm-simd.cc index cba1219655..09b51a0125 100644 --- a/test/cctest/wasm/test-run-wasm-simd.cc +++ b/test/cctest/wasm/test-run-wasm-simd.cc @@ -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 r(execution_tier, lower_simd); - S* memory = r.builder().AddMemoryElems(kWasmPageSize / sizeof(S)); - S* global = r.builder().AddGlobal(kWasmS128); - BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_LOAD_OP(op, WASM_I32V(mem_index))), + constexpr S sentinel = S{-1}; + S* memory; + S* global; + + auto initialize_builder = [](WasmRunner* r) -> std::tuple { + S* memory = r->builder().AddMemoryElems(kWasmPageSize / sizeof(S)); + S* global = r->builder().AddGlobal(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 r(execution_tier, lower_simd); + 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(); + + // Only first lane is set to sentinel. + CHECK_EQ(sentinel, ReadLittleEndianValue(&global[0])); + // The other lanes are zero. + for (int i = 1; i < lanes_s; i++) { + CHECK_EQ(S{0}, ReadLittleEndianValue(&global[i])); + } + } + + { + // Use memarg to specific offset. + WasmRunner 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(); - S sentinel = S{-1}; - r.builder().WriteMemory(&memory[lanes_s], sentinel); - r.Call(); - - // Only first lane is set to sentinel. - CHECK_EQ(sentinel, ReadLittleEndianValue(&global[0])); - // The other lanes are zero. - for (int i = 1; i < lanes_s; i++) { - CHECK_EQ(S{0}, ReadLittleEndianValue(&global[i])); + // Only first lane is set to sentinel. + CHECK_EQ(sentinel, ReadLittleEndianValue(&global[0])); + // The other lanes are zero. + for (int i = 1; i < lanes_s; i++) { + CHECK_EQ(S{0}, ReadLittleEndianValue(&global[i])); + } } // Test for OOB.