Bug 942550: Take care of all particular cases in ecmaPow instead of js_math_pow; r=jandem
authorBenjamin Bouvier <benj@benj.me>
Wed, 29 Jan 2014 12:12:03 +0100
changeset 181753 15d8e67e503508ca1033881ce2ddbdfc5a7f7297
parent 181752 d588d0299cb7262e58792a5c8ea6c81057858c82
child 181754 68444ba6d0a0a1149f4903ba1510f1f80e6ba0a0
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs942550
milestone29.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 942550: Take care of all particular cases in ecmaPow instead of js_math_pow; r=jandem
js/src/jit-test/tests/ion/bug942550.js
js/src/jsmath.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/ion/bug942550.js
@@ -0,0 +1,6 @@
+function pow(x,y) {
+    return Math.pow(x,y);
+}
+var x = pow(3, -.5);
+var y = pow(3, -.5);
+assertEq(x, y);
--- a/js/src/jsmath.cpp
+++ b/js/src/jsmath.cpp
@@ -620,19 +620,31 @@ js::ecmaPow(double x, double y)
         return powi(x, yi);
 
     /*
      * Because C99 and ECMA specify different behavior for pow(),
      * we need to wrap the libm call to make it ECMA compliant.
      */
     if (!IsFinite(y) && (x == 1.0 || x == -1.0))
         return GenericNaN();
+
     /* pow(x, +-0) is always 1, even for x = NaN (MSVC gets this wrong). */
     if (y == 0)
         return 1;
+
+    /*
+     * Special case for square roots. Note that pow(x, 0.5) != sqrt(x)
+     * when x = -0.0, so we have to guard for this.
+     */
+    if (IsFinite(x) && x != 0.0) {
+        if (y == 0.5)
+            return sqrt(x);
+        if (y == -0.5)
+            return 1.0 / sqrt(x);
+    }
     return pow(x, y);
 }
 #if defined(_MSC_VER)
 # pragma optimize("", on)
 #endif
 
 // Disable PGO for Math.pow() and related functions (see bug 791214).
 #if defined(_MSC_VER)
@@ -646,39 +658,17 @@ js_math_pow(JSContext *cx, unsigned argc
     double x;
     if (!ToNumber(cx, args.get(0), &x))
         return false;
 
     double y;
     if (!ToNumber(cx, args.get(1), &y))
         return false;
 
-    /*
-     * Special case for square roots. Note that pow(x, 0.5) != sqrt(x)
-     * when x = -0.0, so we have to guard for this.
-     */
-    if (IsFinite(x) && x != 0.0) {
-        if (y == 0.5) {
-            args.rval().setNumber(sqrt(x));
-            return true;
-        }
-        if (y == -0.5) {
-            args.rval().setNumber(1.0/sqrt(x));
-            return true;
-        }
-    }
-
-    /* pow(x, +-0) is always 1, even for x = NaN. */
-    if (y == 0) {
-        args.rval().setInt32(1);
-        return true;
-    }
-
     double z = ecmaPow(x, y);
-
     args.rval().setNumber(z);
     return true;
 }
 #if defined(_MSC_VER)
 # pragma optimize("", on)
 #endif
 
 static uint64_t