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)
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()

View File

@@ -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 <immintrin.h>
#elif __has_include("arm_neon.h")
#define HAS_ARM_NEON 1
#include <arm_neon.h>
#endif
#endif
#include "ConflictSet.h"
#include "Internal.h"
#include "LongestCommonPrefix.h"
@@ -34,12 +44,6 @@ limitations under the License.
#include <type_traits>
#include <utility>
#ifdef HAS_AVX
#include <immintrin.h>
#elif defined(HAS_ARM_NEON)
#include <arm_neon.h>
#endif
#ifndef __SANITIZE_THREAD__
#if defined(__has_feature)
#if __has_feature(thread_sanitizer)