diff options
author | Matthew Wilcox <willy@linux.intel.com> | 2016-12-14 18:08:26 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-12-14 19:04:10 -0500 |
commit | b328daf3b7130098b105c18bdae694ddaad5b6e3 (patch) | |
tree | 067ba62437e45bfccb080d21c237dbe3c4870397 /tools | |
parent | 101d9607fffefdfc9e3922f0ac9061a61edda1b0 (diff) |
tools: add more bitmap functions
I need the following functions for the radix tree:
bitmap_fill
bitmap_empty
bitmap_full
Copy the implementations from include/linux/bitmap.h
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
Tested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/include/linux/bitmap.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h index 43c1c5021e4b..eef41d500e9e 100644 --- a/tools/include/linux/bitmap.h +++ b/tools/include/linux/bitmap.h | |||
@@ -35,6 +35,32 @@ static inline void bitmap_zero(unsigned long *dst, int nbits) | |||
35 | } | 35 | } |
36 | } | 36 | } |
37 | 37 | ||
38 | static inline void bitmap_fill(unsigned long *dst, unsigned int nbits) | ||
39 | { | ||
40 | unsigned int nlongs = BITS_TO_LONGS(nbits); | ||
41 | if (!small_const_nbits(nbits)) { | ||
42 | unsigned int len = (nlongs - 1) * sizeof(unsigned long); | ||
43 | memset(dst, 0xff, len); | ||
44 | } | ||
45 | dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits); | ||
46 | } | ||
47 | |||
48 | static inline int bitmap_empty(const unsigned long *src, unsigned nbits) | ||
49 | { | ||
50 | if (small_const_nbits(nbits)) | ||
51 | return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); | ||
52 | |||
53 | return find_first_bit(src, nbits) == nbits; | ||
54 | } | ||
55 | |||
56 | static inline int bitmap_full(const unsigned long *src, unsigned int nbits) | ||
57 | { | ||
58 | if (small_const_nbits(nbits)) | ||
59 | return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); | ||
60 | |||
61 | return find_first_zero_bit(src, nbits) == nbits; | ||
62 | } | ||
63 | |||
38 | static inline int bitmap_weight(const unsigned long *src, int nbits) | 64 | static inline int bitmap_weight(const unsigned long *src, int nbits) |
39 | { | 65 | { |
40 | if (small_const_nbits(nbits)) | 66 | if (small_const_nbits(nbits)) |