Subject: Re: new patch

From: Philip Blundell <[email-masked]>
Date: Tue, 06 Jan 1998 11:55:52 +0000

>Yes, but I wasn't suggesting that.  In the case where you /do/ know the
>alignment to be on a 32-bit boundary, doing a load from a non-aligned address
>is silly if the MMU is going to take an exception.  Equally, loading a pair
>of bytes is not a good idea.  So loading a word where you *do* know the
>alignment and then shifting &| masking is the right thing to do.

That's true, and that's more or less what GCC is trying to do.  The reason it 
gets upset is that if you violate the structures-must-be-32-bit-aligned rule, 
it has no way to know whether an element of that structure is going to be 
aligned or not at the time it generates code.  The only two choices you have 
are to generate optimistic code which is fast in the aligned case and fails in 
the non-aligned case, and to generate pessimistic code which always works but 
is slow.  GCC takes the former approach, and I think this is best.

It would be possible, albeit very hard, to make the compiler smarter about 
this - for example it could in theory assume that any structure containing an 
element with size 4 or greater, or any automatic, would be aligned. 

p.