From 386a952b8cb6af426e9d270e4d159efe73540240 Mon Sep 17 00:00:00 2001 From: VitaSmith Date: Mon, 20 Jan 2020 23:48:40 +0000 Subject: [PATCH] gust_g1t: fix incompatibility with non SSE4.2 platforms * Closes #8 --- util.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/util.h b/util.h index a1c62f7..1d972a0 100644 --- a/util.h +++ b/util.h @@ -112,7 +112,12 @@ static __inline uint32_t find_msb(uint32_t v) static __inline uint32_t popcount(uint32_t v) { #if defined (_MSC_VER) - return __popcnt(v); + // The built in __popcnt() used by Microsoft may require SSE4.2 + // which not all machines have => use our own (GitHub issue #8). + v -= (v >> 1) & 0x55555555; + v = (v & 0x33333333) + ((v >> 2) & 0x33333333); + v = (v + (v >> 4)) & 0x0f0f0f0f; + return (v * 0x01010101) >> 24; #else return __builtin_popcount(v); #endif