[U-Boot] [PATCH 2/3] memset: use 32-bit copies if possible

Alessandro Rubini rubini-list at gnudd.com
Wed Oct 7 10:44:36 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 |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/lib_generic/string.c b/lib_generic/string.c
index fdccab6..68e0255 100644
--- a/lib_generic/string.c
+++ b/lib_generic/string.c
@@ -404,7 +404,21 @@ char *strswab(const char *s)
 void * memset(void * s,int c,size_t count)
 {
 	char *xs = (char *) s;
+	u32 *s32 = (u32 *) s;
+	int c32 = 0; /* most common case */
 
+	/* do it 32 bits at a time if possible */
+	if ( ((count & 3) | ((int)s & 3)) == 0) {
+		count /= 4;
+		if (c) { /* not 0: build 32-bit value */
+			c32 = c | (c<<8);
+			c32 |= c32 << 16;
+		}
+		while (count--)
+			*s32++ = c32;
+		return s;
+	}
+	/* else, fill 8 bits at a time */
 	while (count--)
 		*xs++ = c;
 
-- 
1.5.6.5


More information about the U-Boot mailing list