Skip to content

Commit

Permalink
Update check-bmi2.cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenberry committed Sep 23, 2024
1 parent c27c617 commit 94f03ea
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions cmake/check-bmi2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,21 @@ endif()
if (BMI2_FLAG)
check_cxx_compiler_flag("${BMI2_FLAG}" COMPILER_SUPPORTS_BMI2_FLAG)
if (COMPILER_SUPPORTS_BMI2_FLAG)
# Append BMI2 flag to CMAKE_REQUIRED_FLAGS without overwriting existing flags
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${BMI2_FLAG}")
message(STATUS "BMI2 instructions are supported.")

if(MSVC)
target_compile_options(glaze_glaze PRIVATE "/arch:AVX2")
else()
target_compile_options(glaze_glaze PRIVATE "-mbmi2")
endif()
target_compile_definitions(glaze_glaze PRIVATE GLZ_HAS_BMI2)
message(STATUS "BMI2 instructions are being used.
If you are cross-compiling for a 32bit platform or older processors turn glaze_ENABLE_BMI2 off.")
else()
set(BMI2_FLAG "")
endif()
endif()

if (BMI2_FLAG)
# BMI2 detection
check_cxx_source_compiles("
#include <immintrin.h>
int main() {
unsigned long long src = 0xFF, mask = 0xF0;
unsigned long long result = _pext_u64(src, mask);
(void)result;
return 0;
}
" GLZ_HAS_BMI2)

# Reset CMAKE_REQUIRED_FLAGS to avoid affecting other checks
string(REGEX REPLACE "${BMI2_FLAG}" "" CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
endif()

if(GLZ_HAS_BMI2)
message(STATUS "BMI2 instructions are supported.")
if(MSVC)
target_compile_options(glaze_glaze PRIVATE "/arch:AVX2")
else()
target_compile_options(glaze_glaze PRIVATE "-mbmi2")
endif()
target_compile_definitions(glaze_glaze PRIVATE GLZ_HAS_BMI2)
message(STATUS "BMI2 instructions are being used.
If you are cross-compiling for a 32bit platform or older processors turn glaze_ENABLE_BMI2 off.")
else()
message(STATUS "BMI2 instructions: not supported and not used.")
endif()

0 comments on commit 94f03ea

Please sign in to comment.