Bug 933257 - Part 5: Use fdlibm in jsmath.cpp. r=jwalden
authorTooru Fujisawa <arai_a@mac.com>
Thu, 07 Jan 2016 12:30:29 +0900
changeset 288485 f3b11c2b7dbff4219c77adbba9b881481d2f7044
parent 288484 083a4c3175a2b8d183159673faf39e03dc54f9f8
child 288486 41f59bd4b8019b908899664c3dd7ee4c88bb15c6
push id18151
push userryanvm@gmail.com
push dateSun, 13 Mar 2016 23:08:49 +0000
treeherderfx-team@f0c0480732d3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs933257
milestone48.0a1
Bug 933257 - Part 5: Use fdlibm in jsmath.cpp. r=jwalden
config/check_spidermonkey_style.py
js/src/jsmath.cpp
--- a/config/check_spidermonkey_style.py
+++ b/config/check_spidermonkey_style.py
@@ -61,16 +61,17 @@ included_inclnames_to_ignore = set([
     'ffi.h',                    # generated in ctypes/libffi/
     'devtools/sharkctl.h',      # we ignore devtools/ in general
     'devtools/Instruments.h',   # we ignore devtools/ in general
     'double-conversion.h',      # strange MFBT case
     'javascript-trace.h',       # generated in $OBJDIR if HAVE_DTRACE is defined
     'jsautokw.h',               # generated in $OBJDIR
     'jscustomallocator.h',      # provided by embedders;  allowed to be missing
     'js-config.h',              # generated in $OBJDIR
+    'fdlibm.h',                 # fdlibm
     'pratom.h',                 # NSPR
     'prcvar.h',                 # NSPR
     'prerror.h',                # NSPR
     'prinit.h',                 # NSPR
     'prlink.h',                 # NSPR
     'prlock.h',                 # NSPR
     'prprf.h',                  # NSPR
     'prthread.h',               # NSPR
--- a/js/src/jsmath.cpp
+++ b/js/src/jsmath.cpp
@@ -17,16 +17,18 @@
 
 #include <algorithm>  // for std::max
 #include <fcntl.h>
 
 #ifdef XP_UNIX
 # include <unistd.h>
 #endif
 
+#include "fdlibm.h"
+
 #ifdef XP_WIN
 # include "jswin.h"
 #endif
 
 #include "jsapi.h"
 #include "jsatom.h"
 #include "jscntxt.h"
 #include "jscompartment.h"
@@ -134,24 +136,24 @@ js::math_abs(JSContext* cx, unsigned arg
 #else
 #define ACOS_IF_OUT_OF_RANGE(x)
 #endif
 
 double
 js::math_acos_impl(MathCache* cache, double x)
 {
     ACOS_IF_OUT_OF_RANGE(x);
-    return cache->lookup(acos, x, MathCache::Acos);
+    return cache->lookup(fdlibm::acos, x, MathCache::Acos);
 }
 
 double
 js::math_acos_uncached(double x)
 {
     ACOS_IF_OUT_OF_RANGE(x);
-    return acos(x);
+    return fdlibm::acos(x);
 }
 
 #undef ACOS_IF_OUT_OF_RANGE
 
 bool
 js::math_acos(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
@@ -179,24 +181,24 @@ js::math_acos(JSContext* cx, unsigned ar
 #else
 #define ASIN_IF_OUT_OF_RANGE(x)
 #endif
 
 double
 js::math_asin_impl(MathCache* cache, double x)
 {
     ASIN_IF_OUT_OF_RANGE(x);
-    return cache->lookup(asin, x, MathCache::Asin);
+    return cache->lookup(fdlibm::asin, x, MathCache::Asin);
 }
 
 double
 js::math_asin_uncached(double x)
 {
     ASIN_IF_OUT_OF_RANGE(x);
-    return asin(x);
+    return fdlibm::asin(x);
 }
 
 #undef ASIN_IF_OUT_OF_RANGE
 
 bool
 js::math_asin(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
@@ -217,23 +219,23 @@ js::math_asin(JSContext* cx, unsigned ar
     double z = math_asin_impl(mathCache, x);
     args.rval().setDouble(z);
     return true;
 }
 
 double
 js::math_atan_impl(MathCache* cache, double x)
 {
-    return cache->lookup(atan, x, MathCache::Atan);
+    return cache->lookup(fdlibm::atan, x, MathCache::Atan);
 }
 
 double
 js::math_atan_uncached(double x)
 {
-    return atan(x);
+    return fdlibm::atan(x);
 }
 
 bool
 js::math_atan(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     if (args.length() == 0) {
@@ -276,17 +278,17 @@ js::ecmaAtan2(double y, double x)
 #if defined(SOLARIS) && defined(__GNUC__)
     if (y == 0) {
         if (IsNegativeZero(x))
             return js_copysign(M_PI, y);
         if (x == 0)
             return y;
     }
 #endif
-    return atan2(y, x);
+    return fdlibm::atan2(y, x);
 }
 
 bool
 js::math_atan2_handle(JSContext* cx, HandleValue y, HandleValue x, MutableHandleValue res)
 {
     double dy;
     if (!ToNumber(cx, y, &dy))
         return false;
@@ -310,17 +312,17 @@ js::math_atan2(JSContext* cx, unsigned a
 
 double
 js::math_ceil_impl(double x)
 {
 #ifdef __APPLE__
     if (x < 0 && x > -1.0)
         return js_copysign(0, -1);
 #endif
-    return ceil(x);
+    return fdlibm::ceil(x);
 }
 
 bool
 js::math_ceil_handle(JSContext* cx, HandleValue v, MutableHandleValue res)
 {
     double d;
     if(!ToNumber(cx, v, &d))
         return false;
@@ -364,23 +366,23 @@ js::math_clz32(JSContext* cx, unsigned a
 
     args.rval().setInt32(mozilla::CountLeadingZeroes32(n));
     return true;
 }
 
 double
 js::math_cos_impl(MathCache* cache, double x)
 {
-    return cache->lookup(cos, x, MathCache::Cos);
+    return cache->lookup(fdlibm::cos, x, MathCache::Cos);
 }
 
 double
 js::math_cos_uncached(double x)
 {
-    return cos(x);
+    return fdlibm::cos(x);
 }
 
 bool
 js::math_cos(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     if (args.length() == 0) {
@@ -412,24 +414,24 @@ js::math_cos(JSContext* cx, unsigned arg
 #else
 #define EXP_IF_OUT_OF_RANGE(x)
 #endif
 
 double
 js::math_exp_impl(MathCache* cache, double x)
 {
     EXP_IF_OUT_OF_RANGE(x);
-    return cache->lookup(exp, x, MathCache::Exp);
+    return cache->lookup(fdlibm::exp, x, MathCache::Exp);
 }
 
 double
 js::math_exp_uncached(double x)
 {
     EXP_IF_OUT_OF_RANGE(x);
-    return exp(x);
+    return fdlibm::exp(x);
 }
 
 #undef EXP_IF_OUT_OF_RANGE
 
 bool
 js::math_exp(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
@@ -450,17 +452,17 @@ js::math_exp(JSContext* cx, unsigned arg
     double z = math_exp_impl(mathCache, x);
     args.rval().setNumber(z);
     return true;
 }
 
 double
 js::math_floor_impl(double x)
 {
-    return floor(x);
+    return fdlibm::floor(x);
 }
 
 bool
 js::math_floor_handle(JSContext* cx, HandleValue v, MutableHandleValue r)
 {
     double d;
     if (!ToNumber(cx, v, &d))
         return false;
@@ -554,17 +556,17 @@ js::math_log_impl(MathCache* cache, doub
     LOG_IF_OUT_OF_RANGE(x);
     return cache->lookup(math_log_uncached, x, MathCache::Log);
 }
 
 double
 js::math_log_uncached(double x)
 {
     LOG_IF_OUT_OF_RANGE(x);
-    return log(x);
+    return fdlibm::log(x);
 }
 
 #undef LOG_IF_OUT_OF_RANGE
 
 bool
 js::math_log_handle(JSContext* cx, HandleValue val, MutableHandleValue res)
 {
     double in;
@@ -674,17 +676,17 @@ js::powi(double x, int y)
             if (y < 0) {
                 // Unfortunately, we have to be careful when p has reached
                 // infinity in the computation, because sometimes the higher
                 // internal precision in the pow() implementation would have
                 // given us a finite p. This happens very rarely.
 
                 double result = 1.0 / p;
                 return (result == 0 && IsInfinite(p))
-                       ? pow(x, static_cast<double>(y))  // Avoid pow(double, int).
+                       ? fdlibm::pow(x, static_cast<double>(y))  // Avoid pow(double, int).
                        : result;
             }
 
             return p;
         }
         m *= m;
     }
 }
@@ -712,21 +714,21 @@ js::ecmaPow(double x, double y)
         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);
+            return fdlibm::sqrt(x);
         if (y == -0.5)
-            return 1.0 / sqrt(x);
+            return 1.0 / fdlibm::sqrt(x);
     }
-    return pow(x, y);
+    return fdlibm::pow(x, y);
 }
 
 bool
 js::math_pow_handle(JSContext* cx, HandleValue base, HandleValue power, MutableHandleValue result)
 {
     double x;
     if (!ToNumber(cx, base, &x))
         return false;
@@ -838,32 +840,32 @@ js::math_round_impl(double x)
     if (NumberIsInt32(x, &ignored))
         return x;
 
     /* Some numbers are so big that adding 0.5 would give the wrong number. */
     if (ExponentComponent(x) >= int_fast16_t(FloatingPoint<double>::kExponentShift))
         return x;
 
     double add = (x >= 0) ? GetBiggestNumberLessThan(0.5) : 0.5;
-    return js_copysign(floor(x + add), x);
+    return js_copysign(fdlibm::floor(x + add), x);
 }
 
 float
 js::math_roundf_impl(float x)
 {
     int32_t ignored;
     if (NumberIsInt32(x, &ignored))
         return x;
 
     /* Some numbers are so big that adding 0.5 would give the wrong number. */
     if (ExponentComponent(x) >= int_fast16_t(FloatingPoint<float>::kExponentShift))
         return x;
 
     float add = (x >= 0) ? GetBiggestNumberLessThan(0.5f) : 0.5f;
-    return js_copysign(floorf(x + add), x);
+    return js_copysign(fdlibm::floorf(x + add), x);
 }
 
 bool /* ES5 15.8.2.15. */
 js::math_round(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     if (args.length() == 0) {
@@ -878,23 +880,17 @@ double
 js::math_sin_impl(MathCache* cache, double x)
 {
     return cache->lookup(math_sin_uncached, x, MathCache::Sin);
 }
 
 double
 js::math_sin_uncached(double x)
 {
-#ifdef _WIN64
-    // Workaround MSVC bug where sin(-0) is +0 instead of -0 on x64 on
-    // CPUs without FMA3 (pre-Haswell). See bug 1076670.
-    if (IsNegativeZero(x))
-        return -0.0;
-#endif
-    return sin(x);
+    return fdlibm::sin(x);
 }
 
 bool
 js::math_sin_handle(JSContext* cx, HandleValue val, MutableHandleValue res)
 {
     double in;
     if (!ToNumber(cx, val, &in))
         return false;
@@ -961,17 +957,17 @@ js::math_sqrt_handle(JSContext* cx, Hand
     double x;
     if (!ToNumber(cx, number, &x))
         return false;
 
     MathCache* mathCache = cx->runtime()->getMathCache(cx);
     if (!mathCache)
         return false;
 
-    double z = mathCache->lookup(sqrt, x, MathCache::Sqrt);
+    double z = mathCache->lookup(fdlibm::sqrt, x, MathCache::Sqrt);
     result.setDouble(z);
     return true;
 }
 
 bool
 js::math_sqrt(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
@@ -982,23 +978,23 @@ js::math_sqrt(JSContext* cx, unsigned ar
     }
 
     return math_sqrt_handle(cx, args[0], args.rval());
 }
 
 double
 js::math_tan_impl(MathCache* cache, double x)
 {
-    return cache->lookup(tan, x, MathCache::Tan);
+    return cache->lookup(fdlibm::tan, x, MathCache::Tan);
 }
 
 double
 js::math_tan_uncached(double x)
 {
-    return tan(x);
+    return fdlibm::tan(x);
 }
 
 bool
 js::math_tan(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     if (args.length() == 0) {
@@ -1041,23 +1037,23 @@ static bool math_function(JSContext* cx,
     args.rval().setNumber(z);
 
     return true;
 }
 
 double
 js::math_log10_impl(MathCache* cache, double x)
 {
-    return cache->lookup(log10, x, MathCache::Log10);
+    return cache->lookup(fdlibm::log10, x, MathCache::Log10);
 }
 
 double
 js::math_log10_uncached(double x)
 {
-    return log10(x);
+    return fdlibm::log10(x);
 }
 
 bool
 js::math_log10(JSContext* cx, unsigned argc, Value* vp)
 {
     return math_function<math_log10_impl>(cx, argc, vp);
 }
 
@@ -1066,23 +1062,23 @@ double log2(double x)
 {
     return log(x) / M_LN2;
 }
 #endif
 
 double
 js::math_log2_impl(MathCache* cache, double x)
 {
-    return cache->lookup(log2, x, MathCache::Log2);
+    return cache->lookup(fdlibm::log2, x, MathCache::Log2);
 }
 
 double
 js::math_log2_uncached(double x)
 {
-    return log2(x);
+    return fdlibm::log2(x);
 }
 
 bool
 js::math_log2(JSContext* cx, unsigned argc, Value* vp)
 {
     return math_function<math_log2_impl>(cx, argc, vp);
 }
 
@@ -1109,24 +1105,24 @@ double log1p(double x)
 #else
 #define LOG1P_IF_OUT_OF_RANGE(x)
 #endif
 
 double
 js::math_log1p_impl(MathCache* cache, double x)
 {
     LOG1P_IF_OUT_OF_RANGE(x);
-    return cache->lookup(log1p, x, MathCache::Log1p);
+    return cache->lookup(fdlibm::log1p, x, MathCache::Log1p);
 }
 
 double
 js::math_log1p_uncached(double x)
 {
     LOG1P_IF_OUT_OF_RANGE(x);
-    return log1p(x);
+    return fdlibm::log1p(x);
 }
 
 #undef LOG1P_IF_OUT_OF_RANGE
 
 bool
 js::math_log1p(JSContext* cx, unsigned argc, Value* vp)
 {
     return math_function<math_log1p_impl>(cx, argc, vp);
@@ -1151,23 +1147,23 @@ double expm1(double x)
         return exp(x) - 1.0;
     }
 }
 #endif
 
 double
 js::math_expm1_impl(MathCache* cache, double x)
 {
-    return cache->lookup(expm1, x, MathCache::Expm1);
+    return cache->lookup(fdlibm::expm1, x, MathCache::Expm1);
 }
 
 double
 js::math_expm1_uncached(double x)
 {
-    return expm1(x);
+    return fdlibm::expm1(x);
 }
 
 bool
 js::math_expm1(JSContext* cx, unsigned argc, Value* vp)
 {
     return math_function<math_expm1_impl>(cx, argc, vp);
 }
 
@@ -1180,59 +1176,59 @@ double sqrt1pm1(double x)
 
     return expm1(log1p(x) / 2);
 }
 #endif
 
 double
 js::math_cosh_impl(MathCache* cache, double x)
 {
-    return cache->lookup(cosh, x, MathCache::Cosh);
+    return cache->lookup(fdlibm::cosh, x, MathCache::Cosh);
 }
 
 double
 js::math_cosh_uncached(double x)
 {
-    return cosh(x);
+    return fdlibm::cosh(x);
 }
 
 bool
 js::math_cosh(JSContext* cx, unsigned argc, Value* vp)
 {
     return math_function<math_cosh_impl>(cx, argc, vp);
 }
 
 double
 js::math_sinh_impl(MathCache* cache, double x)
 {
-    return cache->lookup(sinh, x, MathCache::Sinh);
+    return cache->lookup(fdlibm::sinh, x, MathCache::Sinh);
 }
 
 double
 js::math_sinh_uncached(double x)
 {
-    return sinh(x);
+    return fdlibm::sinh(x);
 }
 
 bool
 js::math_sinh(JSContext* cx, unsigned argc, Value* vp)
 {
     return math_function<math_sinh_impl>(cx, argc, vp);
 }
 
 double
 js::math_tanh_impl(MathCache* cache, double x)
 {
-    return cache->lookup(tanh, x, MathCache::Tanh);
+    return cache->lookup(fdlibm::tanh, x, MathCache::Tanh);
 }
 
 double
 js::math_tanh_uncached(double x)
 {
-    return tanh(x);
+    return fdlibm::tanh(x);
 }
 
 bool
 js::math_tanh(JSContext* cx, unsigned argc, Value* vp)
 {
     return math_function<math_tanh_impl>(cx, argc, vp);
 }
 
@@ -1265,23 +1261,23 @@ double acosh(double x)
         return sqrt(2 * y) * (1 - y / 12 + 3 * y * y / 160);
     }
 }
 #endif
 
 double
 js::math_acosh_impl(MathCache* cache, double x)
 {
-    return cache->lookup(acosh, x, MathCache::Acosh);
+    return cache->lookup(fdlibm::acosh, x, MathCache::Acosh);
 }
 
 double
 js::math_acosh_uncached(double x)
 {
-    return acosh(x);
+    return fdlibm::acosh(x);
 }
 
 bool
 js::math_acosh(JSContext* cx, unsigned argc, Value* vp)
 {
     return math_function<math_acosh_impl>(cx, argc, vp);
 }
 
@@ -1319,27 +1315,27 @@ static double my_asinh(double x)
     }
 }
 #endif
 
 double
 js::math_asinh_impl(MathCache* cache, double x)
 {
 #ifdef HAVE_ASINH
-    return cache->lookup(asinh, x, MathCache::Asinh);
+    return cache->lookup(fdlibm::asinh, x, MathCache::Asinh);
 #else
     return cache->lookup(my_asinh, x, MathCache::Asinh);
 #endif
 }
 
 double
 js::math_asinh_uncached(double x)
 {
 #ifdef HAVE_ASINH
-    return asinh(x);
+    return fdlibm::asinh(x);
 #else
     return my_asinh(x);
 #endif
 }
 
 bool
 js::math_asinh(JSContext* cx, unsigned argc, Value* vp)
 {
@@ -1372,23 +1368,23 @@ double atanh(double x)
         return result;
     }
 }
 #endif
 
 double
 js::math_atanh_impl(MathCache* cache, double x)
 {
-    return cache->lookup(atanh, x, MathCache::Atanh);
+    return cache->lookup(fdlibm::atanh, x, MathCache::Atanh);
 }
 
 double
 js::math_atanh_uncached(double x)
 {
-    return atanh(x);
+    return fdlibm::atanh(x);
 }
 
 bool
 js::math_atanh(JSContext* cx, unsigned argc, Value* vp)
 {
     return math_function<math_atanh_impl>(cx, argc, vp);
 }
 
@@ -1400,17 +1396,17 @@ js::ecmaHypot(double x, double y)
     /*
      * Workaround MS hypot bug, where hypot(Infinity, NaN or Math.MIN_VALUE)
      * is NaN, not Infinity.
      */
     if (mozilla::IsInfinite(x) || mozilla::IsInfinite(y)) {
         return mozilla::PositiveInfinity<double>();
     }
 #endif
-    return hypot(x, y);
+    return fdlibm::hypot(x, y);
 }
 
 static inline
 void
 hypot_step(double& scale, double& sumsq, double x)
 {
     double xabs = mozilla::Abs(x);
     if (scale < xabs) {
@@ -1438,17 +1434,17 @@ js::hypot4(double x, double y, double z,
     double scale = 0;
     double sumsq = 1;
 
     hypot_step(scale, sumsq, x);
     hypot_step(scale, sumsq, y);
     hypot_step(scale, sumsq, z);
     hypot_step(scale, sumsq, w);
 
-    return scale * sqrt(sumsq);
+    return scale * fdlibm::sqrt(sumsq);
 }
 
 double
 js::hypot3(double x, double y, double z)
 {
     return hypot4(x, y, z, 0.0);
 }
 
@@ -1492,31 +1488,31 @@ js::math_hypot_handle(JSContext* cx, Han
         if (isInfinite || isNaN)
             continue;
 
         hypot_step(scale, sumsq, x);
     }
 
     double result = isInfinite ? PositiveInfinity<double>() :
                     isNaN ? GenericNaN() :
-                    scale * sqrt(sumsq);
+                    scale * fdlibm::sqrt(sumsq);
     res.setNumber(result);
     return true;
 }
 
 double
 js::math_trunc_impl(MathCache* cache, double x)
 {
-    return cache->lookup(trunc, x, MathCache::Trunc);
+    return cache->lookup(fdlibm::trunc, x, MathCache::Trunc);
 }
 
 double
 js::math_trunc_uncached(double x)
 {
-    return trunc(x);
+    return fdlibm::trunc(x);
 }
 
 bool
 js::math_trunc(JSContext* cx, unsigned argc, Value* vp)
 {
     return math_function<math_trunc_impl>(cx, argc, vp);
 }
 
@@ -1557,23 +1553,23 @@ double cbrt(double x)
         return -pow(-x, 1.0 / 3.0);
     }
 }
 #endif
 
 double
 js::math_cbrt_impl(MathCache* cache, double x)
 {
-    return cache->lookup(cbrt, x, MathCache::Cbrt);
+    return cache->lookup(fdlibm::cbrt, x, MathCache::Cbrt);
 }
 
 double
 js::math_cbrt_uncached(double x)
 {
-    return cbrt(x);
+    return fdlibm::cbrt(x);
 }
 
 bool
 js::math_cbrt(JSContext* cx, unsigned argc, Value* vp)
 {
     return math_function<math_cbrt_impl>(cx, argc, vp);
 }