Computer Chess Club Archives


Search

Terms

Messages

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

Author: Uri Blass

Date: 09:17:23 12/05/01

Go up one level in this thread


On December 05, 2001 at 11:53:28, Miguel A. Ballicora wrote:

>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
>
>If I have to bet, I'll say you have a cache problem. Generally, there is a huge
>penalty for accessing (consecutively) two variables that are close to 8192 bytes
>apart (the size of cache). IIRC I've read that reading variables that are close
>to 4096 bytes apart might also give a little penalty (I do not remember now
>why). As general rule, jumping 2^n bytes is not good and there are some
>n that are worse.
>You access side and kingsquare that are roughly 4096 bytes apart.
>Test it with this definitions, putting together side and kingsquare so they
>will be in the same cache line (32 bytes).
>
>int info[64];
>int side;
>int kingsquare[2];
>int direction[64][64];
>int pin[64];

I did not think that the order of the definition is important so I did not copy
exactly the order of my definitions

I have also a lot of other variables in the middle
I already deleted the relevant function and replaced it by a better function so
I cannot test it but here is the list of the relevant variables and all the
knowledge between them(it is not the full list of my variables and I have
variables after int pin[64])

gen_t and hist_t are based on TSCP and I can delete some unnecesary information
that isnot used to calculate perft(for example in fifty from hist_t)

I believe that I increased the value of some constants from TSCP because I was
not happy with them and I was afraid that they may be too small.

It may be possible that I can do the program faster by reducing them and I did
not try it.


int info[64];
int side;
gen_t gen_dat[GEN_STACK];
int ply;
int hply;
hist_t hist_dat[HIST_STACK];
int first_move[MAX_PLY];
int rightdown[64];
int leftdown[64];
int rightup[64];
int leftup[64];
int knightmove[64][8];
int kingmove[64][8];
int ep[3];
int castle;
int kingsquare[2];
int fifty;
int direction[64][64];
int kingincheck;
int pin[64];


#define GEN_STACK 11200
#define MAX_PLY 500
#define HIST_STACK 4000

typedef struct
{
	char from;
	char to;
	char promote;
	char bits;
}
move_bytes;

typedef union
{
	move_bytes b;
	int u;
}
move;
/* an element of the move stack.it's just a move with a
 score,so it can be sorted by the search functions.*/
typedef struct
{
	move m;
	int index;
}
gen_t;

typedef struct
{
   move m;
   int capture;
   int castle;
   int ep[3];
   int fifty;
   int kingincheck;
   int checkingsquare;
}
hist_t;


Uri



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.