Commit 085ec5c2 authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Improve lowering for NumberAbs to Int32Abs.

We can compute the absolute integer value w/o any conditional execution
by using the bit trick formula

  let sign = input >> 31 in
  (input ^ sign) - sign

which generates fairly decent code on all supported architectures.

R=jarin@chromium.org

Review-Url: https://codereview.chromium.org/2169293002
Cr-Commit-Position: refs/heads/master@{#37965}
parent 7b5f56ca
...@@ -3117,14 +3117,18 @@ Node* SimplifiedLowering::Float64Trunc(Node* const node) { ...@@ -3117,14 +3117,18 @@ Node* SimplifiedLowering::Float64Trunc(Node* const node) {
} }
Node* SimplifiedLowering::Int32Abs(Node* const node) { Node* SimplifiedLowering::Int32Abs(Node* const node) {
Node* const zero = jsgraph()->Int32Constant(0);
Node* const input = node->InputAt(0); Node* const input = node->InputAt(0);
// if 0 < input then input else 0 - input // Generate case for absolute integer value.
return graph()->NewNode( //
common()->Select(MachineRepresentation::kWord32, BranchHint::kTrue), // let sign = input >> 31 in
graph()->NewNode(machine()->Int32LessThan(), zero, input), input, // (input ^ sign) - sign
graph()->NewNode(machine()->Int32Sub(), zero, input));
Node* sign = graph()->NewNode(machine()->Word32Sar(), input,
jsgraph()->Int32Constant(31));
return graph()->NewNode(machine()->Int32Sub(),
graph()->NewNode(machine()->Word32Xor(), input, sign),
sign);
} }
Node* SimplifiedLowering::Int32Div(Node* const node) { Node* SimplifiedLowering::Int32Div(Node* const node) {
......
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