1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-29 16:23:09 +00:00

Optimize pop_1st_bit() on 32 bits x86

Operations on 64 bits Bitboard types are slow
on x86 compiled with gcc, so optimize this case.

BTW profiling shows that pop_1st_bit() is a
veeery performance critical path!

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2008-09-18 16:09:19 +02:00
parent 95ce27f926
commit 9ae2b69235

View file

@ -339,6 +339,26 @@ Square first_1(Bitboard b) {
/// pop_1st_bit() finds and clears the least significant nonzero bit in a
/// nonzero bitboard.
#if defined(USE_32BIT_ATTACKS)
Square pop_1st_bit(Bitboard *bb) {
uint32_t t = uint32_t(*bb);
uint32_t* p = t ? (uint32_t*)bb : (uint32_t*)bb + 1; // Little endian only?
uint32_t b = t ? t : *p;
*p = b & (b -1);
if (t)
b ^= (b - 1);
else
b = ~(b ^ (b - 1));
return Square(BitTable[(b * 0x783a9b23) >> 26]);
}
#else
Square pop_1st_bit(Bitboard *b) {
Bitboard bb = *b ^ (*b - 1);
uint32_t fold = int(bb) ^ int(bb >> 32);
@ -346,6 +366,8 @@ Square pop_1st_bit(Bitboard *b) {
return Square(BitTable[(fold * 0x783a9b23) >> 26]);
}
#endif
#else
static const int BitTable[64] = {