fix our aliasing idiocy by extending jsdpun, add Math.sqrt, add strict-aliasing to our Makefile.ref flags
authorshaver@mozilla.org
Mon, 14 Jul 2008 18:22:05 -0400
changeset 17656 be90e8cf66b74f998ecf02015b13015f1587555b
parent 17655 f335c583a41633a2bd16d5f2f5af80ce329aff1e
child 17657 14f0ea38fac42068e461932ef0c704b5e83bfb83
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9.1a1pre
fix our aliasing idiocy by extending jsdpun, add Math.sqrt, add strict-aliasing to our Makefile.ref flags
js/src/builtins.tbl
js/src/config.mk
js/src/jsbuiltins.cpp
js/src/jsmath.cpp
js/src/jsnum.h
js/src/jstracer.cpp
--- a/js/src/builtins.tbl
+++ b/js/src/builtins.tbl
@@ -38,11 +38,12 @@
 
 BUILTIN2(BoxDouble,             LO, F,  LO,     jsval,     JSContext*, jsdouble,               1, 1)
 BUILTIN2(BoxInt32,              LO, LO, LO,     jsval,     JSContext*, jsint,                  1, 1)
 BUILTIN1(UnboxDouble,           LO,     F,      jsdouble,  jsval,                              1, 1)
 BUILTIN1(UnboxInt32,            LO,     LO,     int32,     jsval,                              1, 1)
 BUILTIN2(dmod,                  F,  F,  F,      jsdouble,  jsdouble, jsdouble,                 1, 1)
 BUILTIN1(doubleToInt32,         F,      LO,     int32,     jsdouble,                           1, 1)
 BUILTIN1(doubleToUint32,        F,      LO,     int32,     jsdouble,                           1, 1)
-BUILTIN1(Math_sin,          F,      F,      jsdouble,  jsdouble,                           1, 1)
-BUILTIN1(Math_cos,          F,      F,      jsdouble,  jsdouble,                           1, 1)
-BUILTIN2(Math_pow,          F,  F,  F,      jsdouble,  jsdouble, jsdouble,                 1, 1)
+BUILTIN1(Math_sin,              F,      F,      jsdouble,  jsdouble,                           1, 1)
+BUILTIN1(Math_cos,              F,      F,      jsdouble,  jsdouble,                           1, 1)
+BUILTIN2(Math_pow,              F,  F,  F,      jsdouble,  jsdouble, jsdouble,                 1, 1)
+BUILTIN1(Math_sqrt,             F,      F,      jsdouble,  jsdouble,                           1, 1)
--- a/js/src/config.mk
+++ b/js/src/config.mk
@@ -122,30 +122,30 @@ endif
 
 ifdef BUILD_OPT
 ifdef USE_MSVC
 OPTIMIZER  = -O2 -GL
 INTERP_OPTIMIZER = -O2 -GL
 BUILTINS_OPTIMIZER = -O2 -GL
 LDFLAGS    += -LTCG
 else
-OPTIMIZER  = -Os -fno-exceptions -fno-rtti
+OPTIMIZER  = -Os -fno-exceptions -fno-rtti -fstrict-aliasing -Wall -Wstrict-aliasing=2
 BUILTINS_OPTIMIZER = -O9 -fstrict-aliasing
 INTERP_OPTIMIZER = -O3 -fstrict-aliasing -fno-exceptions -fno-rtti
 endif
 DEFINES    += -UDEBUG -DNDEBUG -UDEBUG_$(USER)
 OBJDIR_TAG = _OPT
 else
 ifdef USE_MSVC
 OPTIMIZER  = -Zi
 INTERP_OPTIMIZER = -Zi
 BUILTINS_OPTIMIZER = $(INTERP_OPTIMIZER)
 else
-OPTIMIZER  = -g3 -fno-exceptions -fno-rtti
-INTERP_OPTIMIZER = -g3 -fno-exceptions -fno-rtti
+OPTIMIZER  = -g3 -fno-exceptions -fno-rtti -Wall -fstrict-aliasing -Wstrict-aliasing=2
+INTERP_OPTIMIZER = -g3 -fno-exceptions -fno-rtti -Wall -fstrict-aliasing
 BUILTINS_OPTIMIZER = $(INTERP_OPTIMIZER)
 endif
 DEFINES    += -DDEBUG -DDEBUG_$(USER)
 OBJDIR_TAG = _DBG
 endif
 
 SO_SUFFIX = so
 
--- a/js/src/jsbuiltins.cpp
+++ b/js/src/jsbuiltins.cpp
@@ -142,16 +142,21 @@ jsdouble FASTCALL builtin_Math_pow(jsdou
     if (!JSDOUBLE_IS_FINITE(p) && (d == 1.0 || d == -1.0))
         return NaN;
 #endif
     if (p == 0)
         return 1.0;
     return pow(d, p);
 }
 
