ref: f5d2782495c7387eb05db93e6e24aed5ff6bd9ad
parent: b09f05c9e34f4e82be68cf59c0e1f43bbe8a9bec
author: Tanguy Fautre <[email protected]>
date: Sat Feb 15 13:38:08 EST 2020
Fix strict aliasing float to int pointer cast
--- a/Engine/src/engine.c
+++ b/Engine/src/engine.c
@@ -295,13 +295,22 @@
}
static inline int32_t krecipasm(int32_t i)
-{ // Ken did this
- float f = (float)i;
- i = *(int32_t *)&f;
- return((reciptable[(i>>12)&2047]>>(((i-0x3f800000)>>23)&31))^(i>>31));
-}
+{
+ // tanguyf: fix strict aliasing rules.
+ union
+ {
+ float f;
+ int32_t i;
+ } value;
+ // Ken did this
+ // float f = (float)i;
+ // i = *(int32_t *)&f;
+ value.f = (float)i;
+ i = value.i;
+ return((reciptable[(i >> 12) & 2047] >> (((i - 0x3f800000) >> 23) & 31)) ^ (i >> 31));
+}
static inline int32_t getclipmask(int32_t a, int32_t b, int32_t c, int32_t d)
{ // Ken did this