Commit 0f90237b authored by balazs.kilvady's avatar balazs.kilvady Committed by Commit bot

MIPS: Use max_d, min_d in LCodeGen::DoMathMinMax.

BUG=

Review URL: https://codereview.chromium.org/1876223003

Cr-Commit-Position: refs/heads/master@{#35497}
parent 93135d8c
......@@ -1728,13 +1728,13 @@ void LCodeGen::DoMathMinMax(LMathMinMax* instr) {
LOperand* left = instr->left();
LOperand* right = instr->right();
HMathMinMax::Operation operation = instr->hydrogen()->operation();
Condition condition = (operation == HMathMinMax::kMathMin) ? le : ge;
Register scratch = scratch1();
if (instr->hydrogen()->representation().IsSmiOrInteger32()) {
Condition condition = (operation == HMathMinMax::kMathMin) ? le : ge;
Register left_reg = ToRegister(left);
Register right_reg = EmitLoadRegister(right, scratch0());
Register result_reg = ToRegister(instr->result());
Label return_right, done;
Register scratch = scratch1();
__ Slt(scratch, left_reg, Operand(right_reg));
if (condition == ge) {
__ Movz(result_reg, left_reg, scratch);
......@@ -1749,43 +1749,19 @@ void LCodeGen::DoMathMinMax(LMathMinMax* instr) {
FPURegister left_reg = ToDoubleRegister(left);
FPURegister right_reg = ToDoubleRegister(right);
FPURegister result_reg = ToDoubleRegister(instr->result());
Label check_nan_left, check_zero, return_left, return_right, done;
__ BranchF(&check_zero, &check_nan_left, eq, left_reg, right_reg);
__ BranchF(&return_left, NULL, condition, left_reg, right_reg);
__ Branch(&return_right);
__ bind(&check_zero);
// left == right != 0.
__ BranchF(&return_left, NULL, ne, left_reg, kDoubleRegZero);
// At this point, both left and right are either 0 or -0.
if (operation == HMathMinMax::kMathMin) {
// The algorithm is: -((-L) + (-R)), which in case of L and R being
// different registers is most efficiently expressed as -((-L) - R).
__ neg_d(left_reg, left_reg);
if (left_reg.is(right_reg)) {
__ add_d(result_reg, left_reg, right_reg);
} else {
__ sub_d(result_reg, left_reg, right_reg);
}
__ neg_d(result_reg, result_reg);
Label nan, done;
if (operation == HMathMinMax::kMathMax) {
__ MaxNaNCheck_d(result_reg, left_reg, right_reg, &nan);
} else {
__ add_d(result_reg, left_reg, right_reg);
DCHECK(operation == HMathMinMax::kMathMin);
__ MinNaNCheck_d(result_reg, left_reg, right_reg, &nan);
}
__ Branch(&done);
__ bind(&check_nan_left);
// left == NaN.
__ BranchF(NULL, &return_left, eq, left_reg, left_reg);
__ bind(&return_right);
if (!right_reg.is(result_reg)) {
__ mov_d(result_reg, right_reg);
}
__ Branch(&done);
__ bind(&nan);
__ LoadRoot(scratch, Heap::kNanValueRootIndex);
__ ldc1(result_reg, FieldMemOperand(scratch, HeapNumber::kValueOffset));
__ bind(&return_left);
if (!left_reg.is(result_reg)) {
__ mov_d(result_reg, left_reg);
}
__ bind(&done);
}
}
......
......@@ -1846,13 +1846,13 @@ void LCodeGen::DoMathMinMax(LMathMinMax* instr) {
LOperand* left = instr->left();
LOperand* right = instr->right();
HMathMinMax::Operation operation = instr->hydrogen()->operation();
Condition condition = (operation == HMathMinMax::kMathMin) ? le : ge;
Register scratch = scratch1();
if (instr->hydrogen()->representation().IsSmiOrInteger32()) {
Condition condition = (operation == HMathMinMax::kMathMin) ? le : ge;
Register left_reg = ToRegister(left);
Register right_reg = EmitLoadRegister(right, scratch0());
Register result_reg = ToRegister(instr->result());
Label return_right, done;
Register scratch = scratch1();
__ Slt(scratch, left_reg, Operand(right_reg));
if (condition == ge) {
__ Movz(result_reg, left_reg, scratch);
......@@ -1867,43 +1867,19 @@ void LCodeGen::DoMathMinMax(LMathMinMax* instr) {
FPURegister left_reg = ToDoubleRegister(left);
FPURegister right_reg = ToDoubleRegister(right);
FPURegister result_reg = ToDoubleRegister(instr->result());
Label check_nan_left, check_zero, return_left, return_right, done;
__ BranchF(&check_zero, &check_nan_left, eq, left_reg, right_reg);
__ BranchF(&return_left, NULL, condition, left_reg, right_reg);
__ Branch(&return_right);
__ bind(&check_zero);
// left == right != 0.
__ BranchF(&return_left, NULL, ne, left_reg, kDoubleRegZero);
// At this point, both left and right are either 0 or -0.
if (operation == HMathMinMax::kMathMin) {
// The algorithm is: -((-L) + (-R)), which in case of L and R being
// different registers is most efficiently expressed as -((-L) - R).
__ neg_d(left_reg, left_reg);
if (left_reg.is(right_reg)) {
__ add_d(result_reg, left_reg, right_reg);
} else {
__ sub_d(result_reg, left_reg, right_reg);
}
__ neg_d(result_reg, result_reg);
Label nan, done;
if (operation == HMathMinMax::kMathMax) {
__ MaxNaNCheck_d(result_reg, left_reg, right_reg, &nan);
} else {
__ add_d(result_reg, left_reg, right_reg);
DCHECK(operation == HMathMinMax::kMathMin);
__ MinNaNCheck_d(result_reg, left_reg, right_reg, &nan);
}
__ Branch(&done);
__ bind(&check_nan_left);
// left == NaN.
__ BranchF(NULL, &return_left, eq, left_reg, left_reg);
__ bind(&return_right);
if (!right_reg.is(result_reg)) {
__ mov_d(result_reg, right_reg);
}
__ Branch(&done);
__ bind(&nan);
__ LoadRoot(scratch, Heap::kNanValueRootIndex);
__ ldc1(result_reg, FieldMemOperand(scratch, HeapNumber::kValueOffset));
__ bind(&return_left);
if (!left_reg.is(result_reg)) {
__ mov_d(result_reg, left_reg);
}
__ bind(&done);
}
}
......
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