@@ -87,13 +87,35 @@ if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL
8787 target_compile_options (FastPFOR PRIVATE -Wall -Wextra -Weffc++ -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion )
8888endif ()
8989include (CheckCXXCompilerFlag )
90- unset (FASTPFOR_COMPILER_SUPPORTS_MARCH_NATIVE CACHE )
91- CHECK_CXX_COMPILER_FLAG (-march=native FASTPFOR_COMPILER_SUPPORTS_MARCH_NATIVE )
92- if (FASTPFOR_COMPILER_SUPPORTS_MARCH_NATIVE)
93- target_compile_options (FastPFOR PRIVATE -march=native )
90+
91+ # SIMD mode: native, portable, or runtime
92+ # - native: Use -march=native for maximum performance on the build machine (not portable)
93+ # - portable: Use baseline SSE4.2 only for maximum compatibility (default)
94+ # - runtime: Use function multi-versioning for runtime CPU dispatch (future)
95+ set (FASTPFOR_SIMD_MODE "native" CACHE STRING "SIMD compilation mode: native, portable, or runtime" )
96+ set_property (CACHE FASTPFOR_SIMD_MODE PROPERTY STRINGS native portable runtime)
97+
98+ if (FASTPFOR_SIMD_MODE STREQUAL "native" )
99+ unset (FASTPFOR_COMPILER_SUPPORTS_MARCH_NATIVE CACHE )
100+ CHECK_CXX_COMPILER_FLAG (-march=native FASTPFOR_COMPILER_SUPPORTS_MARCH_NATIVE )
101+ if (FASTPFOR_COMPILER_SUPPORTS_MARCH_NATIVE)
102+ target_compile_options (FastPFOR PRIVATE -march=native )
103+ else ()
104+ message (STATUS "native target not supported, falling back to portable mode" )
105+ target_compile_options (FastPFOR PRIVATE -msse4.2 )
106+ endif ()
107+ elseif (FASTPFOR_SIMD_MODE STREQUAL "portable" )
108+ # Baseline: SSE4.2 is required by FastPFOR SIMD code
109+ target_compile_options (FastPFOR PRIVATE -msse4.2 )
110+ elseif (FASTPFOR_SIMD_MODE STREQUAL "runtime" )
111+ # Runtime dispatch: compile with baseline SSE4.2 and enable multi-versioning
112+ target_compile_options (FastPFOR PRIVATE -msse4.2 )
113+ target_compile_definitions (FastPFOR PRIVATE FASTPFOR_RUNTIME_DISPATCH )
114+ message (STATUS "Runtime dispatch mode is experimental" )
94115else ()
95- message (STATUS " native target not supported " )
116+ message (FATAL_ERROR "Invalid FASTPFOR_SIMD_MODE: ${FASTPFOR_SIMD_MODE} . Use native, portable, or runtime. " )
96117endif ()
118+ message (STATUS "FASTPFOR_SIMD_MODE: ${FASTPFOR_SIMD_MODE} " )
97119
98120MESSAGE ( STATUS "CMAKE_CXX_FLAGS_DEBUG: " ${CMAKE_CXX_FLAGS_DEBUG } )
99121MESSAGE ( STATUS "CMAKE_CXX_FLAGS_RELEASE: " ${CMAKE_CXX_FLAGS_RELEASE } )
@@ -217,4 +239,4 @@ if (SUPPORT_NEON)
217239 message (WARNING "Building with emulation with SIMDE for ARM NEON support." )
218240 message (WARNING "We do not actually support ARM NEON natively." )
219241 message (WARNING "If you actually want native ARM NEON support, please consider providing a patch." )
220- endif ()
242+ endif ()
0 commit comments