* GCC Optimization?
@ 2004-11-23 0:26 asmfreshmeat
2004-11-23 1:06 ` Brian Raiter
2004-11-23 16:43 ` Mateusz Marzantowicz
0 siblings, 2 replies; 4+ messages in thread
From: asmfreshmeat @ 2004-11-23 0:26 UTC (permalink / raw)
To: linux-assembly
Hello,
where is one question I didnt found a good answer.
When I'm disassembling the main function with gdb or objdump
I see always code like this:
0x08048354 <main+0>: push %ebp
0x08048355 <main+1>: mov %esp,%ebp
0x08048357 <main+3>: sub $0x8,%esp
0x0804835a <main+6>: and $0xfffffff0,%esp
0x0804835d <main+9>: mov $0x0,%eax
0x08048362 <main+14>: sub %eax,%esp
I understand what the first 3 lines are good for. Pushing the
Basepointer, moving the Basepointer to the Stackpointer,
reserving 8 Bytes on the stack for variables.
But why do they use and .... I think and does only even %esp
so that the last 4 Bits are set to Zero.
But if %esp was 0xcccccccc before it would now be 0xccccccc0
what happens to the 4 Bits from 0xccccccc0 to 0xcccccccc?
And what is this good for?
Second question:
What does mov $0x0,%eax? Why dont they use xor %eax and what is it good for?
Third question:
What is sub %eax,%esp good for? We subtract 0 from esp... mmmhh... for what?
Best regards
--
Geschenkt: 3 Monate GMX ProMail + 3 Top-Spielfilme auf DVD
++ Jetzt kostenlos testen http://www.gmx.net/de/go/mail ++
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: GCC Optimization?
2004-11-23 0:26 GCC Optimization? asmfreshmeat
@ 2004-11-23 1:06 ` Brian Raiter
2004-11-23 16:43 ` Mateusz Marzantowicz
1 sibling, 0 replies; 4+ messages in thread
From: Brian Raiter @ 2004-11-23 1:06 UTC (permalink / raw)
To: linux-assembly
> But why do they use and .... I think and does only even %esp
> so that the last 4 Bits are set to Zero.
> But if %esp was 0xcccccccc before it would now be 0xccccccc0
> what happens to the 4 Bits from 0xccccccc0 to 0xcccccccc?
> And what is this good for?
The x86 push and pop instructions are much, much less efficient if the
stack pointer is not dword-aligned. So if one function (say) pushes a
segment register onto the stack, it can affect the performance of
every function that is called from there.
> Second question:
> What does mov $0x0,%eax? Why dont they use xor %eax and what is it
> good for?
It zeros the accumulator, of course. As for why they don't use xor,
why should they? What would be the advantage?
> Third question:
> What is sub %eax,%esp good for? We subtract 0 from
> esp... mmmhh... for what?
Did you try building the same code with gcc optimizations turned on?
b
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: GCC Optimization?
@ 2004-11-23 9:22 an0nym
0 siblings, 0 replies; 4+ messages in thread
From: an0nym @ 2004-11-23 9:22 UTC (permalink / raw)
To: linux-assembly
>> But why do they use and .... I think and does only even %esp
>> so that the last 4 Bits are set to Zero.
>> But if %esp was 0xcccccccc before it would now be 0xccccccc0
>> what happens to the 4 Bits from 0xccccccc0 to 0xcccccccc?
>> And what is this good for?
>
>The x86 push and pop instructions are much, much less efficient if the
>stack pointer is not dword-aligned. So if one function (say) pushes a
>segment register onto the stack, it can affect the performance of
>every function that is called from there.
Alright. Thanks!
>> Second question:
>> What does mov $0x0,%eax? Why dont they use xor %eax and what is it
>> good for?
>
>It zeros the accumulator, of course. As for why they don't use xor,
>why should they? What would be the advantage?
xor is imho a little bit faster than mov and xor %eax,%eax does the same
like mov $0x0,%eax. But I still don't know why the accumulator has to be
zeroed.
>> Third question:
>> What is sub %eax,%esp good for? We subtract 0 from
>> esp... mmmhh... for what?
>
>Did you try building the same code with gcc optimizations turned on?
No I didn't use any optimiziation, I just thought of 'default'
optimiziations without turning -o2 or -o3 on.
So what is this code good for? I subtracts zero from %esp and saves the
result in %esp. So this code doesn't do anything with %esp. But I think
there should be a purpose?!
Best regards
--
Geschenkt: 3 Monate GMX ProMail + 3 Top-Spielfilme auf DVD
++ Jetzt kostenlos testen http://www.gmx.net/de/go/mail ++
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: GCC Optimization?
2004-11-23 0:26 GCC Optimization? asmfreshmeat
2004-11-23 1:06 ` Brian Raiter
@ 2004-11-23 16:43 ` Mateusz Marzantowicz
1 sibling, 0 replies; 4+ messages in thread
From: Mateusz Marzantowicz @ 2004-11-23 16:43 UTC (permalink / raw)
To: linux-assembly
> Second question:
> What does mov $0x0,%eax? Why dont they use xor %eax and what is it good for?
>
It's because GCC was designed for more processors than only x86 based
and in some cases it won't work. With optimization enabled you will find
there xorl %eax, %eax instead of mov $0x0,%ea
Regards
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-11-23 16:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-23 0:26 GCC Optimization? asmfreshmeat
2004-11-23 1:06 ` Brian Raiter
2004-11-23 16:43 ` Mateusz Marzantowicz
-- strict thread matches above, loose matches on Subject: below --
2004-11-23 9:22 an0nym
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 NNTP newsgroup(s).