mirror of
https://github.com/justinian/jsix.git
synced 2025-12-09 16:04:32 -08:00
[libc] Change memcpy back to rep movsb
Influenced by other libc implementations, I had tried to make memcpy smarter for differently-sized ranges, but my benchmarks showed no real change. So change memcpy back to the simple rep movsb implementation.
This commit is contained in:
@@ -10,33 +10,8 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <__j6libc/copy.h>
|
|
||||||
|
|
||||||
using namespace __j6libc;
|
|
||||||
|
|
||||||
inline void memcpy_dispatch(char *s1, const char *s2, size_t n) {
|
|
||||||
if (n == 0) return;
|
|
||||||
if (n == 1) return do_copy<1>(s1, s2);
|
|
||||||
if (n == 2) return do_copy<2>(s1, s2);
|
|
||||||
if (n == 3) return do_copy<3>(s1, s2);
|
|
||||||
if (n == 4) return do_copy<4>(s1, s2);
|
|
||||||
if (n < 8) return do_double_copy<4>(s1, s2, n);
|
|
||||||
if (n == 8) return do_copy<8>(s1, s2);
|
|
||||||
if (n < 16) return do_double_copy<8>(s1, s2, n);
|
|
||||||
if (n < 32) return do_double_copy<16>(s1, s2, n);
|
|
||||||
if (n < 64) return do_double_copy<32>(s1, s2, n);
|
|
||||||
|
|
||||||
if (n < 128)
|
|
||||||
return do_double_copy<64>(s1, s2, n);
|
|
||||||
else
|
|
||||||
return do_large_copy(s1, s2, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *memcpy(void * restrict s1, const void * restrict s2, size_t n) {
|
void *memcpy(void * restrict s1, const void * restrict s2, size_t n) {
|
||||||
memcpy_dispatch(
|
asm volatile ("rep movsb" : "+D"(s1), "+S"(s2), "+c"(n) :: "memory");
|
||||||
reinterpret_cast<char*>(s1),
|
|
||||||
reinterpret_cast<const char*>(s2),
|
|
||||||
n);
|
|
||||||
|
|
||||||
return s1;
|
return s1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user