summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Michal <michal@physics.ubc.ca>2021-05-23 08:24:52 -0700
committerCarl Michal <michal@physics.ubc.ca>2021-05-23 08:24:52 -0700
commit3827c262d128811f3ee36d2bd015544f5922e7c5 (patch)
treeba7a2e653c21b3c109682d5c15e0740f80c54f06
parent59764c6d3621423c9d4e136e99a69078a79ca6f5 (diff)
downloadnumpy-3827c262d128811f3ee36d2bd015544f5922e7c5.tar.gz
Change fix of cpu_popcnt.c to use _mm_popcnt_u64/_mm_popcnt_u32 on GCC
_builtin_popcount is always available, so the compile-time check always succeeds.
-rw-r--r--numpy/distutils/checks/cpu_popcnt.c26
1 files changed, 8 insertions, 18 deletions
diff --git a/numpy/distutils/checks/cpu_popcnt.c b/numpy/distutils/checks/cpu_popcnt.c
index f6c785dd2..540c98dab 100644
--- a/numpy/distutils/checks/cpu_popcnt.c
+++ b/numpy/distutils/checks/cpu_popcnt.c
@@ -4,26 +4,16 @@
#include <popcntintrin.h>
#endif
-#include <stdlib.h>
-
-int main(void)
+int main(int argc, char **argv)
{
- long long a = 0;
- int b;
-
- a = random();
- b = random();
-
-#ifdef _MSC_VER
- #ifdef _M_X64
+ // To make sure popcnt instructions are generated
+ // and been tested against the assembler
+ unsigned long long a = *((unsigned long long*)argv[argc-1]);
+ unsigned int b = *((unsigned int*)argv[argc-2]);
+
+#if defined(_M_X64) || defined(__x86_64__)
a = _mm_popcnt_u64(a);
- #endif
- b = _mm_popcnt_u32(b);
-#else
- #ifdef __x86_64__
- a = __builtin_popcountll(a);
- #endif
- b = __builtin_popcount(b);
#endif
+ b = _mm_popcnt_u32(b);
return (int)a + b;
}