summaryrefslogtreecommitdiff
path: root/nasmlib/ilog2.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2016-11-15 14:23:54 -0800
committerH. Peter Anvin <hpa@linux.intel.com>2016-11-15 14:23:54 -0800
commit8d4fb26ad4eed40831261f0a37065f944c9dc04d (patch)
treec136a5d0cd2e3b5732f4c686b86855b15939ec71 /nasmlib/ilog2.c
parent069ad5fc18c6c7b722ce9be7e83d76283e67b1b5 (diff)
downloadnasm-8d4fb26ad4eed40831261f0a37065f944c9dc04d.tar.gz
Various fixes to the ilog2 functions
Fix several bugs in the ilog2 functions. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'nasmlib/ilog2.c')
-rw-r--r--nasmlib/ilog2.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/nasmlib/ilog2.c b/nasmlib/ilog2.c
index f250262d..51c3e07a 100644
--- a/nasmlib/ilog2.c
+++ b/nasmlib/ilog2.c
@@ -33,6 +33,7 @@
#include "compiler.h"
#include "nasmlib.h"
+#include <limits.h>
#define ROUND(v, a, w) \
do { \
@@ -61,14 +62,20 @@ int ilog2_32(uint32_t v)
{
int n;
+#ifdef __i686__
+ __asm__("bsrl %1,%0 ; cmovz %2,%0\n"
+ : "=&r" (n)
+ : "rm" (v), "r" (0));
+#else
__asm__("bsrl %1,%0 ; jnz 1f ; xorl %0,%0\n"
"1:"
: "=&r" (n)
: "rm" (v));
- return n;
+#endif
+ return n;
}
-#elif defined(HAVE___BUILTIN_CTZ) && INT_MAX == 2147483647
+#elif defined(HAVE___BUILTIN_CLZ) && INT_MAX == 2147483647
int ilog2_32(uint32_t v)
{
@@ -107,7 +114,7 @@ int ilog2_64(uint64_t v)
return n;
}
-#elif defined(HAVE__BUILTIN_CTZLL) && LLONG_MAX == 9223372036854775807LL
+#elif defined(HAVE__BUILTIN_CLZLL) && LLONG_MAX == 9223372036854775807LL
int ilog2_64(uint64_t v)
{