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.

__clz_limb64

limb64.__clz_limb64
fn __clz_limb64(a_ptr: [*]const u64, bits: u16) callconv(.c) u16

File

lib/compiler_rt/limb64.zig:675

Code

fn __clz_limb64(a_ptr: [*]const u64, bits: u16) callconv(.c) u16 {
    const limb_cnt = usedLimbCount(bits);
    const a = constLimbs(a_ptr, bits);

    var res: u16 = 0;
    var i: usize = 0;

    if (bits % 64 != 0) {
        const limb = limbGet(a, limb_cnt - 1);
        if (limb == 0) {
            res += bits % 64;
        } else {
            return @clz(limb << @intCast(64 - bits % 64));
        }
        i += 1;
    }

    while (i < limb_cnt) : (i += 1) {
        const j = limb_cnt - 1 - i;
        const limb = limbGet(a, j);
        if (limb == 0) {
            res += 64;
        } else {
            res += @clz(limb);
            break;
        }
    }

    return res;
}