aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-powerpc/bitops.h
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/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)
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