From owner-svn-src-head@freebsd.org Tue Jan 26 14:31:22 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2F138A46027; Tue, 26 Jan 2016 14:31:22 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EF7331E33; Tue, 26 Jan 2016 14:31:21 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u0QEVKab048030; Tue, 26 Jan 2016 14:31:20 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u0QEVKhu048029; Tue, 26 Jan 2016 14:31:20 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201601261431.u0QEVKhu048029@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Tue, 26 Jan 2016 14:31:20 +0000 (UTC) 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 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jan 2016 14:31:22 -0000 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_ */