Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

muloXi4_genericSmall

mulo.muloXi4_genericSmall
inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST

File

lib/compiler_rt/mulo.zig:19

Code

inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
    overflow.* = 0;
    const min = math.minInt(ST);
    const res: ST = if (ST == i128 and builtin.target.cpu.arch.isWasm()) res: {
        // Despite compiler-rt being built with `-fno-builtin`, LLVM still converts this function to
        // a call to `__muloti4` on WASM. This is an upstream bug: circumvent it by directly calling
        // the "lower-level" compiler-rt routine for this wrapping multiplication.
        break :res @import("mulXi3.zig").__multi3(a, b);
    } else a *% b;
    // Hacker's Delight section Overflow subsection Multiplication
    // case a=-2^{31}, b=-1 problem, because
    // on some machines a*b = -2^{31} with overflow
    // Then -2^{31}/-1 overflows and any result is possible.
    // => check with a<0 and b=-2^{31}
    if ((a < 0 and b == min) or (a != 0 and @divTrunc(res, a) != b))
        overflow.* = 1;
    return res;
}