forked from Mirrors/opensbi
sbi: Introduce sbi_hartmask_weight
Provide a function to count the number of set bits in a hartmask, which builds on a new function for the same that operates on a bitmask. While at it, improve the performance of sbi_popcount() which is used in the implementation. Signed-off-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20250314163021.154530-5-ajones@ventanamicro.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
@@ -130,4 +130,17 @@ static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1,
|
||||
__bitmap_xor(dst, src1, src2, nbits);
|
||||
}
|
||||
|
||||
static inline int bitmap_weight(const unsigned long *src, int nbits)
|
||||
{
|
||||
int i, res = 0;
|
||||
|
||||
for (i = 0; i < nbits / BITS_PER_LONG; i++)
|
||||
res += sbi_popcount(src[i]);
|
||||
|
||||
if (nbits % BITS_PER_LONG)
|
||||
res += sbi_popcount(src[i] & BITMAP_LAST_WORD_MASK(nbits));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user