From 3bc93a6d97f6cbb43c3603291205e26fbc3ca806 Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Fri, 6 Nov 2026 17:27:11 +0100 Subject: [PATCH] STRA-338 size-fn: cpu-sys: build.rs split per ISA level --- crates/cpu-sys/build.rs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/crates/cpu-sys/build.rs b/crates/cpu-sys/build.rs index 1766900b..f4a6e058 100644 --- a/crates/cpu-sys/build.rs +++ b/crates/cpu-sys/build.rs @@ -20,19 +20,27 @@ fn main() { return; } - base() - .file("csrc/dot_scalar.c") - .file("csrc/mxfp4_scalar.c") - .file("csrc/q8_scalar.c") - .compile("leleka_cpu_scalar"); - + build_scalar(); let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default(); if arch != "x86_64" { return; } let msvc = std::env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc"); + build_avx2(msvc); + build_avxvnni(msvc); +} - // "AVX2 level" means AVX2 + FMA + F16C (Haswell and later); MSVC's /arch:AVX2 enables all three. +/// The portable C kernels. +fn build_scalar() { + base() + .file("csrc/dot_scalar.c") + .file("csrc/mxfp4_scalar.c") + .file("csrc/q8_scalar.c") + .compile("leleka_cpu_scalar"); +} + +/// "AVX2 level" means AVX2 + FMA + F16C (Haswell and later); MSVC's /arch:AVX2 enables all three. +fn build_avx2(msvc: bool) { let mut avx2 = base(); avx2.file("csrc/dot_avx2.c") .file("csrc/mxfp4_avx2.c") @@ -43,10 +51,12 @@ fn main() { avx2.flag("-mavx2").flag("-mfma").flag("-mf16c"); } avx2.compile("leleka_cpu_avx2"); +} - // AVX-VNNI needs compiler support (MSVC with /arch:AVX2 provides the intrinsic; GCC 11+ and - // clang 12+ need -mavxvnni). If the compiler lacks it, the level is simply not built and the - // Rust side reports it as unsupported. +/// AVX-VNNI needs compiler support (MSVC with /arch:AVX2 provides the intrinsic; GCC 11+ and +/// clang 12+ need -mavxvnni). If the compiler lacks it, the level is simply not built and the +/// Rust side reports it as unsupported. +fn build_avxvnni(msvc: bool) { let mut vnni = base(); vnni.file("csrc/dot_avxvnni.c") .file("csrc/mxfp4_avxvnni.c")