lib_generic memset: fill one word at a time if possible
PATCH v3 2/3 lib_generic memset: fill one word at a time if possible
From: Alessandro Rubini <[email protected]>
If the destination is aligned, fill ulong values until possible. Then fill remaining part by bytes.
--- lib_generic/string.c | 22 +++++++++++++++++++--- 1 files changed, 19 insertions(+), 3 deletions(-)
lib_generic/string.c +19 -3
@@ -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 ( ((count | (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; }
Signature · 1 line
1.5.6.5
PATCH v3 2/3 lib_generic memset: fill one word at a time if possible
Similar remarks to those for memcpy :
Alessandro Rubini a ?crit :
Quoted 16 lines
From: Alessandro Rubini <[email protected]>
If the destination is aligned, fill ulong values until possible. Then fill remaining part by bytes.
Signed-off-by Alessandro Rubini <[email protected]>Acked-by Andrea Gallo <[email protected]>--- lib_generic/string.c | 22 +++++++++++++++++++--- 1 files changed, 19 insertions(+), 3 deletions(-)lib_generic/string.c +0
-0
lib_generic/string.c char *strswab(const char *s) · line 407
Quoted 7 lines
lib_generic/string.c +1
-2@@ -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;
Nitpick: Cast ?
+ unsigned long *sl = s;
lib_generic/string.c char *strswab(const char *s) · line 426
Quoted 7 lines
lib_generic/string.c +6
-0+unsigned long cl =0 ; +char *s8; +int i; + +/* do it one word at a time (32 bits or 64 bits) while possible */ +if ( ((count | (ulong )s) & (sizeof (*sl) -1 )) ==0 ) {
Remove count from or.
+ if (((ulong)s & (sizeof(*sl) - 1)) == 0) {
lib_generic/string.c char *strswab(const char *s) · line 426
Quoted 2 lines
lib_generic/string.c +1
-0+for (i=0 ; i<sizeof (*sl); ++i) {
Nitpick: for LK spaces around operators are preferred but I am not sure for U-Boot.
+ for (i = 0; i < sizeof(*sl); ++i) {
Quoted 14 lines
lib_generic/string.c +11
-1+ 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;
Quoted 3 lines
return s;
}
Cheers,
Chris