public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Passing arguments of function through registers
@ 2009-02-10 11:21 sumanth
  2009-02-10 11:28 ` Andrew Haley
  0 siblings, 1 reply; 3+ messages in thread
From: sumanth @ 2009-02-10 11:21 UTC (permalink / raw)
  To: gcc-help

Hi .
 I successfully passed function arguments through registers in gcc-3.3.
Every thing seems okay except there is a reshuffling of registers 
happening once the arguments are passed in registers.

see the below example code snippet.


int add(short int x,short int y,short int z)
{
 return x+y+z;
}
main()
{
 int a=5,b=6,c=7,d;
 d=add(a,b,c);
 }

and the objdump of add function is
00000134 <_add>:
 134:   c3 30           000030c3     mov        r3,r0
 136:   c3 01           000001c3     mov        r0,r1
 138:   c3 12           000012c3     mov        r1,r2
 13a:   00 0c           00000c00     add        r0,r3,r0
 13c:   80 00           00000080     add        r0,r0,r1
 13e:   04 08           00000804     rts


The arguments are clearly passed in to r0,r1,r2 but my compiler 
reshuffled them to r3,r0,r1
my return value of a function goes to r0. since i declared r0-r3 as 1 in 
CALL_USED_REGISTERS ,r0-r3
are not pushed in stack.

Can any one help me to avoid the reshuffling of registers ..the idle 
case should be
00000134 <_add>:
 134:  add  r0, r0,r1  ==> r0=r0+r1
 138:  add r0, r0, r2==> r0 = r0+r2
 13c:   rts

since the required values are already in r0,r1,r2.
PS: I am using gcc-3.3

Thanks,
Sumanth G
 

 
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Passing arguments of function through registers
  2009-02-10 11:21 Passing arguments of function through registers sumanth
@ 2009-02-10 11:28 ` Andrew Haley
       [not found]   ` <499165AF.6090503@redpinesignals.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Haley @ 2009-02-10 11:28 UTC (permalink / raw)
  To: sumanth; +Cc: gcc-help

sumanth wrote:

> I successfully passed function arguments through registers in gcc-3.3.
> Every thing seems okay except there is a reshuffling of registers
> happening once the arguments are passed in registers.
> 
> see the below example code snippet.
> 
> 
> int add(short int x,short int y,short int z)
> {
> return x+y+z;
> }
> main()
> {
> int a=5,b=6,c=7,d;
> d=add(a,b,c);
> }
> 
> and the objdump of add function is
> 00000134 <_add>:
> 134:   c3 30           000030c3     mov        r3,r0
> 136:   c3 01           000001c3     mov        r0,r1
> 138:   c3 12           000012c3     mov        r1,r2
> 13a:   00 0c           00000c00     add        r0,r3,r0
> 13c:   80 00           00000080     add        r0,r0,r1
> 13e:   04 08           00000804     rts
> 
> 
> The arguments are clearly passed in to r0,r1,r2 but my compiler
> reshuffled them to r3,r0,r1
> my return value of a function goes to r0. since i declared r0-r3 as 1 in
> CALL_USED_REGISTERS ,r0-r3
> are not pushed in stack.
> 
> Can any one help me to avoid the reshuffling of registers ..the idle
> case should be
> 00000134 <_add>:
> 134:  add  r0, r0,r1  ==> r0=r0+r1
> 138:  add r0, r0, r2==> r0 = r0+r2
> 13c:   rts
> 
> since the required values are already in r0,r1,r2.

We'd need to know what processor this is, and what optimization options
you used.

> PS: I am using gcc-3.3

That's very bad.  Even if there is a bug in that compiler, it's
so very old that it's unlikely to be fixed.

Andrew.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Passing arguments of function through registers
       [not found]   ` <499165AF.6090503@redpinesignals.com>
@ 2009-02-10 11:54     ` Andrew Haley
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Haley @ 2009-02-10 11:54 UTC (permalink / raw)
  To: sumanth; +Cc: gcc-help

sumanth wrote:
>  I am running with -Os level optimization level.
> For the time being assume the processor is arm processor .

OK.  Current gcc (4.4 pre) does this with -Os:

00000000 <add>:
   0:   e0811000        add     r1, r1, r0
   4:   e0810002        add     r0, r1, r2
   8:   e12fff1e        bx      lr

> Guess I can resolve this with gcc-3.3 itself.

Maybe.  I'm quite surprised that any version of gcc generated code
as bad as what you posted.

Andrew.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-02-10 11:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-10 11:21 Passing arguments of function through registers sumanth
2009-02-10 11:28 ` Andrew Haley
     [not found]   ` <499165AF.6090503@redpinesignals.com>
2009-02-10 11:54     ` Andrew Haley

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).