Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!helios!bcm!rice!uw-beaver!milton!dali.cs.montana.edu!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!wuarchive!udel!haven!adm!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.lang.c Subject: Re: Heroic constant folding (was micro-optimizing loops etc.) Message-ID: <7364:Mar202:47:4291@kramden.acf.nyu.edu> Date: 2 Mar 91 02:47:42 GMT References: <14522@ganymede.inmos.co.uk> <10450@dog.ee.lbl.gov> <1991Mar2.010049.21044@grebyn.com> Organization: IR Lines: 27 In article <1991Mar2.010049.21044@grebyn.com> ckp@grebyn.com (Checkpoint Technologies) writes: > >Of course, the best optimization for: > > for (i = 1; i < 100; i++) > > x += i; > >is: > > x += 4950; > OK, so how many more years must it be before a compiler will do this > optimization for you? :-) Actually, one of the few optimizations my q2c supports is loop unrolling. If you tell it to, it will even go all the way to 101 separate statements, and there are probably some C compilers that can collapse x += (1 + 5); x += (1 + 6) into x += 13. > int fib_array[1024] = {1, 1, 2, 3, 5, 8, 13, 21, /* you get the idea */ In Q you can use any pure expression as an initializer. (And arrays are first-class objects so a Fibonacci array initialization can be made pure.) Right now I have q2c just stick the initializations at the top of main(), but I'm thinking of changing it to a two-level system where it first compiles the initializer code, then runs it to produce the C initializers. q2c is slowly improving... Expect to see a usable Q language by the end of the summer. ---Dan