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

[wasm-simd] Improve extadd pairwise test

We splat two different values and then shuffle them together so that we
can test pairwise addition of two different values.

Bug: v8:11086
Change-Id: Id3bb34e9bfe21b6c5cb1d7eee3745c6c9e262f24
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2776513Reviewed-by: 's avatarDeepti Gandluri <gdeepti@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73590}
parent bb2ca416
...@@ -66,6 +66,7 @@ using Int8UnOp = int8_t (*)(int8_t); ...@@ -66,6 +66,7 @@ using Int8UnOp = int8_t (*)(int8_t);
using Int8BinOp = int8_t (*)(int8_t, int8_t); using Int8BinOp = int8_t (*)(int8_t, int8_t);
using Int8CompareOp = int (*)(int8_t, int8_t); using Int8CompareOp = int (*)(int8_t, int8_t);
using Int8ShiftOp = int8_t (*)(int8_t, int); using Int8ShiftOp = int8_t (*)(int8_t, int);
using Shuffle = std::array<int8_t, kSimd128Size>;
#define WASM_SIMD_TEST(name) \ #define WASM_SIMD_TEST(name) \
void RunWasm_##name##_Impl(LowerSimd lower_simd, \ void RunWasm_##name##_Impl(LowerSimd lower_simd, \
...@@ -1537,48 +1538,56 @@ WASM_SIMD_TEST(S128Not) { ...@@ -1537,48 +1538,56 @@ WASM_SIMD_TEST(S128Not) {
template <typename Narrow, typename Wide> template <typename Narrow, typename Wide>
void RunExtAddPairwiseTest(TestExecutionTier execution_tier, void RunExtAddPairwiseTest(TestExecutionTier execution_tier,
LowerSimd lower_simd, WasmOpcode ext_add_pairwise, LowerSimd lower_simd, WasmOpcode ext_add_pairwise,
WasmOpcode splat) { WasmOpcode splat, Shuffle interleaving_shuffle) {
constexpr int num_lanes = kSimd128Size / sizeof(Wide); constexpr int num_lanes = kSimd128Size / sizeof(Wide);
WasmRunner<int32_t, Narrow> r(execution_tier, lower_simd); WasmRunner<int32_t, Narrow, Narrow> r(execution_tier, lower_simd);
Wide* g = r.builder().template AddGlobal<Wide>(kWasmS128); Wide* g = r.builder().template AddGlobal<Wide>(kWasmS128);
// TODO(v8:11086) We splat the same value, so pairwise adding ends up adding BUILD(r,
// the same value to itself, consider a more complicated test, like having 2 WASM_SIMD_I8x16_SHUFFLE_OP(kExprI8x16Shuffle, interleaving_shuffle,
// vectors, and shuffling them. WASM_SIMD_UNOP(splat, WASM_LOCAL_GET(0)),
BUILD(r, WASM_LOCAL_GET(0), WASM_SIMD_OP(splat), WASM_SIMD_UNOP(splat, WASM_LOCAL_GET(1))),
WASM_SIMD_OP(ext_add_pairwise), kExprGlobalSet, 0, WASM_ONE); WASM_SIMD_OP(ext_add_pairwise), kExprGlobalSet, 0, WASM_ONE);
for (Narrow x : compiler::ValueHelper::GetVector<Narrow>()) { auto v = compiler::ValueHelper::GetVector<Narrow>();
r.Call(x); // Iterate vector from both ends to try and splat two different values.
Wide expected = AddLong<Wide>(x, x); for (auto i = v.begin(), j = v.end() - 1; i < v.end(); i++, j--) {
r.Call(*i, *j);
Wide expected = AddLong<Wide>(*i, *j);
for (int i = 0; i < num_lanes; i++) { for (int i = 0; i < num_lanes; i++) {
CHECK_EQ(expected, ReadLittleEndianValue<Wide>(&g[i])); CHECK_EQ(expected, ReadLittleEndianValue<Wide>(&g[i]));
} }
} }
} }
// interleave even lanes from one input and odd lanes from another.
constexpr Shuffle interleave_16x8_shuffle = {0, 1, 18, 19, 4, 5, 22, 23,
8, 9, 26, 27, 12, 13, 30, 31};
constexpr Shuffle interleave_8x16_shuffle = {0, 17, 2, 19, 4, 21, 6, 23,
8, 25, 10, 27, 12, 29, 14, 31};
WASM_SIMD_TEST_NO_LOWERING(I32x4ExtAddPairwiseI16x8S) { WASM_SIMD_TEST_NO_LOWERING(I32x4ExtAddPairwiseI16x8S) {
RunExtAddPairwiseTest<int16_t, int32_t>(execution_tier, lower_simd, RunExtAddPairwiseTest<int16_t, int32_t>(
kExprI32x4ExtAddPairwiseI16x8S, execution_tier, lower_simd, kExprI32x4ExtAddPairwiseI16x8S,
kExprI16x8Splat); kExprI16x8Splat, interleave_16x8_shuffle);
} }
WASM_SIMD_TEST_NO_LOWERING(I32x4ExtAddPairwiseI16x8U) { WASM_SIMD_TEST_NO_LOWERING(I32x4ExtAddPairwiseI16x8U) {
RunExtAddPairwiseTest<uint16_t, uint32_t>(execution_tier, lower_simd, RunExtAddPairwiseTest<uint16_t, uint32_t>(
kExprI32x4ExtAddPairwiseI16x8U, execution_tier, lower_simd, kExprI32x4ExtAddPairwiseI16x8U,
kExprI16x8Splat); kExprI16x8Splat, interleave_16x8_shuffle);
} }
WASM_SIMD_TEST_NO_LOWERING(I16x8ExtAddPairwiseI8x16S) { WASM_SIMD_TEST_NO_LOWERING(I16x8ExtAddPairwiseI8x16S) {
RunExtAddPairwiseTest<int8_t, int16_t>(execution_tier, lower_simd, RunExtAddPairwiseTest<int8_t, int16_t>(
kExprI16x8ExtAddPairwiseI8x16S, execution_tier, lower_simd, kExprI16x8ExtAddPairwiseI8x16S,
kExprI8x16Splat); kExprI8x16Splat, interleave_8x16_shuffle);
} }
WASM_SIMD_TEST_NO_LOWERING(I16x8ExtAddPairwiseI8x16U) { WASM_SIMD_TEST_NO_LOWERING(I16x8ExtAddPairwiseI8x16U) {
RunExtAddPairwiseTest<uint8_t, uint16_t>(execution_tier, lower_simd, RunExtAddPairwiseTest<uint8_t, uint16_t>(
kExprI16x8ExtAddPairwiseI8x16U, execution_tier, lower_simd, kExprI16x8ExtAddPairwiseI8x16U,
kExprI8x16Splat); kExprI8x16Splat, interleave_8x16_shuffle);
} }
void RunI32x4BinOpTest(TestExecutionTier execution_tier, LowerSimd lower_simd, void RunI32x4BinOpTest(TestExecutionTier execution_tier, LowerSimd lower_simd,
...@@ -2586,7 +2595,6 @@ enum ShuffleKey { ...@@ -2586,7 +2595,6 @@ enum ShuffleKey {
kNumShuffleKeys kNumShuffleKeys
}; };
using Shuffle = std::array<int8_t, kSimd128Size>;
using ShuffleMap = std::map<ShuffleKey, const Shuffle>; using ShuffleMap = std::map<ShuffleKey, const Shuffle>;
ShuffleMap test_shuffles = { ShuffleMap test_shuffles = {
......
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