cutils: bitops: Add Hamming weight to bitmask
Change-Id: I5c6b7adf711007edfffcb4fdf8e05b04bcffef54
This commit is contained in:
parent
2448146982
commit
f90fd9eeb3
|
@ -75,6 +75,16 @@ static inline int bitmask_ffz(unsigned int *bitmask, int num_bits)
|
|||
return -1;
|
||||
}
|
||||
|
||||
static inline int bitmask_weight(unsigned int *bitmask, int num_bits)
|
||||
{
|
||||
int i;
|
||||
int weight = 0;
|
||||
|
||||
for (i = 0; i < BITS_TO_WORDS(num_bits); i++)
|
||||
weight += __builtin_popcount(bitmask[i]);
|
||||
return weight;
|
||||
}
|
||||
|
||||
static inline void bitmask_set(unsigned int *bitmask, int bit)
|
||||
{
|
||||
bitmask[BIT_WORD(bit)] |= BIT_MASK(bit);
|
||||
|
|
Loading…
Reference in New Issue