setup memcpy dispatch on every call for now

This commit is contained in:
Brendan Hansknecht 2023-06-02 09:16:21 -07:00
parent 75a035e12d
commit 718b7f0ce2
No known key found for this signature in database
GPG key ID: 0EA784685083E75B

View file

@ -13,9 +13,7 @@ comptime {
const Memcpy = fn (noalias [*]u8, noalias [*]const u8, len: usize) callconv(.C) [*]u8;
pub var memcpy_target: Memcpy = switch (arch) {
// TODO: Switch to dispatch_memcpy once the surgical linker can support it.
// .x86_64 => dispatch_memcpy,
.x86_64 => musl.memcpy,
.x86_64 => dispatch_memcpy,
else => unreachable,
};
@ -32,19 +30,24 @@ pub fn memcpy(noalias dest: [*]u8, noalias src: [*]const u8, len: usize) callcon
}
fn dispatch_memcpy(noalias dest: [*]u8, noalias src: [*]const u8, len: usize) callconv(.C) [*]u8 {
// TODO: Switch this to overwrite the memcpy_target pointer once the surgical linker can support it.
// Then dispatch will just happen on the first call instead of every call.
switch (arch) {
.x86_64 => {
if (cpuid.supports_avx2()) {
if (cpuid.supports_prefetchw()) {
memcpy_target = folly.memcpy_prefetchw;
// memcpy_target = folly.memcpy_prefetchw;
return folly.memcpy_prefetchw(dest, src, len);
} else {
memcpy_target = folly.memcpy_prefetcht0;
// memcpy_target = folly.memcpy_prefetcht0;
return folly.memcpy_prefetcht0(dest, src, len);
}
} else {
memcpy_target = musl.memcpy;
// memcpy_target = musl.memcpy;
return musl.memcpy(dest, src, len);
}
},
else => unreachable,
}
return memcpy_target(dest, src, len);
// return memcpy_target(dest, src, len);
}