This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Passing arguments of function through registers
- From: Andrew Haley <aph at redhat dot com>
- To: sumanth <sumanth dot gundapneni at redpinesignals dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 10 Feb 2009 11:27:59 +0000
- Subject: Re: Passing arguments of function through registers
- References: <499162C1.9020002@redpinesignals.com>
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.