C optimizer
Colin Plumb
w-colinp at microsoft.UUCP
Thu Feb 16 10:37:31 AEST 1989
karl at haddock.ima.isc.com (Karl Heuer) wrote:
> In article <13134 at steinmetz.ge.com> davidsen at crdos1.UUCP (bill davidsen) writes:
> >One solution would be to provide a keyword ... which would indicate that a
> >procedure always returns the same value for a set of given arguments.
>
> If the concept is to be useful, it had better mean "no observable side effects
> AT ALL".
> This is automatic if the "magic" is embedded in the standard
> header files, via a keyword.
Um... Karl, what strange disease has come over your brain to make it suddenly
like adding keywords to C? :-)
This is a perfect example of a good use for #pragma. In <math.h>, I could
just include:
#pragma functional
double sin(double), cos(double);
And the compiler could take that as a hint to use common subexpression
elimination (a pretty common optimisation) on sin and cos. A good
compiler already knows that things like + and ~ are purely functional,
and need only generalise the common subexpression and dead-code eliminators
to handle more conventional function calls.
This is also an example of the point of having a compiler ignore an
unrecognised #pragma. Without this #pragma, the code would compute the
same result, just more wastefully.
--
-Colin (uunet!microsoft!w-colinp)
"Don't listen to me. I never do."
More information about the Comp.lang.c
mailing list