From: Yury Norov <yury.norov@gmail.com>
To: linux-kernel@vger.kernel.org,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Yury Norov <yury.norov@gmail.com>
Subject: [PATCH 1/6] bitmap: add bitmap_empty_from()
Date: Thu, 27 Oct 2022 18:48:29 -0700 [thread overview]
Message-ID: <20221028014834.572819-2-yury.norov@gmail.com> (raw)
In-Reply-To: <20221028014834.572819-1-yury.norov@gmail.com>
New function checks if a bitmap is empty starting from a specific bit.
In the following patch, it's used to replace _reg_op(REG_OP_ISFREE).
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
include/linux/bitmap.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 40e53a2ecc0d..f84553805c9c 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -49,6 +49,7 @@ struct device;
* bitmap_intersects(src1, src2, nbits) Do *src1 and *src2 overlap?
* bitmap_subset(src1, src2, nbits) Is *src1 a subset of *src2?
* bitmap_empty(src, nbits) Are all bits zero in *src?
+ * bitmap_empty_from(src, start, nbits) Are all bits zero in *src starting from @start?
* bitmap_full(src, nbits) Are all bits set in *src?
* bitmap_weight(src, nbits) Hamming Weight: number set bits
* bitmap_weight_and(src1, src2, nbits) Hamming Weight of and'ed bitmap
@@ -433,6 +434,16 @@ static __always_inline bool bitmap_full(const unsigned long *src, unsigned int n
return find_first_zero_bit(src, nbits) == nbits;
}
+static __always_inline
+bool bitmap_empty_from(const unsigned long *src, unsigned int start, unsigned int nbits)
+{
+ if (small_const_nbits_off(nbits, start))
+ return !(src[start/BITS_PER_LONG] &
+ GENMASK((nbits - 1) % BITS_PER_LONG, start % BITS_PER_LONG));
+
+ return find_next_bit(src, nbits, start) == nbits;
+}
+
static __always_inline
unsigned int bitmap_weight(const unsigned long *src, unsigned int nbits)
{
--
2.34.1
next prev parent reply other threads:[~2022-10-28 1:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-28 1:48 [PATCH 0/6] bitmap: remove _reg_op() Yury Norov
2022-10-28 1:48 ` Yury Norov [this message]
2022-10-28 1:48 ` [PATCH 2/6] bitmap: replace _reg_op(REG_OP_ALLOC) with bitmap_set() Yury Norov
2022-11-11 6:54 ` kernel test robot
2022-10-28 1:48 ` [PATCH 3/6] bitmap: replace _reg_op(REG_OP_RELEASE) with bitmap_clear() Yury Norov
2022-10-28 1:48 ` [PATCH 4/6] bitmap: replace _reg_op(REG_OP_ISFREE) with bitmap_empty_from() Yury Norov
2022-10-28 1:48 ` [PATCH 5/6] bitmap: fix opencoded bitmap_allocate_region() Yury Norov
2022-10-28 1:48 ` [PATCH 6/6] bitmap: drop _reg_op() Yury Norov
2022-11-03 2:09 ` [PATCH 0/6] bitmap: remove _reg_op() Yury Norov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221028014834.572819-2-yury.norov@gmail.com \
--to=yury.norov@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®