Skip to content

Commit

Permalink
compiler-rt: refactor memcpy
Browse files Browse the repository at this point in the history
  • Loading branch information
dweiller committed Feb 19, 2024
1 parent 3c4a055 commit 076afc6
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/compiler_rt/memcpy.zig
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,7 @@ pub fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, len: usize) callc
if (@intFromPtr(d) % alignment == 0) {
memcpy_aligned(@alignCast(@ptrCast(d)), @alignCast(@ptrCast(s)), n);
} else {
var vd: [*]align(1) CopyType = @ptrCast(d);
var vs: [*]const CopyType = @alignCast(@ptrCast(s));
var loop_count = n / size;
while (loop_count > 0) : (loop_count -= 1) {
vd[0] = vs[0];
vd += 1;
vs += 1;
}
memcpy_unaligned(@ptrCast(d), @alignCast(@ptrCast(s)), n);
}

dest.?[len - size ..][0..size].* = src.?[len - size ..][0..size].*;
Expand All @@ -82,6 +75,22 @@ inline fn memcpy_aligned(
noalias dest: [*]CopyType,
noalias src: [*]const CopyType,
len: usize,
) void {
memcpy_blocks(dest, src, len);
}

inline fn memcpy_unaligned(
noalias dest: [*]align(1) CopyType,
noalias src: [*]const CopyType,
len: usize,
) void {
memcpy_blocks(dest, src, len);
}

inline fn memcpy_blocks(
noalias dest: anytype,
noalias src: anytype,
len: usize,
) void {
@setRuntimeSafety(false);

Expand Down

0 comments on commit 076afc6

Please sign in to comment.