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
604 B
Zig
26 lines
604 B
Zig
const std = @import("std");
|
|
const common = @import("./common.zig");
|
|
|
|
comptime {
|
|
@export(memmove, .{ .name = "memmove", .linkage = common.linkage });
|
|
}
|
|
|
|
pub fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) callconv(.C) ?[*]u8 {
|
|
@setRuntimeSafety(false);
|
|
|
|
if (@ptrToInt(dest) < @ptrToInt(src)) {
|
|
var index: usize = 0;
|
|
while (index != n) : (index += 1) {
|
|
dest.?[index] = src.?[index];
|
|
}
|
|
} else {
|
|
var index = n;
|
|
while (index != 0) {
|
|
index -= 1;
|
|
dest.?[index] = src.?[index];
|
|
}
|
|
}
|
|
|
|
return dest;
|
|
}
|