Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

David Howells and committed by
Linus Torvalds
ef55d53c 39d61db0

+23 -12
+2 -2
arch/powerpc/Kconfig
··· 43 43 44 44 config ARCH_HAS_ILOG2_U32 45 45 bool 46 - default n 46 + default y 47 47 48 48 config ARCH_HAS_ILOG2_U64 49 49 bool 50 - default n 50 + default y if 64BIT 51 51 52 52 config GENERIC_HWEIGHT 53 53 bool
+20 -1
include/asm-powerpc/bitops.h
··· 190 190 * Return the zero-based bit position (LE, not IBM bit numbering) of 191 191 * the most significant 1-bit in a double word. 192 192 */ 193 - static __inline__ int __ilog2(unsigned long x) 193 + static __inline__ __attribute__((const)) 194 + int __ilog2(unsigned long x) 194 195 { 195 196 int lz; 196 197 197 198 asm (PPC_CNTLZL "%0,%1" : "=r" (lz) : "r" (x)); 198 199 return BITS_PER_LONG - 1 - lz; 199 200 } 201 + 202 + static inline __attribute__((const)) 203 + int __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__ 211 + static inline __attribute__((const)) 212 + int __ilog2_u64(u32 n) 213 + { 214 + int bit; 215 + asm ("cntlzd %0,%1" : "=r" (bit) : "r" (n)); 216 + return 63 - bit; 217 + } 218 + #endif 200 219 201 220 /* 202 221 * Determines the bit position of the least significant 0 bit in the
+1 -9
include/asm-powerpc/page_32.h
··· 26 26 static inline void clear_page(void *page) { clear_pages(page, 0); } 27 27 extern void copy_page(void *to, void *from); 28 28 29 - /* Pure 2^n version of get_order */ 30 - extern __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 - } 29 + #include <asm-generic/page.h> 38 30 39 31 #endif /* __ASSEMBLY__ */ 40 32