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/