From b8b0d01c91b794dc41cf9a0b06b7357b30678d10 Mon Sep 17 00:00:00 2001 From: Tomas Frydrych Date: Fri, 19 Jan 2007 20:00:41 +0000 Subject: [PATCH] work around punned-pointer problem --- ChangeLog | 7 +++++++ clutter/clutter-fixed.c | 27 +++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index ff735655c..6a3c89746 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-01-19 Tomas Frydrych + + * clutter/clutter-fixed.c: (clutter_sqrti): + Use union instead of casting int <-> float to get rid of + punned-pointer warning and avoid gcc optimatisation breaking + the function on arm. + 2007-01-19 Emmanuele Bassi Allow the ClutterGroup subclasses to override the add and diff --git a/clutter/clutter-fixed.c b/clutter/clutter-fixed.c index 92d37d7ae..c0ac9075f 100644 --- a/clutter/clutter-fixed.c +++ b/clutter/clutter-fixed.c @@ -470,17 +470,21 @@ clutter_sqrti (gint number) * elsewhere in clutter is not good enough, and 10.22 is used instead. */ ClutterFixed x; - unsigned long y, y1; /* 10.22 fixed point */ + unsigned long y1; /* 10.22 fixed point */ unsigned long f = 0x600000; /* '1.5' as 10.22 fixed */ - float flt = number; - float flt2; + + union + { + float f; + unsigned long i; + } flt, flt2; + + flt.f = number; x = CLUTTER_INT_TO_FIXED (number) / 2; /* The QIII initial estimate */ - y = * ( unsigned long * ) &flt; - y = 0x5f3759df - ( y >> 1 ); - flt = * ( float * ) &y; + flt.i = 0x5f3759df - ( flt.i >> 1 ); /* Now, we convert the float to 10.22 fixed. We exploit the mechanism * described at http://www.d6.com/users/checker/pdfs/gdmfp.pdf. @@ -494,22 +498,21 @@ clutter_sqrti (gint number) * addition out, and it all goes pear shape, since without it, the bits * in the float will not be correctly aligned. */ - flt2 = flt + 2.0; - y = * ( long * ) &flt2; - y &= 0x7FFFFF; + flt2.f = flt.f + 2.0; + flt2.i &= 0x7FFFFF; /* Now we correct the estimate, only single iterration is needed */ - y1 = (y >> 11) * (y >> 11); + y1 = (flt2.i >> 11) * (flt2.i >> 11); y1 = (y1 >> 8) * (x >> 8); y1 = f - y1; - y = (y >> 11) * (y1 >> 11); + flt2.i = (flt2.i >> 11) * (y1 >> 11); /* Invert, round and convert from 10.22 to an integer * 0x1e3c68 is a magical rounding constant that produces slightly * better results than 0x200000. */ - return (number * y + 0x1e3c68) >> 22; + return (number * flt2.i + 0x1e3c68) >> 22; } /* */