[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <Pine.LNX.4.64.0703242123310.6730@woody.linux-foundation.org>
Date: Sat, 24 Mar 2007 21:28:06 -0700 (PDT)
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: yuan cooper <yuanxjtu@...mail.com>
cc: linux-kernel@...r.kernel.org, akpm@...ux-foundation.org,
dmitry.torokhov@...il.com
Subject: Re: About GCC4 Optimization
On Sun, 25 Mar 2007, yuan cooper wrote:
> �
> during my work, I found�there is a bug with GCC4 O2 optimization.
Technically, it's a misfeature fo gcc4, not a bug.
The C language allows for type-based alias detection, and gcc notices that
a "float *" cannot ever alias with a "unsigned long *", so it decides to
not even do the loads and stores..
Now, there's two things wrong with this picture:
- gcc is being an ass. type-based alias detection should happen only as a
last resort, and gcc should know and notice that *despite* the types
being different, they definitely alias.
So what gcc does may be technically legal, but it's still a horribly
bad thing to do. Sadly, some gcc people seem to care more about "letter
of the law" than "sanity and quality of implementation".
- as a result, you should always compile any kernel stuff with
"-fno-strict-aliasing", which should turn this off. If it *still*
happens with that flag, then it is indeed a compiler bug.
> float ftmp;
> unsigned long tmp;
> ftmp = 1.0/1024.0;
> tmp� = *(unsigned long *)(&ftmp);
> tmp� = (tmp >> 11) && 0xFFF;
> �
> if optimization level is O2, gcc will MOV eax to tmp, but current eax has a random value.
> -O is ok and gcc3 with O2 is ok too.
That said, you really _really_ shouldn't be doing FP in the kernel anyway.
Linus
Powered by blists - more mailing lists