Author: Bo Persson
Date: 04:11:18 11/26/00
Go up one level in this thread
On November 26, 2000 at 04:32:21, Severi Salminen wrote:
>Hi!
>
>I use Bit Scan Forward and Bit Scan Reverse in my chess program to find indexes
>of bits. Does it take longer (On pentium or Athlon PC) to find a bit which is
>further than near the beginning of search? If I have a rook standing at a8
>(which is position 63 in my program) should I use BSR instead of BSF?
Old Pentium & Pentium MMX have these instructions microcoded, so they are very
slow. If I remember correctly it is 11 + 2n clocks, where n is number of zeros
skipped while looking for the next 1. AMD K6 and Athlon are also rather slow,
but I have no numbers.
Pentium II/III and Celeron have dedicated hardware for BSR and BSF so they
execute the instructions in 1 or 2 clock ticks, independent of the number of 1s
and 0s in the data.
> So, should
>I have separate functions to start the scanning from LSB end and MSB end or
>could I use the same function?
It doesn't matter much speedwise, but sometimes you might want to get the pieces
in a specific order. Like, in the evaluation functions I scan pawns from front
to back rank, using a different order for light and dark pawns.
>Is there any way to specify an inline assembler macro which returns a value? Now
>I'm using a function. I'm using VC6++ Ent.
// warning C4035: 'BSR' : no return value
#pragma warning(disable : 4035)
inline unsigned BSR(const unsigned Bits)
{
__asm bsr eax,[Bits]
}
inline unsigned BSF(const unsigned Bits)
{
//__asm mov eax,[Bits]
//__asm bsf eax,eax
__asm bsf eax,[Bits]
}
#pragma warning(default : 4035)
inline SQUARE BitBoard::GetHighMember()
{
if (Half[1] != 0)
{
const unsigned BitFound = BSR(Half[1]);
Half[1] ^= (1 << BitFound);
return static_cast<SQUARE>(BitFound + 4 * FILES);
}
else
{
const unsigned BitFound = BSR(Half[0]);
Half[0] ^= (1 << BitFound);
return static_cast<SQUARE>(BitFound);
}
} /* GetHighMember */
inline SQUARE BitBoard::GetLowMember()
{
if (Half[0] != 0)
{
const unsigned BitFound = BSF(Half[0]);
Half[0] &= Half[0] - 1;
return static_cast<SQUARE>(BitFound);
}
else
{
const unsigned BitFound = BSF(Half[1]);
Half[1] &= Half[1] - 1;
return static_cast<SQUARE>(BitFound + 4 * FILES);
}
} /* GetLowMember */
>Severi
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.