From 6277c8b49c72248e1478f46fcc0251b912f5dc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berke=20Kocao=C4=9Flu?= Date: Fri, 23 Aug 2024 11:50:58 +0300 Subject: [PATCH] popcount: fix incorrect result when not on GNU/Clang --- src/c/util/math/popcount.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/c/util/math/popcount.c b/src/c/util/math/popcount.c index 8b2de12f..d9ef5826 100644 --- a/src/c/util/math/popcount.c +++ b/src/c/util/math/popcount.c @@ -25,8 +25,9 @@ int main(int argc, char *argv[]) #ifdef USE_BUILTIN popcount += __builtin_popcount(c & 0xff); #else - popcount += (c & 0x01) + (c & 0x02) + (c & 0x04) + (c & 0x08) + (c & 0x10) + - (c & 0x20) + (c & 0x40) + (c & 0x80); + popcount += ((c & (1 << 0)) >> 0) + ((c & (1 << 1)) >> 1) + ((c & (1 << 2)) >> 2) + + ((c & (1 << 3)) >> 3) + ((c & (1 << 4)) >> 4) + ((c & (1 << 5)) >> 5) + + ((c & (1 << 6)) >> 6) + ((c & (1 << 7)) >> 7); #endif } }