]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - lib_generic/string.c
lib_generic memcpy: copy one word at a time if possible
[karo-tx-uboot.git] / lib_generic / string.c
index e0b793abbee5106e5614f51f7876fd1e6be1d5e5..61a45dc94d26c9fc9c42682ee0c67221c26c4a2f 100644 (file)
@@ -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
  */
@@ -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;
 }