mirror of
https://github.com/drewcassidy/quicktex.git
synced 2024-09-13 06:37:34 +00:00
70 lines
2.7 KiB
CMake
70 lines
2.7 KiB
CMake
|
function(set_simd_flags target_name)
|
||
|
if (DEFINED ENV{QUICKTEX_HWY_MODE})
|
||
|
set(highway_mode $ENV{QUICKTEX_HWY_MODE})
|
||
|
message("Highway mode is ${highway_mode}")
|
||
|
else ()
|
||
|
message("Defaulting to AUTO highway mode")
|
||
|
set(highway_mode "AUTO")
|
||
|
endif ()
|
||
|
|
||
|
if ((CMAKE_OSX_ARCHITECTURES MATCHES ".*x86_64.*") OR (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)"))
|
||
|
set(X86 TRUE)
|
||
|
message("X86 Detected")
|
||
|
else ()
|
||
|
set(X86 FALSE)
|
||
|
endif ()
|
||
|
|
||
|
if ((CMAKE_OSX_ARCHITECTURES MATCHES ".*arm64.*") OR (CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(ARM64)|(aarch64)"))
|
||
|
set(ARM TRUE)
|
||
|
message("ARM Detected")
|
||
|
else ()
|
||
|
set(ARM FALSE)
|
||
|
endif ()
|
||
|
|
||
|
if (highway_mode STREQUAL "SCALAR")
|
||
|
# force Highway to use scalar ops. This should really only be used for testing
|
||
|
if (MSVC)
|
||
|
target_compile_options(${target_name} PUBLIC /DHWY_COMPILE_ONLY_SCALAR=1)
|
||
|
else ()
|
||
|
target_compile_options(${target_name} PUBLIC -DHWY_COMPILE_ONLY_SCALAR=1)
|
||
|
endif ()
|
||
|
return()
|
||
|
endif ()
|
||
|
|
||
|
# dynamic disbatch is not supported
|
||
|
if (MSVC)
|
||
|
target_compile_options(${target_name} PUBLIC /DHWY_COMPILE_ONLY_STATIC=1)
|
||
|
else ()
|
||
|
target_compile_options(${target_name} PUBLIC -DHWY_COMPILE_ONLY_STATIC=1)
|
||
|
endif ()
|
||
|
|
||
|
if (X86)
|
||
|
if (highway_mode STREQUAL "AUTO")
|
||
|
# setting -march=native on an M1 causes Clang to freak out
|
||
|
if (MSVC)
|
||
|
#MSVC has no -march=native equivalent. womp
|
||
|
message(WARNING "Compiling using MSVC without settig an explicit QUICKTEX_HWY_MODE defaults to serial operations. Please compile with Clang if you need vectorization")
|
||
|
elseif (!ARM)
|
||
|
target_compile_options(${target_name} PUBLIC -march=native)
|
||
|
endif ()
|
||
|
elseif (highway_mode STREQUAL "SSSE3")
|
||
|
if (MSVC)
|
||
|
message(SEND_ERROR "Compiling using SSSE3 is not supported with the MSVC compiler. Please use AVX or compile withClang")
|
||
|
else ()
|
||
|
target_compile_options(${target_name} PUBLIC -mssse3)
|
||
|
endif ()
|
||
|
elseif (highway_mode STREQUAL "SSE4")
|
||
|
if (MSVC)
|
||
|
message(SEND_ERROR "Compiling using SSE4 is not supported with the MSVC compiler. Please use AVX or compile with Clang")
|
||
|
else ()
|
||
|
target_compile_options(${target_name} PUBLIC -msse4)
|
||
|
endif ()
|
||
|
elseif (highway_mode STREQUAL "AVX2")
|
||
|
if (MSVC)
|
||
|
target_compile_options(${target_name} PUBLIC /arch:AVX2)
|
||
|
else ()
|
||
|
target_compile_options(${target_name} PUBLIC -mavx2)
|
||
|
endif ()
|
||
|
endif ()
|
||
|
endif ()
|
||
|
endfunction()
|