diff --git a/src/bitbase.cpp b/src/bitbase.cpp index 8433f0c6b..29a012d27 100644 --- a/src/bitbase.cpp +++ b/src/bitbase.cpp @@ -84,6 +84,7 @@ bool Bitbases::probe(Square wksq, Square wpsq, Square bksq, Color us) { void Bitbases::init() { +#ifndef LARGEBOARDS std::vector db(MAX_INDEX); unsigned idx, repeat = 1; @@ -101,6 +102,7 @@ void Bitbases::init() { for (idx = 0; idx < MAX_INDEX; ++idx) if (db[idx] == WIN) KPKBitbase[idx / 32] |= 1 << (idx & 0x1F); +#endif } diff --git a/src/bitboard.h b/src/bitboard.h index 27870c389..64cd4e4a4 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -372,7 +372,11 @@ inline int popcount(Bitboard b) { #elif defined(_MSC_VER) || defined(__INTEL_COMPILER) +#ifdef LARGEBOARDS + return (int)_mm_popcnt_u64(uint64_t(b >> 64)) + (int)_mm_popcnt_u64(uint64_t(b)); +#else return (int)_mm_popcnt_u64(b); +#endif #else // Assumed gcc or compatible compiler @@ -417,15 +421,41 @@ inline Square msb(Bitboard b) { inline Square lsb(Bitboard b) { assert(b); unsigned long idx; +#ifdef LARGEBOARDS + if (uint64_t(b)) + { + _BitScanForward64(&idx, uint64_t(b)); + return Square(idx); + } + else + { + _BitScanForward64(&idx, uint64_t(b >> 64)); + return Square(idx + 64); + } +#else _BitScanForward64(&idx, b); return (Square) idx; +#endif } inline Square msb(Bitboard b) { assert(b); unsigned long idx; +#ifdef LARGEBOARDS + if (b >> 64) + { + _BitScanReverse64(&idx, uint64_t(b >> 64)); + return Square(idx + 64); + } + else + { + _BitScanReverse64(&idx, uint64_t(b)); + return Square(idx); + } +#else _BitScanReverse64(&idx, b); return (Square) idx; +#endif } #else // MSVC, WIN32 @@ -434,24 +464,49 @@ inline Square lsb(Bitboard b) { assert(b); unsigned long idx; +#ifdef LARGEBOARDS + if (b << 96) { + _BitScanForward(&idx, uint32_t(b)); + return Square(idx); + } else if (b << 64) { + _BitScanForward(&idx, uint32_t(b >> 32)); + return Square(idx + 32); + } else if (b << 32) { + _BitScanForward(&idx, uint32_t(b >> 64)); + return Square(idx + 64); + } else { + _BitScanForward(&idx, uint32_t(b >> 96)); + return Square(idx + 96); + } +#else if (b & 0xffffffff) { - _BitScanForward(&idx, int32_t(b)); + _BitScanForward(&idx, uint32_t(b)); return Square(idx); } else { - _BitScanForward(&idx, int32_t(b >> 32)); + _BitScanForward(&idx, uint32_t(b >> 32)); return Square(idx + 32); } +#endif } inline Square msb(Bitboard b) { assert(b); unsigned long idx; +#ifdef LARGEBOARDS + if (b >> 96) { + _BitScanReverse(&idx, uint32_t(b >> 96)); + return Square(idx + 96); + } else if (b >> 64) { + _BitScanReverse(&idx, uint32_t(b >> 64)); + return Square(idx + 64); + } else +#endif if (b >> 32) { - _BitScanReverse(&idx, int32_t(b >> 32)); + _BitScanReverse(&idx, uint32_t(b >> 32)); return Square(idx + 32); } else { - _BitScanReverse(&idx, int32_t(b)); + _BitScanReverse(&idx, uint32_t(b)); return Square(idx); } }