Heroic constant folding (was micro-optimizing loops etc.)

Checkpoint Technologies ckp at grebyn.com
Tue Mar 5 14:38:39 AEST 1991


In article <619 at taumet.com> steve at taumet.com (Stephen Clamage) writes:
>ckp at grebyn.com (Checkpoint Technologies) writes:
>>int fib_array[1024];
>>	... dynamic initialization of fib_array ...
>>int main(int argc, char **argv)
>>{
>>init_fib();
>
>>...into...
>
>>int fib_array[1024] = {1, 1, 2, 3, 5, 8, 13, 21, /* you get the idea */
>
>I certainly would NOT want the compiler to do this, as it changes the
>meaning of the program.

Not to me.  Maybe to the compiler;  then I would need to have some way
to tell the compiler what *I* know about my program.  I can certainly
see how more information may be needed.

>1. fib_array is a global array which might be set and used elsewhere in the
>program before init_fib() is called.  Replacing the runtime initialization
>with a static initialization could well result in completely different
>program behavior. 

I tried to show that init_fib was called directly after the entry point
main().  In fact it would be important that the compiler know this, and
also the compiler would need to believe that main() is really the
very first executable statement reached, and not just another function.

>2. init_fib() is a global function which might be called elsewhere.  If
>the compiler deletes the function, the program will fail to link.

I probably should have said 'static void init_fib()' so it *could* be
deleted if no other reference were made it it besides the call right
after main.  But the function itself could be kept, if other calls are
made.

In any case, it's *my* (hypothetical) program and *I* know that besides
that init function, the array contents aren't modified.  Somehow the
compiler would have to be told this, or glean it from my usage.
-- 
First comes the logo: C H E C K P O I N T  T E C H N O L O G I E S      / /  
                                                                    \\ / /    
Then, the disclaimer:  All expressed opinions are, indeed, opinions. \  / o
Now for the witty part:    I'm pink, therefore, I'm spam!             \/



More information about the Comp.lang.c mailing list