Revision: 20135
Author: plin...@gmail.com
Date: Thu Mar 20 16:04:51 2014 UTC
Log: MIPS: Implement flooring division by a constant via truncating
division by a constant.
Port r20123 (31ab416)
BUG=
R=plin...@gmail.com
Review URL: https://codereview.chromium.org/206373004
Patch from Balazs Kilvady <kilva...@homejinni.com>.
http://code.google.com/p/v8/source/detail?r=20135
Modified:
/branches/bleeding_edge/src/mips/lithium-codegen-mips.cc
/branches/bleeding_edge/src/mips/lithium-mips.cc
/branches/bleeding_edge/src/mips/lithium-mips.h
=======================================
--- /branches/bleeding_edge/src/mips/lithium-codegen-mips.cc Wed Mar 19
15:46:24 2014 UTC
+++ /branches/bleeding_edge/src/mips/lithium-codegen-mips.cc Thu Mar 20
16:04:51 2014 UTC
@@ -1367,8 +1367,31 @@
DeoptimizeIf(eq, instr->environment(), dividend, Operand(zero_reg));
}
- // TODO(svenpanne) Add correction terms.
- __ TruncatingDiv(result, dividend, divisor);
+ // Easy case: We need no dynamic check for the dividend and the flooring
+ // division is the same as the truncating division.
+ if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) ||
+ (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) {
+ __ TruncatingDiv(result, dividend, Abs(divisor));
+ if (divisor < 0) __ Subu(result, zero_reg, result);
+ return;
+ }
+
+ // In the general case we may need to adjust before and after the
truncating
+ // division to get a flooring division.
+ Register temp = ToRegister(instr->temp());
+ ASSERT(!temp.is(dividend) && !temp.is(result));
+ Label needs_adjustment, done;
+ __ Branch(&needs_adjustment, divisor > 0 ? lt : gt,
+ dividend, Operand(zero_reg));
+ __ TruncatingDiv(result, dividend, Abs(divisor));
+ if (divisor < 0) __ Subu(result, zero_reg, result);
+ __ jmp(&done);
+ __ bind(&needs_adjustment);
+ __ Addu(temp, dividend, Operand(divisor > 0 ? 1 : -1));
+ __ TruncatingDiv(result, temp, Abs(divisor));
+ if (divisor < 0) __ Subu(result, zero_reg, result);
+ __ Subu(result, result, Operand(1));
+ __ bind(&done);
}
=======================================
--- /branches/bleeding_edge/src/mips/lithium-mips.cc Fri Mar 14 19:03:10
2014 UTC
+++ /branches/bleeding_edge/src/mips/lithium-mips.cc Thu Mar 20 16:04:51
2014 UTC
@@ -1337,20 +1337,25 @@
ASSERT(instr->right()->representation().Equals(instr->representation()));
LOperand* dividend = UseRegister(instr->left());
int32_t divisor = instr->right()->GetInteger32Constant();
- LInstruction* result =
- DefineAsRegister(new(zone()) LFlooringDivByConstI(dividend,
divisor));
- bool can_deopt =
- divisor == 0 ||
- (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0);
- return can_deopt ? AssignEnvironment(result) : result;
+ LOperand* temp =
+ ((divisor > 0 && !instr->CheckFlag(HValue::kLeftCanBeNegative)) ||
+ (divisor < 0 && !instr->CheckFlag(HValue::kLeftCanBePositive))) ?
+ NULL : TempRegister();
+ LInstruction* result = DefineAsRegister(
+ new(zone()) LFlooringDivByConstI(dividend, divisor, temp));
+ if (divisor == 0 ||
+ (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0)) {
+ result = AssignEnvironment(result);
+ }
+ return result;
}
LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
if (instr->RightIsPowerOf2()) {
return DoFlooringDivByPowerOf2I(instr);
- } else if (false && instr->right()->IsConstant()) {
- return DoFlooringDivByConstI(instr); // TODO(svenpanne) Fix and
re-enable.
+ } else if (instr->right()->IsConstant()) {
+ return DoFlooringDivByConstI(instr);
} else {
return DoDivI(instr);
}
=======================================
--- /branches/bleeding_edge/src/mips/lithium-mips.h Fri Mar 14 19:03:10
2014 UTC
+++ /branches/bleeding_edge/src/mips/lithium-mips.h Thu Mar 20 16:04:51
2014 UTC
@@ -741,16 +741,17 @@
};
-class LFlooringDivByConstI V8_FINAL : public LTemplateInstruction<1, 1, 0>
{
+class LFlooringDivByConstI V8_FINAL : public LTemplateInstruction<1, 1, 2>
{
public:
- LFlooringDivByConstI(LOperand* dividend, int32_t divisor) {
+ LFlooringDivByConstI(LOperand* dividend, int32_t divisor, LOperand*
temp) {
inputs_[0] = dividend;
divisor_ = divisor;
+ temps_[0] = temp;
}
LOperand* dividend() { return inputs_[0]; }
int32_t divisor() const { return divisor_; }
- LOperand* temp1() { return temps_[0]; }
+ LOperand* temp() { return temps_[0]; }
DECLARE_CONCRETE_INSTRUCTION(FlooringDivByConstI, "flooring-div-by-const-i")
DECLARE_HYDROGEN_ACCESSOR(MathFloorOfDiv)
--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.