STRA-338 size-fn: cpu-sys: build.rs split per ISA level

This commit is contained in:
Pavlo Ratushnyi
2026-11-06 17:27:11 +01:00
parent 058f5c7466
commit 3bc93a6d97
+20 -10
View File
@@ -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")