diff options
author | Max Graey <maxgraey@gmail.com> | 2020-07-07 01:38:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-06 15:38:00 -0700 |
commit | 18095a6c6030fb157f89889b8094eca0b3f654cb (patch) | |
tree | 4b6ce4580b3602de916ab438d94e5ec81fae6970 /src/support/bits.cpp | |
parent | 49421e42a8082a1b75dda65411af3fb4b0ba9fe5 (diff) | |
download | binaryen-18095a6c6030fb157f89889b8094eca0b3f654cb.tar.gz binaryen-18095a6c6030fb157f89889b8094eca0b3f654cb.tar.bz2 binaryen-18095a6c6030fb157f89889b8094eca0b3f654cb.zip |
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.
Diffstat (limited to 'src/support/bits.cpp')
-rw-r--r-- | src/support/bits.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
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 <intrin.h> -#define __builtin_popcount __popcnt -#define __builtin_popcountll __popcnt64 #endif namespace wasm { @@ -36,16 +34,16 @@ template<> int PopCount<uint8_t>(uint8_t v) { } template<> int PopCount<uint16_t>(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>(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>(uint32_t v) { } template<> int PopCount<uint64_t>(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 |