bitmap.c 482 B

12345678910111213141516171819202122
  1. /*
  2. * From lib/bitmap.c
  3. * Helper functions for bitmap.h.
  4. *
  5. * This source code is licensed under the GNU General Public License,
  6. * Version 2. See the file COPYING for more details.
  7. */
  8. #include <linux/bitmap.h>
  9. int __bitmap_weight(const unsigned long *bitmap, int bits)
  10. {
  11. int k, w = 0, lim = bits/BITS_PER_LONG;
  12. for (k = 0; k < lim; k++)
  13. w += hweight_long(bitmap[k]);
  14. if (bits % BITS_PER_LONG)
  15. w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits));
  16. return w;
  17. }