Author: Leen Ammeraal
Date: 04:13:40 01/23/02
Go up one level in this thread
Thanks. I have been using this routine for a long time
without having a clue how it works. Your explanation
was very helpful, as was that from Tom Kerrigan.
Leen
On January 23, 2002 at 00:22:12, Robert Hyatt wrote:
>The idea is very simple. Test the end of the 64 bit value that has
>bits 32-63 with a bit scan instruction (which will give a result of
>0-31. Add 32 to this to adjust to 32-63. Now test the other end. If
>the bit scan finds no bits set, it will leave the dest register unchanged
>which leaves the result of your high-order end in there. If it does find
>a bit set (0-31) it will overwrite the destination and the result will be
>0-31.
>
>Works well. Not quite so easy to do for "hibit" as a branch is going to
>be necessary...
>
>
>>
>>>>
>>>>__forceinline
>>>>int FirstPiece(BITBOARD bits)
>>>>{
>>>>// Given is: bits != 0
>>>>__asm {
>>>>; 64-bit number to move into ECX:EBX, will never be zero!
>>>> mov ecx,dword ptr [bits+4]
>>>> mov ebx,dword ptr [bits]
>>>> bsf eax,ecx
>>>> add eax,32
>>>> bsf eax,ebx
>>>> }
>>>>}
>>>>
This page took 0.01 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.