Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: speed question

Author: Tom Likens

Date: 07:51:04 02/19/03

Go up one level in this thread


On February 19, 2003 at 09:41:35, Dezhi Zhao wrote:

>On February 19, 2003 at 06:39:49, Uri Blass wrote:
>
>>I try to do movei faster and there are things that are supposed to do it
>>slightly faster but for some reasons do it slower so I deleted them(Maybe it is
>>better if I ignore it because it is a compiler optimization noise but I do not
>>like to see the program slower even if it is only 0.1% slower).
>>
>>Note that I do not use now compiler optimization except optimize for speed with
>>visual C++6.
>>
>>
>>Here is an example:
>>My function of adding pawn moves to the stack of moves get 2 numbers(from,to).
>>
>>I found that special functions to generate white moves one square forward,white
>>moves 2 pawns forward,black pawns one square forward,...helped me to do movei
>>faster.
>>
>>Common sense say that now I do not need 2 numbers in my functions because
>>I always have to=from-8 in
>>
>>Here is my function.
>>to is always from-8 and the question is if I can take advantage of that fact.
>>
>>static void gen_quietblackslowpawns(int from,int to)
>>{
>>	gen_t *g;
>>	if (to<=7)
>>	{
>>		gen_promote(from,to);
>>		return;
>>	}
>>	g=&gen_dat[first_move[ply+1]++];
>>	g->m.b.from=(char)from;
>>	g->m.b.to=(char) to;
>>	g->m.b.promote=0;
>>	g->m.b.bits=16;
>>	#if MODE!=MODE_PERFT
>>	g->score = history[from][to];
>>	g->index=-10000;
>>    #endif
>>}
>
>I think you can get a little from that fact. It will save a few push and pop
>operations.
>
>By the way, if you really want to optimize this function, you should consider
>re-designing the b structure so that the move can be saved in a single write
>operation, instead of 4.  After this optimization, you may find out this
>function is too small and fast to be a function entity, and get it inlined.

Uri,

One of the things I did to speed this up in my program was to store a
move in an unsigned integer and use bit operations (shifts, ANDs, ORs)
to access the various fields.  For example, I stored the 'from/to' fields
in the lower 12-bits and then declared my history arrays as

w_history[4096]
b_history[4096]

instead of w_history[64][64].  Then when I wanted to update one of
the arrays, it was just a simply AND operation to get the index into
the table.  Also copying moves becomes much faster, etc.

regards,
--tom



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.