Author: Steve Maughan
Date: 04:59:39 07/02/03
I currently use the routines shown at the bottom to locate the the first set
bit. Many times I'm also clearing the same bit using the "a &= (a-1)". So the
natural question is - has anyone developed efficient BSF and Clear assembler
routines? Since BSF is easier than BSR to implement in 64 bit I'm only looking
for a BSF and Clear and not the equivalent BSR.
Ideally, the routine should take a pointer to the bitboard (unsigned 64 bit int)
and return the index of the first bit as well as clearing it.
Thanks,
Steve
int bsf(bitboard a)
{__asm
{
bsf eax, dword ptr[a + 4]
add eax, 32
bsf eax, dword ptr[a]
}
}
int bsr(bitboard a)
{ __asm
{
bsf edx, dword ptr a
mov eax, 63
jnz l1
bsf edx, dword ptr a+4
mov eax, 31
jnz l1
mov edx, -33
l1: sub eax, edx
}
}
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.