bitmap.c 699 B

12345678910111213141516171819202122232425262728293031
  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. }
  18. void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
  19. const unsigned long *bitmap2, int bits)
  20. {
  21. int k;
  22. int nr = BITS_TO_LONGS(bits);
  23. for (k = 0; k < nr; k++)
  24. dst[k] = bitmap1[k] | bitmap2[k];
  25. }