Gentoo Archives: gentoo-amd64

From: Ian McCulloch <ianmcc@××××××××××××××.au>
To: "gentoo-amd64@l.g.o" <gentoo-amd64@l.g.o>
Subject: Re: [gentoo-amd64] Re: GCC-4.5.2 Has Serious Problems
Date: Fri, 01 Jul 2011 03:22:34
In Reply to: Re: [gentoo-amd64] Re: GCC-4.5.2 Has Serious Problems by Frank Peters
On Fri, 1 Jul 2011, Frank Peters wrote:

> On Fri, 1 Jul 2011 00:58:46 +0000 (UTC) > Duncan <1i5t5.duncan@×××.net> wrote: > >> >> I had wondered if this might be an "undefined behavior" optimization bug, >> > > Well, the amd64 users list may not be the appropriate place to discuss > C programming, but the problem here stems from attempting to do things > with C that are not supposed to be done with C. Such things are aptly > called "tricks" because they stray away from the convention.
I don't think that is true - C has ALWAYS had rules on strict aliasing, even from the first attempts at standardization. Unfortunately it is only recently that common compilers and hardware have really taken advantage of the way the language works to give better optimizing performance by storing more variables in registers rather than reloading pointers from memory every time. Mostly this is due to the small number of registers in the x86 architecture, doesn't lend itself to these optimisations as well as other architectures. Contrast with Itanium for example with lots of registers, some of which are designed to be preserved across a function call. FORTRAN compilers have taken advantage of aliasing optimizations right from the beginning (ie, since the 1960's!), and commodity C compilers are only now just catching up! So these are hardly new optimizations.
> > Ideally, I suppose, for these purposes would be to use assembly language > routines mixed into the C code. But this is not as easy as with the > "tricks."
Not at all, it is about producing more efficient assembly, using the language rules that have existed practically forever. If programmers have become accustomed to violating those rules, then they'll just have to get accustomed to not violating them. The rules aren't hard! And if you DO want to alias pointers of different types, then there are well-defined ways of doing that, and the resulting code tends to be much more readable too. Regards, Ian