Bug 798853 - Some minor changes to mfbt/FloatingPoint.h to adapt it to esr10. r=waldo a=akeybl
authorMats Palmgren <matspal@gmail.com>
Fri, 02 Nov 2012 00:15:15 +0100
changeset 82066 3c7c48e34e747f5eab365a2a2917c004044468d1
parent 82065 278743c3c2fd626a86509c4e5760901ccafca388
child 82067 677added3cc5c95643f5948b90f5439cb6a30123
push id322
push usermpalmgren@mozilla.com
push dateThu, 01 Nov 2012 23:15:27 +0000
reviewerswaldo, akeybl
bugs798853
milestone10.0.11esrpre
Bug 798853 - Some minor changes to mfbt/FloatingPoint.h to adapt it to esr10. r=waldo a=akeybl
mfbt/FloatingPoint.h
--- a/mfbt/FloatingPoint.h
+++ b/mfbt/FloatingPoint.h
@@ -3,19 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Various predicates and operations on IEEE-754 floating point types. */
 
 #ifndef mozilla_FloatingPoint_h_
 #define mozilla_FloatingPoint_h_
 
-#include "mozilla/Assertions.h"
-#include "mozilla/Attributes.h"
-#include "mozilla/StandardInteger.h"
+#include "mozilla/Util.h"
 
 /*
  * It's reasonable to ask why we have this header at all.  Don't isnan,
  * copysign, the built-in comparison operators, and the like solve these
  * problems?  Unfortunately, they don't.  We've found that various compilers
  * (MSVC, MSVC when compiling with PGO, and GCC on OS X, at least) miscompile
  * the standard methods in various situations, so we can't use them.  Some of
  * these compilers even have problems compiling seemingly reasonable bitwise
@@ -32,56 +30,60 @@
  */
 
 /*
  * These implementations all assume |double| is a 64-bit double format number
  * type, compatible with the IEEE-754 standard.  C/C++ don't require this to be
  * the case.  But we required this in implementations of these algorithms that
  * preceded this header, so we shouldn't break anything if we continue doing so.
  */
-MOZ_STATIC_ASSERT(sizeof(double) == sizeof(uint64_t), "double must be 64 bits");
+#if 0
+MOZ_STATIC_ASSERT(sizeof(double) == sizeof(uint64), "double must be 64 bits");
+#endif
 
 /*
  * Constant expressions in C can't refer to consts, unfortunately, so #define
- * these rather than use |const uint64_t|.
+ * these rather than use |const uint64|.
  */
 #define MOZ_DOUBLE_SIGN_BIT          0x8000000000000000ULL
 #define MOZ_DOUBLE_EXPONENT_BITS     0x7ff0000000000000ULL
 #define MOZ_DOUBLE_SIGNIFICAND_BITS  0x000fffffffffffffULL
 
 #define MOZ_DOUBLE_EXPONENT_BIAS   1023
 #define MOZ_DOUBLE_EXPONENT_SHIFT  52
 
+#if 0
 MOZ_STATIC_ASSERT((MOZ_DOUBLE_SIGN_BIT & MOZ_DOUBLE_EXPONENT_BITS) == 0,
                   "sign bit doesn't overlap exponent bits");
 MOZ_STATIC_ASSERT((MOZ_DOUBLE_SIGN_BIT & MOZ_DOUBLE_SIGNIFICAND_BITS) == 0,
                   "sign bit doesn't overlap significand bits");
 MOZ_STATIC_ASSERT((MOZ_DOUBLE_EXPONENT_BITS & MOZ_DOUBLE_SIGNIFICAND_BITS) == 0,
                   "exponent bits don't overlap significand bits");
 
 MOZ_STATIC_ASSERT((MOZ_DOUBLE_SIGN_BIT | MOZ_DOUBLE_EXPONENT_BITS | MOZ_DOUBLE_SIGNIFICAND_BITS)
-                  == ~(uint64_t)0,
+                  == ~(uint64)0,
                   "all bits accounted for");
