Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: speed question about arrays

Author: Gerd Isenberg

Date: 23:05:24 02/19/04

Go up one level in this thread


On February 19, 2004 at 17:41:26, Uri Blass wrote:

>On February 19, 2004 at 16:22:30, Gerd Isenberg wrote:
>
>>On February 19, 2004 at 14:39:16, Uri Blass wrote:
>>
>>>Today I have an array direction[64][64] that gives me different numbers for
>>>different directions(possible directions are queen direction that get 0-7 knight
>>>directions that get -2,identical squares that get -9 or no direction that gets
>>>-1 ).
>>>
>>>I thought about the idea to change it to the following definition:
>>>
>>>#define direction((i)(j)) directionnumber[translate[i]-translate[j]+128]
>>>
>>>The result is that I can get instead of one array of 4096 entries
>>>2 arrays when translate is an array of 64 entries and directionnumber is an
>>>array of 256 entries.
>>>
>>>My question is if it is a good idea from speed point of view.
>>>It will probably be a simple change when I only need to construct the 2 arrays
>>>and the main problem is to construct the translate array.
>>>
>>>It is probably only few hours of work but I do not like to spend time on
>>>constructing these arrays only to discover later that it is not productive so I
>>>ask for your opinion about it.
>>>
>>>Uri
>>
>>Only some few more aspects in addition to Bob's answer ....
>>
>>If it is frequently used eg. with generated moves, i would say the extra memory
>>references and instructions don't pay off. It may even be faster with a 16KByte
>>4096-int-array.
>
>I see that it is not very frequently used in generating moves.
>
>It is used in my genout_of_check function but I think that I can replace it.
>
>for  example:
>
>if  (direction[square][target]<4) can be replaced by
>if ((fil0(square)==fil0(target))||(rank0(square)==rank0(target)) because in the
>releavant case it is a king move and I want to check if the king moves to rook
>direction(note that I jave special array for kingmoves so I do a loop on all the
>squares that the king maybe can goto:
>when I generate king moves
>my move generator starts with
>
>for (k=0;k<kingnumber[square];k++)
>{
>  target=kingmove[square][k];
>
>>
>>I often found arrays of packed structs favorably with such 64*64 arrays with low
>>ranges (eg. distance, taxidistance, unique distance relationship (see links
>>below) or direction).
>
>I aam not sure if I understand
>Do  you say that you found an array as faster than using macros?

yes, i found an array of 4-byte structs faster (16KByte) on Athlon32.
Even with unconditional abs and max.

	struct	SUDRDistance
	{
		BYTE	dist;
		BYTE	taxi;
		BYTE	udr;
		BYTE	vec; // implies direction
	};

SUDRDistance sDist[64][64];



>
>I use today abs and max to calculate Distance and I do not use 64*64 array.
>Do you suggest that it is probably better to use arrays?
>

With conditional compiled macros it is easy to try lookup versus computation.
If you have nothing better to do you may try it ;-)

Gerd



>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.