From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mark Jackson Date: Fri, 09 Oct 2009 11:11:16 +0100 Subject: [U-Boot] [PATCH V2 1/3] memcpy: copy one word at a time if possible In-Reply-To: <4ACEBF19.4010902@free.fr> References: <45d5e3a574bf4844f46f50b2c88054a5b28f973b.1255000877.git.rubini@ unipv.it> <20091008204431.07341E8B31D@gemini.denx.de> <4ACEBF19.4010902@free.fr> Message-ID: <4ACF0C44.9040101@mimc.co.uk> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Chris Moore wrote: > I agree wholeheartedly with the idea but shouldn't it be more like this > (untested) code : > > void * memcpy(void *dest, const void *src, size_t count) > > { > char *d8, *s8; > unsigned long *dl = dest, *sl = src; > In here, would it be overkill to add byte copying until data is aligned, and then fall into the aligned copy code. In that case, you'd still gain a speed increase if you're starting at an unaligned address ? > /* while all data is aligned (common case), copy multiple bytes at a time */ > if ( (((int)(long)dest | (int)(long)src) & (sizeof(*dl) - 1)) == 0) { > while (count >= sizeof(*dl)) { > *dl++ = *sl++; > count -= sizeof(*dl); > } > } > > d8 = (char *)dl; > s8 = (char *)sl; > > /* copy any remaining data byte by byte */ > while (count--) > *d8++ = *s8++; > > return dest; > } Regards Mark