diff options
author | Jiri Olsa <jolsa@kernel.org> | 2016-08-01 20:02:31 +0200 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-08-02 16:33:27 -0300 |
commit | 741c74f55e8a66f3bc5bbc29dc162c952759e47b (patch) | |
tree | cac565727d5c11ee0e6044e16f51d53b2351e251 /tools/lib | |
parent | 820d12b70f91a19eb4a3152b9dd4ea9aee194a36 (diff) |
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 <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1470074555-24889-4-git-send-email-jolsa@kernel.org
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 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; +} |