mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-04-12 22:01:45 +01:00
include: sbi_bitmap: add bitmap_empty() function
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> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20260311125116.1401002-1-peter.lin@sifive.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
committed by
Anup Patel
parent
0b041e58c0
commit
ff7d245b86
@@ -143,4 +143,20 @@ static inline int bitmap_weight(const unsigned long *src, int nbits)
|
|||||||
return res;
|
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
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user