+#endif
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /*
  * This union is NOT a public data structure, and it is not to be used outside
  * this file!
  */
 union MozDoublePun {
     /*
      * Every way to pun the bits of a double introduces an additional layer of
      * complexity, across a multitude of platforms, architectures, and ABIs.
-     * Use *only* uint64_t to reduce complexity.  Don't add new punning here
+     * Use *only* uint64 to reduce complexity.  Don't add new punning here
      * without discussion!
      */
-    uint64_t u;
+    uint64 u;
     double d;
 };
 
 /** Determines whether a double is NaN. */
 static MOZ_ALWAYS_INLINE int
 MOZ_DOUBLE_IS_NaN(double d)
 {
   union MozDoublePun pun;
@@ -125,17 +127,17 @@ MOZ_DOUBLE_IS_FINITE(double d)
  * on a double which is NaN.
  */
 static MOZ_ALWAYS_INLINE int
 MOZ_DOUBLE_IS_NEGATIVE(double d)
 {
   union MozDoublePun pun;
   pun.d = d;
 
-  MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(d), "NaN does not have a sign");
+  MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(d));
 
   /* The sign bit is set if the double is negative. */
   return (pun.u & MOZ_DOUBLE_SIGN_BIT) != 0;
 }
 
 /** Determines whether a double represents -0. */
 static MOZ_ALWAYS_INLINE int
 MOZ_DOUBLE_IS_NEGATIVE_ZERO(double d)
@@ -143,27 +145,27 @@ MOZ_DOUBLE_IS_NEGATIVE_ZERO(double d)
   union MozDoublePun pun;
   pun.d = d;
 
   /* Only the sign bit is set if the double is -0. */
   return pun.u == MOZ_DOUBLE_SIGN_BIT;
 }
 
 /** Returns the exponent portion of the double. */
-static MOZ_ALWAYS_INLINE int_fast16_t
+static MOZ_ALWAYS_INLINE int
 MOZ_DOUBLE_EXPONENT(double d)
 {
   union MozDoublePun pun;
   pun.d = d;
 
   /*
    * The exponent component of a double is an unsigned number, biased from its
    * actual value.  Subtract the bias to retrieve the actual exponent.
    */
-  return (int_fast16_t)((pun.u & MOZ_DOUBLE_EXPONENT_BITS) >> MOZ_DOUBLE_EXPONENT_SHIFT) -
+  return (int)((pun.u & MOZ_DOUBLE_EXPONENT_BITS) >> MOZ_DOUBLE_EXPONENT_SHIFT) -
                         MOZ_DOUBLE_EXPONENT_BIAS;
 }
 
 /** Returns +Infinity. */
 static MOZ_ALWAYS_INLINE double
 MOZ_DOUBLE_POSITIVE_INFINITY()
 {
   union MozDoublePun pun;
@@ -187,17 +189,17 @@ MOZ_DOUBLE_NEGATIVE_INFINITY()
    * significand.
    */
   pun.u = MOZ_DOUBLE_SIGN_BIT | MOZ_DOUBLE_EXPONENT_BITS;
   return pun.d;
 }
 
 /** Constructs a NaN value with the specified sign bit and significand bits. */
 static MOZ_ALWAYS_INLINE double
-MOZ_DOUBLE_SPECIFIC_NaN(int signbit, uint64_t significand)
+MOZ_DOUBLE_SPECIFIC_NaN(int signbit, uint64 significand)
 {
   union MozDoublePun pun;
 
   MOZ_ASSERT(signbit == 0 || signbit == 1);
   MOZ_ASSERT((significand & ~MOZ_DOUBLE_SIGNIFICAND_BITS) == 0);
   MOZ_ASSERT(significand & MOZ_DOUBLE_SIGNIFICAND_BITS);
 
   pun.u = (signbit ? MOZ_DOUBLE_SIGN_BIT : 0) |
@@ -222,23 +224,23 @@ static MOZ_ALWAYS_INLINE double
 MOZ_DOUBLE_MIN_VALUE()
 {
   union MozDoublePun pun;
   pun.u = 1;
   return pun.d;
 }
 
 static MOZ_ALWAYS_INLINE int
-MOZ_DOUBLE_IS_INT32(double d, int32_t* i)
+MOZ_DOUBLE_IS_INT32(double d, int32* i)
 {
   /*
-   * XXX Casting a double that doesn't truncate to int32_t, to int32_t, induces
+   * XXX Casting a double that doesn't truncate to int32, to int32, induces
    *     undefined behavior.  We should definitely fix this (bug 744965), but as
    *     apparently it "works" in practice, it's not a pressing concern now.
    */
-  return !MOZ_DOUBLE_IS_NEGATIVE_ZERO(d) && d == (*i = (int32_t)d);
+  return !MOZ_DOUBLE_IS_NEGATIVE_ZERO(d) && d == (*i = (int32)d);
 }
 
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
 
 #endif  /* mozilla_FloatingPoint_h_ */