[U-Boot] [PATCH 1/3] memcpy: use 32-bit copies if possible

Wolfgang Denk wd at denx.de
Thu Oct 8 10:37:12 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...

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
If I don't document something, it's usually either for a good reason,
or a bad reason.  In this case it's a good reason.  :-)
                 - Larry Wall in <1992Jan17.005405.16806 at netlabs.com>


More information about the U-Boot mailing list