]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
lib_generic memset: fill one word at a time if possible
authorAlessandro Rubini <rubini@unipv.it>
Sat, 10 Oct 2009 09:51:16 +0000 (11:51 +0200)
committerWolfgang Denk <wd@denx.de>
Sun, 18 Oct 2009 21:10:40 +0000 (23:10 +0200)
If the destination is aligned, fill ulong values until possible.
Then fill remaining part by byte.

Signed-off-by: Alessandro Rubini <rubini@unipv.it>
Acked-by: Andrea Gallo <andrea.gallo@stericsson.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
lib_generic/string.c

index 61a45dc94d26c9fc9c42682ee0c67221c26c4a2f..b375b8124a9a1879a831d79b8f956bf8ae8a9537 100644 (file)
@@ -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;
 }