Skip to content

Commit

Permalink
Check if compiler supports SIMD flags before applying (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 authored Aug 3, 2023
1 parent b2531c7 commit 4df9f96
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions modules/cmake/RuntimeSIMDLib.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include(CheckCXXCompilerFlag)
function(make_lib_simd_runtime name file)
add_library(${name}_sse_or_arm STATIC)
target_sources(${name}_sse_or_arm PRIVATE ${file})
Expand All @@ -6,10 +7,21 @@ function(make_lib_simd_runtime name file)
target_sources(${name}_avx PRIVATE ${file})
target_compile_definitions(${name}_avx PRIVATE BYOD_COMPILING_WITH_AVX=1)
if(WIN32)
target_compile_options(${name}_avx PRIVATE /arch:AVX)
CHECK_CXX_COMPILER_FLAG("/arch:AVX" COMPILER_OPT_ARCH_AVX_SUPPORTED)
if(COMPILER_OPT_ARCH_AVX_SUPPORTED)
message(STATUS "Compiler supports flags: /arch:AVX")
target_compile_options(${name}_avx PRIVATE /arch:AVX)
else()
message(STATUS "Compiler DOES NOT supports flags: /arch:AVX")
endif()
else()
# @TODO: can we exclude this for the ARM build altogether?
target_compile_options(${name}_avx PRIVATE -mavx -mfma -Wno-unused-command-line-argument)
CHECK_CXX_COMPILER_FLAG("-mavx -mfma" COMPILER_OPT_ARCH_AVX_SUPPORTED)
if(COMPILER_OPT_ARCH_AVX_SUPPORTED)
message(STATUS "Compiler supports flags: -mavx -mfma")
target_compile_options(${name}_avx PRIVATE -mavx -mfma -Wno-unused-command-line-argument)
else()
message(STATUS "Compiler DOES NOT supports flags: -mavx -mfma")
endif()
endif()

add_library(${name} INTERFACE)
Expand Down

0 comments on commit 4df9f96

Please sign in to comment.