[libc] Attempt to speed up memcpy for aligned mem

Copy long-by-long instead of byte-by-byte if both pointers are similarly
aligned.
This commit is contained in:
Justin C. Miller
2021-01-17 20:54:38 -08:00
parent dcb8a3f3fb
commit 55a5c97034

View File

@@ -10,9 +10,24 @@ void * memcpy( void * restrict s1, const void * restrict s2, size_t n )
{
char * dest = (char *) s1;
const char * src = (const char *) s2;
while ( n-- )
{
if (((uintptr_t)src & 7) == ((uintptr_t)dest & 7)) {
while (((uintptr_t)src & 7) && n--)
*dest++ = *src++;
const uint64_t *srcq = (const uint64_t*)src;
uint64_t *destq = (uint64_t*)dest;
while (n >= 8) {
*destq++ = *srcq++;
n -= 8;
}
src = (const char*)srcq;
dest = (char*)destq;
}
while (n--)
*dest++ = *src++;
}
return s1;
}