From bdd2c0a08d667a537d9dc4f91f6ca3623b2b4dfb Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Fri, 5 Oct 2018 18:22:17 +0200 Subject: [PATCH] Add configure check for altivec and enable it in vectorization.h --- cmake/checks/check_01_cpu_features.cmake | 49 +++++++++++++++++++++++- include/deal.II/base/vectorization.h | 20 +++++----- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/cmake/checks/check_01_cpu_features.cmake b/cmake/checks/check_01_cpu_features.cmake index 23793d3c77..5404df016c 100644 --- a/cmake/checks/check_01_cpu_features.cmake +++ b/cmake/checks/check_01_cpu_features.cmake @@ -27,6 +27,7 @@ # DEAL_II_HAVE_SSE2 *) # DEAL_II_HAVE_AVX *) # DEAL_II_HAVE_AVX512 *) +# DEAL_II_HAVE_ALTIVEC *) # DEAL_II_COMPILER_VECTORIZATION_LEVEL # DEAL_II_HAVE_OPENMP_SIMD *) # DEAL_II_OPENMP_SIMD_PRAGMA @@ -72,7 +73,7 @@ IF(DEAL_II_ALLOW_PLATFORM_INTROSPECTION) # CMAKE_REQUIRED_FLAGS changes.. # UNSET_IF_CHANGED(CHECK_CPU_FEATURES_FLAGS_SAVED "${CMAKE_REQUIRED_FLAGS}" - DEAL_II_HAVE_SSE2 DEAL_II_HAVE_AVX DEAL_II_HAVE_AVX512 + DEAL_II_HAVE_SSE2 DEAL_II_HAVE_AVX DEAL_II_HAVE_AVX512 DEAL_II_HAVE_ALTIVEC ) CHECK_CXX_SOURCE_RUNS( @@ -202,6 +203,48 @@ IF(DEAL_II_ALLOW_PLATFORM_INTROSPECTION) } " DEAL_II_HAVE_AVX512) + + CHECK_CXX_SOURCE_RUNS( + " + #ifndef __ALTIVEC__ + #error \"__ALTIVEC__ flag not set, no support for Altivec\" + #endif + #include + #undef vector + #undef pixel + #undef bool + int main() + { + __vector double a, b, data1, data2; + const int n_vectors = sizeof(a)/sizeof(double); + double * ptr = reinterpret_cast(&a); + ptr[0] = (volatile double)(1.0); + for (int i=1; i(&data2); + unsigned int return_value = 0; + if (ptr[0] != 7.3125) + return_value += 1; + for (int i=1; i(&b); + if (ptr[0] != 7.3125) + return_value += 4; + for (int i=1; i= 2 && !defined(__AVX__) +#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 2 && defined(__SSE2__) && \ + !defined(__AVX__) # error \ "Mismatch in vectorization capabilities: AVX was detected during configuration of deal.II and switched on, but it is apparently not available for the file you are trying to compile at the moment. Check compilation flags controlling the instruction set, such as -march=native." #endif -#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 3 && !defined(__AVX512F__) +#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 3 && defined(__SSE2__) && \ + !defined(__AVX512F__) # error \ "Mismatch in vectorization capabilities: AVX-512F was detected during configuration of deal.II and switched on, but it is apparently not available for the file you are trying to compile at the moment. Check compilation flags controlling the instruction set, such as -march=native." #endif @@ -56,7 +58,7 @@ #endif -#ifdef __ALTIVEC__ +#if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 1 && defined(__ALTIVEC__) # include // altivec.h defines vector, pixel, bool, but we do not use them, so undefine @@ -2190,10 +2192,7 @@ vectorized_transpose_and_store(const bool add_into, -// for safety, also check that __SSE2__ is defined in case the user manually -// set some conflicting compile flags which prevent compilation - -#elif DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 1 +#elif DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 1 && defined(__SSE2__) /** * Specialization for double and SSE2. @@ -2890,10 +2889,10 @@ vectorized_transpose_and_store(const bool add_into, -#endif // if DEAL_II_COMPILER_VECTORIZATION_LEVEL > 0 +#endif // if DEAL_II_COMPILER_VECTORIZATION_LEVEL > 0 && defined(__SSE2__) -#if defined(__ALTIVEC__) && defined(__VSX__) +#if DEAL_II_VECTORIZATION_LEVEL >= 1 && defined(__ALTIVEC__) && defined(__VSX__) template <> class VectorizedArray @@ -3319,7 +3318,8 @@ private: std::min(const VectorizedArray &, const VectorizedArray &); }; -#endif // ALTIVEC && VSX +#endif // if DEAL_II_VECTORIZATION_LEVEL >=1 && defined(__ALTIVEC__) && + // defined(__VSX__) -- 2.39.5