diff options
author | Alexey Budankov | 2019-12-03 14:43:33 +0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo | 2020-01-06 11:46:04 -0300 |
commit | 8812ad412f851216d6c39488a7e563ccc5c604cc (patch) | |
tree | b62268e19d0ac56d65ac8033bb45cfa86004b170 /tools/lib | |
parent | b9fb2de0115bbacab36da31fd10483ea66d9cfab (diff) |
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 <alexey.budankov@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/43757993-0b28-d8af-a6c7-ede12e3a6877@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/bitmap.c | 15 |
1 files changed, 15 insertions, 0 deletions
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; +} |