Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
741c74f5 820d12b7

+32
+17
tools/include/linux/bitmap.h
··· 11 11 int __bitmap_weight(const unsigned long *bitmap, int bits); 12 12 void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, 13 13 const unsigned long *bitmap2, int bits); 14 + int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, 15 + const unsigned long *bitmap2, unsigned int bits); 14 16 15 17 #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) 16 18 ··· 86 84 */ 87 85 size_t bitmap_scnprintf(unsigned long *bitmap, int nbits, 88 86 char *buf, size_t size); 87 + 88 + /** 89 + * bitmap_and - Do logical and on bitmaps 90 + * @dst: resulting bitmap 91 + * @src1: operand 1 92 + * @src2: operand 2 93 + * @nbits: size of bitmap 94 + */ 95 + static inline int bitmap_and(unsigned long *dst, const unsigned long *src1, 96 + const unsigned long *src2, unsigned int nbits) 97 + { 98 + if (small_const_nbits(nbits)) 99 + return (*dst = *src1 & *src2 & BITMAP_LAST_WORD_MASK(nbits)) != 0; 100 + return __bitmap_and(dst, src1, src2, nbits); 101 + } 89 102 90 103 #endif /* _PERF_BITOPS_H */
+15
tools/lib/bitmap.c
··· 58 58 } 59 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 + }