diff options
| author | Jiri Olsa <jolsa@kernel.org> | 2016-08-01 14:02:31 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-08-02 15:33:27 -0400 |
| 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, | |||
| 58 | } | 58 | } |
| 59 | return ret; | 59 | return ret; |
| 60 | } | 60 | } |
| 61 | |||
| 62 | int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, | ||
| 63 | const unsigned long *bitmap2, unsigned int bits) | ||
| 64 | { | ||
| 65 | unsigned int k; | ||
| 66 | unsigned int lim = bits/BITS_PER_LONG; | ||
| 67 | unsigned long result = 0; | ||
| 68 | |||
| 69 | for (k = 0; k < lim; k++) | ||
| 70 | result |= (dst[k] = bitmap1[k] & bitmap2[k]); | ||
| 71 | if (bits % BITS_PER_LONG) | ||
| 72 | result |= (dst[k] = bitmap1[k] & bitmap2[k] & | ||
| 73 | BITMAP_LAST_WORD_MASK(bits)); | ||
| 74 | return result != 0; | ||
| 75 | } | ||
