#.rst: # FindAVX2 # -------- # # Finds AVX2 support # # This module can be used to detect AVX2 support in a C compiler. If # the compiler supports AVX2, the flags required to compile with # AVX2 support are returned in variables for the different languages. # The variables may be empty if the compiler does not need a special # flag to support AVX2. # # The following variables are set: # # :: # # AVX2_C_FLAGS - flags to add to the C compiler for AVX2 support # AVX2_FOUND - true if AVX2 is detected # #============================================================================= set(_AVX2_REQUIRED_VARS) set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET}) set(CMAKE_REQUIRED_QUIET ${AVX2_FIND_QUIETLY}) # sample AVX2 source code to test set(AVX2_C_TEST_SOURCE " #include void parasail_memset___m256i(__m256i *b, __m256i c, size_t len) { size_t i; for (i=0; i #include __m256i foo() { __m256i vOne = _mm256_set1_epi64x(1); return vOne; } int main(void) { foo(); return 0; } ") if(AVX2_C_FLAGS) include(CheckCSourceCompiles) set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}") check_c_source_compiles("${AVX2_C_TEST_SOURCE_SET1_EPI64X}" HAVE_AVX2_MM256_SET1_EPI64X) set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") endif() set(AVX2_C_TEST_SOURCE_SET_EPI64X " #include #include __m256i foo() { __m256i vOne = _mm256_set_epi64x(1,1,1,1); return vOne; } int main(void) { foo(); return 0; } ") if(AVX2_C_FLAGS) include(CheckCSourceCompiles) set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}") check_c_source_compiles("${AVX2_C_TEST_SOURCE_SET_EPI64X}" HAVE_AVX2_MM256_SET_EPI64X) set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") endif() set(AVX2_C_TEST_SOURCE_INSERT64 " #include #include __m256i foo() { __m256i vOne = _mm256_set1_epi8(1); return _mm256_insert_epi64(vOne,INT64_MIN,0); } int main(void) { foo(); return 0; } ") if(AVX2_C_FLAGS) include(CheckCSourceCompiles) set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}") check_c_source_compiles("${AVX2_C_TEST_SOURCE_INSERT64}" HAVE_AVX2_MM256_INSERT_EPI64) set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") endif() set(AVX2_C_TEST_SOURCE_INSERT32 " #include #include __m256i foo() { __m256i vOne = _mm256_set1_epi8(1); return _mm256_insert_epi32(vOne,INT32_MIN,0); } int main(void) { foo(); return 0; } ") if(AVX2_C_FLAGS) include(CheckCSourceCompiles) set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}") check_c_source_compiles("${AVX2_C_TEST_SOURCE_INSERT32}" HAVE_AVX2_MM256_INSERT_EPI32) set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") endif() set(AVX2_C_TEST_SOURCE_INSERT16 " #include #include __m256i foo() { __m256i vOne = _mm256_set1_epi8(1); return _mm256_insert_epi16(vOne,INT16_MIN,0); } int main(void) { foo(); return 0; } ") if(AVX2_C_FLAGS) include(CheckCSourceCompiles) set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}") check_c_source_compiles("${AVX2_C_TEST_SOURCE_INSERT16}" HAVE_AVX2_MM256_INSERT_EPI16) set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") endif() set(AVX2_C_TEST_SOURCE_INSERT8 " #include #include __m256i foo() { __m256i vOne = _mm256_set1_epi8(1); return _mm256_insert_epi8(vOne,INT8_MIN,0); } int main(void) { foo(); return 0; } ") if(AVX2_C_FLAGS) include(CheckCSourceCompiles) set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}") check_c_source_compiles("${AVX2_C_TEST_SOURCE_INSERT8}" HAVE_AVX2_MM256_INSERT_EPI8) set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") endif() set(AVX2_C_TEST_SOURCE_EXTRACT64 " #include #include int64_t foo() { __m256i vOne = _mm256_set1_epi8(1); return (int64_t)_mm256_extract_epi64(vOne,0); } int main(void) { return (int)foo(); } ") if(AVX2_C_FLAGS) include(CheckCSourceCompiles) set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}") check_c_source_compiles("${AVX2_C_TEST_SOURCE_EXTRACT64}" HAVE_AVX2_MM256_EXTRACT_EPI64) set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") endif() set(AVX2_C_TEST_SOURCE_EXTRACT32 " #include #include int32_t foo() { __m256i vOne = _mm256_set1_epi8(1); return (int32_t)_mm256_extract_epi32(vOne,0); } int main(void) { return (int)foo(); } ") if(AVX2_C_FLAGS) include(CheckCSourceCompiles) set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}") check_c_source_compiles("${AVX2_C_TEST_SOURCE_EXTRACT32}" HAVE_AVX2_MM256_EXTRACT_EPI32) set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") endif() set(AVX2_C_TEST_SOURCE_EXTRACT16 " #include #include int16_t foo() { __m256i vOne = _mm256_set1_epi8(1); return (int16_t)_mm256_extract_epi16(vOne,0); } int main(void) { return (int)foo(); } ") if(AVX2_C_FLAGS) include(CheckCSourceCompiles) set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}") check_c_source_compiles("${AVX2_C_TEST_SOURCE_EXTRACT16}" HAVE_AVX2_MM256_EXTRACT_EPI16) set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") endif() set(AVX2_C_TEST_SOURCE_EXTRACT8 " #include #include int8_t foo() { __m256i vOne = _mm256_set1_epi8(1); return (int8_t)_mm256_extract_epi8(vOne,0); } int main(void) { return (int)foo(); } ") if(AVX2_C_FLAGS) include(CheckCSourceCompiles) set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(CMAKE_REQUIRED_FLAGS "${AVX2_C_FLAGS}") check_c_source_compiles("${AVX2_C_TEST_SOURCE_EXTRACT8}" HAVE_AVX2_MM256_EXTRACT_EPI8) set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") endif() if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(CMAKE_C_FLAGS "${SAFE_CMAKE_C_FLAGS}") elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_C_FLAGS "${SAFE_CMAKE_C_FLAGS}") endif()