Bug 496816 - Force x87 FPU to 64-bit mode on any x86-gcc platform, r=brendan.
authorGraydon Hoare <graydon@mozilla.com>
Thu, 27 Aug 2009 11:34:13 -0700
changeset 32599 8ad65f099bb5b427dad06f6dc6092a36f89b9f86
parent 32598 781eb6d940de89034efc51cad7207793e1a1fb20
child 32600 1e581a31c01713851d9cd148b29eadda6ea05fe6
push idunknown
push userunknown
push dateunknown
reviewersbrendan
bugs496816
milestone1.9.3a1pre
Bug 496816 - Force x87 FPU to 64-bit mode on any x86-gcc platform, r=brendan.
js/src/jsnum.cpp
--- a/js/src/jsnum.cpp
+++ b/js/src/jsnum.cpp
@@ -640,28 +640,30 @@ static JSConstDoubleSpec number_constant
     {0,                         "NEGATIVE_INFINITY", 0,{0,0,0}},
     {1.7976931348623157E+308,   "MAX_VALUE",         0,{0,0,0}},
     {0,                         "MIN_VALUE",         0,{0,0,0}},
     {0,0,0,{0,0,0}}
 };
 
 jsdouble js_NaN;
 
-#if (defined XP_WIN || defined XP_OS2) &&                                     \
-    !defined WINCE &&                                                         \
-    !defined __MWERKS__ &&                                                    \
-    (defined _M_IX86 ||                                                       \
-     (defined __GNUC__ && !defined __MINGW32__))
+
+#if (defined __GNUC__ && defined __i486__)
 
 /*
  * Set the exception mask to mask all exceptions and set the FPU precision
- * to 53 bit mantissa.
- * On Alpha platform this is handled via Compiler option.
+ * to 53 bit mantissa (64 bit doubles).
  */
-#define FIX_FPU() _control87(_MCW_EM | _PC_53, _MCW_EM | _MCW_PC)
+inline void FIX_FPU() {
+    short control;
+    asm("fstcw %0" : "=m" (control) : );
+    control &= ~0x300; // Lower bits 8 and 9 (precision control).
+    control |= 0x2f3;  // Raise bits 0-5 (exception masks) and 9 (64-bit precision).
+    asm("fldcw %0" : : "m" (control) );
+}
 
 #else
 
 #define FIX_FPU() ((void)0)
 
 #endif
 
 JSBool