From b8061d80410e05f306e13063ec0f12a2c8eb80b4 Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Sun, 21 May 2017 11:11:05 +0100 Subject: [PATCH] Change popcnt so that the code does not depend on ABM extenstions (SSE4) --- autoAdjustHwloc.hpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/autoAdjustHwloc.hpp b/autoAdjustHwloc.hpp index d2039c0..325d9bc 100644 --- a/autoAdjustHwloc.hpp +++ b/autoAdjustHwloc.hpp @@ -3,6 +3,19 @@ #include "console.h" #include +/* + * compat_popcnt is adapted from public domain code by: + * Portable Snippets - https://gitub.com/nemequ/portable-snippets + * Created by Evan Nemerson + */ +int compat_popcnt(size_t x) +{ + x = x - ((x >> 1) & (size_t)~(size_t)0/3); + x = (x & (size_t)~(size_t)0/15*3) + ((x >> 2) & (size_t)~(size_t)0/15*3); + x = (x + (x >> 4)) & (size_t)~(size_t)0/255*15; + return (size_t)(x * ((size_t)~(size_t)0/255)) >> (sizeof(size_t) - 1) * 8; +} + #ifdef _WIN32 #include #else @@ -98,7 +111,7 @@ private: cpu >>= rightZeros(allcpu); - int nativeCores = __builtin_popcount(cpu); + int nativeCores = compat_popcnt(cpu); int numPus = obj->arity; for (int i = 0; i < numPus && numHashes != 0; i++) {