unaligned structure members (known at compile time)
Shaun Jackman
shaunj@gray-interfaces.com
Mon Sep 4 13:26:00 GMT 2000
Can gcc generate the loads and masks necessary to load unaligned structure
members? my target is arm-elf (little-endian)
example...
typedef struct __attribute__((packed)) {
char c0;
int i0;
} s;
int
main()
{
s mys;
int i;
mys.i0 = 0x12345678;
i = mys.i0;
return 0;
}
The generated assembler would be something like.... (pseudo-asm)
load $r0, &t+(0 bytes)
load $r1, &t+(4 bytes)
load $r2, ($r0 & 0x00ffffff) | ($r2 & 0xff000000)
Failing this...
can gcc generate a warning on accesses to compile-time known unaligned accesses?
Otherwise, my next best thought is to create a function
int load_unaligned_int( int const * p);
that generates the loads from (p&~3) and ((p&~3)+1) and the necessary masks.
Only problem there is, a run time function wouldn't be as efficient as compile
time, and I'd have to break a lot of legacy code.
Thanks,
Shaun
------
Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com
More information about the crossgcc
mailing list