
Dear Alessandro Rubini,
In message <45d5e3a574bf4844f46f50b2c88054a5b28f973b.1255000877.git.rubini@ unipv.it> you wrote:
From: Alessandro Rubini rubini@unipv.it
Signed-off-by: Alessandro Rubini rubini@unipv.it Acked-by: Andrea Gallo andrea.gallo@stericsson.com
lib_generic/string.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/lib_generic/string.c b/lib_generic/string.c index 181eda6..9911941 100644 --- a/lib_generic/string.c +++ b/lib_generic/string.c @@ -446,12 +446,21 @@ 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;
char *d8 = (char *)dest, *s8 = (char *)src;
unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src;
/* if all data is aligned (common case), copy a word at a time */
if ( (((int)dest | (int)src | count) & (sizeof(long) - 1)) == 0) {
count /= sizeof(unsigned long);
while (count--)
*dl++ = *sl++;
return dest;
}
/* else, use 1-byte copy */ while (count--)
*tmp++ = *s++;
*d8++ = *s8++;
return dest;
I think we should change this if-else into a plain if, something like that:
void * memcpy(void *dest, const void *src, size_t count) { char *tmp = (char *) dest, *s = (char *) src; char *d8 = (char *)dest, *s8 = (char *)src; unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src;
/* while all data is aligned (common case), copy a word at a time */ if ( (((int)dest | (int)src | count) & (sizeof(long) - 1)) == 0) { while (count) { *dl++ = *sl++; count -= sizeof(unsigned long); } } while (count--) *d8++ = *s8++;
return dest; }
This way we can have both - the "long" copy of a potential aligne dfirst part, and the byte copy of any trailing (or unaligned) part.
Best regards,
Wolfgang Denk