Re: linux-kernel-digest V1 #128

Rob Janssen reading Linux mailinglist (linux@pe1chl.ampr.org)
Tue, 25 Jul 1995 13:35:24 +0200 (MET DST)


According to owner-linux-kernel-digest@vger.rutgers.edu:
> 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
alternative.

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

Rob

-- 
+------------------------------------+--------------------------------------+
| Rob Janssen         rob@knoware.nl | AMPRnet:   rob@pe1chl.ampr.org       |
| e-mail: pe1chl@wab-tis.rabobank.nl | AX.25 BBS: PE1CHL@PI8WNO.#UTR.NLD.EU |
+------------------------------------+--------------------------------------+