public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Anil Paranjape" <AnilP1@KPITCummins.com>
To: "Kazu Hirata" <kazu@cs.umass.edu>
Cc: <gcc@gcc.gnu.org>
Subject: Ping : H8/300  ABI Document
Date: Tue, 30 Mar 2004 13:10:00 -0000	[thread overview]
Message-ID: <69595093233BB547BB70CF5E492B63F204B96BAE@sohm.kpit.com> (raw)

Hi,

Please review change suggested in H8 ABI document from following link,
http://gcc.gnu.org/ml/gcc/2004-03/msg01325.html

Regards,
Anil Paranjpe

-----Original Message-----
From: Anil Paranjape 
Sent: Tuesday, March 23, 2004 3:24 PM
To: 'Kazu Hirata'; gnuh8@gnuh8.org.uk
Cc: 'gcc@gcc.gnu.org'
Subject: RE: ABI Document


Hi,

Please find following sentence from  http://gcc.gnu.org/projects/h8300-abi.html,

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.

I think this is slightly misleading statement. 
Consider following testcase,

struct test {
  unsigned short a;         /* Address 0,1 */
  unsigned short b;         /* Address 2,3 */
};
  struct test t;
int  main (void)
{
  t.b = 1;
  return 0;
}

Compiler options passed are 
-ms -ms2600 -fverbose-asm -S

Generated assembly for above testcase is following,
        .file   "test.c"
        .h8300s
        .section .text
        .align 1
        .global _main
_main:
        mov.l   er6,@-er7       ;#,
        mov.l   er7,er6 ;#,
        mov.w   #1,r2   ;#, tmp17
        mov.w   r2,@_t+2        ;# tmp17, t.b
        sub.w   r2,r2   ;# <result>
        mov.w   r2,r0   ;# <result>, <result>
        mov.l   @er7+,er6       ;#,
        rts
        .size   _main, .-_main
        .comm   _t,4,2
        .end
        .ident  "GCC: (GNU) 3.4.0 20040303 (prerelease)"

Analysis:

Assuming above mentioned structure alignment is true then instruction "mov.w   r2,@_t+2" used for accessing t.b in generated assembly should be wrong. The instruction should be "mov.w   r2,@_t+4".
According to structure alignment every structure member is aligned to 4 bytes . So padding mentioned in following structure definition should be correct,
struct test {
  unsigned short a;         /* Address 0,1 (2,3 padding) */
  unsigned short b;         /* Address 4,5 (6,7 padding) */
};

But actually it is not the case. By default structure is aligned to 4 byte boundary. 
So instruction for accessing t.b in generated assembly is correct.
The default alignment of structure is 4 bytes unless __attribute__ ((packed)) is used.

I suggest to change the text of structure alignment in ABI document like following,

Structure Alignment
Unless __attribute__ ((packed)) is attached to the declaration of a struct or union, each structure or union is aligned 
to a multiple of 2 bytes on H8/300 and of 4 bytes on H8/300H and H8S. The compiler inserts padding to maintain the alignment of its members. The sizeof a structure is always multiple of its alignment and this may require tail padding. 


Regards,
Anil Paranjpe

-----Original Message-----
From: Kazu Hirata [mailto:kazu@cs.umass.edu]
Sent: Monday, January 19, 2004 11:22 AM
To: gnuh8@gnuh8.org.uk
Subject: ABI Document


Hi,

I just added a document describing H8 ABI for GCC.

http://gcc.gnu.org/projects/h8300-abi.html

I'll try to make it complete over time.  Suggestions, questions, etc,
are all welcome.

Maybe interrupt function handling needs to be described.

Kazu Hirata

-- 
GNUH8 Mailing List | If you encounter difficulties using this service
                   | email: listmaster@gnuh8.org.uk
                   | http://www.gnuh8.org.uk/

             reply	other threads:[~2004-03-30  6:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-30 13:10 Anil Paranjape [this message]
2004-04-01 20:58 ` Jim Wilson
2004-04-02  8:44 Anil Paranjape
2004-04-05 23:57 ` Jim Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=69595093233BB547BB70CF5E492B63F204B96BAE@sohm.kpit.com \
    --to=anilp1@kpitcummins.com \
    --cc=gcc@gcc.gnu.org \
    --cc=kazu@cs.umass.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).