Skip to content

Commit 9f23d9f

Browse files
kartbenThalley
authored andcommitted
tests: kernel: adopt new zephyr_count_bits util function
Adopt new zephyr_count_bits helper from util.h and avoid having conflicting definition Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org> Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
1 parent b09f01b commit 9f23d9f

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed

tests/kernel/common/src/bitarray.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -360,29 +360,13 @@ void alloc_and_free_predefined(void)
360360
"sys_bitarray_alloc() failed bits comparison");
361361
}
362362

363-
static inline size_t count_bits(uint32_t val)
364-
{
365-
/* Implements Brian Kernighan’s Algorithm
366-
* to count bits.
367-
*/
368-
369-
size_t cnt = 0;
370-
371-
while (val != 0) {
372-
val = val & (val - 1);
373-
cnt++;
374-
}
375-
376-
return cnt;
377-
}
378-
379363
size_t get_bitarray_popcnt(sys_bitarray_t *ba)
380364
{
381365
size_t popcnt = 0;
382366
unsigned int idx;
383367

384368
for (idx = 0; idx < ba->num_bundles; idx++) {
385-
popcnt += count_bits(ba->bundles[idx]);
369+
popcnt += zephyr_count_bits(&ba->bundles[idx], sizeof(uint32_t));
386370
}
387371

388372
return popcnt;

0 commit comments

Comments
 (0)