From 32a63f7ff0e044e0bd0554d70a405ae7377f7085 Mon Sep 17 00:00:00 2001 From: wirthual Date: Thu, 12 Feb 2026 16:02:09 -0800 Subject: [PATCH 1/2] add option for building with -march=native flag --- CMakeLists.txt | 3 ++- cmake/option.cmake | 18 ++++++++++++------ pyproject.toml | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 294af340..7c645417 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,8 @@ project(zvec) set(CC_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror=return-type") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror=return-type") +set(CMAKE__FLAGS "${CMAKE_C_FLAGS} -Wall -Werror=return-type") + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-as-needed") diff --git a/cmake/option.cmake b/cmake/option.cmake index ca74cf05..e840f82a 100644 --- a/cmake/option.cmake +++ b/cmake/option.cmake @@ -13,6 +13,8 @@ option(ENABLE_SAPPHIRERAPIDS "Enable Intel Sapphire Rapids Server CPU microarchi option(ENABLE_EMERALDRAPIDS "Enable Intel Emerald Rapids Server CPU microarchitecture" OFF) option(ENABLE_GRANITERAPIDS "Enable Intel Granite Rapids Server CPU microarchitecture" OFF) +option(X86_ARCH_NATIVE "Build with -march=native" OFF) + ## AMD Microarchitectures option(ENABLE_ZEN1 "Enable AMD Zen+ Family 17h CPU microarchitecture" OFF) option(ENABLE_ZEN2 "Enable AMD Zen 2 Family 17h CPU microarchitecture" OFF) @@ -89,12 +91,16 @@ function(_detect_armv8_best) endfunction() function(_detect_x86_best) - set(_x86_flags - "graniterapids" "emeraldrapids" "sapphirerapids" - "skylake-avx512" "skylake" - "broadwell" "haswell" "sandybridge" "nehalem" - "znver3" "znver2" "znver1" - ) + if(X86_ARCH_NATIVE) + set(_x86_flags "native") + else() + set(_x86_flags + "graniterapids" "emeraldrapids" "sapphirerapids" + "skylake-avx512" "skylake" + "broadwell" "haswell" "sandybridge" "nehalem" + "znver3" "znver2" "znver1" + ) + endif() foreach(_arch IN LISTS _x86_flags) check_c_compiler_flag("-march=${_arch}" _COMP_SUPP_${_arch}) if(_COMP_SUPP_${_arch}) diff --git a/pyproject.toml b/pyproject.toml index dee6728d..f669b480 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -116,6 +116,7 @@ sdist.include = [ [tool.scikit-build.cmake.define] BUILD_TOOLS = "OFF" BUILD_PYTHON_BINDINGS = "ON" +X86_ARCH_NATIVE="ON" # Setuptools config for test pypi [tool.setuptools_scm] From f9655e43d189ae32fdadf0f8488e71e4beed30bf Mon Sep 17 00:00:00 2001 From: wirthual Date: Thu, 12 Feb 2026 16:06:51 -0800 Subject: [PATCH 2/2] add option for building with -march=native flag --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c645417..294af340 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,7 @@ project(zvec) set(CC_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror=return-type") -set(CMAKE__FLAGS "${CMAKE_C_FLAGS} -Wall -Werror=return-type") - +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror=return-type") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-as-needed")