summaryrefslogtreecommitdiff
path: root/src/mesa/main/imports.c
diff options
context:
space:
mode:
authorRoland Scheidegger <sroland@vmware.com>2009-12-07 20:11:46 +0100
committerRoland Scheidegger <sroland@vmware.com>2009-12-07 20:11:46 +0100
commitc36d1aacf4c70d76165c91cd7048c0f9f43b8571 (patch)
tree3e51e1b30716832d028be7161987e8a89e1872f7 /src/mesa/main/imports.c
parent7d9b2edb97419b562a542b5cd701724c009421d4 (diff)
mesa: fix strict aliasing issues in half-to-float/float-to-half conversions
use union instead of casts
Diffstat (limited to 'src/mesa/main/imports.c')
-rw-r--r--src/mesa/main/imports.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index c9e00cf752..f2ef84f35c 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -460,7 +460,7 @@ _mesa_inv_sqrtf(float n)
#if 0 /* not used, see below -BP */
float r3, x3, y3;
#endif
- union { float f; unsigned int i; } u;
+ fi_type u;
unsigned int magic;
/*
@@ -649,10 +649,10 @@ _mesa_bitcount(unsigned int n)
GLhalfARB
_mesa_float_to_half(float val)
{
- const int flt = *((int *) (void *) &val);
- const int flt_m = flt & 0x7fffff;
- const int flt_e = (flt >> 23) & 0xff;
- const int flt_s = (flt >> 31) & 0x1;
+ const fi_type fi = {val};
+ const int flt_m = fi.i & 0x7fffff;
+ const int flt_e = (fi.i >> 23) & 0xff;
+ const int flt_s = (fi.i >> 31) & 0x1;
int s, e, m = 0;
GLhalfARB result;
@@ -739,7 +739,8 @@ _mesa_half_to_float(GLhalfARB val)
const int m = val & 0x3ff;
const int e = (val >> 10) & 0x1f;
const int s = (val >> 15) & 0x1;
- int flt_m, flt_e, flt_s, flt;
+ int flt_m, flt_e, flt_s;
+ fi_type fi;
float result;
/* sign bit */
@@ -774,8 +775,8 @@ _mesa_half_to_float(GLhalfARB val)
flt_m = m << 13;
}
- flt = (flt_s << 31) | (flt_e << 23) | flt_m;
- result = *((float *) (void *) &flt);
+ fi.i = (flt_s << 31) | (flt_e << 23) | flt_m;
+ result = fi.f;
return result;
}