summaryrefslogtreecommitdiff
path: root/include/asm-powerpc/bitops.h
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2006-12-08 02:37:53 -0800
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-08 08:28:51 -0800
commitef55d53caa055aedee13e77da82740987dd64f2d (patch)
tree243bbfca98e504401ea563d6c799ed23c12c08b8 /include/asm-powerpc/bitops.h
parent39d61db0edb34d60b83c5e0d62d0e906578cc707 (diff)
[PATCH] LOG2: Provide ilog2() fallbacks for powerpc
Provide ilog2() fallbacks for powerpc for 32-bit numbers and 64-bit numbers on ppc64. Signed-off-by: David Howells <dhowells@redhat.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/asm-powerpc/bitops.h')
-rw-r--r--include/asm-powerpc/bitops.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/include/asm-powerpc/bitops.h b/include/asm-powerpc/bitops.h
index c341063d0804..0288144ea024 100644
--- a/include/asm-powerpc/bitops.h
+++ b/include/asm-powerpc/bitops.h
@@ -190,7 +190,8 @@ static __inline__ void set_bits(unsigned long mask, unsigned long *addr)
* Return the zero-based bit position (LE, not IBM bit numbering) of
* the most significant 1-bit in a double word.
*/
-static __inline__ int __ilog2(unsigned long x)
+static __inline__ __attribute__((const))
+int __ilog2(unsigned long x)
{
int lz;
@@ -198,6 +199,24 @@ static __inline__ int __ilog2(unsigned long x)
return BITS_PER_LONG - 1 - lz;
}
+static inline __attribute__((const))
+int __ilog2_u32(u32 n)
+{
+ int bit;
+ asm ("cntlzw %0,%1" : "=r" (bit) : "r" (n));
+ return 31 - bit;
+}
+
+#ifdef __powerpc64__
+static inline __attribute__((const))
+int __ilog2_u64(u32 n)
+{
+ int bit;
+ asm ("cntlzd %0,%1" : "=r" (bit) : "r" (n));
+ return 63 - bit;
+}
+#endif
+
/*
* Determines the bit position of the least significant 0 bit in the
* specified double word. The returned bit position will be