Re: linux-kernel-digest V1 #128

Rob Janssen reading Linux mailinglist (
Tue, 25 Jul 1995 13:35:24 +0200 (MET DST)

According to
> From: Linus Torvalds <Linus.Torvalds@cs.Helsinki.FI>
> Date: Sun, 23 Jul 1995 19:59:45 +0300
> Subject: Re: goto
> Nothing strange about this at all: look at the assembly code this
> generates, and you'll find that this is a good way to make gcc do better
> machine code. I could have used more "goto" statements to get _exactly_
> what I wanted, but this mixture of a switch and a goto gets rather good
> results.
> Now, looking at the code, you can obviously replace the goto statement
> with the cleaner (?) "{ current->state = TASK_RUNNING; break; }". Now,
> use "make kernel/sched.s" to find out what assembly code this results
> in, and you'll notice that by using the goto we avoid one jump for the
> common case and use some shared code instead.

Well, some 10 years ago I wrote an extra optimization phase that
processed the assembly output of the Alcyon C compiler for the Atari ST.
(I used a lot of switch/case constructs with common code, and got
irritated by the inefficient code generated)

With some simple (fixed-pattern) code sequence substitutions, followed
by analyzing common code, jumps-to-jumps, and jumps-over-unconditional-jumps,
I was able to improve code for examples like that quite a bit. In fact,
there would be no difference between the use of goto and the cleaner

The optimizer was very simple. I'm sure similar operations could be done
internal to GCC, but apparently it is not doing it.


| Rob Janssen | AMPRnet:       |
| e-mail: | AX.25 BBS: PE1CHL@PI8WNO.#UTR.NLD.EU |