summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2016-08-27 10:21:40 +0200
committerJulian Taylor <jtaylor.debian@googlemail.com>2016-08-27 10:36:37 +0200
commit10723a9b73feb59278bf6e0c8ad0830c3ddb0600 (patch)
treee8f422c138e641cf89c48bd038cd3a064c542de3 /numpy/core
parenteeb4e17a165e90430a01936914afb2bbeb34acc7 (diff)
downloadnumpy-10723a9b73feb59278bf6e0c8ad0830c3ddb0600.tar.gz
MAINT: add avx __builtin_cpu_supports and target attribute checks
NPY_CPU_SUPPORTS_AVX2 checks at runtime if AVX2 is supported
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/include/numpy/npy_common.h17
-rw-r--r--numpy/core/setup_common.py3
2 files changed, 20 insertions, 0 deletions
diff --git a/numpy/core/include/numpy/npy_common.h b/numpy/core/include/numpy/npy_common.h
index baf5549d9..d851b7fb2 100644
--- a/numpy/core/include/numpy/npy_common.h
+++ b/numpy/core/include/numpy/npy_common.h
@@ -28,6 +28,13 @@
#define NPY_GCC_OPT_3
#endif
+/* compile target attributes */
+#ifdef HAVE_ATTRIBUTE_TARGET_AVX2
+#define NPY_GCC_TARGET_AVX2 __attribute__((target("avx2")))
+#else
+#define NPY_GCC_TARGET_AVX2
+#endif
+
/*
* mark an argument (starting from 1) that must not be NULL and is not checked
* DO NOT USE IF FUNCTION CHECKS FOR NULL!! the compiler will remove the check
@@ -79,6 +86,16 @@
#endif
#endif
+#ifdef HAVE___BUILTIN_CPU_SUPPORTS
+ #ifdef HAVE_ATTRIBUTE_TARGET_AVX2
+ #define NPY_CPU_SUPPORTS_AVX2 __builtin_cpu_supports("avx2")
+ #else
+ #define NPY_CPU_SUPPORTS_AVX2 0
+ #endif
+#else
+ #define NPY_CPU_SUPPORTS_AVX2 0
+#endif
+
#if defined(_MSC_VER)
#define NPY_INLINE __inline
#elif defined(__GNUC__)
diff --git a/numpy/core/setup_common.py b/numpy/core/setup_common.py
index ba7521e30..2a42a0638 100644
--- a/numpy/core/setup_common.py
+++ b/numpy/core/setup_common.py
@@ -125,6 +125,7 @@ OPTIONAL_INTRINSICS = [("__builtin_isnan", '5.'),
("__builtin_bswap64", '5u'),
("__builtin_expect", '5, 0'),
("__builtin_mul_overflow", '5, 5, (int*)5'),
+ ("__builtin_cpu_supports", '"sse"'),
("_mm_load_ps", '(float*)0', "xmmintrin.h"), # SSE
("_mm_prefetch", '(float*)0, _MM_HINT_NTA',
"xmmintrin.h"), # SSE
@@ -141,6 +142,8 @@ OPTIONAL_FUNCTION_ATTRIBUTES = [('__attribute__((optimize("unroll-loops")))',
'attribute_optimize_opt_3'),
('__attribute__((nonnull (1)))',
'attribute_nonnull'),
+ ('__attribute__((target ("avx2")))',
+ 'attribute_target_avx2'),
]
# variable attributes tested via "int %s a" % attribute