5 #include <linux/bitops.h>
7 #define DECLARE_BITMAP(name,bits) \
8 unsigned long name[BITS_TO_LONGS(bits)]
10 int __bitmap_weight(const unsigned long *bitmap, int bits);
11 void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
12 const unsigned long *bitmap2, int bits);
14 #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
16 #define BITMAP_LAST_WORD_MASK(nbits) \
18 ((nbits) % BITS_PER_LONG) ? \
19 (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \
22 #define small_const_nbits(nbits) \
23 (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG)
25 static inline void bitmap_zero(unsigned long *dst, int nbits)
27 if (small_const_nbits(nbits))
30 int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
35 static inline int bitmap_weight(const unsigned long *src, int nbits)
37 if (small_const_nbits(nbits))
38 return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
39 return __bitmap_weight(src, nbits);
42 static inline void bitmap_or(unsigned long *dst, const unsigned long *src1,
43 const unsigned long *src2, int nbits)
45 if (small_const_nbits(nbits))
48 __bitmap_or(dst, src1, src2, nbits);
52 * test_and_set_bit - Set a bit and return its old value
54 * @addr: Address to count from
56 static inline int test_and_set_bit(int nr, unsigned long *addr)
58 unsigned long mask = BIT_MASK(nr);
59 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
65 return (old & mask) != 0;
68 #endif /* _PERF_BITOPS_H */