From 076afc6c1379bcd06e458ee235b47275121c2708 Mon Sep 17 00:00:00 2001 From: dweiller <4678790+dweiller@users.noreply.github.com> Date: Mon, 19 Feb 2024 00:45:19 +1100 Subject: [PATCH] compiler-rt: refactor memcpy --- lib/compiler_rt/memcpy.zig | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/compiler_rt/memcpy.zig b/lib/compiler_rt/memcpy.zig index 65d195cf5cb2..dac57123a255 100644 --- a/lib/compiler_rt/memcpy.zig +++ b/lib/compiler_rt/memcpy.zig @@ -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].*; @@ -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);