mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
[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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user