Re: Gotos

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>>>>> "Momchil" == Momchil Velikov <velco@fadata.bg> writes:

Phil> Actually, if you try compiling that file with the patch and
Phil> without it, they do not turn out the same.  I tried without -O,
Phil> with -O2, and with -O3.

One more example:

x1.c:
-----
int foo (), bar ();

int
baz ()
{
  int ret;
  
  if (__builtin_expect (foo (), 0))
    {
      ret = 0;
      goto out;
    }
  
  bar ();
  ret = 1;

 out:
  return ret;
}


x2.c:
-----
int foo (), bar ();

int
baz ()
{
  int ret;
  
  if (__builtin_expect (foo (), 0))
    {
      ret = 0;
      return ret;
    }
  
  bar ();
  ret = 1;

 out:
  return ret;
}

gcc -S -O3 -fomit-frame-pointer x1.c x2.c

x1.s:
-----
	.file	"x1.c"
	.text
	.p2align 4,,15
.globl baz
	.type	baz, @function
baz:
	subl	$12, %esp
	call	foo
	xorl	%edx, %edx
	testl	%eax, %eax
	jne	.L3
	call	bar
	movl	$1, %edx
.L3:
	movl	%edx, %eax
	addl	$12, %esp
	ret
	.size	baz, .-baz
	.ident	"GCC: (GNU) 3.3.2"


x2.s:
-----
	.file	"x2.c"
	.text
	.p2align 4,,15
.globl baz
	.type	baz, @function
baz:
	subl	$12, %esp
	call	foo
	xorl	%edx, %edx
	testl	%eax, %eax
	jne	.L1
.L3:
	call	bar
	movl	$1, %edx
.L1:
	movl	%edx, %eax
	addl	$12, %esp
	ret
	.size	baz, .-baz
	.ident	"GCC: (GNU) 3.3.2"


Right, they are identical :)

~velco

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux