Author: Gerd Isenberg
Date: 10:48:01 06/13/04
Go up one level in this thread
On June 13, 2004 at 12:32:37, milix wrote:
>UINT32 WalterFaxonsMagicBitscan(BitBoard &bb)
>{
> BitBoard t64;
> UINT32 t32;
> t64 = bb - 1;
> bb &= t64; // omit this line to retain current LSB
> t64 ^= bb;
> t32 = (UINT32)t64 ^ (UINT32)(t64 >> 32);
> t32 ^= LSB_64_magic;
> t32 += t32 >> 16;
> t32 -= t32 >> 8;
> return LSB_64_table [LSB_64_adj + t32];
>}
>
>// omit this line to retain current LSB
>is this really correct? If we omit this line we have to change the next line to
>t64 ^= (bb & t64);
Yes, you are correct.
But rather than an additional "and" one may modify the table a bit ;-)
The idea is to get a trailing one sequence behind the lsb.
By ommiting the reset line the trailing sequence includes the lsb:
bb = 0010 0100
bb-1 => t64 = 0010 0011
bb & t64 => bb = 0010 0000 lsb reset
t64 ^= bb = 0000 0011 ==> lsb-1
otherwise
bb = 0010 0100
bb-1 => t64 = 0010 0011
t64 ^= bb = 0000 0111 ==> 2*lsb-1
During postedit i deleted a BYTE cast further down.
return LSB_64_table [LSB_64_adj + (unsigned char)t32];
Sorry Walter, for disparage your name with such a buggy function ;-(
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.