Closed
Description
The godbolt compile demo for _tzcnt_u32 under MSVC/ICL/GCC/Clang not optimize
The godbolt compile demo for _tzcnt_u32 under MSVC/ICL/GCC/Clang optimized
_tzcnt_u32 can be optimized to:
#include <stdio.h>
#ifdef __x86_64__
__attribute__((naked))
unsigned _tzcnt_u32(unsigned x)
{
__asm(
"mov $0x20, %eax;\n"
"bsf %edi, %eax;\n"
"ret;\n"
);
}
#else
__attribute__((naked))
unsigned _tzcnt_u32(unsigned x)
{
__asm(
"mov $0x20, %eax;\n"
"bsf 4(%esp), %eax;\n"
"ret;\n"
);
}
#endif
int main(int argc, char **argv)
{
printf("hello %d\n", _tzcnt_u32(0));
return 0;
}