• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _PERF_BITOPS_H
2 #define _PERF_BITOPS_H
3 
4 #include <string.h>
5 /* ANDROID_CHANGE_BEGIN */
6 #if 0
7 #include <linux/bitops.h>
8 #else
9 #include "bitops.h"
10 #endif
11 /* ANDROID_CHANGE_END */
12 
13 int __bitmap_weight(const unsigned long *bitmap, int bits);
14 
15 #define BITMAP_LAST_WORD_MASK(nbits)					\
16 (									\
17 	((nbits) % BITS_PER_LONG) ?					\
18 		(1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL		\
19 )
20 
21 #define small_const_nbits(nbits) \
22 	(__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG)
23 
bitmap_zero(unsigned long * dst,int nbits)24 static inline void bitmap_zero(unsigned long *dst, int nbits)
25 {
26 	if (small_const_nbits(nbits))
27 		*dst = 0UL;
28 	else {
29 		int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
30 		memset(dst, 0, len);
31 	}
32 }
33 
bitmap_weight(const unsigned long * src,int nbits)34 static inline int bitmap_weight(const unsigned long *src, int nbits)
35 {
36 	if (small_const_nbits(nbits))
37 		return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
38 	return __bitmap_weight(src, nbits);
39 }
40 
41 #endif /* _PERF_BITOPS_H */
42