From a5258f78dc7a70e63c992c67110ecae73abd8355 Mon Sep 17 00:00:00 2001 From: Code Cade Date: Fri, 21 Nov 2025 02:53:37 +0300 Subject: [PATCH] Update arch.cmake --- cpp/cmake/arch.cmake | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/cpp/cmake/arch.cmake b/cpp/cmake/arch.cmake index 1812e8eb..aead097a 100644 --- a/cpp/cmake/arch.cmake +++ b/cpp/cmake/arch.cmake @@ -1,10 +1,34 @@ -if(WASM) - # Disable SLP vectorization on WASM as it's brokenly slow. To give an idea, with this off it still takes - # 2m:18s to compile scalar_multiplication.cpp, and with it on I estimate it's 50-100 times longer. I never - # had the patience to wait it out... +# 🛡️ ARCHITECTURE DETECTION: Rely on CMake's built-in variables for robustness. +# 'EMSCRIPTEN' is automatically set by the emscripten toolchain file. +if(EMSCRIPTEN OR CMAKE_SYSTEM_NAME MATCHES "Emscripten") + # 🚀 WASM OPTIMIZATION + # Disable SLP vectorization on WASM as it causes massive compile-time regressions. + # (As noted: scalar_multiplication.cpp compile time explodes without this). + # -fno-exceptions: Standard for high-perf WASM/Crypto to reduce code size and overhead. add_compile_options(-fno-exceptions -fno-slp-vectorize) -endif() -if(NOT WASM AND NOT APPLE AND NOT ARM) - add_compile_options(-march=skylake) +else() + # 🖥️ NATIVE OPTIMIZATION (Linux/macOS/Windows) + + # Check if we are specifically on x86_64 architecture. + if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64") + + # 🍎 APPLE SILICON / INTEL MAC HANDLING + # Apple's Clang usually handles architecture selection well via CMAKE_OSX_ARCHITECTURES. + # We explicitly avoid overriding flags on Apple unless necessary to prevent conflicts. + if(NOT APPLE) + # 🛡️ PORTABILITY FIX: Changed '-march=skylake' to '-march=native'. + # '-march=native': Tells the compiler to use all instructions available on THIS machine + # (AVX2, BMI2, ADX, etc.). It works on both Intel and AMD. + # + # NOTE: If building Docker images for distribution, consider using '-march=x86-64-v3' + # instead of 'native' to ensure binaries work on diverse servers. + add_compile_options(-march=native) + endif() + + endif() + + # Note: No explicit 'else' needed for ARM (M1/M2/M3 etc.) as '-march=native' + # is implied or handled by the compiler defaults on those platforms usually, + # or CMAKE_OSX_ARCHITECTURES handles it for macOS. endif()