From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcEEi-0003M2-Qf for qemu-devel@nongnu.org; Mon, 31 Jul 2017 13:12:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dcEEd-0007b6-RP for qemu-devel@nongnu.org; Mon, 31 Jul 2017 13:12:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35686) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dcEEd-0007Xo-MH for qemu-devel@nongnu.org; Mon, 31 Jul 2017 13:12:03 -0400 Date: Mon, 31 Jul 2017 18:11:56 +0100 From: "Dr. David Alan Gilbert" Message-ID: <20170731171155.GE2122@work-vm> References: <1501229198-30588-1-git-send-email-peterx@redhat.com> <1501229198-30588-5-git-send-email-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1501229198-30588-5-git-send-email-peterx@redhat.com> Subject: Re: [Qemu-devel] [RFC 04/29] bitmap: introduce bitmap_invert() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Xu Cc: qemu-devel@nongnu.org, Laurent Vivier , Alexey Perevalov , Juan Quintela , Andrea Arcangeli * Peter Xu (peterx@redhat.com) wrote: > It is used to invert the whole bitmap. Would it be easier to change bitmap_complement to use ^ in it's macro and slow_bitmap_complement, and then you could call it with src==dst to do the same thing with just that small change? Dave > Signed-off-by: Peter Xu > --- > include/qemu/bitmap.h | 10 ++++++++++ > util/bitmap.c | 13 +++++++++++++ > 2 files changed, 23 insertions(+) > > diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h > index c318da1..460d899 100644 > --- a/include/qemu/bitmap.h > +++ b/include/qemu/bitmap.h > @@ -82,6 +82,7 @@ int slow_bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1, > const unsigned long *bitmap2, long bits); > int slow_bitmap_intersects(const unsigned long *bitmap1, > const unsigned long *bitmap2, long bits); > +void slow_bitmap_invert(unsigned long *bitmap, long nbits); > > static inline unsigned long *bitmap_try_new(long nbits) > { > @@ -216,6 +217,15 @@ static inline int bitmap_intersects(const unsigned long *src1, > } > } > > +static inline void bitmap_invert(unsigned long *bitmap, long nbits) > +{ > + if (small_nbits(nbits)) { > + *bitmap ^= BITMAP_LAST_WORD_MASK(nbits); > + } else { > + slow_bitmap_invert(bitmap, nbits); > + } > +} > + > 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); > diff --git a/util/bitmap.c b/util/bitmap.c > index efced9a..9b7408c 100644 > --- a/util/bitmap.c > +++ b/util/bitmap.c > @@ -355,3 +355,16 @@ int slow_bitmap_intersects(const unsigned long *bitmap1, > } > return 0; > } > + > +void slow_bitmap_invert(unsigned long *bitmap, long nbits) > +{ > + long k, lim = nbits/BITS_PER_LONG; > + > + for (k = 0; k < lim; k++) { > + bitmap[k] ^= ULONG_MAX; > + } > + > + if (nbits % BITS_PER_LONG) { > + bitmap[k] ^= BITMAP_LAST_WORD_MASK(nbits); > + } > +} > -- > 2.7.4 > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK