[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC 04/29] bitmap: introduce bitmap_invert()
From: |
Dr. David Alan Gilbert |
Subject: |
Re: [Qemu-devel] [RFC 04/29] bitmap: introduce bitmap_invert() |
Date: |
Mon, 31 Jul 2017 18:11:56 +0100 |
User-agent: |
Mutt/1.8.3 (2017-05-23) |
* Peter Xu (address@hidden) 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 <address@hidden>
> ---
> 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 / address@hidden / Manchester, UK
- [Qemu-devel] [RFC 00/29] Migration: postcopy failure recovery, Peter Xu, 2017/07/28
- [Qemu-devel] [RFC 01/29] migration: fix incorrect postcopy recved_bitmap, Peter Xu, 2017/07/28
- [Qemu-devel] [RFC 02/29] migration: fix comment disorder in RAMState, Peter Xu, 2017/07/28
- [Qemu-devel] [RFC 03/29] io: fix qio_channel_socket_accept err handling, Peter Xu, 2017/07/28
- [Qemu-devel] [RFC 04/29] bitmap: introduce bitmap_invert(), Peter Xu, 2017/07/28
- Re: [Qemu-devel] [RFC 04/29] bitmap: introduce bitmap_invert(),
Dr. David Alan Gilbert <=
- [Qemu-devel] [RFC 05/29] bitmap: introduce bitmap_count_one(), Peter Xu, 2017/07/28
- [Qemu-devel] [RFC 06/29] migration: dump str in migrate_set_state trace, Peter Xu, 2017/07/28
- [Qemu-devel] [RFC 08/29] migration: reuse mis->userfault_quit_fd, Peter Xu, 2017/07/28
- [Qemu-devel] [RFC 07/29] migration: better error handling with QEMUFile, Peter Xu, 2017/07/28
- [Qemu-devel] [RFC 09/29] migration: provide postcopy_fault_thread_notify(), Peter Xu, 2017/07/28