mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-22 01:56:58 +08:00
Help GCC to optimize msb() to single instruction
GCC compiles builtin_clzll to “63 ^ BSR”. BSR is processor instruction "Bit Scan Reverse".
So old msb() function is basically 63 - 63 ^ BSR.
Unfortunately, GCC fails to simplify this expression.
Old function compiles to
bsrq %rdi, %rdi
movl $63, %eax
xorq $63, %rdi
subl %edi, %eax
ret
New function compiles to
bsrq %rdi, %rax
ret
BTW, Clang compiles both function to the same (optimal) code.
No functional change.
This commit is contained in:
committed by
Marco Costalba
parent
e70da0d2eb
commit
bf8b45fe63
@@ -291,7 +291,7 @@ inline Square lsb(Bitboard b) {
|
|||||||
|
|
||||||
inline Square msb(Bitboard b) {
|
inline Square msb(Bitboard b) {
|
||||||
assert(b);
|
assert(b);
|
||||||
return Square(63 - __builtin_clzll(b));
|
return Square(63 ^ __builtin_clzll(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(_WIN64) && defined(_MSC_VER)
|
#elif defined(_WIN64) && defined(_MSC_VER)
|
||||||
|
|||||||
Reference in New Issue
Block a user