Fix bug 583 properly, this time.
authorMike Smith <msmith@xiph.org>
Mon, 5 Sep 2005 11:04:48 +0000 (11:04 +0000)
committerMike Smith <msmith@xiph.org>
Mon, 5 Sep 2005 11:04:48 +0000 (11:04 +0000)
Use magic-union tricks to prevent breaking C aliasing rules.
This means we can remove the turning-off-optimisations hack we temporarily put
in for gcc4.
Thanks to Richard Guenther for the tips.

svn path=/trunk/vorbis/; revision=9959

configure.in
lib/scales.h

index 8855029..cdd7511 100644 (file)
@@ -169,14 +169,6 @@ else
                CFLAGS="-O20 -D__NO_MATH_INLINES -fsigned-char"
                PROFILE="-O20 -g -pg -D__NO_MATH_INLINES -fsigned-char" ;;
         esac
-
-       case "$GCC_VERSION" in
-       4.*)
-               # work around a problem with the gcc4 optimizer
-               PROFILE="$DEBUG -fno-inline-functions"
-               CFLAGS="$CFLAGS -fno-inline-functions"
-               PROFILE="$PROFILE -fno-inline-functions" ;;
-       esac
 fi
 CFLAGS="$CFLAGS $cflags_save"
 LDFLAGS="$LDFLAGS $ldflags_save"
index 4bfa82d..c74b847 100644 (file)
 #ifdef VORBIS_IEEE_FLOAT32
 
 static float unitnorm(float x){
-  ogg_uint32_t *ix=(ogg_uint32_t *)&x;
-  *ix=(*ix&0x80000000UL)|(0x3f800000UL);
-  return(x);
-}
-
-static float FABS(float *x){
-  ogg_uint32_t *ix=(ogg_uint32_t *)x;
-  *ix&=0x7fffffffUL;
-  return(*x);
+  union {
+    ogg_uint32_t i;
+    float f;
+  } ix;
+  ix.f = x;
+  ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
+  return ix.f;
 }
 
 /* Segher was off (too high) by ~ .3 decibel.  Center the conversion correctly. */
 static float todB(const float *x){
-  return (float)((*(ogg_int32_t *)x)&0x7fffffff) * 7.17711438e-7f -764.6161886f;
+  union {
+    ogg_uint32_t i;
+    float f;
+  } ix;
+  ix.f = *x;
+  ix.i = ix.i&0x7fffffff;
+  return (float)(ix.i * 7.17711438e-7f -764.6161886f);
 }
 
 #define todB_nn(x) todB(x)
@@ -51,8 +55,6 @@ static float unitnorm(float x){
   return(1.f);
 }
 
-#define FABS(x) fabs(*(x))
-
 #define todB(x)   (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
 #define todB_nn(x)   (*(x)==0.f?-400.f:log(*(x))*8.6858896f)