mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Micro-optimize pop_1st_bit() for 32 bits
Small perft speed-up of 2% and also a code simplification. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
7b4b65d7a9
commit
3b906ffc27
1 changed files with 10 additions and 16 deletions
|
@ -112,7 +112,7 @@ Square first_1(Bitboard b) {
|
||||||
// Use type-punning
|
// Use type-punning
|
||||||
union b_union {
|
union b_union {
|
||||||
|
|
||||||
Bitboard b;
|
Bitboard dummy;
|
||||||
struct {
|
struct {
|
||||||
#if defined (BIGENDIAN)
|
#if defined (BIGENDIAN)
|
||||||
uint32_t h;
|
uint32_t h;
|
||||||
|
@ -121,27 +121,21 @@ union b_union {
|
||||||
uint32_t l;
|
uint32_t l;
|
||||||
uint32_t h;
|
uint32_t h;
|
||||||
#endif
|
#endif
|
||||||
} dw;
|
} b;
|
||||||
};
|
};
|
||||||
|
|
||||||
Square pop_1st_bit(Bitboard* bb) {
|
Square pop_1st_bit(Bitboard* b) {
|
||||||
|
|
||||||
b_union u;
|
const b_union u = *((b_union*)b);
|
||||||
Square ret;
|
|
||||||
|
|
||||||
u.b = *bb;
|
if (u.b.l)
|
||||||
|
|
||||||
if (u.dw.l)
|
|
||||||
{
|
{
|
||||||
ret = Square(BSFTable[((u.dw.l ^ (u.dw.l - 1)) * 0x783A9B23) >> 26]);
|
((b_union*)b)->b.l = u.b.l & (u.b.l - 1);
|
||||||
u.dw.l &= (u.dw.l - 1);
|
return Square(BSFTable[((u.b.l ^ (u.b.l - 1)) * 0x783A9B23) >> 26]);
|
||||||
*bb = u.b;
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
ret = Square(BSFTable[((~(u.dw.h ^ (u.dw.h - 1))) * 0x783A9B23) >> 26]);
|
|
||||||
u.dw.h &= (u.dw.h - 1);
|
((b_union*)b)->b.h = u.b.h & (u.b.h - 1);
|
||||||
*bb = u.b;
|
return Square(BSFTable[((~(u.b.h ^ (u.b.h - 1))) * 0x783A9B23) >> 26]);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !defined(USE_BSFQ)
|
#endif // !defined(USE_BSFQ)
|
||||||
|
|
Loading…
Add table
Reference in a new issue