+endif()
+
+##############################################################################
+# CPU optimizations and multiarch support
+##############################################################################
+
+option(VPP_BUILD_NATIVE_ONLY "Build only for native CPU." OFF)
+
+if(VPP_BUILD_NATIVE_ONLY)
+ check_c_compiler_flag("-march=native" compiler_flag_march_native)
+ if(NOT compiler_flag_march_native)
+ message(FATAL_ERROR "Native-only build not supported by compiler")
+ endif()
+endif()
+
+macro(add_vpp_march_variant v)
+ cmake_parse_arguments(ARG
+ "OFF"
+ "N_PREFETCHES;CACHE_PREFETCH_BYTES"
+ "FLAGS"
+ ${ARGN}
+ )
+
+ if(ARG_FLAGS)
+ set(flags_ok 1)
+ set(fs "")
+ foreach(f ${ARG_FLAGS})
+ string(APPEND fs " ${f}")
+ string(REGEX REPLACE "[-=+]" "_" sfx ${f})
+ if(NOT DEFINED compiler_flag${sfx})
+ check_c_compiler_flag(${f} compiler_flag${sfx})
+ endif()
+ if(NOT compiler_flag${sfx})
+ unset(flags_ok)
+ endif()
+ endforeach()
+ if(ARG_N_PREFETCHES)
+ string(APPEND fs " -DCLIB_N_PREFETCHES=${ARG_N_PREFETCHES}")
+ endif()
+ if(ARG_CACHE_PREFETCH_BYTES)
+ set_log2_cacheline_size(log2 ${ARG_CACHE_PREFETCH_BYTES})
+ string(APPEND fs " -DCLIB_LOG2_CACHE_PREFETCH_BYTES=${log2}")
+ endif()
+ if(flags_ok)
+ string(TOUPPER ${v} uv)
+ if(ARG_OFF)
+ option(VPP_MARCH_VARIANT_${uv} "Build ${v} multiarch variant." OFF)
+ else()
+ option(VPP_MARCH_VARIANT_${uv} "Build ${v} multiarch variant." ON)
+ endif()
+ if (VPP_MARCH_VARIANT_${uv})
+ list(APPEND MARCH_VARIANTS "${v}\;${fs}")
+ list(APPEND MARCH_VARIANTS_NAMES "${v}")
+ else()
+ list(APPEND MARCH_VARIANTS_DISABLED "${v}\;${fs}")
+ endif()
+ endif()
+ endif()
+endmacro()
+
+if(VPP_BUILD_NATIVE_ONLY)
+ set(VPP_DEFAULT_MARCH_FLAGS -march=native)
+ set(MARCH_VARIANTS_NAMES "native-only")
+elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
+ set(VPP_DEFAULT_MARCH_FLAGS -march=corei7 -mtune=corei7-avx)
+
+ add_vpp_march_variant(hsw
+ FLAGS -march=haswell -mtune=haswell
+ )
+
+ add_vpp_march_variant(trm
+ FLAGS -march=tremont -mtune=tremont
+ OFF
+ )
+
+ add_vpp_march_variant(adl
+ FLAGS -march=alderlake -mtune=alderlake -mprefer-vector-width=256
+ OFF
+ )
+
+ add_vpp_march_variant(scalar
+ FLAGS -march=core2 -mno-mmx -mno-sse
+ OFF
+ )
+
+ add_vpp_march_variant(znver3
+ FLAGS -march=znver3 -mtune=znver3 -mprefer-vector-width=256
+ OFF
+ )
+
+ if (GNU_ASSEMBLER_AVX512_BUG)
+ message(WARNING "AVX-512 multiarch variant(s) disabled due to GNU Assembler bug")
+ else()
+ add_vpp_march_variant(skx
+ FLAGS -march=skylake-avx512 -mtune=skylake-avx512 -mprefer-vector-width=256
+ )
+
+ add_vpp_march_variant(icl
+ FLAGS -march=icelake-client -mtune=icelake-client -mprefer-vector-width=512
+ )
+
+ add_vpp_march_variant(spr
+ FLAGS -march=sapphirerapids -mtune=sapphirerapids -mprefer-vector-width=512
+ OFF
+ )
+
+ add_vpp_march_variant(znver4
+ FLAGS -march=znver4 -mtune=znver4 -mprefer-vector-width=512
+ OFF
+ )