From e7a32806c9e0254a1dca7ef7306c3f265ca6e9fb Mon Sep 17 00:00:00 2001 From: "reed@reedloden.com" Date: Fri, 25 Jan 2008 00:02:04 -0800 Subject: [PATCH] Bug 289394 - "Double.cpp causes unaligned accesses" [p=davidm@hpl.hp.com (David Mosberger) / eric@debian.org (Eric Dorland) / mh+mozilla@glandium.org (Mike Hommey) r+sr=sicking sr=bryner a1.9=beltzner] --- content/xslt/public/txDouble.h | 21 ++++++++++----------- content/xslt/src/base/txDouble.cpp | 16 ++++++++-------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/content/xslt/public/txDouble.h b/content/xslt/public/txDouble.h index 90647714565..422eeff2090 100644 --- a/content/xslt/public/txDouble.h +++ b/content/xslt/public/txDouble.h @@ -68,14 +68,7 @@ static fp_except_t oldmask = fpsetmask(~allmask); #endif #endif -#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. - */ - typedef union txdpun { - PRFloat64 d; struct { #if defined(IS_LITTLE_ENDIAN) && !defined(FPU_IS_ARM_FPA) PRUint32 lo, hi; @@ -83,8 +76,14 @@ typedef union txdpun { PRUint32 hi, lo; #endif } s; + PRFloat64 d; } txdpun; +#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. + */ #define TX_DOUBLE_HI32(x) (__extension__ ({ txdpun u; u.d = (x); u.s.hi; })) #define TX_DOUBLE_LO32(x) (__extension__ ({ txdpun u; u.d = (x); u.s.lo; })) @@ -113,11 +112,11 @@ typedef union txdpun { (TX_DOUBLE_LO32(x) || (TX_DOUBLE_HI32(x) & TX_DOUBLE_HI32_MANTMASK))) #ifdef IS_BIG_ENDIAN -#define TX_DOUBLE_NaN {TX_DOUBLE_HI32_EXPMASK | TX_DOUBLE_HI32_MANTMASK, \ - 0xffffffff} +#define TX_DOUBLE_NaN {{TX_DOUBLE_HI32_EXPMASK | TX_DOUBLE_HI32_MANTMASK, \ + 0xffffffff}} #else -#define TX_DOUBLE_NaN {0xffffffff, \ - TX_DOUBLE_HI32_EXPMASK | TX_DOUBLE_HI32_MANTMASK} +#define TX_DOUBLE_NaN {{0xffffffff, \ + TX_DOUBLE_HI32_EXPMASK | TX_DOUBLE_HI32_MANTMASK}} #endif #if defined(XP_WIN) diff --git a/content/xslt/src/base/txDouble.cpp b/content/xslt/src/base/txDouble.cpp index c1a7d2f33b3..06a3b59690d 100644 --- a/content/xslt/src/base/txDouble.cpp +++ b/content/xslt/src/base/txDouble.cpp @@ -50,18 +50,18 @@ */ //-- Initialize Double related constants -const PRUint32 nanMask[2] = TX_DOUBLE_NaN; +const txdpun nanMask = TX_DOUBLE_NaN; #ifdef IS_BIG_ENDIAN -const PRUint32 infMask[2] = {TX_DOUBLE_HI32_EXPMASK, 0}; -const PRUint32 negInfMask[2] = {TX_DOUBLE_HI32_EXPMASK | TX_DOUBLE_HI32_SIGNBIT, 0}; +const txdpun infMask = {{TX_DOUBLE_HI32_EXPMASK, 0}}; +const txdpun negInfMask = {{TX_DOUBLE_HI32_EXPMASK | TX_DOUBLE_HI32_SIGNBIT, 0}}; #else -const PRUint32 infMask[2] = {0, TX_DOUBLE_HI32_EXPMASK}; -const PRUint32 negInfMask[2] = {0, TX_DOUBLE_HI32_EXPMASK | TX_DOUBLE_HI32_SIGNBIT}; +const txdpun infMask = {{0, TX_DOUBLE_HI32_EXPMASK}}; +const txdpun negInfMask = {{0, TX_DOUBLE_HI32_EXPMASK | TX_DOUBLE_HI32_SIGNBIT}}; #endif -const double Double::NaN = *((double*)nanMask); -const double Double::POSITIVE_INFINITY = *((double*)infMask); -const double Double::NEGATIVE_INFINITY = *((double*)negInfMask); +const double Double::NaN = nanMask.d; +const double Double::POSITIVE_INFINITY = infMask.d; +const double Double::NEGATIVE_INFINITY = negInfMask.d; /* * Determines whether the given double represents positive or negative