Commit | Line | Data |
---|---|---|
fb72014d ACM |
1 | #ifndef _PERF_BITOPS_H |
2 | #define _PERF_BITOPS_H | |
3 | ||
4 | #include <string.h> | |
5 | #include <linux/bitops.h> | |
6 | ||
7 | int __bitmap_weight(const unsigned long *bitmap, int bits); | |
850f8127 JO |
8 | void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, |
9 | const unsigned long *bitmap2, int bits); | |
fb72014d ACM |
10 | |
11 | #define BITMAP_LAST_WORD_MASK(nbits) \ | |
12 | ( \ | |
13 | ((nbits) % BITS_PER_LONG) ? \ | |
14 | (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \ | |
15 | ) | |
16 | ||
17 | #define small_const_nbits(nbits) \ | |
18 | (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) | |
19 | ||
20 | static inline void bitmap_zero(unsigned long *dst, int nbits) | |
21 | { | |
22 | if (small_const_nbits(nbits)) | |
23 | *dst = 0UL; | |
24 | else { | |
25 | int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); | |
26 | memset(dst, 0, len); | |
27 | } | |
28 | } | |
29 | ||
30 | static inline int bitmap_weight(const unsigned long *src, int nbits) | |
31 | { | |
32 | if (small_const_nbits(nbits)) | |
33 | return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); | |
34 | return __bitmap_weight(src, nbits); | |
35 | } | |
36 | ||
850f8127 JO |
37 | static inline void bitmap_or(unsigned long *dst, const unsigned long *src1, |
38 | const unsigned long *src2, int nbits) | |
39 | { | |
40 | if (small_const_nbits(nbits)) | |
41 | *dst = *src1 | *src2; | |
42 | else | |
43 | __bitmap_or(dst, src1, src2, nbits); | |
44 | } | |
45 | ||
fb72014d | 46 | #endif /* _PERF_BITOPS_H */ |