[U-Boot] [PATCH 1/3] memcpy: use 32-bit copies if possible
Alessandro Rubini
rubini-list at gnudd.com
Thu Oct 8 09:41:15 CEST 2009
I was making my v2, and I found a problem wrt:
> while 64bit isnt in today, might as well avoid unclean code from the start
> when possible. in other words, used "unsigned int" rather than "u32" and cast
> to "unsigned long" rather than "int".
Since int is 32 also on 64bit systems, I used unsigned long.
For memcpy all is well, for memset I have this problem:
void * memset(void * s,int c,size_t count)
{
char *xs = (char *) s;
unsigned long *sl = (unsigned long *) s;
unsigned long cl;
/* 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);
cl = (c & 0xff) | ((c & 0xff) << 8);
cl |= cl << 16;
if (sizeof(long) > 4)
cl |= cl << 32;
while (count--)
*sl++ = cl;
return s;
}
/* else, fill 8 bits at a time */
while (count--)
*xs++ = c;
return s;
}
string.c:416: warning: left shift count >= width of type
(obviously there is no such shift in the generated code,
since the condition is false at compile time).
I think I'll stick to u32 for memset, unless I get better suggestions.
/alessandro
More information about the U-Boot
mailing list