aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-powerpc
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 /include/asm-powerpc
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')
-rw-r--r--include/asm-powerpc/bitops.h21
-rw-r--r--include/asm-powerpc/page_32.h10
2 files changed, 21 insertions, 10 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)
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