summaryrefslogtreecommitdiffstats
path: root/sys/compat
diff options
context:
space:
mode:
authorhselasky <hselasky@FreeBSD.org>2016-01-26 14:31:20 +0000
committerhselasky <hselasky@FreeBSD.org>2016-01-26 14:31:20 +0000
commit01e92615b0258ad313473e9a5fbbc576e25354b4 (patch)
treeadc7a7a3ebaade93c15885656e7edeb97204abb8 /sys/compat
parent821336ce2f2365f2088975b4b4d9fe1306222915 (diff)
downloadFreeBSD-src-01e92615b0258ad313473e9a5fbbc576e25354b4.zip
FreeBSD-src-01e92615b0258ad313473e9a5fbbc576e25354b4.tar.gz
Implement bitmap_weight() and bitmap_equal() for the LinuxKPI.
MFC after: 1 week Sponsored by: Mellanox Technologies
Diffstat (limited to 'sys/compat')
-rw-r--r--sys/compat/linuxkpi/common/include/linux/bitops.h32
1 files changed, 31 insertions, 1 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/bitops.h b/sys/compat/linuxkpi/common/include/linux/bitops.h
index 2f402e8..0dcdfe0 100644
--- a/sys/compat/linuxkpi/common/include/linux/bitops.h
+++ b/sys/compat/linuxkpi/common/include/linux/bitops.h
@@ -467,10 +467,40 @@ bitmap_release_region(unsigned long *bitmap, int pos, int order)
__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_ */
OpenPOWER on IntegriCloud