1 #ifndef _LINUX_BITOPS_H
2 #define _LINUX_BITOPS_H
6 #define BIT(nr) (1UL << (nr))
7 #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
8 #define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
9 #define BITS_PER_BYTE 8
10 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
22 #include <asm/bitops.h>
24 #define for_each_set_bit(bit, addr, size) \
25 for ((bit) = find_first_bit((addr), (size)); \
27 (bit) = find_next_bit((addr), (size), (bit) + 1))
30 #define for_each_set_bit_from(bit, addr, size) \
31 for ((bit) = find_next_bit((addr), (size), (bit)); \
33 (bit) = find_next_bit((addr), (size), (bit) + 1))
35 #define for_each_clear_bit(bit, addr, size) \
36 for ((bit) = find_first_zero_bit((addr), (size)); \
38 (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
41 #define for_each_clear_bit_from(bit, addr, size) \
42 for ((bit) = find_next_zero_bit((addr), (size), (bit)); \
44 (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
58 order = fls(count) - 1;
59 if (count & (count - 1))
64 static inline unsigned long hweight_long(
unsigned long w)
76 return (word << shift) | (word >> (64 - shift));
84 static inline __u64 ror64(
__u64 word,
unsigned int shift)
86 return (word >> shift) | (word << (64 - shift));
94 static inline __u32 rol32(
__u32 word,
unsigned int shift)
96 return (word << shift) | (word >> (32 - shift));
104 static inline __u32 ror32(
__u32 word,
unsigned int shift)
106 return (word >> shift) | (word << (32 - shift));
114 static inline __u16 rol16(
__u16 word,
unsigned int shift)
116 return (word << shift) | (word >> (16 - shift));
124 static inline __u16 ror16(
__u16 word,
unsigned int shift)
126 return (word >> shift) | (word << (16 - shift));
134 static inline __u8 rol8(
__u8 word,
unsigned int shift)
136 return (word << shift) | (word >> (8 - shift));
144 static inline __u8 ror8(
__u8 word,
unsigned int shift)
146 return (word >> shift) | (word << (8 - shift));
157 return (
__s32)(value << shift) >> shift;
160 static inline unsigned fls_long(
unsigned long l)
175 static inline unsigned long __ffs64(
u64 word)
177 #if BITS_PER_LONG == 32
178 if (((
u32)word) == 0
UL)
179 return __ffs((
u32)(word >> 32)) + 32;
180 #elif BITS_PER_LONG != 64
181 #error BITS_PER_LONG not 32 or 64
183 return __ffs((
unsigned long)word);
188 #ifndef find_last_bit