Index: src/arm/lithium-arm.cc |
diff --git a/src/arm/lithium-arm.cc b/src/arm/lithium-arm.cc |
index 14c7b08fa7c1a928c3e07491178039c4078c02aa..c5e6b0486734e3537fdd41f4a9d0eac2c9cabb6c 100644 |
--- a/src/arm/lithium-arm.cc |
+++ b/src/arm/lithium-arm.cc |
@@ -1238,21 +1238,40 @@ LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) { |
} |
+LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) { |
+ ASSERT(instr->representation().IsSmiOrInteger32()); |
+ ASSERT(instr->left()->representation().Equals(instr->representation())); |
+ ASSERT(instr->right()->representation().Equals(instr->representation())); |
+ LOperand* dividend = UseRegister(instr->left()); |
+ int32_t divisor = instr->right()->GetInteger32Constant(); |
+ LInstruction* result = |
+ DefineAsRegister(new(zone()) LDivByPowerOf2I(dividend, divisor)); |
+ bool can_deopt = |
+ (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
+ instr->left()->RangeCanInclude(0) && divisor < 0) || |
+ (instr->CheckFlag(HValue::kCanOverflow) && |
+ instr->left()->RangeCanInclude(kMinInt) && divisor == -1) || |
+ (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && |
+ divisor != 1 && divisor != -1); |
+ return can_deopt ? AssignEnvironment(result) : result; |
+} |
+ |
+ |
+LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) { |
+ ASSERT(instr->representation().IsSmiOrInteger32()); |
+ ASSERT(instr->left()->representation().Equals(instr->representation())); |
+ ASSERT(instr->right()->representation().Equals(instr->representation())); |
+ LOperand* dividend = UseRegister(instr->left()); |
+ LOperand* divisor = UseRegister(instr->right()); |
+ LOperand* temp = CpuFeatures::IsSupported(SUDIV) ? NULL : FixedTemp(d4); |
+ LDivI* div = new(zone()) LDivI(dividend, divisor, temp); |
+ return AssignEnvironment(DefineAsRegister(div)); |
+} |
+ |
+ |
LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { |
if (instr->representation().IsSmiOrInteger32()) { |
- ASSERT(instr->left()->representation().Equals(instr->representation())); |
- ASSERT(instr->right()->representation().Equals(instr->representation())); |
- if (instr->RightIsPowerOf2()) { |
- ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero)); |
- LOperand* value = UseRegister(instr->left()); |
- LDivI* div = new(zone()) LDivI(value, UseConstant(instr->right()), NULL); |
- return AssignEnvironment(DefineAsRegister(div)); |
- } |
- LOperand* dividend = UseRegister(instr->left()); |
- LOperand* divisor = UseRegister(instr->right()); |
- LOperand* temp = CpuFeatures::IsSupported(SUDIV) ? NULL : FixedTemp(d4); |
- LDivI* div = new(zone()) LDivI(dividend, divisor, temp); |
- return AssignEnvironment(DefineAsRegister(div)); |
+ return instr->RightIsPowerOf2() ? DoDivByPowerOf2I(instr) : DoDivI(instr); |
} else if (instr->representation().IsDouble()) { |
return DoArithmeticD(Token::DIV, instr); |
} else { |
@@ -1263,10 +1282,8 @@ LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { |
bool LChunkBuilder::HasMagicNumberForDivisor(int32_t divisor) { |
uint32_t divisor_abs = abs(divisor); |
- // Dividing by 0, 1, and powers of 2 is easy. |
- // Note that IsPowerOf2(0) returns true; |
- ASSERT(IsPowerOf2(0) == true); |
- if (IsPowerOf2(divisor_abs)) return true; |
+ // Dividing by 0 or powers of 2 is easy. |
+ if (divisor == 0 || IsPowerOf2(divisor_abs)) return true; |
// We have magic numbers for a few specific divisors. |
// Details and proofs can be found in: |
@@ -1282,77 +1299,103 @@ bool LChunkBuilder::HasMagicNumberForDivisor(int32_t divisor) { |
CompilerIntrinsics::CountTrailingZeros(divisor_abs); |
DivMagicNumbers magic_numbers = |
DivMagicNumberFor(divisor_abs >> power_of_2_factor); |
- if (magic_numbers.M != InvalidDivMagicNumber.M) return true; |
- |
- return false; |
+ return magic_numbers.M != InvalidDivMagicNumber.M; |
} |
-LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { |
- // LMathFloorOfDiv can only handle a subset of divisors, so fall |
- // back to a flooring division in all other cases. |
- HValue* right = instr->right(); |
- if (!right->IsInteger32Constant() || |
- (!CpuFeatures::IsSupported(SUDIV) && |
- !HasMagicNumberForDivisor(HConstant::cast(right)->Integer32Value()))) { |
- LOperand* dividend = UseRegister(instr->left()); |
- LOperand* divisor = UseRegister(right); |
- LOperand* temp = CpuFeatures::IsSupported(SUDIV) ? NULL : FixedTemp(d4); |
- LDivI* div = new(zone()) LDivI(dividend, divisor, temp); |
- return AssignEnvironment(DefineAsRegister(div)); |
- } |
+LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) { |
+ LOperand* dividend = UseRegisterAtStart(instr->left()); |
+ int32_t divisor = instr->right()->GetInteger32Constant(); |
+ LInstruction* result = |
+ DefineSameAsFirst( |
+ new(zone()) LFlooringDivByPowerOf2I(dividend, divisor)); |
+ bool can_deopt = |
+ (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) || |
+ (instr->left()->RangeCanInclude(kMinInt) && divisor == -1); |
+ return can_deopt ? AssignEnvironment(result) : result; |
+} |
+ |
+LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) { |
LOperand* dividend = UseRegister(instr->left()); |
LOperand* divisor = CpuFeatures::IsSupported(SUDIV) |
- ? UseRegister(right) |
- : UseOrConstant(right); |
+ ? UseRegister(instr->right()) |
+ : UseOrConstant(instr->right()); |
LOperand* remainder = TempRegister(); |
- return AssignEnvironment(DefineAsRegister( |
- new(zone()) LMathFloorOfDiv(dividend, divisor, remainder))); |
+ LInstruction* result = |
+ DefineAsRegister( |
+ new(zone()) LFlooringDivByConstI(dividend, divisor, remainder)); |
+ return AssignEnvironment(result); |
+} |
+ |
+ |
+LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { |
+ if (instr->RightIsPowerOf2()) { |
+ return DoFlooringDivByPowerOf2I(instr); |
+ } else if (instr->right()->IsConstant()) { |
+ // LMathFloorOfDiv can currently only handle a subset of divisors, so fall |
+ // back to a flooring division in all other cases. |
+ return (CpuFeatures::IsSupported(SUDIV) || |
+ HasMagicNumberForDivisor(instr->right()->GetInteger32Constant())) |
+ ? DoFlooringDivByConstI(instr) |
+ : DoDivI(instr); |
+ } else { |
+ return DoDivI(instr); |
+ } |
+} |
+ |
+ |
+LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) { |
+ ASSERT(instr->representation().IsSmiOrInteger32()); |
+ ASSERT(instr->left()->representation().Equals(instr->representation())); |
+ ASSERT(instr->right()->representation().Equals(instr->representation())); |
+ LOperand* dividend = UseRegisterAtStart(instr->left()); |
+ int32_t divisor = instr->right()->GetInteger32Constant(); |
+ LInstruction* result = |
+ DefineSameAsFirst(new(zone()) LModByPowerOf2I(dividend, divisor)); |
+ bool can_deopt = |
+ instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
+ instr->left()->CanBeNegative(); |
+ return can_deopt ? AssignEnvironment(result) : result; |
+} |
+ |
+ |
+LInstruction* LChunkBuilder::DoModI(HMod* instr) { |
+ ASSERT(instr->representation().IsSmiOrInteger32()); |
+ ASSERT(instr->left()->representation().Equals(instr->representation())); |
+ ASSERT(instr->right()->representation().Equals(instr->representation())); |
+ if (CpuFeatures::IsSupported(SUDIV)) { |
+ LOperand* dividend = UseRegister(instr->left()); |
+ LOperand* divisor = UseRegister(instr->right()); |
+ LInstruction* result = |
+ DefineAsRegister(new(zone()) LModI(dividend, divisor, NULL, NULL)); |
+ bool can_deopt = (instr->right()->CanBeZero() || |
+ (instr->left()->RangeCanInclude(kMinInt) && |
+ instr->right()->RangeCanInclude(-1) && |
+ instr->CheckFlag(HValue::kBailoutOnMinusZero)) || |
+ (instr->left()->CanBeNegative() && |
+ instr->CanBeZero() && |
+ instr->CheckFlag(HValue::kBailoutOnMinusZero))); |
+ return can_deopt ? AssignEnvironment(result) : result; |
+ } else { |
+ LOperand* dividend = UseRegister(instr->left()); |
+ LOperand* divisor = UseRegister(instr->right()); |
+ LOperand* temp = FixedTemp(d10); |
+ LOperand* temp2 = FixedTemp(d11); |
+ LInstruction* result = |
+ DefineAsRegister(new(zone()) LModI(dividend, divisor, temp, temp2)); |
+ bool can_deopt = (instr->right()->CanBeZero() || |
+ (instr->left()->CanBeNegative() && |
+ instr->CanBeZero() && |
+ instr->CheckFlag(HValue::kBailoutOnMinusZero))); |
+ return can_deopt ? AssignEnvironment(result) : result; |
+ } |
} |
LInstruction* LChunkBuilder::DoMod(HMod* instr) { |
- HValue* left = instr->left(); |
- HValue* right = instr->right(); |
if (instr->representation().IsSmiOrInteger32()) { |
- ASSERT(instr->left()->representation().Equals(instr->representation())); |
- ASSERT(instr->right()->representation().Equals(instr->representation())); |
- if (instr->RightIsPowerOf2()) { |
- ASSERT(!right->CanBeZero()); |
- LModI* mod = new(zone()) LModI(UseRegisterAtStart(left), |
- UseConstant(right)); |
- LInstruction* result = DefineAsRegister(mod); |
- return (left->CanBeNegative() && |
- instr->CheckFlag(HValue::kBailoutOnMinusZero)) |
- ? AssignEnvironment(result) |
- : result; |
- } else if (CpuFeatures::IsSupported(SUDIV)) { |
- LModI* mod = new(zone()) LModI(UseRegister(left), |
- UseRegister(right)); |
- LInstruction* result = DefineAsRegister(mod); |
- return (right->CanBeZero() || |
- (left->RangeCanInclude(kMinInt) && |
- right->RangeCanInclude(-1) && |
- instr->CheckFlag(HValue::kBailoutOnMinusZero)) || |
- (left->CanBeNegative() && |
- instr->CanBeZero() && |
- instr->CheckFlag(HValue::kBailoutOnMinusZero))) |
- ? AssignEnvironment(result) |
- : result; |
- } else { |
- LModI* mod = new(zone()) LModI(UseRegister(left), |
- UseRegister(right), |
- FixedTemp(d10), |
- FixedTemp(d11)); |
- LInstruction* result = DefineAsRegister(mod); |
- return (right->CanBeZero() || |
- (left->CanBeNegative() && |
- instr->CanBeZero() && |
- instr->CheckFlag(HValue::kBailoutOnMinusZero))) |
- ? AssignEnvironment(result) |
- : result; |
- } |
+ return instr->RightIsPowerOf2() ? DoModByPowerOf2I(instr) : DoModI(instr); |
} else if (instr->representation().IsDouble()) { |
return DoArithmeticD(Token::MOD, instr); |
} else { |