ilog2: optimize use of bsr for x86-64

On x86-64 platforms, we can rely on BSR not changing the destination
operand when the input is zero.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2010-04-22 11:02:56 -07:00
parent 671a19600c
commit c138e6a4b2

12
ilog2.c
View File

@ -48,9 +48,9 @@ int ilog2_32(uint32_t v)
{
int n;
__asm__("bsrl %1,%0 ; cmovel %2,%0"
: "=&r" (n)
: "rm" (v), "rm" (0));
__asm__("bsrl %1,%0"
: "=r" (n)
: "rm" (v), "0" (0));
return n;
}
@ -100,9 +100,9 @@ int ilog2_64(uint64_t v)
{
uint64_t n;
__asm__("bsrq %1,%0 ; cmoveq %2,%0"
: "=&r" (n)
: "rm" (v), "rm" (UINT64_C(0)));
__asm__("bsrq %1,%0"
: "=r" (n)
: "rm" (v), "0" (UINT64_C(0)));
return n;
}