From: Andrey Neporada Date: Sat, 3 Dec 2016 08:37:07 +0000 (+0400) Subject: Help GCC to optimize msb() to single instruction X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=bf8b45fe6305c89a9a30f660de34164cf3bdcdf2;hp=bf8b45fe6305c89a9a30f660de34164cf3bdcdf2 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. ---