Commit 0445e41b authored by Ng Zhi An's avatar Ng Zhi An Committed by Commit Bot

[wasm-simd][scalar-lowering] Fix lowering for unsigned average

Small int nodes are stored in sign-extended form, for unsigned average,
mask away the top bits before performing operation.

Bug: v8:10507
Change-Id: I04d3be5758e6ee3fd946adca0943b2874910b4cf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2405751
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Reviewed-by: 's avatarBill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69892}
parent 97c062ba
...@@ -2058,11 +2058,18 @@ void SimdScalarLowering::LowerNode(Node* node) { ...@@ -2058,11 +2058,18 @@ void SimdScalarLowering::LowerNode(Node* node) {
Node** rep_right = GetReplacementsWithType(node->InputAt(1), rep_type); Node** rep_right = GetReplacementsWithType(node->InputAt(1), rep_type);
int num_lanes = NumLanes(rep_type); int num_lanes = NumLanes(rep_type);
Node** rep_node = zone()->NewArray<Node*>(num_lanes); Node** rep_node = zone()->NewArray<Node*>(num_lanes);
// Nodes are stored signed, so mask away the top bits.
// rounding_average(left, right) = (left + right + 1) >> 1 // rounding_average(left, right) = (left + right + 1) >> 1
const int bit_mask = num_lanes == 16 ? kMask8 : kMask16;
for (int i = 0; i < num_lanes; ++i) { for (int i = 0; i < num_lanes; ++i) {
Node* mask_left = graph()->NewNode(machine()->Word32And(), rep_left[i],
mcgraph_->Int32Constant(bit_mask));
Node* mask_right =
graph()->NewNode(machine()->Word32And(), rep_right[i],
mcgraph_->Int32Constant(bit_mask));
Node* left_plus_right_plus_one = graph()->NewNode( Node* left_plus_right_plus_one = graph()->NewNode(
machine()->Int32Add(), machine()->Int32Add(),
graph()->NewNode(machine()->Int32Add(), rep_left[i], rep_right[i]), graph()->NewNode(machine()->Int32Add(), mask_left, mask_right),
mcgraph_->Int32Constant(1)); mcgraph_->Int32Constant(1));
rep_node[i] = rep_node[i] =
graph()->NewNode(machine()->Word32Shr(), left_plus_right_plus_one, graph()->NewNode(machine()->Word32Shr(), left_plus_right_plus_one,
......
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