mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-07-24 10:25:42 -04:00
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:
parent
671a19600c
commit
c138e6a4b2
12
ilog2.c
12
ilog2.c
@ -48,9 +48,9 @@ int ilog2_32(uint32_t v)
|
|||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
__asm__("bsrl %1,%0 ; cmovel %2,%0"
|
__asm__("bsrl %1,%0"
|
||||||
: "=&r" (n)
|
: "=r" (n)
|
||||||
: "rm" (v), "rm" (0));
|
: "rm" (v), "0" (0));
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,9 +100,9 @@ int ilog2_64(uint64_t v)
|
|||||||
{
|
{
|
||||||
uint64_t n;
|
uint64_t n;
|
||||||
|
|
||||||
__asm__("bsrq %1,%0 ; cmoveq %2,%0"
|
__asm__("bsrq %1,%0"
|
||||||
: "=&r" (n)
|
: "=r" (n)
|
||||||
: "rm" (v), "rm" (UINT64_C(0)));
|
: "rm" (v), "0" (UINT64_C(0)));
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user