gcc return struct code generation
jose gomez valcarcel
jcgv33@yahoo.es
Tue Aug 30 20:23:00 GMT 2011
Hi,
You are right and this is the reason. The x86_64 ABI explicity mention this.
The definitive proof is the generated code for:
extern long calc (long);
long fn (long m)
{
return calc (m) * 2;
}
0000000000000000 <fn>:
0:48 83 ec 08 sub $0x8,%rsp
4:e8 00 00 00 00 callq 9 <fn+0x9>
9:48 83 c4 08 add $0x8,%rsp
d:48 01 c0 add %rax,%rax
10:c3 retq
The code generated is a little more clever to me. The code with return a struct is also performing a 16 byte align substracting 40 bytes.
You have to told me this two times. Excuse me for the inconvenience.
Regards.
----- Mensaje original -----
De: Ian Lance Taylor <iant@google.com>
Para: jose gomez valcarcel <jcgv33@yahoo.es>
CC: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Enviado: martes 30 de agosto de 2011 19:45
Asunto: Re: gcc return struct code generation
jose gomez valcarcel <jcgv33@yahoo.es> writes:
> For curiosity, today i test this code with the intel compiler (12.0.5.220). It generates this code for fn:
>
> icc -O2 -fomit-frame-pointer -c z.c
>
>
> 0000000000000000 <fn>:
> 0:56 push %rsi
> 1:e8 00 00 00 00 callq 6 <fn+0x6>
> 6:48 03 c2 add %rdx,%rax
> 9:59 pop %rcx
> a:c3 retq
>
> Yo can see the code changes the values of registers RSI and RCX with apparently no reason ! (appart of computing correctly the c code of fn).
> Also this code uses stack with apparently no reason, or i can not see it.
The stack has to be aligned at a 16-byte boundary before the function
call. The function call itself pushes 8 bytes onto the stack. So
another 8 byte adjustment is required before making another function
call. icc is choosing to do that adjustment using push and pop. I
don't know why that is preferable to adding and subtracting a constant,
but there may well be a reason.
Ian
More information about the Gcc-help
mailing list