Skip to content

Commit 0445e41

Browse files
ngzhianCommit Bot
authored and
Commit Bot
committed
[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 <[email protected]> Reviewed-by: Bill Budge <[email protected]> Cr-Commit-Position: refs/heads/master@{#69892}
1 parent 97c062b commit 0445e41

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/compiler/simd-scalar-lowering.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -2058,11 +2058,18 @@ void SimdScalarLowering::LowerNode(Node* node) {
20582058
Node** rep_right = GetReplacementsWithType(node->InputAt(1), rep_type);
20592059
int num_lanes = NumLanes(rep_type);
20602060
Node** rep_node = zone()->NewArray<Node*>(num_lanes);
2061+
// Nodes are stored signed, so mask away the top bits.
20612062
// rounding_average(left, right) = (left + right + 1) >> 1
2063+
const int bit_mask = num_lanes == 16 ? kMask8 : kMask16;
20622064
for (int i = 0; i < num_lanes; ++i) {
2065+
Node* mask_left = graph()->NewNode(machine()->Word32And(), rep_left[i],
2066+
mcgraph_->Int32Constant(bit_mask));
2067+
Node* mask_right =
2068+
graph()->NewNode(machine()->Word32And(), rep_right[i],
2069+
mcgraph_->Int32Constant(bit_mask));
20632070
Node* left_plus_right_plus_one = graph()->NewNode(
20642071
machine()->Int32Add(),
2065-
graph()->NewNode(machine()->Int32Add(), rep_left[i], rep_right[i]),
2072+
graph()->NewNode(machine()->Int32Add(), mask_left, mask_right),
20662073
mcgraph_->Int32Constant(1));
20672074
rep_node[i] =
20682075
graph()->NewNode(machine()->Word32Shr(), left_plus_right_plus_one,

0 commit comments

Comments
 (0)