From 63c92ffe0b48286c7015cf33042a45018c995222 Mon Sep 17 00:00:00 2001 From: Kim Walisch Date: Sun, 26 Mar 2017 14:41:26 +0200 Subject: [PATCH] Fix clang-cl (Windows) compilation 1) Don't do AVX2 because requires /arch:AVX2 flag 2) clang-cl does not know _mm_popcnt_u64(), _mm_popcnt_u32() --- ChangeLog | 5 +++-- libpopcnt.h | 47 ++++++++++++++++++++++++----------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2ae60a6..e25c0b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,10 @@ -2017-03-25 Kim Walisch +2017-03-26 Kim Walisch 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. diff --git a/libpopcnt.h b/libpopcnt.h index 5039789..2b55a67 100644 --- a/libpopcnt.h +++ b/libpopcnt.h @@ -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 && \ @@ -110,29 +111,8 @@ static inline uint64_t popcount64c(uint64_t x) return (x * h01) >> 56; } -#if defined(_MSC_VER) && \ - defined(_M_X64) - -#include - -static inline uint64_t popcnt64(uint64_t x) -{ - return _mm_popcnt_u64(x); -} - -#elif defined(_MSC_VER) && \ - defined(_M_IX86) - -#include - -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) { @@ -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 + +static inline uint64_t popcnt64(uint64_t x) +{ + return _mm_popcnt_u64(x); +} + +#elif defined(_MSC_VER) && \ + defined(_M_IX86) + +#include + +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)