This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Why the discrepancy?
I think I might have found the reason for this; here's what I've been experimenting with today:
extern int i;
extern void f2();
void f()
{
f2();
i = 3;
}f: pushl %ebp
movl %esp, %ebp
subl $8, %esp
call f2
movl $3, %eax
movl %eax, i
leave
retThe pushed %ebp uses 4 bytes on the stack and GCC reserves another 8 bytes (which are never used) for a total of 12 bytes.
Now if I compile the same with the option "-fomit-frame-pointer" added I get this:
f: subl $12, %esp
call f2
movl $3, %eax
movl %eax, i
addl $12, %esp
retIn both cases the function f() uses 12 bytes of stack and together with the 4 bytes of return address being on the stack already, it totals to 16 bytes, which is a nice alignment. And as you know, proper alignment makes code faster. If f() does not call any function, GCC does not reserve any unnecessary space.
In your sample code, you didn't use optimization at all, so it probably did the alignment anyway, even if no other function gets called from your function. This might be the reason why it allocates 40 bytes instead of only what it requires for storage.
Then I did some measurements and apparently, calling a function with the stack not aligned to 16-bytes is slower. So GCC actually does a good job here.
Attachment:
signature.asc
Description: OpenPGP digital signature
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |