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]
Other format: [Raw text]

RE: Ping : H8/300 ABI Document


Hi Jim,

>This is a maximum.  Fields get natural alignment (alignment same as 
>size) up to this maximum.  So shorts are always 2 byte aligned, but 
>4-byte ints get 2-byte alignment on H8/300 and 4-byte alignment on H8S.

>Structure alignment is the max of the alignment of all fields.

I agree to this. 

In my example, there were two short variables as members of structure. 
Each will be treated as separate member. 

> Structure Alignment
> Unless __attribute__ ((packed)) is attached to the declaration of a struct, each structure member is aligned 
> to a multiple of 2 bytes on H8/300 and of 4 bytes on H8/300H and H8S.
Hence as per above statement,
Each short variable(each structure member) should be aligned to multiple of 4 bytes on H8S.

This is not the case. Because as you have rightly said "shorts always have 2-byte alignment".
So size of structure is 4 bytes and alignment is 2 bytes. 

I am suggesting to change the description of "structure alignment" to proper one. 

Thanks and Regards,
Anil


-----Original Message-----
From: Jim Wilson [mailto:wilson@specifixinc.com]
Sent: Friday, April 02, 2004 2:29 AM
To: Anil Paranjape
Cc: gcc@gcc.gnu.org
Subject: Re: Ping : H8/300 ABI Document


Anil Paranjape wrote:
> Structure Alignment
> Unless __attribute__ ((packed)) is attached to the declaration of a struct, each structure member is aligned 
> to a multiple of 2 bytes on H8/300 and of 4 bytes on H8/300H and H8S.

This is a maximum.  Fields get natural alignment (alignment same as 
size) up to this maximum.  So shorts are always 2 byte aligned, but 
4-byte ints get 2-byte alignment on H8/300 and 4-byte alignment on H8S.

Structure alignment is the max of the alignment of all fields.

Your suggested wording is not correct.  The structure in your example 
still has only 2-byte alignment even whwn compiled for H8S.
         .comm   _t,4,2
gives it a 4-byte size and 2-byte alignment.  This is because shorts 
always have 2-byte alignment.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com


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