Revision: 21780
Author:   [email protected]
Date:     Wed Jun 11 20:06:01 2014 UTC
Log:      MIPS: Fixed flooring division by a power of 2, once again...

Port r21769 (52e191b)

Original commit message:
Avoid right shifts by zero bits: On ARM it actually means shifting by
32 bits (correctness issue) and on other platforms they are useless
(performance issue). This is fix for the fix in r20544.

BUG=v8:3259
LOG=y
[email protected]

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

Patch from Balazs Kilvady <[email protected]>.
http://code.google.com/p/v8/source/detail?r=21780

Modified:
 /branches/bleeding_edge/src/mips/lithium-codegen-mips.cc

=======================================
--- /branches/bleeding_edge/src/mips/lithium-codegen-mips.cc Wed Jun 11 09:09:15 2014 UTC +++ /branches/bleeding_edge/src/mips/lithium-codegen-mips.cc Wed Jun 11 20:06:01 2014 UTC
@@ -1309,8 +1309,8 @@
   Register dividend = ToRegister(instr->dividend());
   Register result = ToRegister(instr->result());
   int32_t divisor = instr->divisor();
-  Register scratch = scratch0();
-  ASSERT(!scratch.is(dividend));
+  Register scratch = result.is(dividend) ? scratch0() : dividend;
+  ASSERT(!result.is(dividend) || !scratch.is(dividend));

   // If the divisor is 1, return the dividend.
   if (divisor == 1) {
@@ -1328,23 +1328,27 @@

   // If the divisor is negative, we have to negate and handle edge cases.
   if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
+    // divident can be the same register as result so save the value of it
+    // for checking overflow.
     __ Move(scratch, dividend);
   }
   __ Subu(result, zero_reg, dividend);
   if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
     DeoptimizeIf(eq, instr->environment(), result, Operand(zero_reg));
   }
-
-  // If the negation could not overflow, simply shifting is OK.
-  if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
-    __ sra(result, dividend, shift);
-    return;
-  }

   // Dividing by -1 is basically negation, unless we overflow.
   __ Xor(at, scratch, result);
   if (divisor == -1) {
-    DeoptimizeIf(ge, instr->environment(), at, Operand(zero_reg));
+    if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
+      DeoptimizeIf(ge, instr->environment(), at, Operand(zero_reg));
+    }
+    return;
+  }
+
+  // If the negation could not overflow, simply shifting is OK.
+  if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
+    __ sra(result, result, shift);
     return;
   }

@@ -1353,7 +1357,7 @@
   __ li(result, Operand(kMinInt / divisor));
   __ Branch(&done);
   __ bind(&no_overflow);
-  __ sra(result, dividend, shift);
+  __ sra(result, result, shift);
   __ bind(&done);
 }

--
--
v8-dev mailing list
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to