Bug 686323: Put JSOP_DIV logic into its own function r=dvander
authorTom Schuster <evilpies@gmail.com>
Wed, 14 Sep 2011 20:47:08 +0200
changeset 78283 c614dabf94e21e10e7274efbad4ab8417f7cae15
parent 78282 fec42fae34a724cdcef5fb1493831d103bf038e8
child 78284 44977dedb48546dc11ecc611b83238afdb610771
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs686323
milestone9.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 686323: Put JSOP_DIV logic into its own function r=dvander
js/src/jsinterp.cpp
js/src/jslibmath.h
js/src/methodjit/FastArithmetic.cpp
--- a/js/src/jsinterp.cpp
+++ b/js/src/jsinterp.cpp
@@ -3061,39 +3061,21 @@ END_CASE(JSOP_MUL)
 BEGIN_CASE(JSOP_DIV)
 {
     Value rval = regs.sp[-1];
     Value lval = regs.sp[-2];
     double d1, d2;
     if (!ToNumber(cx, lval, &d1) || !ToNumber(cx, rval, &d2))
         goto error;
     regs.sp--;
-    if (d2 == 0) {
-        const Value *vp;
-#ifdef XP_WIN
-        /* XXX MSVC miscompiles such that (NaN == 0) */
-        if (JSDOUBLE_IS_NaN(d2))
-            vp = &rt->NaNValue;
-        else
-#endif
-        if (d1 == 0 || JSDOUBLE_IS_NaN(d1))
-            vp = &rt->NaNValue;
-        else if (JSDOUBLE_IS_NEG(d1) != JSDOUBLE_IS_NEG(d2))
-            vp = &rt->negativeInfinityValue;
-        else
-            vp = &rt->positiveInfinityValue;
-        regs.sp[-1] = *vp;
+
+    regs.sp[-1].setNumber(NumberDiv(d1, d2));
+
+    if (d2 == 0 || (regs.sp[-1].isDouble() && !(lval.isDouble() || rval.isDouble())))
         TypeScript::MonitorOverflow(cx, script, regs.pc);
-    } else {
-        d1 /= d2;
-        if (!regs.sp[-1].setNumber(d1) &&
-            !(lval.isDouble() || rval.isDouble())) {
-            TypeScript::MonitorOverflow(cx, script, regs.pc);
-        }
-    }
 }
 END_CASE(JSOP_DIV)
 
 BEGIN_CASE(JSOP_MOD)
 {
     Value &lref = regs.sp[-2];
     Value &rref = regs.sp[-1];
     int32_t l, r;
--- a/js/src/jslibmath.h
+++ b/js/src/jslibmath.h
@@ -37,19 +37,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _LIBMATH_H
 #define _LIBMATH_H
 
 #include <math.h>
-#ifdef XP_WIN
-# include "jsnum.h"
-#endif
+#include "jsnum.h"
 
 /*
  * Use system provided math routines.
  */
 
 /* The right copysign function is not always named the same thing. */
 #if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
 #define js_copysign __builtin_copysign
@@ -83,10 +81,32 @@ js_fmod(double d, double d2)
     if ((JSDOUBLE_IS_FINITE(d) && JSDOUBLE_IS_INFINITE(d2)) ||
         (d == 0 && JSDOUBLE_IS_FINITE(d2))) {
         return d;
     }
 #endif
     return fmod(d, d2);
 }
 
+namespace js {
+
+inline double
+NumberDiv(double a, double b) {
+    if (b == 0) {
+        if (a == 0 || JSDOUBLE_IS_NaN(a) 
+#ifdef XP_WIN
+            || JSDOUBLE_IS_NaN(a) /* XXX MSVC miscompiles such that (NaN == 0) */
+#endif
+        )
+            return js_NaN;    
+        else if (JSDOUBLE_IS_NEG(a) != JSDOUBLE_IS_NEG(b))
+            return js_NegativeInfinity;
+        else
+            return js_PositiveInfinity; 
+    }
+
+    return a / b;
+}
+
+}
+
 #endif /* _LIBMATH_H */
 
--- a/js/src/methodjit/FastArithmetic.cpp
+++ b/js/src/methodjit/FastArithmetic.cpp
@@ -108,31 +108,17 @@ mjit::Compiler::tryBinaryConstantFold(JS
         break;
       case JSOP_SUB:
         dL -= dR;
         break;
       case JSOP_MUL:
         dL *= dR;
         break;
       case JSOP_DIV:
-        if (dR == 0) {
-#ifdef XP_WIN
-            if (JSDOUBLE_IS_NaN(dR))
-                dL = js_NaN;
-            else
-#endif
-            if (dL == 0 || JSDOUBLE_IS_NaN(dL))
-                dL = js_NaN;
-            else if (JSDOUBLE_IS_NEG(dL) != JSDOUBLE_IS_NEG(dR))
-                dL = cx->runtime->negativeInfinityValue.toDouble();
-            else
-                dL = cx->runtime->positiveInfinityValue.toDouble();
-        } else {
-            dL /= dR;
-        }
+        dL = js::NumberDiv(dL, dR);
         break;
       case JSOP_MOD:
         if (needInt)
             nL %= nR;
         else if (dR == 0)
             dL = js_NaN;
         else
             dL = js_fmod(dL, dR);