| author | |
| committer | |
| log | d6e1166f1a93e8ed5dd0a74cc0b0daeae5c050a0 |
| tree | 445a9c5806cb3a2288abc77624bcd07e82a9492b |
| parent | bf89482f23aae3524c92d385d6d8241d065d1031 |
2 files changed, 49 insertions(+), 4 deletions(-)
lib/compiler_rt/memcpy.zig+21-2| ... | ... | @@ -4,10 +4,29 @@ const builtin = @import("builtin"); |
| 4 | 4 | |
| 5 | 5 | comptime { |
| 6 | 6 | if (builtin.object_format != .c) { |
| 7 | @export(&memcpy, .{ .name = "memcpy", .linkage = common.linkage, .visibility = common.visibility }); | |
| 7 | const export_options: std.builtin.ExportOptions = .{ | |
| 8 | .name = "memcpy", | |
| 9 | .linkage = common.linkage, | |
| 10 | .visibility = common.visibility, | |
| 11 | }; | |
| 12 | ||
| 13 | if (builtin.mode == .ReleaseSmall) | |
| 14 | @export(&memcpySmall, export_options) | |
| 15 | else | |
| 16 | @export(&memcpyFast, export_options); | |
| 17 | } | |
| 18 | } | |
| 19 | ||
| 20 | fn memcpySmall(noalias dest: ?[*]u8, noalias src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 { | |
| 21 | @setRuntimeSafety(builtin.is_test); | |
| 22 | ||
| 23 | for (0..len) |i| { | |
| 24 | dest.?[i] = src.?[i]; | |
| 8 | 25 | } |
| 26 | ||
| 27 | return dest; | |
| 9 | 28 | } |
| 10 | 29 | |
| 11 | fn memcpy(opt_dest: ?[*]u8, opt_src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 { | |
| 30 | fn memcpyFast(opt_dest: ?[*]u8, opt_src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 { | |
| 12 | 31 | return @call(.always_inline, @import("memmove.zig").memmove, .{ opt_dest, opt_src, len }); |
| 13 | 32 | } |
lib/compiler_rt/memmove.zig+28-2| ... | ... | @@ -4,11 +4,37 @@ const builtin = @import("builtin"); |
| 4 | 4 | |
| 5 | 5 | comptime { |
| 6 | 6 | if (builtin.object_format != .c) { |
| 7 | @export(&memmove, .{ .name = "memmove", .linkage = common.linkage, .visibility = common.visibility }); | |
| 7 | const export_options: std.builtin.ExportOptions = .{ | |
| 8 | .name = "memmove", | |
| 9 | .linkage = common.linkage, | |
| 10 | .visibility = common.visibility, | |
| 11 | }; | |
| 12 | ||
| 13 | if (builtin.mode == .ReleaseSmall) | |
| 14 | @export(&memmoveSmall, export_options) | |
| 15 | else | |
| 16 | @export(&memmoveFast, export_options); | |
| 8 | 17 | } |
| 9 | 18 | } |
| 10 | 19 | |
| 11 | pub fn memmove(opt_dest: ?[*]u8, opt_src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 { | |
| 20 | fn memmoveSmall(opt_dest: ?[*]u8, opt_src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 { | |
| 21 | const dest = opt_dest.?; | |
| 22 | const src = opt_src.?; | |
| 23 | ||
| 24 | if (@intFromPtr(dest) < @intFromPtr(src)) { | |
| 25 | for (0..len) |i| { | |
| 26 | dest[i] = src[i]; | |
| 27 | } | |
| 28 | } else { | |
| 29 | for (0..len) |i| { | |
| 30 | dest[len - 1 - i] = src[len - 1 - i]; | |
| 31 | } | |
| 32 | } | |
| 33 | ||
| 34 | return dest; | |
| 35 | } | |
| 36 | ||
| 37 | pub fn memmoveFast(opt_dest: ?[*]u8, opt_src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 { | |
| 12 | 38 | // a port of https://github.com/facebook/folly/blob/1c8bc50e88804e2a7361a57cd9b551dd10f6c5fd/folly/memcpy.S |
| 13 | 39 | if (len == 0) { |
| 14 | 40 | @branchHint(.unlikely); |