public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Mohamed Shafi <shafitvm@gmail.com>
To: GCC <gcc@gcc.gnu.org>
Subject: How to support 40bit GP register
Date: Wed, 21 Oct 2009 15:56:00 -0000	[thread overview]
Message-ID: <ba0bd44d0910210725qc90b297g187f8d8712e2520f@mail.gmail.com> (raw)

HI all,

I am porting GCC 4.4.0 for a 32bit target. The target has 40bit data
registers and 32bit address registers that can be used as general
purpose registers. When 40bit registers are used for arithmetic
operations or comparison operations GCC generates code assuming that
its a 32bit register. Whenever there is a move from address register
to data register sign extension is automatically performed by the
target. Since the data register is 40bit after some operations
sign/zero extension has to be performed for the result to be proper.
Take the following test case for example :

typedef struct
{
  char b0;
  char b1;
  char b2;
  char b3;
  char b4;
  char b5;
} __attribute__ ((packed)) b_struct;


typedef struct
{
  short a;
  long b;
  short c;
  short d;
  b_struct e;
} __attribute__ ((packed)) a_struct;


int
main(void)
{
  volatile a_struct *a;
  volatile a_struct b;

  a = &b;
  *a = (a_struct){1,2,3,4};
  a->e.b4 = 'c';

  if (a->b != 2)
    abort ();

  exit (0);
}

For accessing a->b GCC generates the following code:

       move.l  (sp-16), d3
       lsrr.l  #<16, d3
       move.l  (sp-12),d2
       asll    #<16,d2
       or      d3,d2
       cmpeq.w #<2,d2
       jf      _L2

Because data registers are 40 bit for 'asll' operation the shift count
should be 16+8 or there should be sign extension from 32bit to 40 bits
after the 'or' operation. The target has instruction to sign extend
from 32bit to 40 bit.

Similarly there are other operation that requires sign/zero extension.
So is there any way to tell GCC that the data registers are 40bit and
there by expect it to generate sign/zero extension accordingly ?

Regards,
Shafi

             reply	other threads:[~2009-10-21 14:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-21 15:56 Mohamed Shafi [this message]
2009-10-22  6:24 ` Richard Henderson
2009-11-04 13:35   ` Mohamed Shafi
2009-11-04 14:12     ` Dave Korn
2009-11-04 16:39     ` Richard Henderson
2009-11-09 14:14   ` Mohamed Shafi
2009-11-09 16:16     ` Richard Henderson

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=ba0bd44d0910210725qc90b297g187f8d8712e2520f@mail.gmail.com \
    --to=shafitvm@gmail.com \
    --cc=gcc@gcc.gnu.org \
    /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).