Re: oom() _still_ killing init

Oliver Xymoron (oxymoron@waste.org)
Fri, 18 Jun 1999 13:43:22 -0500 (CDT)


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

---8<---

int foo(int a)
{
printf("Checking...\n");

if(!a)
goto out;

printf("Doing something...\n");

out:
printf("Cleanup...\n");
}

static inline int bar2(int a)
{
printf("Checking...\n");

if(!a) return;

printf("Doing something...\n");
}

int bar(int a)
{
bar2(a);

printf("Cleanup...\n");
}

---8<---

gcc -O2 -s -c gives us:

foo:
pushl %ebp
movl %esp,%ebp
pushl %ebx
movl 8(%ebp),%ebx
pushl $.LC0
call printf
addl $4,%esp
testl %ebx,%ebx
je .L3
pushl $.LC1
call printf
addl $4,%esp
..L3:
pushl $.LC2
call printf
movl -4(%ebp),%ebx
leave
ret

bar:
pushl %ebp
movl %esp,%ebp
pushl %ebx
movl 8(%ebp),%ebx
pushl $.LC0
call printf
addl $4,%esp
testl %ebx,%ebx
je .L8
pushl $.LC1
call printf
addl $4,%esp
..L8:
pushl $.LC2
call printf
movl -4(%ebp),%ebx
leave
ret

> [And it's ugly IMO]

Fine - it's not intended as a style guideline, merely as a proof that goto
is avoidable. Any function using goto can be transformed into two or more
functions using return. Many alternate transformations exist. Personally,
I think breaking one large function into two smaller function is a good
thing. I hate having to read through single functions that are pages long.

--
 "Love the dolphins," she advised him. "Write by W.A.S.T.E.." 

- 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/