Date: Tue, 26 Jan 2016 14:31:20 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r294829 - head/sys/compat/linuxkpi/common/include/linux Message-ID: <201601261431.u0QEVKhu048029@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201601261431.u0QEVKhu048029>