Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: Heroic constant folding (was micro-optimizing loops etc.) Message-ID: <619@taumet.com> Date: 4 Mar 91 16:18:24 GMT References: <10191@dog.ee.lbl.gov> <14522@ganymede.inmos.co.uk> <10450@dog.ee.lbl.gov> <1991Mar2.010049.21044@grebyn.com> Organization: Taumetric Corporation, San Diego Lines: 38 ckp@grebyn.com (Checkpoint Technologies) writes: >int fib_array[1024]; >void init_fib(void) >{ ... 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. 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. 2. init_fib() is a global function which might be called elsewhere. If the compiler deletes the function, the program will fail to link. You could argue for replacing the loop in init_fib() with a series of constant assignments. ('Loop unrolling' is a standard optimization technique on parallelizing computers with lots of memory.) This would preserve the program's semantics, but might result in a larger program. Depending on instruction caching and look-ahead, the unrolled loop might execute more slowly than the original loop, apart from being larger. -- Steve Clamage, TauMetric Corp, steve@taumet.com