feature. See also
. The project being documented here (as the example) is the Zig library itself.
compiler_rt.fastMemset
fn fastMemset(dest: ?[*]u8, c: c_int, len: usize) callconv(.c) ?[*]u8
File
Code
fn fastMemset(dest: ?[*]u8, c: c_int, len: usize) callconv(.c) ?[*]u8 {
const b: u8 = @truncate(@as(c_uint, @bitCast(c)));
const n = std.simd.suggestVectorLength(u8) orelse @sizeOf(usize);
const d = dest.?;
if (len > 2 * n) {
memsetSmallPowerOf2(d, b, n);
const begin_aligned = std.mem.alignBackward(usize, @intFromPtr(d) + n, n);
const end_aligned = std.mem.alignForward(usize, @intFromPtr(d) + len - n, n);
const aligned_ptr: [*]align(n) u8 = @ptrFromInt(begin_aligned);
var i: usize = 0;
while (true) {
memsetSmallPowerOf2(aligned_ptr + n * i, b, n);
i += 1;
if (i == @divExact(end_aligned - begin_aligned, n))
break;
}
memsetSmallPowerOf2(d + len - n, b, n);
} else {
if (len == 0) return dest;
shortMemset(0, @ctz(@as(usize, 2 * n)), d, b, len);
}
return dest;
}