diff --git a/libtransmission/tr-popcount.h b/libtransmission/tr-popcount.h index 6c2714a8c..638c5d758 100644 --- a/libtransmission/tr-popcount.h +++ b/libtransmission/tr-popcount.h @@ -27,17 +27,11 @@ #define TR_HAVE_BUILTIN_POPCOUNT #endif #endif -#if defined(__x86_64__) && defined(__SSE__) +#if (defined(__x86_64__) || defined(__i386__)) && defined(__POPCNT__) #define TR_HAVE_ASM_POPCNT #endif #endif -#if defined(_MSC_VER) -#if defined(_M_X64) || defined(_M_IX86) -#include -#endif -#endif - #if defined(TR_HAVE_STD_POPCOUNT) #include #endif @@ -65,7 +59,7 @@ struct tr_popcnt return static_cast(std::popcount(unsigned_v)); } -#elif defined(TR_HAVE_BUILTIN_POPCOUNT) && defined(TR_HAVE_ASM_POPCNT) +#elif defined(TR_HAVE_BUILTIN_POPCOUNT) /* Use __builtin as opposed to straight assembly to avoid any strain the latter puts on the optimized. */ static inline unsigned count(T v) @@ -95,50 +89,6 @@ struct tr_popcnt return __builtin_popcount(unsigned_v); } } - -#elif defined(_MSC_VER) && defined(_M_X64) - /* 64-bit x86 intrinsics. */ - static inline unsigned count(T v) - { - if constexpr (sizeof(T) == sizeof(uint64_t)) - { - return _mm_popcnt_u64(v); - } - else if constexpr (sizeof(T) == sizeof(uint32_t)) - { - return _mm_popcnt_u32(v); - } - else - { - static_assert(sizeof(T) < sizeof(uint32_t)); - /* Need to avoid sign extension. */ - unsigned_T unsigned_v = static_cast(v); - return _mm_popcnt_u32(unsigned_v); - } - } -#elif defined(_MSC_VER) && defined(_M_IX86) - /* 32-bit x86 intrinsics. */ - static inline unsigned count(T v) - { - if constexpr (sizeof(T) == sizeof(uint64_t)) - { - /* Avoid signed shift. */ - unsigned_T unsigned_v = static_cast(v); - - return _mm_popcnt_u32(static_cast(unsigned_v)) + _mm_popcnt_u32(static_cast(unsigned_v >> 32)); - } - else if constexpr (sizeof(T) == sizeof(uint32_t)) - { - return _mm_popcnt_u32(v); - } - else - { - static_assert(sizeof(T) < sizeof(uint32_t)); - /* Need to avoid sign extension. */ - unsigned_T unsigned_v = static_cast(v); - return _mm_popcnt_u32(unsigned_v); - } - } #elif defined(TR_HAVE_ASM_POPCNT) /* raw assembly. This prohibits constexpr so may be worth dropping if there * is need for count() to be constexpr. */