[prev in list] [next in list] [prev in thread] [next in thread]
List: qemu-block
Subject: [Qemu-block] [PATCH 15/21] bitmap: add bitmap_count_between() function
From: Vladimir Sementsov-Ogievskiy <vsementsov () virtuozzo ! com>
Date: 2016-12-23 14:28:58
Message-ID: 1482503344-6424-16-git-send-email-vsementsov () virtuozzo ! com
[Download RAW message or body]
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
---
include/qemu/bitmap.h | 4 ++++
util/bitmap.c | 27 +++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h
index 63ea2d0..3bfc33e 100644
--- a/include/qemu/bitmap.h
+++ b/include/qemu/bitmap.h
@@ -216,6 +216,10 @@ static inline int bitmap_intersects(const unsigned long *src1,
}
}
+unsigned long bitmap_count_between(const unsigned long *src,
+ unsigned long start,
+ unsigned long end);
+
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 43ed011..e5aaa1c 100644
--- a/util/bitmap.c
+++ b/util/bitmap.c
@@ -336,3 +336,30 @@ int slow_bitmap_intersects(const unsigned long *bitmap1,
}
return 0;
}
+
+unsigned long bitmap_count_between(const unsigned long *src,
+ unsigned long start,
+ unsigned long end)
+{
+ unsigned long first = start / BITS_PER_LONG;
+ unsigned long lim = end / BITS_PER_LONG;
+ unsigned long sum, i;
+
+ assert(start < end);
+
+ sum = ctpopl(src[first] & BITMAP_FIRST_WORD_MASK(start));
+
+ for (i = first + 1; i < lim; ++i) {
+ sum += ctpopl(src[i]);
+ }
+
+ if (end % BITS_PER_LONG) {
+ if (first == lim) {
+ sum -= ctpopl(src[first] & BITMAP_FIRST_WORD_MASK(end));
+ } else {
+ sum += ctpopl(src[i] & BITMAP_LAST_WORD_MASK(end));
+ }
+ }
+
+ return sum;
+}
--
1.8.3.1
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic