This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: m68k structure packing



>My recollection is that it will only fail if you compile for the 68000,
>because the 68000 has no bit field instructions, and requires 2 byte alignment
>for non-byte loads/stores.  (As per the PCC_BITFIELD_TYPE_MATTERS
>documentation.) Most other 68k family members do not have both these
>restrictions.

Yes, the 68000 did not have bit field instructions, and everything
besides a byte access had to be even aligned(including the stack).

It will also fail on the AMD29000 since it too does not have bit field
insns and can only access memory on word boundaries.

I don't see any trouble with a structure that contains only bytes
being sized and aligned on byte boundaries:

struct {
	char a,b,c;
} z, list[10];

sizeof(z) would be 3, and sizeof(list) would be 30.

If you have a short in the struct:

struct {
	short b;
	char a;
} z, list[10];

then sizeof(z) could be 3 but is 4 due to alignment requirements(i.e
malloc(n*sizeof(z))) and sizeof(list) is 40.

And obviously if you have a long, then the sizeof has to round up to a
long.

Even if you pack the structure, you have to allow for alignment
requirements.
	
>Because I have seen the problem before, and I have seen it so many times
>that it falls into the category of things that are obvious to me, but which
>I can't easily explain because I forgot the reasons for it long ago.

Yes, I agree its obvious, and the answer is that the sizeof a
structure has to be rounded up to the most strict alignment of any of
its elements to allow an array of these objects to have each element
conform to the alignment requirements.

If any 'improvement' breaks any port, then the 'improvement' is not,
and has to be fixed.

-- 
Peter Barada				pbarada@wavemark.com
Wizard					617-270-7098 x1226
WaveMark Technologies, Inc.		617-270-0193 (fax)

"Real men know that you should never attempt to accomplish with words
what you can do with a flame thrower" --Bruce Ferstein


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]