From 80d53839dda96a023a6bfc717a3210e087ca6aed 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 aef86b05..57f3f42d 100644 --- a/src/msvc/msvc_compat.h +++ b/src/msvc/msvc_compat.h @@ -32,10 +32,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,