Merge "cutils: bitops: Add Hamming weight to bitmask"

This commit is contained in:
Alex Ray 2013-02-26 05:25:43 +00:00 committed by Android (Google) Code Review
commit 3954d778ab
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);