From 18095a6c6030fb157f89889b8094eca0b3f654cb Mon Sep 17 00:00:00 2001 From: Max Graey Date: Tue, 7 Jul 2020 01:38:00 +0300 Subject: Avoid __popcnt and __popcnt64 intrinsics for MSVC (#2944) We may need to check the CPU ID or something else before using those special things on MSVC. To be safe, avoid them for now. --- src/support/bits.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/support/bits.cpp') diff --git a/src/support/bits.cpp b/src/support/bits.cpp index f57a6d0e8..8dc0f31df 100644 --- a/src/support/bits.cpp +++ b/src/support/bits.cpp @@ -21,8 +21,6 @@ #ifdef _MSC_VER #include -#define __builtin_popcount __popcnt -#define __builtin_popcountll __popcnt64 #endif namespace wasm { @@ -36,16 +34,16 @@ template<> int PopCount(uint8_t v) { } template<> int PopCount(uint16_t v) { -#if __has_builtin(__builtin_popcount) || defined(__GNUC__) || defined(_MSC_VER) - return (int)__builtin_popcount(v); +#if __has_builtin(__builtin_popcount) || defined(__GNUC__) + return __builtin_popcount(v); #else return PopCount((uint8_t)(v & 0xFF)) + PopCount((uint8_t)(v >> 8)); #endif } template<> int PopCount(uint32_t v) { -#if __has_builtin(__builtin_popcount) || defined(__GNUC__) || defined(_MSC_VER) - return (int)__builtin_popcount(v); +#if __has_builtin(__builtin_popcount) || defined(__GNUC__) + return __builtin_popcount(v); #else // See Stanford bithacks, counting bits set in parallel, "best method": // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel @@ -56,8 +54,8 @@ template<> int PopCount(uint32_t v) { } template<> int PopCount(uint64_t v) { -#if __has_builtin(__builtin_popcount) || defined(__GNUC__) || defined(_MSC_VER) - return (int)__builtin_popcountll(v); +#if __has_builtin(__builtin_popcount) || defined(__GNUC__) + return __builtin_popcountll(v); #else return PopCount((uint32_t)v) + PopCount((uint32_t)(v >> 32)); #endif -- cgit v1.2.3