Skip to content

Commit

Permalink
Fix clang-cl (Windows) compilation
Browse files Browse the repository at this point in the history
1) Don't do AVX2 because requires /arch:AVX2 flag
2) clang-cl does not know _mm_popcnt_u64(), _mm_popcnt_u32()
  • Loading branch information
kimwalisch committed Mar 26, 2017
1 parent ec6fd44 commit 63c92ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
5 changes: 3 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
2017-03-25 Kim Walisch <[email protected]>
2017-03-26 Kim Walisch <[email protected]>

Version 1.2 released.

* Add cpuid check for x86 CPUs.
* Compiles without -mpopcnt, -mavx2 flags.
* Tested successfully on IBM POWER8 (generates popcntd, GCC 5.4)
* Successfully tested on IBM POWER8 (generates popcntd, GCC 5.4).
* Successfully tested using clang-cl (Windows).
* Add ChangeLog.
* Update README.md.
47 changes: 24 additions & 23 deletions libpopcnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#if (defined(__x86_64__) || \
defined(__i386__)) && \
defined(__clang__) && \
!defined(_MSC_VER) && \
!defined(__apple_build_version__) && \
(__clang_major__ > 3 || \
(__clang_major__ == 3 && \
Expand Down Expand Up @@ -110,29 +111,8 @@ static inline uint64_t popcount64c(uint64_t x)
return (x * h01) >> 56;
}

#if defined(_MSC_VER) && \
defined(_M_X64)

#include <nmmintrin.h>

static inline uint64_t popcnt64(uint64_t x)
{
return _mm_popcnt_u64(x);
}

#elif defined(_MSC_VER) && \
defined(_M_IX86)

#include <nmmintrin.h>

static inline uint64_t popcnt64(uint64_t x)
{
return _mm_popcnt_u32((uint32_t) x) +
_mm_popcnt_u32((uint32_t)(x >> 32));
}

#elif defined(HAS_ASM_POPCNT) && \
defined(__x86_64__)
#if defined(HAS_ASM_POPCNT) && \
defined(__x86_64__)

static inline uint64_t popcnt64(uint64_t x)
{
Expand All @@ -155,6 +135,27 @@ static inline uint64_t popcnt64(uint64_t x)
popcnt32((uint32_t)(x >> 32));
}

#elif defined(_MSC_VER) && \
defined(_M_X64)

#include <nmmintrin.h>

static inline uint64_t popcnt64(uint64_t x)
{
return _mm_popcnt_u64(x);
}

#elif defined(_MSC_VER) && \
defined(_M_IX86)

#include <nmmintrin.h>

static inline uint64_t popcnt64(uint64_t x)
{
return _mm_popcnt_u32((uint32_t) x) +
_mm_popcnt_u32((uint32_t)(x >> 32));
}

// non x86 CPUs
#elif defined(HAS_BUILTIN_POPCOUNT)

Expand Down

0 comments on commit 63c92ff

Please sign in to comment.