function(set_simd_flags target_name) if (DEFINED ENV{QUICKTEX_SIMD_MODE}) set(simd_mode $ENV{QUICKTEX_SIMD_MODE}) message("SIMD mode is ${simd_mode}") else () message("Defaulting to AUTO SIMD mode. Resulting binary is not fit for distributing to other computers!") set(simd_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 (simd_mode STREQUAL "SCALAR") # force xsimd to use scalar ops. This should really only be used for testing, # since SSE2 and NEON are guranteed on 64-bit platforms if (MSVC) target_compile_options(${target_name} PUBLIC /DXSIMD_NO_SUPPORTED_ARCHITECTURE=1) else () target_compile_options(${target_name} PUBLIC -DXSIMD_NO_SUPPORTED_ARCHITECTURE=1) endif () return() endif () if (X86) if (simd_mode STREQUAL "AUTO") if (MSVC) #MSVC has no -march=native equivalent. womp elseif (NOT ARM) # setting -march=native on an M1 causes Clang to freak out, # and arm64 is pretty samey instruction set wise (arm9 and SVE2 notwithstanding) # Currently AVX512 will cause problems with buffer overruns, # and I dont have good test hardware for it anyways target_compile_options(${target_name} PUBLIC -march=native -mno-avx512f) endif () elseif (simd_mode STREQUAL "SSSE3") if (MSVC) target_compile_options(${target_name} PUBLIC /DXSIMD_WITH_SSSE3) else () target_compile_options(${target_name} PUBLIC -mssse3) endif () elseif (simd_mode STREQUAL "SSE4") if (MSVC) target_compile_options(${target_name} PUBLIC /DXSIMD_WITH_SSE4_2 /d2archSSE42) else () target_compile_options(${target_name} PUBLIC -msse4) endif () elseif (simd_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()