From: Yu-Chien Peter Lin <peter.lin@sifive.com>
To: opensbi@lists.infradead.org
Cc: Yu-Chien Peter Lin <peter.lin@sifive.com>
Subject: [PATCH 1/2] include: sbi_bitmap: add bitmap_empty() function
Date: Wed, 11 Mar 2026 20:51:15 +0800 [thread overview]
Message-ID: <20260311125116.1401002-1-peter.lin@sifive.com> (raw)
Add bitmap_empty() to check if bitmap has no bits set.
Unlike bitmap_weight() which calls sbi_popcount() on every word,
bitmap_empty() uses simple non-zero comparisons with early exit.
Signed-off-by: Yu-Chien Peter Lin <peter.lin@sifive.com>
---
include/sbi/sbi_bitmap.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/include/sbi/sbi_bitmap.h b/include/sbi/sbi_bitmap.h
index 596bcc7d..80d3fe3b 100644
--- a/include/sbi/sbi_bitmap.h
+++ b/include/sbi/sbi_bitmap.h
@@ -143,4 +143,20 @@ static inline int bitmap_weight(const unsigned long *src, int nbits)
return res;
}
+static inline bool bitmap_empty(const unsigned long *src, int nbits)
+{
+ if (nbits == 0)
+ return true;
+
+ if (small_const_nbits(nbits))
+ return !(*src & BITMAP_LAST_WORD_MASK(nbits));
+ else {
+ size_t i, len = BITS_TO_LONGS(nbits);
+ for (i = 0; i < len - 1; i++)
+ if (src[i])
+ return false;
+ return !(src[len - 1] & BITMAP_LAST_WORD_MASK(nbits));
+ }
+}
+
#endif
--
2.53.0
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next reply other threads:[~2026-03-11 12:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 12:51 Yu-Chien Peter Lin [this message]
2026-03-11 12:51 ` [PATCH 2/2] lib: sbi_bitmap_test: add tests for bitmap_empty() Yu-Chien Peter Lin
2026-04-08 12:37 ` Anup Patel
2026-04-08 12:37 ` [PATCH 1/2] include: sbi_bitmap: add bitmap_empty() function Anup Patel
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=20260311125116.1401002-1-peter.lin@sifive.com \
--to=peter.lin@sifive.com \
--cc=opensbi@lists.infradead.org \
/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