> I have this option turned on in Codewarrior, but I know that I have to
> declare my structs a certain way, something like shorts first, then ints,
> then floats. I'm not sure exactly how though. Could someone please tell
> me exactly what order I need to be declaring stuff in in order to
> maximize my efficiency. Thanks.
PowerPC processors work best with data that are "naturally aligned."
Natural alignment means that an N-byte data type is aligned to an
N-byte boundary (e.g. a 4-byte word begins on a 4-byte boundary).
To maintain this alignment, structures may be padded with pad bytes in
places, rather than packing the data together. To minimize the pad
bytes required, you should (whenever possible) arrange your structures
so that the largest data items are first, in the order: 8-byte doubles,
4-byte floats/ints, 2-byte shorts, 1-byte chars & strings.
To see the difference, look at the following (padded) structures:
struct { struct {
char c; double d;
double d; long l;
short s; short s;
long l; char c;
}; }
c******* dddddddd
dddddddd llll
ss** ss
llll c*
9 pad bytes 1 pad byte
sizeof = 24 sizeof = 16
-- Tim Olson
Apple Computer, Inc.
(t...@apple.com)
If you are on an AIX system (and presumably a MAC or Be, since they use the
same ABI), that d will be at offset 4, not offset 8 in first example. This is
because the AIX PowerOpen ABI states that doubles within a structure get
aligned to a 4 byte boundary, not an 8 byte boundary (page 3-16, table 3-11 of
the June 30th, 1994 PowerOpen ABI spec). Since those systems are big endian,
and the hardware handles loading floating point from an 4 byte alignment in big
endian mode, you will get no traps. Thus, on those systems, there is 5 bytes
of padding, and the whole structure takes 20 bytes.
If you are using the System V.4 ABI (including the eabi), doubles are always
aligned to an 8 byte boundary.
Windows NT uses mostly the PowerOpen ABI, but does align doubles in structures
to an 8 byte boundary, since it runs in little endian mode, where the current
generation of hardware traps when a double is not aligned to an 8 byte
boundary.
--
Michael Meissner, Cygnus Support (East Coast)
Suite 105, 48 Grove Street, Somerville, MA 02144, USA
meis...@cygnus.com, 617-629-3016 (office), 617-629-3010 (fax)