Index: src/x64/lithium-codegen-x64.cc |
=================================================================== |
--- src/x64/lithium-codegen-x64.cc (revision 13175) |
+++ src/x64/lithium-codegen-x64.cc (working copy) |
@@ -1133,6 +1133,43 @@ |
void LCodeGen::DoDivI(LDivI* instr) { |
+ if (instr->hydrogen()->HasPowerOf2Divisor()) { |
+ Register dividend = ToRegister(instr->left()); |
+ int32_t divisor = |
+ HConstant::cast(instr->hydrogen()->right())->Integer32Value(); |
+ int32_t test_value = 0; |
+ int32_t power = 0; |
+ |
+ if (divisor > 0) { |
+ test_value = divisor - 1; |
+ power = WhichPowerOf2(divisor); |
+ } else { |
+ // Check for (0 / -x) that will produce negative zero. |
+ if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
+ __ testl(dividend, dividend); |
+ DeoptimizeIf(zero, instr->environment()); |
+ } |
+ // Check for (kMinInt / -1). |
+ if (divisor == -1 && instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
+ __ cmpl(dividend, Immediate(kMinInt)); |
+ DeoptimizeIf(zero, instr->environment()); |
+ } |
+ test_value = - divisor - 1; |
+ power = WhichPowerOf2(-divisor); |
+ } |
+ |
+ if (test_value != 0) { |
Yang
2012/12/10 09:47:28
Ditto.
|
+ // Deoptimize if remainder is not 0. |
+ __ testl(dividend, Immediate(test_value)); |
+ DeoptimizeIf(not_zero, instr->environment()); |
+ __ sarl(dividend, Immediate(power)); |
+ } |
+ |
+ if (divisor < 0) __ negl(dividend); |
+ |
+ return; |
+ } |
+ |
LOperand* right = instr->right(); |
ASSERT(ToRegister(instr->result()).is(rax)); |
ASSERT(ToRegister(instr->left()).is(rax)); |
@@ -1158,7 +1195,7 @@ |
__ bind(&left_not_zero); |
} |
- // Check for (-kMinInt / -1). |
+ // Check for (kMinInt / -1). |
if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
Label left_not_min_int; |
__ cmpl(left_reg, Immediate(kMinInt)); |