From 8812ad412f851216d6c39488a7e563ccc5c604cc Mon Sep 17 00:00:00 2001 From: Alexey Budankov Date: Tue, 3 Dec 2019 14:43:33 +0300 Subject: tools bitmap: Implement bitmap_equal() operation at bitmap API Extend tools bitmap API with bitmap_equal() implementation. The implementation has been derived from the kernel. Extend tools bitmap API with bitmap_free() implementation for symmetry with bitmap_alloc() function. Signed-off-by: Alexey Budankov Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lore.kernel.org/lkml/43757993-0b28-d8af-a6c7-ede12e3a6877@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/bitmap.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tools/lib/bitmap.c') diff --git a/tools/lib/bitmap.c b/tools/lib/bitmap.c index 38494782be06..5043747ef6c5 100644 --- a/tools/lib/bitmap.c +++ b/tools/lib/bitmap.c @@ -71,3 +71,18 @@ int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, BITMAP_LAST_WORD_MASK(bits)); return result != 0; } + +int __bitmap_equal(const unsigned long *bitmap1, + const unsigned long *bitmap2, unsigned int bits) +{ + unsigned int k, lim = bits/BITS_PER_LONG; + for (k = 0; k < lim; ++k) + if (bitmap1[k] != bitmap2[k]) + return 0; + + if (bits % BITS_PER_LONG) + if ((bitmap1[k] ^ bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits)) + return 0; + + return 1; +} -- cgit v1.2.3