X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fbitboard.h;h=6aa35874df7d3a244a8be9a919c81e09cc46105e;hp=cc039397e3330728022f22c2905891a20849a343;hb=55bd27b8f08a151128d7065fa2819aa3e9605299;hpb=2f47844c7cb34c7de5b5d41cda10b7d8736a20bc diff --git a/src/bitboard.h b/src/bitboard.h index cc039397..6aa35874 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -25,8 +25,15 @@ namespace Bitboards { -extern void init(); -extern void print(Bitboard b); +void init(); +void print(Bitboard b); + +} + +namespace Bitbases { + +void init_kpk(); +uint32_t probe_kpk(Square wksq, Square wpsq, Square bksq, Color stm); } @@ -50,6 +57,7 @@ extern Bitboard ThisAndAdjacentFilesBB[8]; extern Bitboard InFrontBB[2][8]; extern Bitboard StepAttacksBB[16][64]; extern Bitboard BetweenBB[64][64]; +extern Bitboard DistanceRingsBB[64][8]; extern Bitboard ForwardBB[2][64]; extern Bitboard PassedPawnMask[2][64]; extern Bitboard AttackSpanMask[2][64]; @@ -220,51 +228,67 @@ inline Bitboard attacks_bb(Square s, Bitboard occ) { } -/// first_1() finds the least significant nonzero bit in a nonzero bitboard. -/// pop_1st_bit() finds and clears the least significant nonzero bit in a -/// nonzero bitboard. +/// lsb()/msb() finds the least/most significant bit in a nonzero bitboard. +/// pop_lsb() finds and clears the least significant bit in a nonzero bitboard. #if defined(USE_BSFQ) -#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) +# if defined(_MSC_VER) && !defined(__INTEL_COMPILER) -FORCE_INLINE Square first_1(Bitboard b) { +FORCE_INLINE Square lsb(Bitboard b) { unsigned long index; _BitScanForward64(&index, b); return (Square) index; } -FORCE_INLINE Square last_1(Bitboard b) { +FORCE_INLINE Square msb(Bitboard b) { unsigned long index; _BitScanReverse64(&index, b); return (Square) index; } -#else -FORCE_INLINE Square first_1(Bitboard b) { // Assembly code by Heinz van Saanen - Bitboard dummy; - __asm__("bsfq %1, %0": "=r"(dummy): "rm"(b) ); - return (Square) dummy; +# elif defined(__arm__) + +FORCE_INLINE int lsb32(uint32_t v) { + __asm__("rbit %0, %1" : "=r"(v) : "r"(v)); + return __builtin_clz(v); } -FORCE_INLINE Square last_1(Bitboard b) { - Bitboard dummy; - __asm__("bsrq %1, %0": "=r"(dummy): "rm"(b) ); - return (Square) dummy; +FORCE_INLINE Square msb(Bitboard b) { + return (Square) (63 - __builtin_clzll(b)); } -#endif -FORCE_INLINE Square pop_1st_bit(Bitboard* b) { - const Square s = first_1(*b); - *b &= ~(1ULL<> 32))); +} + +# else + +FORCE_INLINE Square lsb(Bitboard b) { // Assembly code by Heinz van Saanen + Bitboard index; + __asm__("bsfq %1, %0": "=r"(index): "rm"(b) ); + return (Square) index; +} + +FORCE_INLINE Square msb(Bitboard b) { + Bitboard index; + __asm__("bsrq %1, %0": "=r"(index): "rm"(b) ); + return (Square) index; +} + +# endif + +FORCE_INLINE Square pop_lsb(Bitboard* b) { + const Square s = lsb(*b); + *b &= ~(1ULL << s); return s; } #else // if !defined(USE_BSFQ) -extern Square first_1(Bitboard b); -extern Square last_1(Bitboard b); -extern Square pop_1st_bit(Bitboard* b); +extern Square msb(Bitboard b); +extern Square lsb(Bitboard b); +extern Square pop_lsb(Bitboard* b); #endif