about summary refs log tree commit diff
path: root/arch/x32/atomic_arch.h
diff options
context:
space:
mode:
authorSzabolcs Nagy <nsz@port70.net>2017-04-19 00:20:54 +0200
committerRich Felker <dalias@aerifal.cx>2017-08-29 21:47:10 -0400
commit06fbefd10046a0fae7e588b7c6d25fb51811b931 (patch)
tree032c4ece67f6217ceb354ebff4c9889f2f0133eb /arch/x32/atomic_arch.h
parent3356177979bea717451362e746252ed38de77514 (diff)
downloadmusl-06fbefd10046a0fae7e588b7c6d25fb51811b931.tar.gz
musl-06fbefd10046a0fae7e588b7c6d25fb51811b931.tar.xz
musl-06fbefd10046a0fae7e588b7c6d25fb51811b931.zip
add a_clz_64 helper function
counts leading zero bits of a 64bit int, undefined on zero input.
(has nothing to do with atomics, added to atomic.h so target specific
helper functions are together.)

there is a logarithmic generic implementation and another in terms of
a 32bit a_clz_32 on targets where that's available.
Diffstat (limited to 'arch/x32/atomic_arch.h')
-rw-r--r--arch/x32/atomic_arch.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/arch/x32/atomic_arch.h b/arch/x32/atomic_arch.h
index 7daf4ae2..a744c299 100644
--- a/arch/x32/atomic_arch.h
+++ b/arch/x32/atomic_arch.h
@@ -112,3 +112,10 @@ static inline int a_ctz_l(unsigned long x)
 	__asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
 	return x;
 }
+
+#define a_clz_64 a_clz_64
+static inline int a_clz_64(uint64_t x)
+{
+	__asm__( "bsr %1,%0 ; xor $63,%0" : "=r"(x) : "r"(x) );
+	return x;
+}