aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2006-12-08 05:37:53 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-08 11:28:51 -0500
commitef55d53caa055aedee13e77da82740987dd64f2d (patch)
tree243bbfca98e504401ea563d6c799ed23c12c08b8
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>
-rw-r--r--arch/powerpc/Kconfig4
-rw-r--r--include/asm-powerpc/bitops.h21
-rw-r--r--include/asm-powerpc/page_32.h10
3 files changed, 23 insertions, 12 deletions
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 97c7a212cdda..56c3c4065eb0 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -43,11 +43,11 @@ config RWSEM_XCHGADD_ALGORITHM
43 43
44config ARCH_HAS_ILOG2_U32 44config ARCH_HAS_ILOG2_U32
45 bool 45 bool
46 default n 46 default y
47 47
48config ARCH_HAS_ILOG2_U64 48config ARCH_HAS_ILOG2_U64
49 bool 49 bool
50 default n 50 default y if 64BIT
51 51
52config GENERIC_HWEIGHT 52config GENERIC_HWEIGHT
53 bool 53 bool
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)
190 * Return the zero-based bit position (LE, not IBM bit numbering) of 190 * Return the zero-based bit position (LE, not IBM bit numbering) of
191 * the most significant 1-bit in a double word. 191 * the most significant 1-bit in a double word.
192 */ 192 */
193static __inline__ int __ilog2(unsigned long x) 193static __inline__ __attribute__((const))
194int __ilog2(unsigned long x)
194{ 195{
195 int lz; 196 int lz;
196 197
@@ -198,6 +199,24 @@ static __inline__ int __ilog2(unsigned long x)
198 return BITS_PER_LONG - 1 - lz; 199 return BITS_PER_LONG - 1 - lz;
199} 200}
200 201
202static inline __attribute__((const))
203int __ilog2_u32(u32 n)
204{
205 int bit;
206 asm ("cntlzw %0,%1" : "=r" (bit) : "r" (n));
207 return 31 - bit;
208}
209
210#ifdef __powerpc64__
211static inline __attribute__((const))
212int __ilog2_u64(u32 n)
213{
214 int bit;
215 asm ("cntlzd %0,%1" : "=r" (bit) : "r" (n));
216 return 63 - bit;
217}
218#endif
219
201/* 220/*
202 * Determines the bit position of the least significant 0 bit in the 221 * Determines the bit position of the least significant 0 bit in the
203 * specified double word. The returned bit position will be 222 * specified double word. The returned bit position will be
diff --git a/include/asm-powerpc/page_32.h b/include/asm-powerpc/page_32.h
index 2677bad70f40..07f6d3cf5e5a 100644
--- a/include/asm-powerpc/page_32.h
+++ b/include/asm-powerpc/page_32.h
@@ -26,15 +26,7 @@ extern void clear_pages(void *page, int order);
26static inline void clear_page(void *page) { clear_pages(page, 0); } 26static inline void clear_page(void *page) { clear_pages(page, 0); }
27extern void copy_page(void *to, void *from); 27extern void copy_page(void *to, void *from);
28 28
29/* Pure 2^n version of get_order */ 29#include <asm-generic/page.h>
30extern __inline__ int get_order(unsigned long size)
31{
32 int lz;
33
34 size = (size-1) >> PAGE_SHIFT;
35 asm ("cntlzw %0,%1" : "=r" (lz) : "r" (size));
36 return 32 - lz;
37}
38 30
39#endif /* __ASSEMBLY__ */ 31#endif /* __ASSEMBLY__ */
40 32