This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: 3.0 Changes in ASM
- To: Bill Wendling <wendling at ncsa dot uiuc dot edu>
- Subject: Re: 3.0 Changes in ASM
- From: Erik Mouw <J dot A dot K dot Mouw at ITS dot TUDelft dot NL>
- Date: Sun, 18 Feb 2001 15:58:32 +0100
- Cc: gcc at gcc dot gnu dot org
- Organization: Eric Conspiracy Secret Labs
- References: <20010218032852.A1009@ncsa.uiuc.edu>
On Sun, Feb 18, 2001 at 03:28:52AM -0600, Bill Wendling wrote:
> I was wondering about the changes in the assembly language for the
> following C code:
>
> #include <stdio.h>
>
> int main(void)
> {
> printf("hello world\n");
> return 0;
> }
>
> GCC 2.95.2 outputs the following asm code:
>
> main:
> pushl %ebp
> movl %esp,%ebp
> subl $8,%esp
> addl $-12,%esp
> pushl $.LC0
> call printf
> addl $16,%esp
> xorl %eax,%eax
> jmp .L2
> .p2align 4,,7
> .L2:
> movl %ebp,%esp
> popl %ebp
> ret
>
> while 3.0 outputs:
>
> main:
> pushl %ebp
> movl %esp, %ebp
> subl $8, %esp
> subl $12, %esp
> pushl $.LC0
> call printf
> addl $16, %esp
> movl $0, %eax
> movl %ebp, %esp
> popl %ebp
> ret
>
> The question is, why the "movl $0, %eax" when an "xor" is typically
> faster (or so I'm lead to believe)?
Try compiling with -O2:
main:
pushl %ebp
movl %esp, %ebp
subl $20, %esp
pushl $.LC0
call puts
xorl %eax, %eax
movl %ebp, %esp
popl %ebp
ret
Apparently the faster code is only generated with -O2 or better.
(Good to see that gcc-3.0 combines the "subl $8,%esp; addl $-12,%esp"
pair from gcc-2.95.2 into a single "subl $20, %esp".)
Erik
--
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands
Phone: +31-15-2783635 Fax: +31-15-2781843 Email: J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/