| ... | @@ -5,19 +5,23 @@ const builtin = @import("builtin"); | ... | @@ -5,19 +5,23 @@ const builtin = @import("builtin"); |
| 5 | comptime { | 5 | comptime { |
| 6 | if (builtin.object_format != .c) { | 6 | if (builtin.object_format != .c) { |
| 7 | @export(&memcpy, .{ .name = "memcpy", .linkage = common.linkage, .visibility = common.visibility }); | 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 | 12 | fn memcpy(noalias opt_dest: ?[*]u8, noalias opt_src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 { |
| 13 | pub fn memcpy(maybe_dest: ?[*]u8, maybe_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 | if (len == 0) { | 18 | if (len == 0) { |
| 15 | @branchHint(.unlikely); | 19 | @branchHint(.unlikely); |
| 16 | return maybe_dest; | 20 | return opt_dest; |
| 17 | } | 21 | } |
| 18 | | 22 | |
| 19 | const dest = maybe_dest.?; | 23 | const dest = opt_dest.?; |
| 20 | const src = maybe_src.?; | 24 | const src = opt_src.?; |
| 21 | | 25 | |
| 22 | if (len < 8) { | 26 | if (len < 8) { |
| 23 | @branchHint(.unlikely); | 27 | @branchHint(.unlikely); |