This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: recent troubles with float vectors & bitwise ops


On 22 August 2007 11:40, Andrew Pinski wrote:

> On 8/22/07, Dave Korn <dave.korn@artimi.com> wrote:
>> float InvSqrt (float x){
>>     float xhalf = 0.5f*x;
>>     int i = *(int*)&x;
> 
> You are violating C/C++ aliasing rules here anyways.
> 
>>     i = 0x5f3759df - (i>>1);
>>     x = *(float*)&i;
> 
> Likewise.
> 
> So I guess you like to depend on undefined code :).

  Well, I like to think that I could cast the address to unsigned char*, memcpy a bunch of them to the address of an int, then dereference the int and the compiler would realise it was a no-op and optimise it away, but I doubt thatt would actually happen...


    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]