Commit e3427051 authored by Benjamin Cabé's avatar Benjamin Cabé Committed by Benjamin Cabé
Browse files

tests: kernel: adopt new count_bits util function

Adopt new count_bits helper from util.h and avoid
having conflicting definition

Signed-off-by: default avatarBenjamin Cabé <benjamin@zephyrproject.org>
parent 17c42550
Loading
Loading
Loading
Loading
+1 −17
Changes for tests/kernel/common/src/bitarray.c: 1 added line, 17 removed lines.
Original line number Diff line number Diff line
@@ -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;