authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-17 13:21:30-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-17 13:21:30-08:00
logacf70439551fc3f49b2d292ff93ee519901cdf42
treeb70f5c87c1b023e7a4acc5d8ae32429657d9a967
parent59acfb12635b79fd83950eed10172cf43694b978

work around llvm failing to lower memcpy

triggers an assertion in LegalizeDAG otherwise

1 files changed, 26 insertions(+), 2 deletions(-)

lib/compiler_rt/memcpy.zig+26-2
......@@ -9,12 +9,36 @@ comptime {
99 }
1010}
1111
12const llvm_cannot_lower = switch (builtin.cpu.arch) {
13 .arm, .armeb, .thumb, .thumbeb => builtin.zig_backend == .stage2_llvm,
14 else => false,
15};
16
1217fn memcpy(noalias opt_dest: ?[*]u8, noalias opt_src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 {
13 return memmove(opt_dest, opt_src, len);
18 if (llvm_cannot_lower) {
19 for (0..len) |i| opt_dest.?[i] = opt_src.?[i];
20 return opt_dest;
21 } else {
22 return memmove(opt_dest, opt_src, len);
23 }
1424}
1525
26/// A port of https://github.com/facebook/folly/blob/1c8bc50e88804e2a7361a57cd9b551dd10f6c5fd/folly/memcpy.S
1627fn memmove(opt_dest: ?[*]u8, opt_src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 {
17 // a port of https://github.com/facebook/folly/blob/1c8bc50e88804e2a7361a57cd9b551dd10f6c5fd/folly/memcpy.S
28 if (llvm_cannot_lower) {
29 if (@intFromPtr(opt_dest) < @intFromPtr(opt_src)) {
30 for (0..len) |i| opt_dest.?[i] = opt_src.?[i];
31 return opt_dest;
32 } else {
33 var index = len;
34 while (index != 0) {
35 index -= 1;
36 opt_dest.?[index] = opt_src.?[index];
37 }
38 return opt_dest;
39 }
40 }
41
1842 if (len == 0) {
1943 @branchHint(.unlikely);
2044 return opt_dest;