Author: Gerd Isenberg
Date: 12:44:12 11/28/03
Go up one level in this thread
On November 28, 2003 at 14:37:15, scott farrell wrote:
>My poor chompster is Java, and is bitboard based.
>
>I moved to incremental attackTables, and have a attackFrom[64] and attackTo[64]
>arrays of bitboards.
>
>Actually doing them incremently didnt give much performance difference over
>calculating the whole let each node - but I think my msb is so slow, everything
>is slow.
>
>I either need
>- a much faster msb function, it takes about 35% of my processing time.
>- a smarter way of making the attackTo array, as I am currently using msb to
>iterate/popoff bits from the attackFrom bitboard, and then OR them indiviually
>to the appropriate attackTo[] bitboard. Hence lots of slow msb calls.
>- remove the attackTo array, and compute forward when necessary with the
>attackFrom bitboards as I did before (which was fairly fast).
>
>Maybe Mr Grok (Peter Knappler) is listening and can help.
>
>I guess I would love some of those assembler msb's you C guys use, but I dont
>know that is possible with java.
>
>My current msb function is below for reference.
>
>
> * Returns the integer position of the Most Significant Bit in the 64-bit long.
> * Uses a pre-calculated, 65,536 byte lookup table for speed.
> *
> * @return Value from 0 to 63, specifying the location of the bit.
> */
>//msb
> public static int msb(long bitboard){
> if (bitboard==0)
> return -1;
> int w = (int)((bitboard >>> 48) & 65535);
> if (w != 0){
> return msb_table[w]+48;
> }
>
> w = (int)((bitboard >>> 32) & 65535);
> if (w != 0){
> return msb_table[w]+32;
> }
>
> w = (int)((bitboard >>> 16) & 65535);
> if (w != 0){
> return msb_table[w]+16;
> }
>
> w = (int)(bitboard & 65535);
> if (w != 0){
> return msb_table[w];
> }
>
> return -1;
> }
>
>thanx
>Scott
Hi Scott,
no idea how fast unsigned shift is in Java, but instead of
int w = (int)((bitboard >>> 48) & 65535);
if (w != 0) {
return msb_table[w]+48;
}
if would prefere
if ( (bitboard & (65535<<48)) != 0 )
{
int w = (int)(bitboard >>> 48); // and is not necessary for >>> 48;
return msb_table[w]+48;
}
That saves a shift if the word is zero. I guess (65535<<48) is precalculated as
long constant by the Java-compiler, otherwise you should use hex constants like
0xffff000000000000.
Then you have one tautology, the last "if (w != 0)" is always true.
I suggest binary divide like this:
if ( bitboard == 0 )
return -1;
if ( (bitboard & 0xffffffff00000000) != 0 )
{
int w = (int)(bitboard >>> 32);
if ( (w & 0xffff0000) != 0 )
return msb_table[w>>>16]+48;
else
return msb_table[w]+32;
}
else
{ // the lower 32 bit
int w = (int) bitboard;
if ( (w & 0xffff0000) != 0 )
return msb_table[w>>>16]+16;
else
return msb_table[w];
}
Gerd
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.