Skip to content

Commit 5a386f5

Browse files
committed
Make: Stack-realign for i386 builds
Relates to #280
1 parent f473b2b commit 5a386f5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

build.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ fn main() -> Result<(), cc::Error> {
1313
.flag_if_supported("-pedantic") // Strict compliance when supported
1414
.warnings(false);
1515

16+
// On 32-bit x86, ensure proper stack alignment for floating-point operations
17+
// See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38534
18+
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
19+
if target_arch == "x86" {
20+
build.flag_if_supported("-mstackrealign");
21+
build.flag_if_supported("-mpreferred-stack-boundary=4");
22+
}
23+
1624
if let Err(e) = build.try_compile("simsimd") {
1725
print!("cargo:warning=Failed to compile with all SIMD backends...");
18-
19-
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
2026
let flags_to_try = match target_arch.as_str() {
2127
"arm" | "aarch64" => vec![
2228
"SIMSIMD_TARGET_SVE2",

0 commit comments

Comments
 (0)