Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: a question about speed difference that I do not understand

Author: Pham Minh Tri

Date: 16:27:47 12/05/01

Go up one level in this thread


[snip]
>A good rule is to define not more that 3-4 integers in a routine.
>

I am not really sure about that advice. I know some good compilers (like VC6.0)
could optimize using variables if it knows their values will use in local areas.

For example:
void routine (void)
{
int x,y,z;
// do something

int x2;
// do other thing with x2

int x3;
// do something with x3 but without x2

...
int xn;
// do something with xn only
}

VC6.0 could know x2 is used only in a small area and will not use any more after
that, it may use register instead and not store its value into memory (save some
maintenance circles/statements). Then it may do the same optimization for x3 and
so on. The number of integers does not matter.

That is not happened if I use only one x instead of x2, x3... xn.

Pham

>void routine (void)
>
>{ int x,y,z;         // the most used variables in the routine
>
>// do something
>
>}
>
>
>Always use "int", avoid "short" by all means. "char" can be used too but
>realize that this is processor expensive as soon as you are going to index.
>
>It will depend on the quality of the compiler if you can use 4 integers.
>
>Ed



This page took 0 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.