aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bitmap.c
diff options
context:
space:
mode:
authorJiri Olsa <[email protected]>2016-08-01 18:02:31 +0000
committerArnaldo Carvalho de Melo <[email protected]>2016-08-02 19:33:27 +0000
commit741c74f55e8a66f3bc5bbc29dc162c952759e47b (patch)
treecac565727d5c11ee0e6044e16f51d53b2351e251 /tools/lib/bitmap.c
parenttools lib: Add bitmap_scnprintf function (diff)
downloadkernel-741c74f55e8a66f3bc5bbc29dc162c952759e47b.tar.gz
kernel-741c74f55e8a66f3bc5bbc29dc162c952759e47b.zip
tools lib: Add bitmap_and function
Add support to perform logical and on bitmaps. Code taken from kernel's include/linux/bitmap.h. Signed-off-by: Jiri Olsa <[email protected]> Cc: David Ahern <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Diffstat (limited to 'tools/lib/bitmap.c')
-rw-r--r--tools/lib/bitmap.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/lib/bitmap.c b/tools/lib/bitmap.c
index 5c7e3185507c..38748b0e342f 100644
--- a/tools/lib/bitmap.c
+++ b/tools/lib/bitmap.c
@@ -58,3 +58,18 @@ size_t bitmap_scnprintf(unsigned long *bitmap, int nbits,
}
return ret;
}
+
+int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
+ const unsigned long *bitmap2, unsigned int bits)
+{
+ unsigned int k;
+ unsigned int lim = bits/BITS_PER_LONG;
+ unsigned long result = 0;
+
+ for (k = 0; k < lim; k++)
+ result |= (dst[k] = bitmap1[k] & bitmap2[k]);
+ if (bits % BITS_PER_LONG)
+ result |= (dst[k] = bitmap1[k] & bitmap2[k] &
+ BITMAP_LAST_WORD_MASK(bits));
+ return result != 0;
+}