tests: kernel: adopt new count_bits util function
Adopt new count_bits helper from util.h and avoid having conflicting definition Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
This commit is contained in:
parent
17c42550f3
commit
e34270519e
1 changed files with 1 additions and 17 deletions
|
@ -355,29 +355,13 @@ void alloc_and_free_predefined(void)
|
|||
"sys_bitarray_alloc() failed bits comparison");
|
||||
}
|
||||
|
||||
static inline size_t count_bits(uint32_t val)
|
||||
{
|
||||
/* Implements Brian Kernighan’s Algorithm
|
||||
* to count bits.
|
||||
*/
|
||||
|
||||
size_t cnt = 0;
|
||||
|
||||
while (val != 0) {
|
||||
val = val & (val - 1);
|
||||
cnt++;
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
size_t get_bitarray_popcnt(sys_bitarray_t *ba)
|
||||
{
|
||||
size_t popcnt = 0;
|
||||
unsigned int idx;
|
||||
|
||||
for (idx = 0; idx < ba->num_bundles; idx++) {
|
||||
popcnt += count_bits(ba->bundles[idx]);
|
||||
popcnt += count_bits(&ba->bundles[idx], sizeof(uint32_t));
|
||||
}
|
||||
|
||||
return popcnt;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue