[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}
This commit is contained in:
parent
7b5f56ca60
commit
085ec5c25f
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user