(snip on optimizing and compilers)
On January 24, 2018 at 8:54 PM Paul Raulerson wrote:
Of course, the C compiler took this:
#include
int main(int argc, char *argv[]) {
int c=0;
int x=0;
for (x=0; x< 100000000; x++) { c++; }
printf ("\nThe final value is [%d]\n", c);
}
and optimized it during compile time.
In fact it optimized it so much it simply generated a LHI of a
register with 100000000 in it. (grin) Needless to say, it ran somewhat
faster than my friend’s program. Even counting the screen print. :)
ite: http://www.gkc.org.uk/gkc | Erdos number: 4
There is a story from the OS/360 days of a popular Fortran benchmark
that evaluated
complicated math functions and such, all done using statement functions.
It seems that Fortran H expands statement functions inline, and also
does constant evaluation
at compile time.
As in the above example, the compiler evaluated the whole thing at
compile time
(very slowly) and at run time printed out the precomputed value (fast).
If Fortran H could do it 40 years ago, C compilers should do it today.
(But I don't know that Fortran H did loop evaluation.)
-- glen