Author: Vincent Diepeveen
Date: 06:42:44 09/03/01
Go up one level in this thread
On September 02, 2001 at 12:25:44, Dieter Buerssner wrote: >I think, one shouldn't use global variable, when not really needed. > >Usually local variables are faster, because they can be stored in registers. >The optimize can often not store global variable in registers on the PC >architecture. Also, it often cannot store them in registers, because it cannot >(easily) prove, that the values are unchanged. Assume > > for (i=0; i<N; i++) > func(); > >With i global, the compiler cannot know, if func() actually changes i. With a >local i, the compiler know, that i will not be changed by func(), and it can >store it in a register, that is not changed by a function call. > >On the PC-architecture there are only few free registers. So, for any slightly >complicated function, the optimizer has to do some guesswork, which variable are Nowadays P3, K7 processors have loads of registers, but most are only accessible by register renaming, so using loads of local variables is not a big problem. the problem lies always in the compilers. From head i remember P3 has like 44 registers available for register renaming and K7 has like 64 registers from 32 bits available for that. >best kept in registers. Often it will do this of course not in an optimal way. >In this case, using some global variable, may help the compiler to do some >better guessing. But a small modification to the code may yield again in >different results. > >Another point is, where the data is actually stored. Adding some global data, >may yield in better or worse cache efficiency. Again, a slight modification may >make things totally different again. > >Regards, >Dieter
This page took 0.01 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.