Chromium Code Reviews| Index: src/arm/lithium-codegen-arm.cc |
| diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc |
| index 0e4497fcc8d5196b8c5e785f74e459910972b62e..61c5eafce88915b04acc7cff6ad7a44949f5f9ee 100644 |
| --- a/src/arm/lithium-codegen-arm.cc |
| +++ b/src/arm/lithium-codegen-arm.cc |
| @@ -832,7 +832,80 @@ void LCodeGen::DoModI(LModI* instr) { |
| void LCodeGen::DoDivI(LDivI* instr) { |
| - Abort("DoDivI unimplemented."); |
| + const Register left = ToRegister(instr->left()); |
| + const Register right = ToRegister(instr->right()); |
| + const Register scratch = scratch0(); |
| + const Register result = ToRegister(instr->result()); |
| + |
| + // Check for x / 0. |
| + if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) { |
| + __ tst(right, right); |
| + DeoptimizeIf(eq, instr->environment()); |
| + } |
| + |
| + // Check for (0 / -x) that will produce negative zero. |
| + if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| + Label left_not_zero; |
| + __ tst(left, Operand(left)); |
| + __ b(ne, &left_not_zero); |
| + __ tst(right, Operand(right)); |
| + DeoptimizeIf(mi, instr->environment()); |
| + __ bind(&left_not_zero); |
| + } |
| + |
| + // Check for (-kMinInt / -1). |
| + if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| + Label left_not_min_int; |
| + __ cmp(left, Operand(kMinInt)); |
| + __ b(ne, &left_not_min_int); |
| + __ cmp(right, Operand(-1)); |
| + DeoptimizeIf(eq, instr->environment()); |
| + __ bind(&left_not_min_int); |
| + } |
| + |
| + Label done, deoptimize; |
| + // Test for a few common cases first. |
| + __ cmp(right, Operand(1)); |
| + __ mov(result, left, LeaveCC, eq); |
| + __ b(eq, &done); |
| + |
| + __ cmp(right, Operand(2)); |
| + __ tst(left, Operand(1), eq); |
| + __ mov(result, Operand(left, ASR, 1), LeaveCC, eq); |
| + __ b(eq, &done); |
| + |
| + __ cmp(right, Operand(4)); |
| + __ tst(left, Operand(3), eq); |
| + __ mov(result, Operand(left, ASR, 2), LeaveCC, eq); |
| + __ b(eq, &done); |
| + |
| + // Call the generic stub. The numbers in r0 and r1 have |
| + // to be tagged to Smis. If that is not possible, deoptimize. |
| + const int32_t kTwoHighestBits = 3<<30; |
|
Søren Thygesen Gjesse
2011/01/13 08:28:38
In other parts of the code we write this as 0xc000
Karl Klose
2011/01/13 13:52:31
I have created a TrySmiTag instruction in the macr
|
| + __ and_(scratch, left, Operand(kTwoHighestBits)); |
|
Søren Thygesen Gjesse
2011/01/13 08:28:38
You can use SetCC on the and instruction to set th
Karl Klose
2011/01/13 13:52:31
s.a.
|
| + __ cmp(scratch, Operand(1 << 31)); |
| + __ cmp(scratch, Operand(1 << 30), ne); |
| + __ b(eq, &deoptimize); |
|
Søren Thygesen Gjesse
2011/01/13 08:28:38
There is a SmiTag instruction in the macro assembl
Karl Klose
2011/01/13 13:52:31
s.a.
|
| + __ mov(left, Operand(left, LSL, 1)); |
| + |
| + __ and_(scratch, right, Operand(kTwoHighestBits)); |
| + __ cmp(scratch, Operand(1 << 31)); |
| + __ cmp(scratch, Operand(1 << 30), ne); |
| + __ b(eq, &deoptimize); |
| + __ mov(right, Operand(right, LSL, 1)); |
| + |
| + GenericBinaryOpStub stub(Token::DIV, OVERWRITE_LEFT, left, right); |
|
Søren Thygesen Gjesse
2011/01/13 08:28:38
The LDivI instruction is not marked as call which
Karl Klose
2011/01/13 13:52:31
Done.
|
| + __ CallStub(&stub); |
| + |
| + // If the result in r0 is a Smi, untag it, else deoptimize. |
| + __ BranchOnNotSmi(result, &deoptimize); |
| + __ mov(result, Operand(result, ASR, 1)); |
| + __ b(&done); |
| + |
| + __ bind(&deoptimize); |
| + DeoptimizeIf(al, instr->environment()); |
| + __ bind(&done); |
| + |
| } |