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 315577 f1f3e847cdb3e0a565dde92e448ce27e6f12f89e
parent 315576 a4163f930b2193f2a329a95ce9eaa7d39c8b90ea
child 315578 b053ad6763d638384a7ae0f4d5c1238277afcea5
push id9480
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 17:12:58 +0000
treeherdermozilla-aurora@0d6a91c76a9e [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;
@@ -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;
@@ -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) {
@@ -872,28 +874,28 @@ js::math_round(JSContext* cx, unsigned a
     }
 
     return math_round_handle(cx, args[0], args.rval());
 }
 
 double
 js::math_sin_impl(MathCache* cache, 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 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);
 }
 
 bool
 js::math_sin_handle(JSContext* cx, HandleValue val, MutableHandleValue res)
 {
     double in;
     if (!ToNumber(cx, val, &in))
@@ -1041,23 +1043,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 +1068,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 +1111,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 +1153,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 +1182,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 +1267,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 +1321,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 +1374,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 +1402,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) {
@@ -1500,23 +1502,23 @@ js::math_hypot_handle(JSContext* cx, Han
                     scale * 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 +1559,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);
 }