Path: utzoo!utgpu!water!watmath!clyde!att!mtunx!mtune!codas!peora!ge-dab!ge-rtp!edison!toylnd!dca From: dca@toylnd.UUCP (David C. Albrecht) Newsgroups: comp.sys.amiga.tech Subject: Re: Lattice 4.1 register yuck! Message-ID: <226@toylnd.UUCP> Date: 25 Jun 88 02:19:25 GMT References: <8806212123.AA01328@cory.Berkeley.EDU> Organization: Dave & Anne in Charlottesville, VA Lines: 63 > One thing I have yet to see addressed properly by either Aztec or > Lattice is the following: > > { > register short i, j, k; > > for (i = 0; i < 10; ++i) >> for (j = 0; j < 10; ++j) > > for (k = 0; k < 10; ++k) > > } > > I is not used while J is being used, neither I or J are being > used while K is being used, etc.... > > ONLY ONE REGISTER SHOULD BE USED FOR ALL THREE REGISTER VARIABLES!! > Well, this is a bit more complicated as it requires live/dead analysis. In brace entry/exit they have to clear the variables from the symbol table, in a proper implementation freeing register variable allocations and local variable stack space ought to be relatively easy. Virtually every C compiler I know of gets this right. Even pcc (gasp). To some degree you can use this 'basic' feature to get good register allocation in the absense of a good register allocator. This is what really miffs me about Lattice's screw up. > :Or how bout this: > : > : { short i[100]; > : i[0] = 12; > : } > : > : You would expect the space for i on the stack to be freed after the last > : brace for re-use. Nope. > > Actually, no. Usually, stack space is overlayed: > Apologies for obscure terminology. The compiler should be maintaining the value for the stack necessary to store local variables for the routine. On exit from a set of braces any local variables should be 'freed' and thus that stack space be available for re-use. Note that when I say 'freed' I am referring to a compile time concept here not any sort of actual run-time adjustment of the stack pointer. I would expect that the high water mark of the stack space required in the routine would be allocated at runtime on entry and deallocated on exit but local variables would reuse portions of the allocated section if they are not simultaneously active or as Matt put it they should be 'overlayed'. The point remains, however, that Lattice 4.1 doesn't 'overlay' variables local to braces within the body of a routine but rather allocates space enough for every variable in the routine. This isn't as big a faux paux as the register allocation but it is generally wasteful. postnews f o o d David Albrecht