This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Efficiency question


In article <7on4v2$sgr@gap.cco.caltech.edu>
           gah@ugcs.caltech.edu "glen herrmannsfeldt" writes:

>Joe Wright <conserv3@infi.net> writes:
>
>(snip)
>
>>> : As in most cases of micro-optimization (of which this is a perfect
>>> : example), it depends entirely on the compiler.  I wrote a piece of code
>>> : that rotated a bitmap.  Using automatic variables was four times slower
>>> : with this particular compiler than using global variables because of the
>>> : penalty (on this machine) for accessing data on the stack than in the
>>> : heap.
>>> 
>>Not sure what you mean by the heap.  Static memory variables are
>>addressed directly, automatics are addressed indirectly.  Automatics are
>>slower.
>
>This is entirely processor dependent.  It may be true for currently
>popular processors, but not all.

It isn't even true for processors like the Pentium or later. Calculating
a register offset takes no more time than "direct" access. It may even be
that the overall instruction size is smaller (since the offset
is generally mall) and will cache better. Also from a data point of
view automatic variables tend to have a good memory reuse and will
cache better from that perspective. This is assuming that the variables
are all local to the function. static file scope variables cause much
bigger problems for compiler optimisers due to aliasing issues and
potential accessibility from within called functions.

-- 
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]