[U-Boot] [PATCH V2 2/3] memset: fill one word at a time if possible
Alessandro Rubini
rubini-list at gnudd.com
Thu Oct 8 13:30:12 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, 16 insertions(+), 1 deletions(-)
diff --git a/lib_generic/string.c b/lib_generic/string.c
index 9911941..5f7aff9 100644
--- a/lib_generic/string.c
+++ b/lib_generic/string.c
@@ -404,7 +404,22 @@ 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;
+ int i;
+
+ /* do it one word at a time (32 bits or 64 bits) if possible */
+ if ( ((count | (int)s) & (sizeof(long) - 1)) == 0) {
+ count /= sizeof(long);
+ for (i=0; i<sizeof(long); ++i) {
+ cl <<= 8;
+ cl |= c & 0xff;
+ }
+ while (count--)
+ *sl++ = cl;
+ return s;
+ }
+ /* else, fill 8 bits at a time */
while (count--)
*xs++ = c;
--
1.6.0.2
More information about the U-Boot
mailing list