Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information