authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-28 09:53:13+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-28 19:25:01+00:00
logb36cfc6352df4c5c5005c7a720dbc84894097d11
tree7f513c992a33e8072e50f5d57f007c42a0950546
parent2ac47fe314f0a88a2e5ac6c0116392504369b466
signaturelock-open Commit is signed but in an unrecognized format.

compiler-rt: work around LLVM not respecting -fno-builtin


1 files changed, 6 insertions(+), 1 deletions(-)

lib/compiler_rt/mulo.zig+6-1
......@@ -19,7 +19,12 @@ comptime {
1919inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
2020 overflow.* = 0;
2121 const min = math.minInt(ST);
22 const res: ST = a *% b;
22 const res: ST = if (ST == i128 and builtin.target.cpu.arch.isWasm()) res: {
23 // Despite compiler-rt being built with `-fno-builtin`, LLVM still converts this function to
24 // a call to `__muloti4` on WASM. This is an upstream bug: circumvent it by directly calling
25 // the "lower-level" compiler-rt routine for this wrapping multiplication.
26 break :res @import("mulXi3.zig").__multi3(a, b);
27 } else a *% b;
2328 // Hacker's Delight section Overflow subsection Multiplication
2429 // case a=-2^{31}, b=-1 problem, because
2530 // on some machines a*b = -2^{31} with overflow