From 230fa182a8a1d79cbe7bc6c7b13d87e99bd39ece Mon Sep 17 00:00:00 2001 From: Kim Walisch Date: Sat, 22 Jun 2024 11:05:44 +0200 Subject: [PATCH] Refactor --- include/popcnt.hpp | 10 ++++++++-- test/cpuid.cpp | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/popcnt.hpp b/include/popcnt.hpp index 054ae88e..7cdadc5e 100644 --- a/include/popcnt.hpp +++ b/include/popcnt.hpp @@ -134,13 +134,16 @@ namespace { ALWAYS_INLINE uint64_t popcnt64(uint64_t x) { -#if defined(__AVX__) +#if defined(__POPCNT__) || \ + defined(__AVX__) return __popcnt64(x); + #elif defined(ENABLE_MULTIARCH_x86_POPCNT) if_likely(cpu_supports_popcnt) return __popcnt64(x); else return popcnt64_bitwise(x); + #else return popcnt64_bitwise(x); #endif @@ -158,15 +161,18 @@ namespace { ALWAYS_INLINE uint64_t popcnt64(uint64_t x) { -#if defined(__AVX__) +#if defined(__POPCNT__) || \ + defined(__AVX__) return __popcnt(uint32_t(x)) + __popcnt(uint32_t(x >> 32)); + #elif defined(ENABLE_MULTIARCH_x86_POPCNT) if_likely(cpu_supports_popcnt) return __popcnt(uint32_t(x)) + __popcnt(uint32_t(x >> 32)); else return popcnt64_bitwise(x); + #else return popcnt64_bitwise(x); #endif diff --git a/test/cpuid.cpp b/test/cpuid.cpp index a656911a..7bdea756 100644 --- a/test/cpuid.cpp +++ b/test/cpuid.cpp @@ -25,7 +25,9 @@ int main() std::cerr << "Error: ENABLE_MULTIARCH_x86_POPCNT must not be defined if __POPCNT__ is defined!" << std::endl; #endif - #if defined(_MSC_VER) + #if defined(_MSC_VER) && \ + !defined(__POPCNT__) + #if defined(__AVX__) && defined(ENABLE_MULTIARCH_x86_POPCNT) std::cerr << "Error: ENABLE_MULTIARCH_x86_POPCNT must not be defined if __AVX__ is defined!" << std::endl; #endif