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.

__subo_limb64

limb64.__subo_limb64
fn __subo_limb64(out_ptr: [*]u64, a_ptr: [*]const u64, b_ptr: [*]const u64, is_signed: bool, bits: u16) callconv(.c) bool

File

lib/compiler_rt/limb64.zig:183

Code

fn __subo_limb64(out_ptr: [*]u64, a_ptr: [*]const u64, b_ptr: [*]const u64, is_signed: bool, bits: u16) callconv(.c) bool {
    const limb_cnt = usedLimbCount(bits);
    const out = varLimbs(out_ptr, bits);
    const a = constLimbs(a_ptr, bits);
    const b = constLimbs(b_ptr, bits);

    var borrow: u1 = 0;
    var i: usize = 0;
    while (i < limb_cnt - 1) : (i += 1) {
        const s1 = @subWithOverflow(limbGet(a, i), limbGet(b, i));
        const s2 = @subWithOverflow(s1[0], borrow);
        borrow = s1[1] | s2[1];
        limbSet(out, i, s2[0]);
    }

    const limb: u64 = b: {
        if (!is_signed) {
            const s1 = @subWithOverflow(limbGet(a, i), limbGet(b, i));
            const s2 = @subWithOverflow(s1[0], borrow);
            borrow = s1[1] | s2[1];
            break :b s2[0];
        } else {
            const as: i64 = @bitCast(limbGet(a, i));
            const bs: i64 = @bitCast(limbGet(b, i));
            const s1 = @subWithOverflow(as, bs);
            const s2 = @subWithOverflow(s1[0], borrow);
            borrow = s1[1] | s2[1];
            break :b @bitCast(s2[0]);
        }
    };

    if (bits % 64 == 0) {
        limbSet(out, i, limb);
        fixLastLimb(out_ptr, is_signed, bits);
        return borrow != 0;
    } else {
        const wrapped_limb = limbWrap(limb, is_signed, bits);
        limbSet(out, i, wrapped_limb);
        fixLastLimb(out_ptr, is_signed, bits);
        return borrow != 0 or wrapped_limb != limb;
    }
}