Aliasing problem in function InvSqrt_Lomont() in tsMesh.cc
by Todd "zaz" Koeckeritz · in Torque Game Engine · 10/06/2006 (1:50 pm) · 0 replies
My last few posts today in this thread document an aliasing problem in InvSqrt_Lomont() in engine/ts/tsMesh.cc.
I can only verify the problem under SuSE 10.0 w/ gcc 4.0.2 and ubuntu dapper w/ gcc 4.0.3, however it could affect optimization results from other compilers as well.
See this thread for more discussion and some solutions I tried.
F32 InvSqrt_Lomont(F32 x)
{
F32 xhalf = 0.5f*x;
S32 i = *(S32*)&x; // [b]ALIASING PROBLEM[/b]
i = 0x5f375a84 - (i>>1); // hidden initial guess, fast
x = *(F32*)&i; // [b]ALIASING PROBLEM[/b]
x = x*(1.5f-xhalf*x*x);
return x;
}I can only verify the problem under SuSE 10.0 w/ gcc 4.0.2 and ubuntu dapper w/ gcc 4.0.3, however it could affect optimization results from other compilers as well.
See this thread for more discussion and some solutions I tried.