diff options
author | Peter Xu | 2017-08-30 10:31:59 +0200 |
---|---|---|
committer | Juan Quintela | 2017-09-22 14:11:24 +0200 |
commit | fc7deeea26af3d08f45bad85b8bd3fc3d790a090 (patch) | |
tree | ca91cb9b106b244d641bfd07d06d52cef7c9459c /util | |
parent | bitmap: remove BITOP_WORD() (diff) | |
download | qemu-fc7deeea26af3d08f45bad85b8bd3fc3d790a090.tar.gz qemu-fc7deeea26af3d08f45bad85b8bd3fc3d790a090.tar.xz qemu-fc7deeea26af3d08f45bad85b8bd3fc3d790a090.zip |
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 'util')
-rw-r--r-- | util/bitmap.c | 15 |
1 files changed, 15 insertions, 0 deletions
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; +} |