diff options
author | Peter Xu <peterx@redhat.com> | 2017-08-30 16:31:59 +0800 |
---|---|---|
committer | Juan Quintela <quintela@redhat.com> | 2017-09-22 14:11:24 +0200 |
commit | fc7deeea26af3d08f45bad85b8bd3fc3d790a090 (patch) | |
tree | ca91cb9b106b244d641bfd07d06d52cef7c9459c /include/qemu/bitmap.h | |
parent | ab089e058eb443a9a11ade4d3fc57ced1947bfa3 (diff) | |
download | qemu-fc7deeea26af3d08f45bad85b8bd3fc3d790a090.zip qemu-fc7deeea26af3d08f45bad85b8bd3fc3d790a090.tar.gz qemu-fc7deeea26af3d08f45bad85b8bd3fc3d790a090.tar.bz2 |
bitmap: introduce bitmap_count_one()
Count how many bits set in the bitmap.
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Diffstat (limited to 'include/qemu/bitmap.h')
-rw-r--r-- | include/qemu/bitmap.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index c318da1..2718706 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); |