From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alessandro Rubini Date: Thu, 8 Oct 2009 09:41:15 +0200 Subject: [U-Boot] [PATCH 1/3] memcpy: use 32-bit copies if possible In-Reply-To: <200910070452.02225.vapier@gentoo.org> References: <200910070452.02225.vapier@gentoo.org> Message-ID: <20091008074114.GA30203@mail.gnudd.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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@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