[U-Boot] [PATCH 1/3] memcpy: use 32-bit copies if possible
Joakim Tjernlund
joakim.tjernlund at transmode.se
Thu Oct 8 11:05:21 CEST 2009
>
> Dear Alessandro Rubini,
>
> In message <20091008074114.GA30203 at mail.gnudd.com> you wrote:
> >
> > Since int is 32 also on 64bit systems, I used unsigned long.
>
> Note that this is not guaranteed, though. It could be 64 bit as well.
>
>
> > /* 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;
>
> How about:
>
> cl = 0;
> for (i=0; i<sizeof(long); ++i) {
> cl <<= 8;
> cl |= c & 0xff;
> }
>
> GCC optimization will do the rest...
If you want gcc to optimise well, make it easy to do so.
Changing the for loop into:
for (i=sizeof(long); i; --i)
makes it easier for gcc and more likely to result in optimal code.
Similarly for copy ops
for(--top,--fromp, i = len/4; i; --i)
*++top = *++fromp; /* pre incr can be one op on some archs */
Jocke
More information about the U-Boot
mailing list