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.

bswapXi2

bswap.bswapXi2
inline fn bswapXi2(comptime T: type, a: T) T

File

lib/compiler_rt/bswap.zig:22

Code

inline fn bswapXi2(comptime T: type, a: T) T {
    switch (@bitSizeOf(T)) {
        32 => {
            // zig fmt: off
            return (((a & 0xff000000) >> 24)
                 |  ((a & 0x00ff0000) >> 8 )
                 |  ((a & 0x0000ff00) << 8 )
                 |  ((a & 0x000000ff) << 24));
            // zig fmt: on
        },
        64 => {
            // zig fmt: off
            return (((a & 0xff00000000000000) >> 56)
                 |  ((a & 0x00ff000000000000) >> 40 )
                 |  ((a & 0x0000ff0000000000) >> 24 )
                 |  ((a & 0x000000ff00000000) >> 8 )
                 |  ((a & 0x00000000ff000000) << 8 )
                 |  ((a & 0x0000000000ff0000) << 24 )
                 |  ((a & 0x000000000000ff00) << 40 )
                 |  ((a & 0x00000000000000ff) << 56));
            // zig fmt: on
        },
        128 => {
            // zig fmt: off
            return (((a & 0xff000000000000000000000000000000) >> 120)
                 |  ((a & 0x00ff0000000000000000000000000000) >> 104)
                 |  ((a & 0x0000ff00000000000000000000000000) >> 88 )
                 |  ((a & 0x000000ff000000000000000000000000) >> 72 )
                 |  ((a & 0x00000000ff0000000000000000000000) >> 56 )
                 |  ((a & 0x0000000000ff00000000000000000000) >> 40 )
                 |  ((a & 0x000000000000ff000000000000000000) >> 24 )
                 |  ((a & 0x00000000000000ff0000000000000000) >> 8  )
                 |  ((a & 0x0000000000000000ff00000000000000) << 8  )
                 |  ((a & 0x000000000000000000ff000000000000) << 24 )
                 |  ((a & 0x00000000000000000000ff0000000000) << 40 )
                 |  ((a & 0x0000000000000000000000ff00000000) << 56 )
                 |  ((a & 0x000000000000000000000000ff000000) << 72 )
                 |  ((a & 0x00000000000000000000000000ff0000) << 88 )
                 |  ((a & 0x0000000000000000000000000000ff00) << 104)
                 |  ((a & 0x000000000000000000000000000000ff) << 120));
            // zig fmt: on
        },
        else => unreachable,
    }
}