Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!gorodish!guy
From: guy@gorodish.Sun.COM (Guy Harris)
Newsgroups: comp.arch
Subject: Re: RISC machines and scoreboarding
Message-ID: <58488@sun.uucp>
Date: 30 Jun 88 01:42:25 GMT
References: <1082@nud.UUCP> <2438@winchester.mips.COM> <1098@nud.UUCP> <1639@osiris.UUCP>
Sender: news@sun.uucp
Lines: 38

> And we've been told to avoid the global optimizer like the plague when any
> of the code to be tuned is asynchronous, like the signal handlers we have
> in 99.99% of our applications...

Umm, this has nothing whatsoever to do with RISC vs. CISC nor optimizer bugs;
the problem here is that signal handlers (and other forms of asynchrony)
violate assumptions that optimizers tend to make.  For example, in the
following case:

	extern int j;
	int i, l, a, b, c;

	...

	i = j;
	k = a + b + c;
	l = j;

if the value assigned to "i" happens to be lying around in a register (as a
side effect of the code that performs that assignment) when the value of "j" is
assigned to "l", you can just store that register into "l", right?  Wrong.  A
signal could arrive between the point at which the value was loaded into the
register and the point at which the value was stored into "l", and the signal
handler can change the value of "j" in that interval.  The same can happen with
values stored in registers on I/O devices, or variables shared between
processes.

Unfortunately, optimizers tend not to know that certain external variables are
"safe", and won't change asynchronously, while others are "unsafe" and may
change asynchronously.  Some optimizers may simply assume that all external
variables are "safe", in which case you'd better disable the optimizer when
writing code where not all external variables are "safe" (or, at least, cut the
optimization down to a level where the optimizer no longer makes this
assumption).

To see a painfully elaborate discussion of ways to handle this problem, just
search for the word "volatile" in all articles in "comp.lang.c" on your machine
and print all the articles in question.  :-)