[U-Boot] [PATCH V2 1/3] memcpy: copy one word at a time if possible

Alessandro Rubini rubini-list at gnudd.com
Thu Oct 8 13:30:02 CEST 2009


From: Alessandro Rubini <rubini at unipv.it>

Signed-off-by: Alessandro Rubini <rubini at unipv.it>
Acked-by: Andrea Gallo <andrea.gallo at 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;
 }
-- 
1.6.0.2


More information about the U-Boot mailing list