mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00: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:
parent
e70da0d2eb
commit
bf8b45fe63
1 changed files with 1 additions and 1 deletions
|
@ -291,7 +291,7 @@ inline Square lsb(Bitboard b) {
|
|||
|
||||
inline Square msb(Bitboard b) {
|
||||
assert(b);
|
||||
return Square(63 - __builtin_clzll(b));
|
||||
return Square(63 ^ __builtin_clzll(b));
|
||||
}
|
||||
|
||||
#elif defined(_WIN64) && defined(_MSC_VER)
|
||||
|
|
Loading…
Add table
Reference in a new issue