| ... | @@ -19,7 +19,12 @@ comptime { | ... | @@ -19,7 +19,12 @@ comptime { |
| 19 | inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST { | 19 | inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST { |
| 20 | overflow.* = 0; | 20 | overflow.* = 0; |
| 21 | const min = math.minInt(ST); | 21 | 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; |
| 23 | // Hacker's Delight section Overflow subsection Multiplication | 28 | // Hacker's Delight section Overflow subsection Multiplication |
| 24 | // case a=-2^{31}, b=-1 problem, because | 29 | // case a=-2^{31}, b=-1 problem, because |
| 25 | // on some machines a*b = -2^{31} with overflow | 30 | // on some machines a*b = -2^{31} with overflow |