Commit ecd830b863e5c6ac5d804d3b3a92453a98d526fc
Committed by
Wolfgang Denk
1 parent
9c5586aa19
Exists in
master
and in
54 other branches
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: Alessandro Rubini <rubini@unipv.it> Acked-by: Andrea Gallo <andrea.gallo@stericsson.com> Acked-by: Mike Frysinger <vapier@gentoo.org>
Showing 1 changed file with 15 additions and 4 deletions Side-by-side Diff
lib_generic/string.c
... | ... | @@ -446,12 +446,23 @@ |
446 | 446 | * You should not use this function to access IO space, use memcpy_toio() |
447 | 447 | * or memcpy_fromio() instead. |
448 | 448 | */ |
449 | -void * memcpy(void * dest,const void *src,size_t count) | |
449 | +void * memcpy(void *dest, const void *src, size_t count) | |
450 | 450 | { |
451 | - char *tmp = (char *) dest, *s = (char *) src; | |
451 | + unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src; | |
452 | + char *d8, *s8; | |
452 | 453 | |
454 | + /* while all data is aligned (common case), copy a word at a time */ | |
455 | + if ( (((ulong)dest | (ulong)src) & (sizeof(*dl) - 1)) == 0) { | |
456 | + while (count >= sizeof(*dl)) { | |
457 | + *dl++ = *sl++; | |
458 | + count -= sizeof(*dl); | |
459 | + } | |
460 | + } | |
461 | + /* copy the reset one byte at a time */ | |
462 | + d8 = (char *)dl; | |
463 | + s8 = (char *)sl; | |
453 | 464 | while (count--) |
454 | - *tmp++ = *s++; | |
465 | + *d8++ = *s8++; | |
455 | 466 | |
456 | 467 | return dest; |
457 | 468 | } |