Skip to content

Commit 70ca373

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 6698629 commit 70ca373

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
@@ -355,29 +355,13 @@ void alloc_and_free_predefined(void)
355355
"sys_bitarray_alloc() failed bits comparison");
356356
}
357357

358-
static inline size_t count_bits(uint32_t val)
359-
{
360-
/* Implements Brian Kernighan’s Algorithm
361-
* to count bits.
362-
*/
363-
364-
size_t cnt = 0;
365-
366-
while (val != 0) {
367-
val = val & (val - 1);
368-
cnt++;
369-
}
370-
371-
return cnt;
372-
}
373-
374358
size_t get_bitarray_popcnt(sys_bitarray_t *ba)
375359
{
376360
size_t popcnt = 0;
377361
unsigned int idx;
378362

379363
for (idx = 0; idx < ba->num_bundles; idx++) {
380-
popcnt += count_bits(ba->bundles[idx]);
364+
popcnt += zephyr_count_bits(&ba->bundles[idx], sizeof(uint32_t));
381365
}
382366

383367
return popcnt;

0 commit comments

Comments
 (0)