lkml.org 
[lkml]   [1999]   [Jun]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: oom() _still_ killing init
On Fri, 18 Jun 1999, Oliver Xymoron wrote:
> On Fri, 18 Jun 1999, Jamie Lokier wrote:
> > Last time I checked GCC, your proposed style generated worse code -- it
> > had branches in the fast path and extra tests.
>
> a) It's not a proposal of any sort, it's merely a demonstration of a way
> of eliminating gotos without creating ridiculous levels of nesting,
> something that was claimed to be impossible.
>
> b) Unlike sched.c, most of the places where goto is used are _not_
> performance critical in any way - most are of the form goto out. Let's not
> confuse the structural hacks and the performance hacks here.
>
> c) And anyway, it generates identical code for me with both 2.7.2 and 2.91
> so you must have checked a long time ago. :P

i've found that when using egcs or gcc with -O2, a "goto" will generate
the same assembly as the same logic expressed with structured programming,
*in* *the* *general* *case*. something like find_buffer() looks like a
complete mess, but it does generate better assembly than using idiomatic C
programming style. but simple cases like this:

int function(int a)
{
if (a > 3)
goto out;
a = a + 7
do_work;
out:
return a;
}
will generate exactly the same assembly as this:

int function(int a)
{
if (a <= 3) {
a = a + 7;
do_work;
}
return a;
}
if compiled with -O2. building the kernel with -O2 means we can probably
lose many "gotos" without losing any fast path performance. if the kernel
were compiled without optimization, the gotos would definitely win.

another case where goto is superfluous is this:

int function(int a)
{
int something = an error;
if (some error case)
goto out;
if (some other error case)
goto out;
do_work;
something = 0;

out:
return something;
}
you'll get the same generated assembly with this:

int function(int a)
{
if ((some error case) || (some other error case))
return an error;
do_work;

return 0;
}
the C compiler is smart enough to convert the first "return an error"
into a branch to the end of function.

- Chuck Lever
--
corporate: <chuckl@netscape.com>
personal: <chucklever@netscape.net> or <cel@monkey.org>

The Linux Scalability project:
http://www.citi.umich.edu/projects/linux-scalability/


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:52    [from the cache]
©2003-2014 Jasper Spaans. Advertise on this site