C optimizer
Joseph Nathan Hall
jnh at ece-csc.UUCP
Thu Feb 16 02:50:47 AEST 1989
In article <954 at philmds.UUCP> leo at philmds.UUCP (Leo de Wit) writes:
>In article <515 at larry.UUCP> jwp at larry.UUCP (Jeffrey W Percival) writes:
>|I have a question about how much optimizing I should worry about when
>|writing programs in C. Suppose I have this code fragment:
>|
>| x = (1 + cos(r)) / (cos(r) * sin(r));
>| y = (cos(r) - sin(r)) / (1 + sin(r));
>|
>|I made this up, but the point is the re-use of the sin() and cos()
>|calls. Now, can I expect the compiler to form only one call to sin and
>|cos?
>
>Try rand() instead of sin(), cos(). Now, you wouldn't want the compiler
>to form only one call to rand(), would you?
>
Now, you know, this is an interesting point. The functions (call them
"pure" or "mathematical") that can be optimized in the fashion of redundant
subexpressions have to depend SOLELY on their inputs, and furthermore
(this is the point) can't have any "memory" of previous state.
I think language support for pure functions would be very useful, personally.
No static variables, no references to external variables (other than other
pure functions).
The function rand() would be OK if it required a seed value as a parameter.
--
v v sssss|| joseph hall || 201-1D Hampton Lee Court
v v s s || jnh at ece-csc.ncsu.edu (Internet) || Cary, NC 27511
v sss || the opinions expressed herein are not necessarily those of my
-----------|| employer, north carolina state university . . . . . . . . . . .
More information about the Comp.lang.c
mailing list