Received: from eggs.gnu.org ([209.51.188.92]:43679) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1UxE-0006Si-1S for qemu-devel@nongnu.org; Wed, 06 Mar 2019 06:43:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1UxD-0005HZ-A4 for qemu-devel@nongnu.org; Wed, 06 Mar 2019 06:43:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58630) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1UxD-0005Gu-4h for qemu-devel@nongnu.org; Wed, 06 Mar 2019 06:43:19 -0500 From: "Dr. David Alan Gilbert (git)" Date: Wed, 6 Mar 2019 11:42:19 +0000 Message-Id: <20190306114227.9125-15-dgilbert@redhat.com> In-Reply-To: <20190306114227.9125-1-dgilbert@redhat.com> References: <20190306114227.9125-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 14/22] bitmap: bitmap_count_one_with_offset List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, quintela@redhat.com, peterx@redhat.com, marcel.apfelbaum@gmail.com, wei.w.wang@intel.com, yury-kotov@yandex-team.ru, chen.zhang@intel.com Cc: eblake@redhat.com, armbru@redhat.com From: Wei Wang Count the number of 1s in a bitmap starting from an offset. Signed-off-by: Wei Wang CC: Dr. David Alan Gilbert CC: Juan Quintela CC: Michael S. Tsirkin Reviewed-by: Dr. David Alan Gilbert Message-Id: <1544516693-5395-3-git-send-email-wei.w.wang@intel.com> Signed-off-by: Dr. David Alan Gilbert --- include/qemu/bitmap.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index 679f1bdce4..5c313346b9 100644 --- a/include/qemu/bitmap.h +++ b/include/qemu/bitmap.h @@ -232,6 +232,19 @@ static inline long bitmap_count_one(const unsigned l= ong *bitmap, long nbits) } } =20 +static inline long bitmap_count_one_with_offset(const unsigned long *bit= map, + long offset, long nbits) +{ + long aligned_offset =3D QEMU_ALIGN_DOWN(offset, BITS_PER_LONG); + long redundant_bits =3D offset - aligned_offset; + long bits_to_count =3D nbits + redundant_bits; + const unsigned long *bitmap_start =3D bitmap + + aligned_offset / BITS_PER_LONG; + + return bitmap_count_one(bitmap_start, bits_to_count) - + bitmap_count_one(bitmap_start, redundant_bits); +} + void bitmap_set(unsigned long *map, long i, long len); void bitmap_set_atomic(unsigned long *map, long i, long len); void bitmap_clear(unsigned long *map, long start, long nr); --=20 2.20.1