mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 23:52:31 +00:00
f5edaa96dd
This moves functions that LLVM generates calls to, to the compiler_rt implementation itself, rather than c.zig. This is a prerequisite for native backends to link with compiler-rt. This also allows native backends to generate calls to `memcpy` and the like.
26 lines
545 B
Zig
26 lines
545 B
Zig
const std = @import("std");
|
|
const common = @import("./common.zig");
|
|
|
|
comptime {
|
|
@export(memcpy, .{ .name = "memcpy", .linkage = common.linkage });
|
|
}
|
|
|
|
pub fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 {
|
|
@setRuntimeSafety(false);
|
|
|
|
if (len != 0) {
|
|
var d = dest.?;
|
|
var s = src.?;
|
|
var n = len;
|
|
while (true) {
|
|
d[0] = s[0];
|
|
n -= 1;
|
|
if (n == 0) break;
|
|
d += 1;
|
|
s += 1;
|
|
}
|
|
}
|
|
|
|
return dest;
|
|
}
|