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

Final touches to pop_1st_bit optimization

This final version is a little bit faster then
previous patch and is a bit cleaned up also.

On 32 bit x86 pop_1st_bit is now more then
two times faster then the original one that
is optimized for 64 bit processors.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2008-09-19 05:33:55 +02:00
parent 9ae2b69235
commit 1373a00187

View file

@ -343,18 +343,16 @@ Square first_1(Bitboard b) {
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;
uint32_t a = uint32_t(*bb);
uint32_t* ptr = a ? (uint32_t*)bb : (uint32_t*)bb + 1; // Little endian only?
uint32_t b = a ? a : *ptr;
uint32_t c = ~(b ^ (b - 1));
*p = b & (b -1);
*ptr = b & c; // clear the bit
if (a)
c = ~c;
if (t)
b ^= (b - 1);
else
b = ~(b ^ (b - 1));
return Square(BitTable[(b * 0x783a9b23) >> 26]);
return Square(BitTable[(c * 0x783a9b23) >> 26]);
}
#else