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.

__shr_limb64

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

File

lib/compiler_rt/limb64.zig:602

Code

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

    assert(shift < bits);

    const limb_shift = shift / 64;
    const bit_shift = shift % 64;

    const ms = limbGet(a, limb_cnt - 1);
    const sign_extend: u64 = if (is_signed and (ms >> 63) == 1) ~@as(u64, 0) else 0;

    var carry: u64 = if (bit_shift != 0) (sign_extend << @intCast(64 - bit_shift)) else 0;
    var i: usize = 0;
    while (i < limb_cnt) : (i += 1) {
        const j = limb_cnt - 1 - i;
        if (i < limb_shift) {
            limbSet(out, j, sign_extend);
        } else {
            const limb = limbGet(a, j + limb_shift);
            limbSet(out, j, (limb >> @intCast(bit_shift)) | carry);
            carry = if (bit_shift != 0) (limb << @intCast(64 - bit_shift)) else 0;
        }
    }

    fixLastLimb(out_ptr, is_signed, bits);
}