ilog2: optimize use of bsr for x86-64
authorH. Peter Anvin <hpa@zytor.com>
Thu, 22 Apr 2010 18:02:56 +0000 (11:02 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Thu, 22 Apr 2010 18:02:56 +0000 (11:02 -0700)
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>
ilog2.c

diff --git a/ilog2.c b/ilog2.c
index df11561..9c054fd 100644 (file)
--- a/ilog2.c
+++ b/ilog2.c
@@ -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;
 }