Detect simd headers in c++ instead of cmake

This commit is contained in:
2024-11-12 14:51:34 -08:00
parent 6e229b6b36
commit 0dbfb4deae
2 changed files with 14 additions and 18 deletions

View File

@@ -104,19 +104,11 @@ else()
add_link_options(-Wl,--gc-sections) add_link_options(-Wl,--gc-sections)
endif() endif()
if(NOT USE_SIMD_FALLBACK) if(USE_SIMD_FALLBACK)
cmake_push_check_state() add_compile_definitions(USE_SIMD_FALLBACK)
list(APPEND CMAKE_REQUIRED_FLAGS -mavx) else()
check_include_file_cxx("immintrin.h" HAS_AVX) if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
if(HAS_AVX)
add_compile_options(-mavx) 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()
endif() endif()

View File

@@ -14,6 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
#if !defined(USE_SIMD_FALLBACK) && defined(__has_include)
#if __has_include("immintrin.h")
#define HAS_AVX 1
#include <immintrin.h>
#elif __has_include("arm_neon.h")
#define HAS_ARM_NEON 1
#include <arm_neon.h>
#endif
#endif
#include "ConflictSet.h" #include "ConflictSet.h"
#include "Internal.h" #include "Internal.h"
#include "LongestCommonPrefix.h" #include "LongestCommonPrefix.h"
@@ -34,12 +44,6 @@ limitations under the License.
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#ifdef HAS_AVX
#include <immintrin.h>
#elif defined(HAS_ARM_NEON)
#include <arm_neon.h>
#endif
#ifndef __SANITIZE_THREAD__ #ifndef __SANITIZE_THREAD__
#if defined(__has_feature) #if defined(__has_feature)
#if __has_feature(thread_sanitizer) #if __has_feature(thread_sanitizer)