[PATCH 1/2] include: sbi_bitmap: add bitmap_empty() function
Anup Patel
anup at brainfault.org
Wed Apr 8 05:37:15 PDT 2026
On Wed, Mar 11, 2026 at 6:21 PM Yu-Chien Peter Lin <peter.lin at sifive.com> wrote:
>
> 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 at sifive.com>
LGTM.
Reviewed-by: Anup Patel <anup at brainfault.org>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
> ---
> 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 at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
More information about the opensbi
mailing list