Skip to content
Snippets Groups Projects
Commit ecd830b8 authored by Alessandro Rubini's avatar Alessandro Rubini Committed by Wolfgang Denk
Browse files

lib_generic memcpy: copy one word at a time if possible


If source and destination are aligned, this copies ulong values
until possible, trailing part is copied by byte. Thanks for the details
to Wolfgang Denk, Mike Frysinger, Peter Tyser, Chris Moore.

Signed-off-by: default avatarAlessandro Rubini <rubini@unipv.it>
Acked-by: default avatarAndrea Gallo <andrea.gallo@stericsson.com>
Acked-by: default avatarMike Frysinger <vapier@gentoo.org>
parent 9c5586aa
No related branches found
No related tags found
No related merge requests found
......@@ -446,12 +446,23 @@ char * bcopy(const char * src, char * dest, int count)
* You should not use this function to access IO space, use memcpy_toio()
* or memcpy_fromio() instead.
*/
void * memcpy(void * dest,const void *src,size_t count)
void * memcpy(void *dest, const void *src, size_t count)
{
char *tmp = (char *) dest, *s = (char *) src;
unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src;
char *d8, *s8;
/* while all data is aligned (common case), copy a word at a time */
if ( (((ulong)dest | (ulong)src) & (sizeof(*dl) - 1)) == 0) {
while (count >= sizeof(*dl)) {
*dl++ = *sl++;
count -= sizeof(*dl);
}
}
/* copy the reset one byte at a time */
d8 = (char *)dl;
s8 = (char *)sl;
while (count--)
*tmp++ = *s++;
*d8++ = *s8++;
return dest;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment