]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
include/linux/bitmap.h: inline __bitmap_weight and __bitmap_and
authorLeah Neukirchen <leah@vuxu.org>
Fri, 9 Feb 2018 23:08:32 +0000 (00:08 +0100)
committerLeah Neukirchen <leah@vuxu.org>
Fri, 9 Feb 2018 23:08:32 +0000 (00:08 +0100)
include/linux/bitmap.h

index a7231b8b42b6a545fe5a69e280d3f033809ab1df..80e8ecda27da7405f4785188067fbddf23ca0f1c 100644 (file)
@@ -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)
 {