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.

ashrXi3

shift.ashrXi3
inline fn ashrXi3(comptime T: type, a: T, b: i32) T

File

lib/compiler_rt/shift.zig:52

Code

inline fn ashrXi3(comptime T: type, a: T, b: i32) T {
    const word_t = compiler_rt.HalveInt(T, true);

    const input = word_t{ .all = a };
    var output: word_t = undefined;

    if (b >= word_t.bits) {
        output.s.high = input.s.high >> (word_t.bits - 1);
        output.s.low = input.s.high >> @intCast(b - word_t.bits);
    } else if (b == 0) {
        return a;
    } else {
        output.s.high = input.s.high >> @intCast(b);
        output.s.low = input.s.high << @intCast(word_t.bits - b);
        // Avoid sign-extension here
        output.s.low |= @bitCast(@as(word_t.HalfTU, @bitCast(input.s.low)) >> @intCast(b));
    }

    return output.all;
}