Re: Optimization Question

rkrayhawk@aol.com (RKRayhawk)
31 Jul 2000 23:50:13 -0400

          From comp.compilers

Related articles
Optimization Question braung@ert.rwth-aachen.de (Gunnar Braun) (2000-07-27)
Re: Optimization Question gunnar@moria.net.dhis.org (Gunnar Braun) (2000-07-30)
Re: Optimization Question rkrayhawk@aol.com (2000-07-31)
Re: Optimization Question chase@naturalbridge.com (David Chase) (2000-08-04)
| List of all articles for this month |

From: rkrayhawk@aol.com (RKRayhawk)
Newsgroups: comp.compilers
Date: 31 Jul 2000 23:50:13 -0400
Organization: AOL http://www.aol.com
References: 00-07-074
Keywords: optimize

Your code displays good practices: for example, your auto variables declared as


long SavedLine = 0;
char SavedTableNr = 0;


are being initialized upon each entry to the routine shown. That is
nice and you should stay on the path of creating code in that fashion,
... but... you asked for optimization ideas...


The init is not free, the compiler must get zeroes into those autos
somehow (CPU time on each invocation of the routine). With the code
shown it actually appears to be entirely safe to not initialize
them. This is true since they are always set to some exact specific
value before use, by one of the set of statement pairs


          SavedLine = m_CurrentLine;
            SavedTableNr = m_TableNr;


If you have shown all of the code, then the inits can be safely
removed. There is more though. It is probably possible to eliminate
one of those two SavedXYZ variable.


The multiple indexes is costing you. Some tricks available depend upon
your compiler. For example, an even dimension is faster then an odd
one sometimes. (So if you happen to have an odd dimension, add a row
or column to get it even, and see if the emitted code looks better to
you).


And it can be easy for the compiler to optimize if you have separate
arrays for things like


TargetTableNo;
and
TargetTableIndex;


instead of an array of structures. This affords the compiler atleast a
chance to engage the built in functions of CPUs to increment by
1/2/4/8 bytes. Usually structures are too long to allow the compiler
to do that, instead explicit addition must be used to bump to the next
occurence.


Otherwise, generally, maybe try a single dimensional array, and calc
the index, once, as x*width + y, and then use that single index into
any array (the multiply is likely to cost you, though).


Hope that helps,


Robert Rayhawk
RKRayhawk@aol.com


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.