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.

popcountXi2

popcount.popcountXi2
inline fn popcountXi2(comptime ST: type, a: ST) i32

File

lib/compiler_rt/popcount.zig:29

Code

inline fn popcountXi2(comptime ST: type, a: ST) i32 {
    const UT = switch (ST) {
        i32 => u32,
        i64 => u64,
        i128 => u128,
        else => unreachable,
    };
    var x: UT = @bitCast(a);
    x -= (x >> 1) & (~@as(UT, 0) / 3); // 0x55...55, aggregate duos
    x = ((x >> 2) & (~@as(UT, 0) / 5)) // 0x33...33, aggregate nibbles
        + (x & (~@as(UT, 0) / 5));
    x += x >> 4;
    x &= ~@as(UT, 0) / 17; // 0x0F...0F, aggregate bytes
    // 8 most significant bits of x + (x<<8) + (x<<16) + ..
    x *%= ~@as(UT, 0) / 255; // 0x01...01
    x >>= (@bitSizeOf(ST) - 8);
    return @intCast(x);
}