Commit 36ce4cdc authored by Ng Zhi An's avatar Ng Zhi An Committed by Commit Bot

[wasm-simd] Implement scalar lowering for rounding average

Bug: v8:10039
Change-Id: Ibb0fea59b180d8e015aeee6d6e211ef1f85b0c61
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2041698Reviewed-by: 's avatarDeepti Gandluri <gdeepti@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66177}
parent 23c09ad4
......@@ -183,7 +183,8 @@ void SimdScalarLowering::LowerGraph() {
V(I16x8LtS) \
V(I16x8LeS) \
V(I16x8LtU) \
V(I16x8LeU)
V(I16x8LeU) \
V(I16x8RoundingAverageU)
#define FOREACH_INT8X16_OPCODE(V) \
V(I8x16Splat) \
......@@ -214,7 +215,8 @@ void SimdScalarLowering::LowerGraph() {
V(I8x16LtU) \
V(I8x16LeU) \
V(S8x16Swizzle) \
V(S8x16Shuffle)
V(S8x16Shuffle) \
V(I8x16RoundingAverageU)
MachineType SimdScalarLowering::MachineTypeFrom(SimdType simdType) {
switch (simdType) {
......@@ -1506,6 +1508,26 @@ void SimdScalarLowering::LowerNode(Node* node) {
ReplaceNode(node, rep_node, num_lanes);
break;
}
case IrOpcode::kI8x16RoundingAverageU:
case IrOpcode::kI16x8RoundingAverageU: {
DCHECK_EQ(2, node->InputCount());
Node** rep_left = GetReplacementsWithType(node->InputAt(0), rep_type);
Node** rep_right = GetReplacementsWithType(node->InputAt(1), rep_type);
int num_lanes = NumLanes(rep_type);
Node** rep_node = zone()->NewArray<Node*>(num_lanes);
// rounding_average(left, right) = (left + right + 1) >> 1
for (int i = 0; i < num_lanes; ++i) {
Node* left_plus_right_plus_one = graph()->NewNode(
machine()->Int32Add(),
graph()->NewNode(machine()->Int32Add(), rep_left[i], rep_right[i]),
mcgraph_->Int32Constant(1));
rep_node[i] =
graph()->NewNode(machine()->Word32Shr(), left_plus_right_plus_one,
mcgraph_->Int32Constant(1));
}
ReplaceNode(node, rep_node, num_lanes);
break;
}
default: { DefaultLowering(node); }
}
}
......
......@@ -2198,7 +2198,7 @@ WASM_SIMD_TEST(I16x8LeU) {
UnsignedLessEqual);
}
WASM_SIMD_TEST_NO_LOWERING(I16x8RoundingAverageU) {
WASM_SIMD_TEST(I16x8RoundingAverageU) {
RunI16x8BinOpTest<uint16_t>(execution_tier, lower_simd,
kExprI16x8RoundingAverageU,
base::RoundingAverageUnsigned);
......@@ -2428,7 +2428,7 @@ WASM_SIMD_TEST(I8x16Mul) {
base::MulWithWraparound);
}
WASM_SIMD_TEST_NO_LOWERING(I8x16RoundingAverageU) {
WASM_SIMD_TEST(I8x16RoundingAverageU) {
RunI8x16BinOpTest<uint8_t>(execution_tier, lower_simd,
kExprI8x16RoundingAverageU,
base::RoundingAverageUnsigned);
......
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