On 2006-09-13, Peter Jansen <peter.jan...@aad.gov.au> wrote: >> What? You just admitted foo is aligned on a word boundary. >> Therefore foo+1 _isn't_ on a word boundary. The compiler >> generated a word move with &foo+1 as the destination. How is >> that fine? > > Ok got that now, and your example also generates bad code. > > When I try and link the first example I get a fixup waring from the > linker, I think that must be telling us something :-).
Yup, sometimes it does. The cases that are nasty are when there is no warning (which I suppose might be a bug in the linker). I don't have a minimal test case for that yet. In my real world case where memcpy and memset generate mov.w with odd destinations, the destination is a field inside packed structures that are nested a couple deep. It's a static structure (aligned on a word boundary), and the destiation for the move was at an offset of 15, IIRC. I don't know why there wasn't a linker warning. I was using an assignment (also without a linker warning), but I wasn't seeing any data written to the destination bytes. Assuming it was because of a misallignment, I switched to memcpy(), but that generated exactly the same code. While debugging I also tried a memset both generated mov.w with a misaligned destination. As a work-around, I wrote a mymemcpy() function and did a #define memcpy(d,s,c) mymemcpy(d,s,c). It works now, but I don't like it much. > Thanks Ill add a few more efficient (code size) "ll : br ll" > 's to the compiler output where the code is too long :-). It would sure look good in the benchmarks. :) > I'll have a look where the memset is optimized out by the compiler. The intrinsic memcpy does the same thing (for lengths of 2 and 4 that I know of). In the cases where both the source and destination are known to be aligned, then word moves are fine. If they aren't both known to be aligned, then you have to either fall back on byte moves or generate a call to memcpy. IMO, it's perfectly OK for the compiler to assume that a word pointer always has an even value. Even targets like the ARM that handle assignments to packed, misaligned structure fields don't check pointers before dereferencing them. -- Grant Edwards grante Yow! I've been WRITING at to SOPHIA LOREN every 45 visi.com MINUTES since JANUARY 1ST!!