+jsdouble FASTCALL builtin_Math_sqrt(jsdouble d)
+{
+    return sqrt(d);
+}
+
 #define LO ARGSIZE_LO
 #define F  ARGSIZE_F
 #define Q  ARGSIZE_Q
 
 #ifdef DEBUG
 #define NAME(op) ,#op
 #else
 #define NAME(op)
--- a/js/src/jsmath.cpp
+++ b/js/src/jsmath.cpp
@@ -486,18 +486,18 @@ js_math_sin(JSContext *cx, uintN argc, j
 
     x = js_ValueToNumber(cx, &vp[2]);
     if (JSVAL_IS_NULL(vp[2]))
         return JS_FALSE;
     z = fd_sin(x);
     return js_NewNumberInRootedValue(cx, z, vp);
 }
 
-static JSBool
-math_sqrt(JSContext *cx, uintN argc, jsval *vp)
+JSBool
+js_math_sqrt(JSContext *cx, uintN argc, jsval *vp)
 {
     jsdouble x, z;
 
     x = js_ValueToNumber(cx, &vp[2]);
     if (JSVAL_IS_NULL(vp[2]))
         return JS_FALSE;
     z = fd_sqrt(x);
     return js_NewNumberInRootedValue(cx, z, vp);
@@ -539,17 +539,17 @@ static JSFunctionSpec math_static_method
     JS_FN("floor",          math_floor,         1, 1, 0),
     JS_FN("log",            math_log,           1, 1, 0),
     JS_FN("max",            math_max,           0, 2, 0),
     JS_FN("min",            math_min,           0, 2, 0),
     JS_FN("pow",            js_math_pow,        2, 2, 0),
     JS_FN("random",         math_random,        0, 0, 0),
     JS_FN("round",          math_round,         1, 1, 0),
     JS_FN("sin",            js_math_sin,        1, 1, 0),
-    JS_FN("sqrt",           math_sqrt,          1, 1, 0),
+    JS_FN("sqrt",           js_math_sqrt,       1, 1, 0),
     JS_FN("tan",            math_tan,           1, 1, 0),
     JS_FS_END
 };
 
 JSObject *
 js_InitMathClass(JSContext *cx, JSObject *obj)
 {
     JSObject *Math;
--- a/js/src/jsnum.h
+++ b/js/src/jsnum.h
@@ -64,16 +64,17 @@ JS_BEGIN_EXTERN_C
 typedef union jsdpun {
     struct {
 #if defined(IS_LITTLE_ENDIAN) && !defined(FPU_IS_ARM_FPA)
         uint32 lo, hi;
 #else
         uint32 hi, lo;
 #endif
     } s;
+    JSUint64 u64;
     jsdouble d;
 } jsdpun;
 
 #if (__GNUC__ == 2 && __GNUC_MINOR__ > 95) || __GNUC__ > 2
 /*
  * This version of the macros is safe for the alias optimizations that gcc
  * does, but uses gcc-specific extensions.
  */
--- a/js/src/jstracer.cpp
+++ b/js/src/jstracer.cpp
@@ -1281,18 +1281,19 @@ bool TraceRecorder::ifop()
 }
 
 bool
 TraceRecorder::inc(jsval& v, jsint incr, bool pre)
 {
     if (isNumber(v)) {
         LIns* before = get(&v);
         LIns* after;
-        jsdouble d = (jsdouble)incr;
-        after = lir->ins2(LIR_fadd, before, lir->insImmq(*(uint64_t*)&d));
+        jsdpun u;
+        u.d = (jsdouble)incr;
+        after = lir->ins2(LIR_fadd, before, lir->insImmq(u.u64));
         set(&v, after);
 
         const JSCodeSpec& cs = js_CodeSpec[*cx->fp->regs->pc];
         JS_ASSERT(cs.ndefs == 1);
         stack(cs.nuses, pre ? after : before);
         return true;
     }
     return false;
@@ -1921,16 +1922,19 @@ JSBool
 js_math_sin(JSContext *cx, uintN argc, jsval *vp);
 
 JSBool
 js_math_cos(JSContext *cx, uintN argc, jsval *vp);
 
 JSBool
 js_math_pow(JSContext *cx, uintN argc, jsval *vp);
 
+JSBool
+js_math_sqrt(JSContext *cx, uintN argc, jsval *vp);
+
 bool TraceRecorder::record_JSOP_CALL()
 {
     uintN argc = GET_ARGC(cx->fp->regs->pc);
     jsval& fval = stackval(-(argc + 2));
 
     if (!VALUE_IS_FUNCTION(cx, fval))
         ABORT_TRACE("CALL on non-function");
 
@@ -1942,19 +1946,20 @@ bool TraceRecorder::record_JSOP_CALL()
         ABORT_TRACE("slow native");
 
     struct JSTraceableNative {
         JSFastNative native;
         int          builtin;
         intN         argc;
         const char  *argtypes;
     } knownNatives[] = {
-        { js_math_sin, F_Math_sin, 1, "d" },
-        { js_math_cos, F_Math_cos, 1, "d" },
-        { js_math_pow, F_Math_pow, 2, "dd" },
+        { js_math_sin,  F_Math_sin,  1, "d" },
+        { js_math_cos,  F_Math_cos,  1, "d" },
+        { js_math_pow,  F_Math_pow,  2, "dd" },
+        { js_math_sqrt, F_Math_sqrt, 1, "d" }
     };
 
     for (uintN i = 0; i < JS_ARRAY_LENGTH(knownNatives); i++) {
         JSTraceableNative* known = &knownNatives[i];
         if ((JSFastNative)fun->u.n.native != known->native)
             continue;
         
         LIns* args[5];
@@ -2001,33 +2006,37 @@ bool TraceRecorder::record_JSOP_NAME()
 
     stack(0, get(&STOBJ_GET_SLOT(obj, slot)));
     return true;
 }
 
 bool TraceRecorder::record_JSOP_DOUBLE()
 {
     jsval v = jsval(atoms[GET_INDEX(cx->fp->regs->pc)]);
-    stack(0, lir->insImmq(*(uint64_t*)JSVAL_TO_DOUBLE(v)));
+    jsdpun u;
+    u.d = *JSVAL_TO_DOUBLE(v);
+    stack(0, lir->insImmq(u.u64));
     return true;
 }
 bool TraceRecorder::record_JSOP_STRING()
 {
     return false;
 }
 bool TraceRecorder::record_JSOP_ZERO()
 {
-    jsdouble d = (jsdouble)0;
-    stack(0, lir->insImmq(*(uint64_t*)&d));
+    jsdpun u;
+    u.d = 0.0;
+    stack(0, lir->insImmq(u.u64));
     return true;
 }
 bool TraceRecorder::record_JSOP_ONE()
 {
-    jsdouble d = (jsdouble)1;
-    stack(0, lir->insImmq(*(uint64_t*)&d));
+    jsdpun u;
+    u.d = 1.0;
+    stack(0, lir->insImmq(u.u64));
     return true;
 }
 bool TraceRecorder::record_JSOP_NULL()
 {
     stack(0, lir->insImmPtr(NULL));
     return true;
 }
 bool TraceRecorder::record_JSOP_THIS()
@@ -2125,18 +2134,19 @@ bool TraceRecorder::record_JSOP_GETVAR()
 }
 bool TraceRecorder::record_JSOP_SETVAR()
 {
     var(GET_VARNO(cx->fp->regs->pc), stack(-1));
     return true;
 }
 bool TraceRecorder::record_JSOP_UINT16()
 {
-    jsdouble d = (jsdouble)GET_UINT16(cx->fp->regs->pc);
-    stack(0, lir->insImmq(*(uint64_t*)&d));
+    jsdpun u;
+    u.d = (jsdouble)GET_UINT16(cx->fp->regs->pc);
+    stack(0, lir->insImmq(u.u64));
     return true;
 }
 bool TraceRecorder::record_JSOP_NEWINIT()
 {
     return false;
 }
 bool TraceRecorder::record_JSOP_ENDINIT()
 {
@@ -2622,18 +2632,19 @@ bool TraceRecorder::record_JSOP_UNUSED18
     return false;
 }
 bool TraceRecorder::record_JSOP_DELDESC()
 {
     return false;
 }
 bool TraceRecorder::record_JSOP_UINT24()
 {
-    jsdouble d = (jsdouble) GET_UINT24(cx->fp->regs->pc);
-    stack(0, lir->insImmq(*(uint64_t*)&d));
+    jsdpun u;
+    u.d = (jsdouble)GET_UINT24(cx->fp->regs->pc);
+    stack(0, lir->insImmq(u.u64));
     return true;
 }
 bool TraceRecorder::record_JSOP_INDEXBASE()
 {
     atoms += GET_INDEXBASE(cx->fp->regs->pc);
     return true;
 }
 
@@ -2824,25 +2835,27 @@ bool TraceRecorder::record_JSOP_CALLARG(
 
 bool TraceRecorder::record_JSOP_CALLLOCAL()
 {
     return false;
 }
 
 bool TraceRecorder::record_JSOP_INT8()
 {
-    jsdouble d = (jsdouble)GET_INT8(cx->fp->regs->pc);
-    stack(0, lir->insImmq(*(uint64_t*)&d));
+    jsdpun u;
+    u.d = (jsdouble)GET_INT8(cx->fp->regs->pc);
+    stack(0, lir->insImmq(u.u64));
     return true;
 }
 
 bool TraceRecorder::record_JSOP_INT32()
 {
-    jsdouble d = (jsdouble)GET_INT32(cx->fp->regs->pc);
-    stack(0, lir->insImmq(*(uint64_t*)&d));
+    jsdpun u;
+    u.d = (jsdouble)GET_INT32(cx->fp->regs->pc);
+    stack(0, lir->insImmq(u.u64));
     return true;
 }
 
 bool TraceRecorder::record_JSOP_LENGTH()
 {
     return false;
 }