Skip to content

Commit cac12bb

Browse files
committed
Add a build flag for aarch64 Neoverse 512TVB optimizations and gate behind CPU detection
`lore-base/build.rs` passed `-mcpu=neoverse-512tvb` unconditionally to the C compiler for all `linux/aarch64` targets, causing binaries to crash with `illegal hardware instruction` on hardware that does not implement SVE2 and other Neoverse 512TVB extensions. Introduce a `neoverse-512tvb` Cargo feature to opt in to the optimization, and gate it behind a `/proc/cpuinfo` SVE2 check so the flag is only applied when the hardware supports it. Fixes #42 Signed-off-by: subhramit <subhramit.bb@live.in>
1 parent 4bffa76 commit cac12bb

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

lore-base/build.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2626
.includes(Some(native_dir.join("thirdparty")));
2727

2828
if platform == "linux" && arch == "aarch64" {
29-
cc_builder.flag("-mcpu=neoverse-512tvb");
29+
if env::var("LORE_CPU_NEOVERSE_512TVB").is_ok() {
30+
let cpuinfo = std::fs::read_to_string("/proc/cpuinfo").unwrap_or_default();
31+
if cpuinfo.contains("sve2") {
32+
cc_builder.flag("-mcpu=neoverse-512tvb");
33+
} else {
34+
println!(
35+
"cargo:warning=LORE_CPU_NEOVERSE_512TVB is set but SVE2 not detected in /proc/cpuinfo; binary may crash with illegal hardware instruction. Unset LORE_CPU_NEOVERSE_512TVB to build for generic aarch64"
36+
);
37+
}
38+
} else {
39+
println!(
40+
"cargo:warning=Building rpmalloc without -mcpu=neoverse-512tvb; binary may be slower on Graviton3+. Set LORE_CPU_NEOVERSE_512TVB=1 to opt in"
41+
);
42+
}
3043
}
3144

3245
if cc_builder.get_compiler().is_like_msvc() {

0 commit comments

Comments
 (0)