Fix __popcnt on MSVC only if SSE 4.2 is available

This commit is contained in:
Wojtek Figat
2021-10-25 10:52:13 +02:00
parent 8fdfbfdfe2
commit b9e29520cf
2 changed files with 15 additions and 3 deletions

View File

@@ -4,7 +4,7 @@
#include "Types/BaseTypes.h"
#include "Types/String.h"
#if _MSC_VER
#if _MSC_VER && PLATFORM_SIMD_SSE4_2
#include <intrin.h>
#endif
@@ -53,7 +53,7 @@ namespace Utilities
// [Reference: https://stackoverflow.com/questions/109023/how-to-count-the-number-of-set-bits-in-a-32-bit-integer]
#ifdef __GNUC_
return __builtin_popcount(x);
#elif _MSC_VER
#elif _MSC_VER && PLATFORM_SIMD_SSE4_2
return __popcnt(x);
#else
x = x - ((x >> 1) & 0x55555555);

View File

@@ -192,8 +192,20 @@ API_ENUM() enum class ArchitectureType
#define PLATFORM_APPLE_FAMILY (PLATFORM_IOS || PLATFORM_OSX)
// SIMD defines
#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) || (defined (__EMSCRIPTEN__) && defined(__SSE2__))
#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) || defined(__SSE2__)
#define PLATFORM_SIMD_SSE2 1
#if defined(__SSE3__)
#define PLATFORM_SIMD_SSE3 1
#endif
#if defined(__SSE4__)
#define PLATFORM_SIMD_SSE4 1
#endif
#if defined(__SSE4_1__)
#define PLATFORM_SIMD_SSE4_1 1
#endif
#if defined(__SSE4_2__)
#define PLATFORM_SIMD_SSE4_2 1
#endif
#endif
#if defined(_M_ARM) || defined(__ARM_NEON__) || defined(__ARM_NEON)
#define PLATFORM_SIMD_NEON 1