[Numpy-discussion] Request for review: dynamic_cpu_branch

Charles R Harris charlesr.harris@gmail....
Fri Dec 26 21:02:44 CST 2008


On Fri, Dec 26, 2008 at 6:57 PM, David Cournapeau <cournape@gmail.com>wrote:

> On Sat, Dec 27, 2008 at 10:47 AM, David Cournapeau <cournape@gmail.com>
> wrote:
>
> >
> > I don't understand why. The whole point of union in that case is to
> > make it clear that type punning is ok, since by definition the two
> > values start at the same address. If this broke aliasing, any union
> > would. Here is what man gcc tells me under the -fstrict-aliasing:
> >
>
> hm, seems to be a gcc extension, actually, so you're right. We have to
> find another way, then.
>

Just use -fno-strict-aliasing, the linux kernel does, numpy does, it's just
one of those things where the gnu language lawyers found a loop hole in the
specification and made strict aliasing the default because it yields some
optimization sugar. Google for torvalds and -fno-strict-aliasing and you
might find an old rant on the subject. It can also sneak up on you because
it only kicks in if you compile with optimization, say -O2, and the union
won't help because the compiler is onto your tricks ;) I went through the
whole mess myself trying to set random ieee floats directly from random
ints. In that case the compiler version didn't issue a warning and I got
some fantastic benchmarks because the code was completely optimized away.
Unfortunately, the values were wrong.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20081226/0a78f512/attachment-0001.html 


More information about the Numpy-discussion mailing list