mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] arm: provide a_ctz_l and a_ctz_64 helper functions
@ 2017-12-01  0:00 Andre McCurdy
  2017-12-01  0:46 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Andre McCurdy @ 2017-12-01  0:00 UTC (permalink / raw)
  To: musl; +Cc: Andre McCurdy

Provide an ARM specific a_ctz_l helper function for architecture
versions for which it can be implemented efficiently via the "rbit"
instruction (ie all Thumb-2 capable versions of ARM v6 and above).

Signed-off-by: Andre McCurdy <armccurdy@gmail.com>
---
 arch/arm/atomic_arch.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/arch/arm/atomic_arch.h b/arch/arm/atomic_arch.h
index 6e2e3b4..9242df8 100644
--- a/arch/arm/atomic_arch.h
+++ b/arch/arm/atomic_arch.h
@@ -91,4 +91,26 @@ static inline int a_clz_32(uint32_t x)
 	return x;
 }
 
+#if __ARM_ARCH_6T2__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
+
+#define a_ctz_l a_ctz_l
+static inline int a_ctz_l(unsigned long x)
+{
+	uint32_t xr;
+	__asm__ ("rbit %0, %1" : "=r"(xr) : "r"(x));
+	return a_clz_32(xr);
+}
+
+#define a_ctz_64 a_ctz_64
+static inline int a_ctz_64(uint64_t x)
+{
+	uint32_t y = x;
+	if (!y) {
+		y = x>>32;
+		return 32 + a_ctz_l(y);
+	}
+	return a_ctz_l(y);
+}
+
+#endif
 #endif
-- 
1.9.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-12-01  0:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-01  0:00 [PATCH] arm: provide a_ctz_l and a_ctz_64 helper functions Andre McCurdy
2017-12-01  0:46 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).