From 0dbfb4deae0f60a89132e819d58846567e70ad92 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Tue, 12 Nov 2024 14:51:34 -0800 Subject: [PATCH] Detect simd headers in c++ instead of cmake --- CMakeLists.txt | 16 ++++------------ ConflictSet.cpp | 16 ++++++++++------ 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e42756..217901f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,19 +104,11 @@ else() add_link_options(-Wl,--gc-sections) endif() -if(NOT USE_SIMD_FALLBACK) - cmake_push_check_state() - list(APPEND CMAKE_REQUIRED_FLAGS -mavx) - check_include_file_cxx("immintrin.h" HAS_AVX) - if(HAS_AVX) +if(USE_SIMD_FALLBACK) + add_compile_definitions(USE_SIMD_FALLBACK) +else() + if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64) add_compile_options(-mavx) - add_compile_definitions(HAS_AVX) - endif() - cmake_pop_check_state() - - check_include_file_cxx("arm_neon.h" HAS_ARM_NEON) - if(HAS_ARM_NEON) - add_compile_definitions(HAS_ARM_NEON) endif() endif() diff --git a/ConflictSet.cpp b/ConflictSet.cpp index 9a80685..cec8f48 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -14,6 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ +#if !defined(USE_SIMD_FALLBACK) && defined(__has_include) +#if __has_include("immintrin.h") +#define HAS_AVX 1 +#include +#elif __has_include("arm_neon.h") +#define HAS_ARM_NEON 1 +#include +#endif +#endif + #include "ConflictSet.h" #include "Internal.h" #include "LongestCommonPrefix.h" @@ -34,12 +44,6 @@ limitations under the License. #include #include -#ifdef HAS_AVX -#include -#elif defined(HAS_ARM_NEON) -#include -#endif - #ifndef __SANITIZE_THREAD__ #if defined(__has_feature) #if __has_feature(thread_sanitizer)