Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Jun 22, 2024
1 parent aac06e6 commit 230fa18
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions include/popcnt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion test/cpuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 230fa18

Please sign in to comment.