1 #ifndef _PERF_LINUX_BITOPS_H_
2 #define _PERF_LINUX_BITOPS_H_
4 #include <linux/kernel.h>
5 #include <linux/compiler.h>
9 #define __WORDSIZE (__SIZEOF_LONG__ * 8)
12 #define BITS_PER_LONG __WORDSIZE
13 #define BITS_PER_BYTE 8
14 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
15 #define BITS_TO_U64(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64))
16 #define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32))
18 #define for_each_set_bit(bit, addr, size) \
19 for ((bit) = find_first_bit((addr), (size)); \
21 (bit) = find_next_bit((addr), (size), (bit) + 1))
24 #define for_each_set_bit_from(bit, addr, size) \
25 for ((bit) = find_next_bit((addr), (size), (bit)); \
27 (bit) = find_next_bit((addr), (size), (bit) + 1))
42 (((
unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
45 static inline unsigned long hweight_long(
unsigned long w)
50 #define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
62 #if BITS_PER_LONG == 64
63 if ((word & 0xffffffff) == 0) {
68 if ((word & 0xffff) == 0) {
72 if ((word & 0xff) == 0) {
76 if ((word & 0xf) == 0) {
80 if ((word & 0x3) == 0) {
84 if ((word & 0x1) == 0)
92 static inline unsigned long
95 const unsigned long *
p =
addr;
99 while (size & ~(BITS_PER_LONG-1)) {
108 tmp = (*p) & (~0
UL >> (BITS_PER_LONG -
size));
110 return result +
size;
112 return result +
__ffs(tmp);
118 static inline unsigned long
121 const unsigned long *p = addr +
BITOP_WORD(offset);
122 unsigned long result = offset & ~(BITS_PER_LONG-1);
132 if (size < BITS_PER_LONG)
139 while (size & ~(BITS_PER_LONG-1)) {
150 tmp &= (~0
UL >> (BITS_PER_LONG -
size));
152 return result +
size;
154 return result +
__ffs(tmp);