unsigned long f(unsigned long long value)
{
unsigned int result;
if ((value & 0xFFFFFFFF) == 0)
{
result = __builtin_ctz(value >> 32) + 32;
}
else
{
if ((unsigned int)value != 0)
result = __builtin_ctz((unsigned int)value);
}
return result;
}
LLVM 11 -O2
f(unsigned long long): # @​f(unsigned long long)
mov rax, rdi
shr rax, 32
bsf ecx, eax
or ecx, 32
bsf eax, edi
cmove eax, ecx
ret
LLVM12+ -O2:
f(unsigned long long): # @​f(unsigned long f(unsigned long long): # @​f(unsigned long long)
test edi, edi
je .LBB0_1
test edi, edi
je .LBB0_3
bsf eax, edi
mov eax, eax
ret
.LBB0_1:
shr rdi, 32
bsf eax, edi
or eax, 32
mov eax, eax
ret
.LBB0_3:
mov eax, eax
ret
Extended Description
LLVM 11 -O2
LLVM12+ -O2:
https://godbolt.org/z/M9q4d13nq