Mesa (master): util: fix strict aliasing issues in u_format_r11g11b10f.h

Roland Scheidegger sroland at kemper.freedesktop.org
Wed Jun 8 23:15:19 UTC 2011


Module: Mesa
Branch: master
Commit: d302804debeed13ced27fce222110c629e55d6f9
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d302804debeed13ced27fce222110c629e55d6f9

Author: Roland Scheidegger <sroland at vmware.com>
Date:   Thu Jun  9 01:11:52 2011 +0200

util: fix strict aliasing issues in u_format_r11g11b10f.h

---

 src/gallium/auxiliary/util/u_format_r11g11b10f.h |   24 ++++++++++++++-------
 1 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_format_r11g11b10f.h b/src/gallium/auxiliary/util/u_format_r11g11b10f.h
index c4181d0..8e0572a 100644
--- a/src/gallium/auxiliary/util/u_format_r11g11b10f.h
+++ b/src/gallium/auxiliary/util/u_format_r11g11b10f.h
@@ -45,14 +45,18 @@
 
 static INLINE unsigned f32_to_uf11(float val)
 {
-   uint32_t f32 = (*(uint32_t *) &val);
+   union {
+      float f;
+      uint32_t ui;
+   } f32 = {val};
+
    uint16_t uf11 = 0;
 
    /* Decode little-endian 32-bit floating-point value */
-   int sign = (f32 >> 16) & 0x8000;
+   int sign = (f32.ui >> 16) & 0x8000;
    /* Map exponent to the range [-127,128] */
-   int exponent = ((f32 >> 23) & 0xff) - 127;
-   int mantissa = f32 & 0x007fffff;
+   int exponent = ((f32.ui >> 23) & 0xff) - 127;
+   int mantissa = f32.ui & 0x007fffff;
 
    if (sign) return 0;
 
@@ -111,14 +115,18 @@ static INLINE float uf11_to_f32(uint16_t val)
 
 static INLINE unsigned f32_to_uf10(float val)
 {
-   uint32_t f32 = (*(uint32_t *) &val);
+   union {
+      float f;
+      uint32_t ui;
+   } f32 = {val};
+
    uint16_t uf10 = 0;
 
    /* Decode little-endian 32-bit floating-point value */
-   int sign = (f32 >> 16) & 0x8000;
+   int sign = (f32.ui >> 16) & 0x8000;
    /* Map exponent to the range [-127,128] */
-   int exponent = ((f32 >> 23) & 0xff) - 127;
-   int mantissa = f32 & 0x007fffff;
+   int exponent = ((f32.ui >> 23) & 0xff) - 127;
+   int mantissa = f32.ui & 0x007fffff;
 
    if (sign) return 0;
 




More information about the mesa-commit mailing list