diff options
author | Leah Neukirchen <leah@vuxu.org> | 2018-02-10 00:08:32 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2018-02-10 00:08:32 +0100 |
commit | e8a350841ca12302f2c32459a671dce7ff171f70 (patch) | |
tree | 1d7e249ddbbacc568259336c0ff0117119bfbe4e /include | |
parent | 0f85ced7992d6abbead0f0f9288ad3708565a71d (diff) |
include/linux/bitmap.h: inline __bitmap_weight and __bitmap_and
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/bitmap.h | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index a7231b8b..80e8ecda 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -8,11 +8,8 @@ #define DECLARE_BITMAP(name,bits) \ unsigned long name[BITS_TO_LONGS(bits)] -int __bitmap_weight(const unsigned long *bitmap, int bits); void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, const unsigned long *bitmap2, int bits); -int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, - const unsigned long *bitmap2, unsigned int bits); #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) @@ -25,6 +22,34 @@ int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, #define small_const_nbits(nbits) \ (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) +static inline int __bitmap_weight(const unsigned long *bitmap, int bits) +{ + int k, w = 0, lim = bits/BITS_PER_LONG; + + for (k = 0; k < lim; k++) + w += hweight_long(bitmap[k]); + + if (bits % BITS_PER_LONG) + w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits)); + + return w; +} + +static inline int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, + const unsigned long *bitmap2, unsigned int bits) +{ + unsigned int k; + unsigned int lim = bits/BITS_PER_LONG; + unsigned long result = 0; + + for (k = 0; k < lim; k++) + result |= (dst[k] = bitmap1[k] & bitmap2[k]); + if (bits % BITS_PER_LONG) + result |= (dst[k] = bitmap1[k] & bitmap2[k] & + BITMAP_LAST_WORD_MASK(bits)); + return result != 0; +} + static inline void bitmap_complement(unsigned long *dst, const unsigned long *src, unsigned int bits) { |