Reviewers: Søren Gjesse,

Description:
Implement fast code for the common cases of left hand sides that are less than
three times larger as the right hand side and and right hand sides that are
powers of two up and including 32.

In the covered special cases the result is computed directly, else the generic stub is called. The implementation deoptimizes only for mod 0 and if the result
may be a negative zero.

BUG=none
TEST=none

Please review this at http://codereview.chromium.org/6331005/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/arm/lithium-codegen-arm.cc


Index: src/arm/lithium-codegen-arm.cc
diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc
index 5baed365c0b3922ad98623329a86737c1c71d0d9..99cec39d78ddfdb8a7b6c177b74b19ce821e5bfa 100644
--- a/src/arm/lithium-codegen-arm.cc
+++ b/src/arm/lithium-codegen-arm.cc
@@ -1038,6 +1038,25 @@ void LCodeGen::DoModI(LModI* instr) {
     __ bind(&ok);
   }

+  // Try a few common cases before using the generic stub.
+  const int kUnfolds = 3;
+  __ mov(scratch, left);
+  for (int i = 0; i < kUnfolds; i++) {
+    // Check if the left hand side is less or equal.
+    if (i == 0) __ cmp(scratch, right);
+    __ mov(result, scratch, LeaveCC, le);
+    __ b(le, &done);
+    if (i < kUnfolds - 1) __ sub(scratch, left, right);
+  }
+
+  // Check for power of two on the right hand side.
+  const int kMaxPowerOfTwo = 32;
+  for (int i = 2; i <= kMaxPowerOfTwo; i <<= 1) {
+    __ cmp(right, Operand(i));
+    __ and_(result, left, Operand(i-1), LeaveCC, eq);
+    __ b(&done, eq);
+  }
+
   // Call the generic stub. The numbers in r0 and r1 have
   // to be tagged to Smis. If that is not possible, deoptimize.
   DeferredModI* deferred = new DeferredModI(this, instr);
@@ -1049,7 +1068,7 @@ void LCodeGen::DoModI(LModI* instr) {

   // If the result in r0 is a Smi, untag it, else deoptimize.
   __ BranchOnNotSmi(result, &deoptimize);
-  __ mov(result, Operand(result, ASR, 1));
+  __ SmiUntag(result);

   __ b(al, &done);
   __ bind(&deoptimize);


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to