Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423437AbcKPWab (ORCPT ); Wed, 16 Nov 2016 17:30:31 -0500 Received: from p3plsmtps2ded01.prod.phx3.secureserver.net ([208.109.80.58]:48190 "EHLO p3plsmtps2ded01.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936237AbcKPWYF (ORCPT ); Wed, 16 Nov 2016 17:24:05 -0500 x-originating-ip: 72.167.245.219 From: Matthew Wilcox To: linux-kernel@vger.kernel.org, Andrew Morton , Konstantin Khlebnikov , Ross Zwisler Cc: linux-fsdevel@vger.kernel.org, Matthew Wilcox , linux-mm@kvack.org, "Kirill A . Shutemov" Subject: [PATCH 08/29] tools: Add more bitmap functions Date: Wed, 16 Nov 2016 16:16:35 -0800 Message-Id: <1479341856-30320-11-git-send-email-mawilcox@linuxonhyperv.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1479341856-30320-1-git-send-email-mawilcox@linuxonhyperv.com> References: <1479341856-30320-1-git-send-email-mawilcox@linuxonhyperv.com> X-CMAE-Envelope: MS4wfBGzj7szfEWrsrJyWSPt3WE0BzMWXUn9UQzCodZilZ8Rqwo3A8lJel5uM5XSE+QF+RnEYMjC91y5cARd/Pvu+0f7skwUQkdT6m099GclRZu0MXI9HY6w /vzWehVI9cO3T9fTLqLX8ybvMuy5INroc7OBBmK4+bI0xAqPQUJzKsrNYdB03lV1a7HjA1b4t4sEU8hv50QYdj9L7a721jp4l2aBYFeuKMGv2BH4iDVSJodc AFBZAydNNi3ofT8kJSp5uEamX0C+gpoSI2SkfVq1EO6aGzfw0dEao08GK3mDCondKbD0UCXKYFhPzqWn7SgS3eJW1ofKiImq73FSr8wPvJOXcBl3mistPYrc hS6i8Ywo3Lx+QBmi9V33aSwggtymUqvRpVKyjjgPhEYWgqQnDA12TzKNjd80Fo3HCK6vmmrNj8Xuvwc99ziWa3QN5a8+Z8GbtqQB9Kk3fevvQOcjLC4= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2018 Lines: 73 From: Matthew Wilcox I need the following functions for the radix tree: bitmap_fill find_next_zero_bit bitmap_empty bitmap_full Copy the implementations from include/linux/bitmap.h and lib/find_bit.c --- tools/include/linux/bitmap.h | 26 ++++++++++++++++++++++++++ tools/lib/find_bit.c | 8 ++++++++ 2 files changed, 34 insertions(+) diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h index 43c1c50..eef41d5 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) } } +static inline void bitmap_fill(unsigned long *dst, unsigned int nbits) +{ + unsigned int nlongs = BITS_TO_LONGS(nbits); + if (!small_const_nbits(nbits)) { + unsigned int len = (nlongs - 1) * sizeof(unsigned long); + memset(dst, 0xff, len); + } + dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits); +} + +static inline int bitmap_empty(const unsigned long *src, unsigned nbits) +{ + if (small_const_nbits(nbits)) + return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); + + return find_first_bit(src, nbits) == nbits; +} + +static inline int bitmap_full(const unsigned long *src, unsigned int nbits) +{ + if (small_const_nbits(nbits)) + return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); + + return find_first_zero_bit(src, nbits) == nbits; +} + static inline int bitmap_weight(const unsigned long *src, int nbits) { if (small_const_nbits(nbits)) diff --git a/tools/lib/find_bit.c b/tools/lib/find_bit.c index 9122a9e..de26b6f 100644 --- a/tools/lib/find_bit.c +++ b/tools/lib/find_bit.c @@ -66,6 +66,14 @@ unsigned long find_next_bit(const unsigned long *addr, unsigned long size, } #endif +#ifndef find_next_zero_bit +unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, + unsigned long offset) +{ + return _find_next_bit(addr, size, offset, ~0UL); +} +#endif + #ifndef find_first_bit /* * Find the first set bit in a memory region. -- 2.10.2