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.

copyRange4

memmove.copyRange4
inline fn copyRange4(
    comptime copy_len: comptime_int,
    dest: [*]u8,
    src: [*]const u8,
    len: usize,
) void

File

lib/compiler_rt/memmove.zig:116

Code

inline fn copyRange4(
    comptime copy_len: comptime_int,
    dest: [*]u8,
    src: [*]const u8,
    len: usize,
) void {
    @setRuntimeSafety(compiler_rt.test_safety);
    comptime assert(std.math.isPowerOfTwo(copy_len));
    assert(len >= copy_len);
    assert(len < 4 * copy_len);

    const a = len & (copy_len * 2);
    const b = a / 2;

    const last = len - copy_len;
    const pen = last - b;

    const d0 = src[0..copy_len].*;
    const d1 = src[b..][0..copy_len].*;
    const d2 = src[pen..][0..copy_len].*;
    const d3 = src[last..][0..copy_len].*;

    // the slice dest[0..len] is needed to workaround -ODebug miscompilation
    dest[0..len][0..copy_len].* = d0;
    dest[b..][0..copy_len].* = d1;
    dest[pen..][0..copy_len].* = d2;
    dest[last..][0..copy_len].* = d3;
}