From df94dfc0ee825442f804dc2f5b69f04063c2e622 Mon Sep 17 00:00:00 2001 From: Marius Greuel Date: Wed, 5 Jan 2022 16:52:41 +0100 Subject: [PATCH] Replace MSVC implementation of __builtin_popcount with C code --- src/msvc/msvc_compat.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/msvc/msvc_compat.h b/src/msvc/msvc_compat.h index 19acf5b8..03bb178e 100644 --- a/src/msvc/msvc_compat.h +++ b/src/msvc/msvc_compat.h @@ -36,10 +36,21 @@ #define PATH_MAX _MAX_PATH -#define __builtin_popcount __popcnt - #define setvbuf msvc_setvbuf +static inline int __builtin_popcount(unsigned int v) +{ + int count = 0; + + while (v) + { + count += v & 1; + v >>= 1; + } + + return count; +} + static inline int msvc_setvbuf( FILE* const public_stream, char* const buffer,