2008-08-05 Maciej Stachowiak <mjs@apple.com>
authormjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Aug 2008 04:29:57 +0000 (04:29 +0000)
committermjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Aug 2008 04:29:57 +0000 (04:29 +0000)
        Reviewed by Cameron.

        - add fast path for immediates to % operator, as we have for many other math ops

        This fixes handling for a 0 divisor relative to the last patch. Only an 0.2% speedup on SunSpider but
        still a 1.4x win on Oliver's prime test.

        * VM/Machine.cpp:
        (KJS::Machine::privateExecute):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@35586 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/VM/Machine.cpp

index 4fdaae51af726af3055566ac92587fadf7803b13..21543b40bc20f612c99112f43d7680c6b4120eb8 100644 (file)
@@ -1,3 +1,15 @@
+2008-08-05  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Cameron.
+
+        - add fast path for immediates to % operator, as we have for many other math ops
+        
+        This fixes handling for a 0 divisor relative to the last patch. Only an 0.2% speedup on SunSpider but
+        still a 1.4x win on Oliver's prime test.
+        
+        * VM/Machine.cpp:
+        (KJS::Machine::privateExecute):
+
 2008-08-05  Cameron Zwarich  <cwzwarich@uwaterloo.ca>
 
         Reviewed by Darin.
index 19a520fcb0d975086625aa5c860db6e2a3ef2c87..de4ccc5a14f9b52d8857ec4c0fe840e7025523f8 100644 (file)
@@ -1432,8 +1432,18 @@ JSValue* Machine::privateExecute(ExecutionFlag flag, ExecState* exec, RegisterFi
         int dst = (++vPC)->u.operand;
         int dividend = (++vPC)->u.operand;
         int divisor = (++vPC)->u.operand;
-        double d = r[dividend].jsValue(exec)->toNumber(exec);
-        JSValue* result = jsNumber(exec, fmod(d, r[divisor].jsValue(exec)->toNumber(exec)));
+
+        JSValue* dividendValue = r[dividend].jsValue(exec);
+        JSValue* divisorValue = r[divisor].jsValue(exec);
+
+        if (JSImmediate::areBothImmediateNumbers(dividendValue, divisorValue) && divisorValue != JSImmediate::from(0)) {
+            r[dst] = JSImmediate::from(JSImmediate::getTruncatedInt32(dividendValue) % JSImmediate::getTruncatedInt32(divisorValue));
+            ++vPC;
+            NEXT_OPCODE;
+        }
+
+        double d = dividendValue->toNumber(exec);
+        JSValue* result = jsNumber(exec, fmod(d, divisorValue->toNumber(exec)));
         VM_CHECK_EXCEPTION();
         r[dst] = result;
         ++vPC;