mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-22 01:56:58 +08:00
Rewrite bsfq management
Use compiler intrinsics when possible to avoid writing platform specific asm code. Tested on Windows 7 with MSVC 2013 and mingw 4.8.3 (32 and 64 bit) and on Linux Mint with g++ 4.8.4 and clang 3.4 (32 and 64 bit). No functional change Resolves #609
This commit is contained in:
committed by
Joona Kiiski
parent
24dac5ccd3
commit
db4b0d8b7d
@@ -259,9 +259,12 @@ inline Bitboard attacks_bb(Piece pc, Square s, Bitboard occupied) {
|
||||
|
||||
/// lsb() and msb() return the least/most significant bit in a non-zero bitboard
|
||||
|
||||
#ifdef USE_BSFQ
|
||||
#if defined(__GNUC__)
|
||||
|
||||
# if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
|
||||
inline Square lsb(Bitboard b) { return Square(__builtin_ctzll(b)); }
|
||||
inline Square msb(Bitboard b) { return Square(63 - __builtin_clzll(b)); }
|
||||
|
||||
#elif defined(_WIN64) && defined(_MSC_VER)
|
||||
|
||||
inline Square lsb(Bitboard b) {
|
||||
unsigned long idx;
|
||||
@@ -275,38 +278,9 @@ inline Square msb(Bitboard b) {
|
||||
return (Square) idx;
|
||||
}
|
||||
|
||||
# elif defined(__arm__)
|
||||
#else
|
||||
|
||||
inline int lsb32(uint32_t v) {
|
||||
__asm__("rbit %0, %1" : "=r"(v) : "r"(v));
|
||||
return __builtin_clz(v);
|
||||
}
|
||||
|
||||
inline Square msb(Bitboard b) {
|
||||
return (Square) (63 - __builtin_clzll(b));
|
||||
}
|
||||
|
||||
inline Square lsb(Bitboard b) {
|
||||
return (Square) (uint32_t(b) ? lsb32(uint32_t(b)) : 32 + lsb32(uint32_t(b >> 32)));
|
||||
}
|
||||
|
||||
# else // Assumed gcc or compatible compiler
|
||||
|
||||
inline Square lsb(Bitboard b) { // Assembly code by Heinz van Saanen
|
||||
Bitboard idx;
|
||||
__asm__("bsfq %1, %0": "=r"(idx): "rm"(b) );
|
||||
return (Square) idx;
|
||||
}
|
||||
|
||||
inline Square msb(Bitboard b) {
|
||||
Bitboard idx;
|
||||
__asm__("bsrq %1, %0": "=r"(idx): "rm"(b) );
|
||||
return (Square) idx;
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
#else // ifdef(USE_BSFQ)
|
||||
#define NO_BSF // Fallback on software implementation for other cases
|
||||
|
||||
Square lsb(Bitboard b);
|
||||
Square msb(Bitboard b);
|
||||
|
||||
Reference in New Issue
Block a user