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

[POWERPC] Add "is_power_of_2" checking to log2.h.

Add the inline function "is_power_of_2()" to log2.h, where the value
zero is *not* considered to be a power of two.

Signed-off-by: Robert P. J. Day <rpjday@mindspring.com>
Acked-by: Kumar Gala <galak@kernel.crashing.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>

authored by

Robert P. J. Day and committed by
Paul Mackerras
63c2f782 7df2457d

+13 -12
+1 -4
arch/powerpc/mm/pgtable_32.c
··· 294 294 } 295 295 } 296 296 297 - /* is x a power of 2? */ 298 - #define is_power_of_2(x) ((x) != 0 && (((x) & ((x) - 1)) == 0)) 299 - 300 297 /* is x a power of 4? */ 301 - #define is_power_of_4(x) ((x) != 0 && (((x) & (x-1)) == 0) && (ffs(x) & 1)) 298 + #define is_power_of_4(x) is_power_of_2(x) && (ffs(x) & 1)) 302 299 303 300 /* 304 301 * Set up a mapping for a block of I/O.
+1 -4
arch/ppc/mm/pgtable.c
··· 313 313 } 314 314 } 315 315 316 - /* is x a power of 2? */ 317 - #define is_power_of_2(x) ((x) != 0 && (((x) & ((x) - 1)) == 0)) 318 - 319 316 /* is x a power of 4? */ 320 - #define is_power_of_4(x) ((x) != 0 && (((x) & (x-1)) == 0) && (ffs(x) & 1)) 317 + #define is_power_of_4(x) is_power_of_2(x) && (ffs(x) & 1)) 321 318 322 319 /* 323 320 * Set up a mapping for a block of I/O.
-2
arch/ppc/syslib/ppc85xx_rio.c
··· 59 59 #define DBELL_TID(x) (*(u8 *)(x + DOORBELL_TID_OFFSET)) 60 60 #define DBELL_INF(x) (*(u16 *)(x + DOORBELL_INFO_OFFSET)) 61 61 62 - #define is_power_of_2(x) (((x) & ((x) - 1)) == 0) 63 - 64 62 struct rio_atmu_regs { 65 63 u32 rowtar; 66 64 u32 pad1;
-2
drivers/net/gianfar_ethtool.c
··· 42 42 43 43 #include "gianfar.h" 44 44 45 - #define is_power_of_2(x) ((x) != 0 && (((x) & ((x) - 1)) == 0)) 46 - 47 45 extern void gfar_start(struct net_device *dev); 48 46 extern int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit); 49 47
+11
include/linux/log2.h
··· 44 44 #endif 45 45 46 46 /* 47 + * Determine whether some value is a power of two, where zero is 48 + * *not* considered a power of two. 49 + */ 50 + 51 + static inline __attribute__((const)) 52 + bool is_power_of_2(unsigned long n) 53 + { 54 + return (n != 0 && ((n & (n - 1)) == 0)); 55 + } 56 + 57 + /* 47 58 * round up to nearest power of two 48 59 */ 49 60 static inline __attribute__((const))