LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [POWERPC] Optimize fls64() on 64-bit processors
@ 2008-04-18  5:19 Paul Mackerras
  0 siblings, 0 replies; only message in thread
From: Paul Mackerras @ 2008-04-18  5:19 UTC (permalink / raw)
  To: linuxppc-dev

64-bit powerpc processors can find the leftmost 1 bit in a 64-bit
doubleword in one instruction, so use that rather than using the
generic fls64(), which does two 32-bit fls() calls.

Signed-off-by: Paul Mackerras <paulus@samba.org>
---
This is on top of a patch from Alexander van Heukelum that was posted
to lkml (http://lkml.org/lkml/2008/4/16/107), which just uses
asm-generic/bitops/find.h in place of some declarations we had in
asm-powerpc/bitops.h.

diff --git a/include/asm-powerpc/bitops.h b/include/asm-powerpc/bitops.h
index 36c8f3a..a99a749 100644
--- a/include/asm-powerpc/bitops.h
+++ b/include/asm-powerpc/bitops.h
@@ -312,7 +312,24 @@ static __inline__ int fls(unsigned int x)
 	asm ("cntlzw %0,%1" : "=r" (lz) : "r" (x));
 	return 32 - lz;
 }
+
+/*
+ * 64-bit can do this using one cntlzd (count leading zeroes doubleword)
+ * instruction; for 32-bit we use the generic version, which does two
+ * 32-bit fls calls.
+ */
+#ifdef __powerpc64__
+static __inline__ int fls64(__u64 x)
+{
+	int lz;
+
+	asm ("cntlzd %0,%1" : "=r" (lz) : "r" (x));
+	return 64 - lz;
+}
+#else
 #include <asm-generic/bitops/fls64.h>
+#endif /* __powerpc64__ */
+
 #include <asm-generic/bitops/hweight.h>
 #include <asm-generic/bitops/find.h>
 

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2008-04-18  5:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-18  5:19 [POWERPC] Optimize fls64() on 64-bit processors Paul Mackerras

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox