| ... | ... | @@ -5,19 +5,23 @@ const builtin = @import("builtin"); |
| 5 | 5 | comptime { |
| 6 | 6 | if (builtin.object_format != .c) { |
| 7 | 7 | @export(&memcpy, .{ .name = "memcpy", .linkage = common.linkage, .visibility = common.visibility }); |
| 8 | | @export(&memcpy, .{ .name = "memmove", .linkage = common.linkage, .visibility = common.visibility }); |
| 8 | @export(&memmove, .{ .name = "memmove", .linkage = common.linkage, .visibility = common.visibility }); |
| 9 | 9 | } |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | | // a port of https://github.com/facebook/folly/blob/1c8bc50e88804e2a7361a57cd9b551dd10f6c5fd/folly/memcpy.S |
| 13 | | pub fn memcpy(maybe_dest: ?[*]u8, maybe_src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 { |
| 12 | fn memcpy(noalias opt_dest: ?[*]u8, noalias opt_src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 { |
| 13 | return memmove(opt_dest, opt_src, len); |
| 14 | } |
| 15 | |
| 16 | fn 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 |
| 14 | 18 | if (len == 0) { |
| 15 | 19 | @branchHint(.unlikely); |
| 16 | | return maybe_dest; |
| 20 | return opt_dest; |
| 17 | 21 | } |
| 18 | 22 | |
| 19 | | const dest = maybe_dest.?; |
| 20 | | const src = maybe_src.?; |
| 23 | const dest = opt_dest.?; |
| 24 | const src = opt_src.?; |
| 21 | 25 | |
| 22 | 26 | if (len < 8) { |
| 23 | 27 | @branchHint(.unlikely); |