File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,26 @@ elseif(MSVC)
4242 message (WARNING "BMI1 support is not available for MSVC in this configuration." )
4343endif ()
4444
45+ # Detect AVX2 or native CPU optimizations and enable them if available
46+ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
47+ include (CheckCXXCompilerFlag)
48+ check_cxx_compiler_flag("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
49+ if (COMPILER_SUPPORTS_MARCH_NATIVE)
50+ add_compile_options (-march=native)
51+ else ()
52+ check_cxx_compiler_flag("-mavx2" COMPILER_SUPPORTS_AVX2)
53+ if (COMPILER_SUPPORTS_AVX2)
54+ add_compile_options (-mavx2)
55+ endif ()
56+ endif ()
57+ elseif (MSVC )
58+ include (CheckCXXCompilerFlag)
59+ check_cxx_compiler_flag("/arch:AVX2" COMPILER_SUPPORTS_AVX2)
60+ if (COMPILER_SUPPORTS_AVX2)
61+ add_compile_options (/arch:AVX2)
62+ endif ()
63+ endif ()
64+
4565# Optionally disable bounds checking in the bitvector implementation
4666
4767# Enable testing
Original file line number Diff line number Diff line change @@ -4,7 +4,10 @@ This repository provides a small bit vector implementation along with tests and
44
55## Running the benchmarks without bounds checking
66
7- Bounds checking is enabled by default. To benchmark without checks, configure and build with (this defines ` BITVECTOR_NO_BOUND_CHECK ` ):
7+ Bounds checking is enabled by default. To benchmark without checks, configure
8+ and build with (this defines ` BITVECTOR_NO_BOUND_CHECK ` ). The build system now
9+ detects whether the compiler and host CPU support AVX2 or other native
10+ instructions and enables them when possible:
811
912``` bash
1013cmake -S . -B build -DBITVECTOR_NO_BOUND_CHECK=ON -DCMAKE_BUILD_TYPE=Release
You can’t perform that action at this time.
0 commit comments