optimization Re: volatile (ad nauseum)

Jeff Loucks jeff at dad.UUCP
Thu Apr 28 06:19:30 AEST 1988


In article <20224 at think.UUCP> barmar at think.COM (Barry Margolin) writes:
>In article <174 at obie.UUCP> wes at obie.UUCP (Barnacle Wes) writes:
>>In article <20065 at think.UUCP>, barmar at think.COM (Barry Margolin) writes:
>>> 	a = b;
>>> 	a = b;
>>> It doesn't take much of a flow analysis to determine that the second
>>> statement is redundant.  Most peephole optimizers will hack this.
>>Aha!  But this code is not always redundant!
>
>I know, but it usually is.  And that's the whole point of "volatile":
>it tells the compiler not to assume that such code is redundant, among
>other things.  You certainly wouldn't want a compiler to generate
>double accesses for all such cases, just the ones where a or b is
>volatile.

Finally, somebody gets back near the point:

    C  is  a  wonderful  tool  for programming computers, from kernal to
applications,  so we use it. We often write code that will NEVER move to
another  machine  for whatever reason, so portability is not necessarily
the issue.

What IS the issue?

    We  want  our programming tool to be effective (high level enough to
save   us   from   assembler),   efficient  (optimizations  are  greatly
appreciated),  and  as  universally  understood  as possible (somebody's
gotta fix the stuff).

    However,  we  also (and usually more importantly) must to be able to
do our job (you remember having to do a job don't you?).

    I  have written perfectly legitimate C code that does the equivalent
of  the  a=b;  a=b;  example  above,  and  have  meant every word of it.
Consider  memory  mapped  devices;  if multiple reads/writes of the same
constant  value  from/to  the  same location is what you asked for, it's
precisely what you should get. Consider shared memory; not only multiple
processes,  but  multiple processors speaking to a common location. If I
request a read/write now, I want it NOW. Need I continue?

    The   issue   has   nothing   whatsoever  to  do  with  portability,
hypothetical CPU architectures, registers, or whatever. It is simply:

    If  I  don't  want  the  compiler  fiddling with something, I want a
reasonable way to tell it so. Period.

'Volatile' works great. What's the big deal?

-- 
uw-beaver!tikal!dad!jeff     (jeff loucks (206) h851-8908 w581-1322)
------------- YISDERSOMENIMORORSISASISDENDERISORSIS ? --------------



More information about the Comp.lang.c mailing list