svn commit: r294829 - head/sys/compat/linuxkpi/common/include/linux
Hans Petter Selasky
hselasky at FreeBSD.org
Tue Jan 26 14:31:22 UTC 2016
Author: hselasky
Date: Tue Jan 26 14:31:20 2016
New Revision: 294829
URL: https://svnweb.freebsd.org/changeset/base/294829
Log:
Implement bitmap_weight() and bitmap_equal() for the LinuxKPI.
MFC after: 1 week
Sponsored by: Mellanox Technologies
Modified:
head/sys/compat/linuxkpi/common/include/linux/bitops.h
Modified: head/sys/compat/linuxkpi/common/include/linux/bitops.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/linux/bitops.h Tue Jan 26 14:30:03 2016 (r294828)
+++ head/sys/compat/linuxkpi/common/include/linux/bitops.h Tue Jan 26 14:31:20 2016 (r294829)
@@ -467,10 +467,40 @@ bitmap_release_region(unsigned long *bit
__reg_op(bitmap, pos, order, REG_OP_RELEASE);
}
-
#define for_each_set_bit(bit, addr, size) \
for ((bit) = find_first_bit((addr), (size)); \
(bit) < (size); \
(bit) = find_next_bit((addr), (size), (bit) + 1))
+static inline unsigned
+bitmap_weight(unsigned long *bitmap, unsigned nbits)
+{
+ unsigned bit;
+ unsigned retval = 0;
+
+ for_each_set_bit(bit, bitmap, nbits)
+ retval++;
+ return (retval);
+}
+
+static inline int
+bitmap_equal(const unsigned long *pa,
+ const unsigned long *pb, unsigned bits)
+{
+ unsigned x;
+ unsigned y = bits / BITS_PER_LONG;
+
+ for (x = 0; x != y; x++) {
+ if (pa[x] != pb[x])
+ return (0);
+ }
+
+ y = bits % BITS_PER_LONG;
+ if (y != 0) {
+ if ((pa[x] ^ pb[x]) & BITMAP_LAST_WORD_MASK(y))
+ return (0);
+ }
+ return (1);
+}
+
#endif /* _LINUX_BITOPS_H_ */
More information about the svn-src-all
mailing list