Author: Andreas G. Nowatzyk
Date: 14:47:04 02/03/00
Go up one level in this thread
On February 03, 2000 at 06:36:55, Tijs van Dam wrote:
>On February 02, 2000 at 21:57:27, Michael Neish wrote:
>
>>
>>Excuse me if I gripe. I just spent two months converting my program to
>>bitboards and when I finally removed all the obvious bugs I find it's searching
>>about 30% slower than the original routine, which just used simple arrays and
>>loops to generate moves, a la TCSP.
>>
>>So where does the magic of bitboards come alive? It's certainly not in my case.
>>
>>Cheers,
>>
>>Mike.
>
>For me, the big change came when, instead of
>
>inline int CountOnes(BitBoard b)
>{
> int n=0;
> while(b)
> {
> if(b&1)n++;
> b>>=1;
> }
> return n;
>}
>
>I wrote:
>
>inline int CountOnes(BitBoard b)
>{
> register int i=0;
> while(b)
> {
> i++;
> b&=b-1; // b &= b-1 clears least significant bit
> }
> return i;
>}
>
>
>I use a few CountOnes in the evaluation function. Speed increased almost 300%!
>The calculation methods and update routines are VERY important...
>
>Grts
>Tijs
On alpha's the fastest way to count 1s in a 64 bit word is:
unsigned CountOnes(unsigned long t)
{
unsigned long x, y;
y = (t >> 1) & 0x7777777777777777;
x = (y >> 1) & 0x7777777777777777;
x = t - y - x - ((x >> 1) & 0x7777777777777777);
return ((x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f) % 255;
}
if you are sure that there will never be more than 62 ones, there
is a simple version of this:
unsigned Ones(unsigned long x) /* HACKMEM 169 */
{
unsigned long y;
y = (x >> 1) & 01333333333333333333333;
y = x - y - ((y >> 1) & 01333333333333333333333);
y = (y + (y >> 3)) & 0707070707070707070707;
return y % 63;
}
(the original idea for this code originates from antic mainframe software)
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.