Commit fadaae42 authored by Emil Gydesen's avatar Emil Gydesen Committed by Benjamin Cabé
Browse files

Revert "tests: kernel: adopt new count_bits util function"

This reverts commit e3427051.

Signed-off-by: default avatarEmil Gydesen <emil.gydesen@nordicsemi.no>
parent 60a98018
Loading
Loading
Loading
Loading
+17 −1
Changes for tests/kernel/common/src/bitarray.c: 17 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -355,13 +355,29 @@ 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], sizeof(uint32_t));
		popcnt += count_bits(ba->bundles[idx]);
	}

	return popcnt;