cutils: bitops: Add Hamming weight to bitmask

Change-Id: I5c6b7adf711007edfffcb4fdf8e05b04bcffef54
This commit is contained in:
Alex Ray 2013-01-19 22:53:46 -08:00
parent 2448146982
commit f90fd9eeb3
1 changed files with 10 additions and 0 deletions

View File

@ -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);