Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: speed question

Author: Filip Tvrzsky

Date: 08:06:15 02/19/03

Go up one level in this thread


On February 19, 2003 at 09:57:13, Uri Blass wrote:

>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.
>
>Thanks for the advise but how do I do it
>
>I have the same data structure as tscp here(Note that 90% of my code is
>different than tscp but I copied part of it's data structures).
>
>Here is my b structure
>
>typedef struct
>{
>	char from;
>	char to;
>	char promote;
>	char bits;
>}
>move_bytes;
>
>typedef union
>{
>	move_bytes b;
>	int u;
>}
>move;
>
>
>I can think about deleting the b and have something like
>g->m.u=from+(to<<8)+(promote<<16)+bits<<24) but the question in that case is if
>it is not going to do accesing the varaibles slower because there are places in
>the code when I use bits and now I will need to use things like u>>24.
>
>I have no idea about the price of these things so I cannot evaluate speed here.
>
>Uri

My own personal experience says that the storing and accesing all move
information together in one 32bit variable has made my engine faster though I
can't just remember how much exactly. You can still read only that part of
information which you need like this :

 char from = *(((char*) &move) + 1),

but I guess there will be no gain compared to ((move>>8) & 0xff). Once you have
the move stored in the register its shifting or ORing or ANDing isn't much
expensive. I have rewrote my Make_move() and Unmake_move() functions in assembly
to profit from this approach, so I have to read the move from memory one time
only there. I store in it the sort of moved (eventually captured and promoted)
piece as well, thus I don't need to acces the Board array to get this
information. And finally, it was quite a fun to play with these all bits.

Filip






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.