bitmap.h 824 B

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef _PERF_BITOPS_H
  2. #define _PERF_BITOPS_H
  3. #include <string.h>
  4. #include <linux/bitops.h>
  5. int __bitmap_weight(const unsigned long *bitmap, int bits);
  6. #define BITMAP_LAST_WORD_MASK(nbits) \
  7. ( \
  8. ((nbits) % BITS_PER_LONG) ? \
  9. (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \
  10. )
  11. #define small_const_nbits(nbits) \
  12. (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG)
  13. static inline void bitmap_zero(unsigned long *dst, int nbits)
  14. {
  15. if (small_const_nbits(nbits))
  16. *dst = 0UL;
  17. else {
  18. int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
  19. memset(dst, 0, len);
  20. }
  21. }
  22. static inline int bitmap_weight(const unsigned long *src, int nbits)
  23. {
  24. if (small_const_nbits(nbits))
  25. return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
  26. return __bitmap_weight(src, nbits);
  27. }
  28. #endif /* _PERF_BITOPS_H */