X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=lib_generic%2Fstring.c;h=b375b8124a9a1879a831d79b8f956bf8ae8a9537;hb=bffbb2a86d2a3aa28bd8f9869aa553082fb5af5f;hp=e0b793abbee5106e5614f51f7876fd1e6be1d5e5;hpb=38546f08c608b871a65bd538b9c460b3348b1261;p=u-boot diff --git a/lib_generic/string.c b/lib_generic/string.c index e0b793abbe..b375b8124a 100644 --- a/lib_generic/string.c +++ b/lib_generic/string.c @@ -263,7 +263,7 @@ char * strdup(const char *s) #ifndef __HAVE_ARCH_STRSPN /** * strspn - Calculate the length of the initial substring of @s which only - * contain letters in @accept + * contain letters in @accept * @s: The string to be searched * @accept: The string to search for */ @@ -403,10 +403,26 @@ char *strswab(const char *s) */ void * memset(void * s,int c,size_t count) { - char *xs = (char *) s; - + unsigned long *sl = (unsigned long *) s; + unsigned long cl = 0; + char *s8; + int i; + + /* do it one word at a time (32 bits or 64 bits) while possible */ + if ( ((ulong)s & (sizeof(*sl) - 1)) == 0) { + for (i = 0; i < sizeof(*sl); i++) { + cl <<= 8; + cl |= c & 0xff; + } + while (count >= sizeof(*sl)) { + *sl++ = cl; + count -= sizeof(*sl); + } + } + /* fill 8 bits at a time */ + s8 = (char *)sl; while (count--) - *xs++ = c; + *s8++ = c; return s; } @@ -446,12 +462,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; }