From b9e29520cf4d800fab8ee4b905ceb6310e876032 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 25 Oct 2021 10:52:13 +0200 Subject: [PATCH] Fix `__popcnt` on MSVC only if SSE 4.2 is available --- Source/Engine/Core/Utilities.h | 4 ++-- Source/Engine/Platform/Defines.h | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Core/Utilities.h b/Source/Engine/Core/Utilities.h index c6d476884..bdd5b5f22 100644 --- a/Source/Engine/Core/Utilities.h +++ b/Source/Engine/Core/Utilities.h @@ -4,7 +4,7 @@ #include "Types/BaseTypes.h" #include "Types/String.h" -#if _MSC_VER +#if _MSC_VER && PLATFORM_SIMD_SSE4_2 #include #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); diff --git a/Source/Engine/Platform/Defines.h b/Source/Engine/Platform/Defines.h index 7ca4f3b9d..2ac7f8e1f 100644 --- a/Source/Engine/Platform/Defines.h +++ b/Source/Engine/Platform/Defines.h @@ -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