Skip to content
Snippets Groups Projects
Commit e3ea948d authored by Alessandro Rubini's avatar Alessandro Rubini Committed by Wolfgang Denk
Browse files

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: default avatarAlessandro Rubini <rubini@unipv.it>
Acked-by: default avatarAndrea Gallo <andrea.gallo@stericsson.com>
Acked-by: default avatarMike Frysinger <vapier@gentoo.org>
parent ecd830b8
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment