[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 11/18] bitmap: introduce bitmap_count_one()
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PULL 11/18] bitmap: introduce bitmap_count_one() |
Date: |
Fri, 22 Sep 2017 01:08:05 +0200 |
From: Peter Xu <address@hidden>
Count how many bits set in the bitmap.
Reviewed-by: Dr. David Alan Gilbert <address@hidden>
Signed-off-by: Peter Xu <address@hidden>
Reviewed-by: Juan Quintela <address@hidden>
Signed-off-by: Juan Quintela <address@hidden>
---
include/qemu/bitmap.h | 10 ++++++++++
util/bitmap.c | 15 +++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h
index c318da12d7..2718706edb 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);
+long slow_bitmap_count_one(const 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 long bitmap_count_one(const unsigned long *bitmap, long nbits)
+{
+ if (small_nbits(nbits)) {
+ return ctpopl(*bitmap & BITMAP_LAST_WORD_MASK(nbits));
+ } else {
+ return slow_bitmap_count_one(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 efced9a7d8..90a42ff625 100644
--- a/util/bitmap.c
+++ b/util/bitmap.c
@@ -355,3 +355,18 @@ int slow_bitmap_intersects(const unsigned long *bitmap1,
}
return 0;
}
+
+long slow_bitmap_count_one(const unsigned long *bitmap, long nbits)
+{
+ long k, lim = nbits / BITS_PER_LONG, result = 0;
+
+ for (k = 0; k < lim; k++) {
+ result += ctpopl(bitmap[k]);
+ }
+
+ if (nbits % BITS_PER_LONG) {
+ result += ctpopl(bitmap[k] & BITMAP_LAST_WORD_MASK(nbits));
+ }
+
+ return result;
+}
--
2.13.5
- [Qemu-devel] [PULL 01/18] migration: Create migration_ioc_process_incoming(), (continued)
- [Qemu-devel] [PULL 01/18] migration: Create migration_ioc_process_incoming(), Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 02/18] migration: Teach it about G_SOURCE_REMOVE, Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 03/18] migration: Add comments to channel functions, Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 04/18] migration: Create migration_has_all_channels, Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 06/18] migration: Create x-multifd-channels parameter, Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 05/18] migration: Add multifd capability, Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 07/18] migration: Create x-multifd-page-count parameter, Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 08/18] migration: Create multifd migration threads, Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 10/18] bitmap: remove BITOP_WORD(), Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 09/18] migration: Split migration_fd_process_incoming, Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 11/18] bitmap: introduce bitmap_count_one(),
Juan Quintela <=
- [Qemu-devel] [PULL 12/18] bitmap: provide to_le/from_le helpers, Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 13/18] migration: add has_postcopy savevm handler, Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 14/18] migration: fix ram_save_pending, Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 15/18] migration: split common postcopy out of ram postcopy, Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 16/18] migration: pass MigrationIncomingState* into migration check functions, Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 17/18] migration: fix hardcoded function name in error report, Juan Quintela, 2017/09/21
- [Qemu-devel] [PULL 18/18] migration: split ufd_version_check onto receive/request features part, Juan Quintela, 2017/09/21
- Re: [Qemu-devel] [PULL 00/18] Migration PULL request, no-reply, 2017/09/21