From 04fb4d4fc795c999afabdc27e02e13b9c6df6583 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Thu, 19 Nov 2020 19:48:20 +0100 Subject: [PATCH] Fix bits_set --- lib/utils.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/utils.c b/lib/utils.c index 96ad730..96ab676 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -93,14 +93,10 @@ uint8_t bits_set(uint32_t x) static const uint8_t bval_bsets[] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4}; uint8_t r = 0; /* Accumulator for the total bits set in x */ - r = bval_bsets[x & 0xFF]; - x >>= 8; - r += bval_bsets[x & 0xFF]; - x >>= 8; - r += bval_bsets[x & 0xFF]; - x >>= 8; - r += bval_bsets[x & 0xFF]; - + while (x) { + r += bval_bsets[x & 0x0F]; + x >>= 4; + } return r; } -- 2.43.0