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:
parent
95ce27f926
commit
9ae2b69235
1 changed files with 80 additions and 58 deletions
|
@ -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] = {
|
||||
|
|
Loading…
Add table
Reference in a new issue