Computer Chess Club Archives


Search

Terms

Messages

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

Author: Ulrich Tuerke

Date: 03:36:59 12/05/01

Go up one level in this thread


On December 05, 2001 at 05:33:08, Uri Blass wrote:

>In my program I have the following commands when I generate my pin arrays:
>
>if (color(sq)==side)
>{
>   pin[sq]=-1;
>   d=direction[kingsquare[color(sq)]][sq];
>...
>
>The strange speed demage to my program happens when I try to replace color(sq)
>with side in the last line
>
>color(sq) is more complicated to find  then finding side that is simply integer.
>I expected that in the worst case there will be no speed change thanks to
>optimazion of compiler but I did not imagine that my program could run slower
>when I do something simpler.
>
>some data about my program that may help:
>
>
>
>my defs.h file includes
>
>#define color(target) (((info[target])>>3)&3)
>
>
>my data.c file includes
>
>int info[64];
>int side;
>int direction[64][64];
>int kingsquare[2];
>int pin[64];
>
>you can see that calculating color(sq) is not something simple(you need first to
>calculate info[sq] and later to calculate from it the value for color(sq))
>
>Uri


Perhaps the data types could be a reason for some microscopic effects. If the
variable "side" is for instance of type "short", the compiler has to zero-extend
the variable to word-size before indexing (because of the array access).

OTOH, the result of the expression is perhaps still stored in a hardware
register, and so has the right size to be used for indexing immediately.

Just a guess. I think that your observation may be also depend on implementation
details of the compiler in use. Another compiler might behave different.

Uli



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