diff options
| author | Alessandro Rubini <rubini@unipv.it> | 2009-10-10 11:51:16 +0200 |
|---|---|---|
| committer | Wolfgang Denk <wd@denx.de> | 2009-10-18 23:10:40 +0200 |
| commit | e3ea948d4588e7efddbf0ee92147d93f827d7cea (patch) | |
| tree | 9fbbe1bdda3923d5cc54f73120ceea4a3772a0c6 | |
| parent | ecd830b863e5c6ac5d804d3b3a92453a98d526fc (diff) | |
| download | olio-uboot-2014.01-e3ea948d4588e7efddbf0ee92147d93f827d7cea.tar.xz olio-uboot-2014.01-e3ea948d4588e7efddbf0ee92147d93f827d7cea.zip | |
lib_generic memset: fill one word at a time if possible
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>
| -rw-r--r-- | lib_generic/string.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib_generic/string.c b/lib_generic/string.c index 61a45dc94..b375b8124 100644 --- a/lib_generic/string.c +++ b/lib_generic/string.c @@ -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; } |