[U-Boot] [PATCH V2 1/3] memcpy: copy one word at a time if possible

Peter Tyser ptyser at xes-inc.com
Thu Oct 8 17:12:46 CEST 2009


On Thu, 2009-10-08 at 13:30 +0200, Alessandro Rubini wrote:
> From: Alessandro Rubini <rubini at unipv.it>
> 
> Signed-off-by: Alessandro Rubini <rubini at unipv.it>
> Acked-by: Andrea Gallo <andrea.gallo at stericsson.com>
> ---
>  lib_generic/string.c |   17 +++++++++++++----
>  1 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/lib_generic/string.c b/lib_generic/string.c
> index 181eda6..9911941 100644
> --- a/lib_generic/string.c
> +++ b/lib_generic/string.c
> @@ -446,12 +446,21 @@ char * bcopy(const char * src, char * dest, int count)
>   * You should not use this function to access IO space, use memcpy_toio()
>   * or memcpy_fromio() instead.
>   */
> -void * memcpy(void * dest,const void *src,size_t count)
> +void * memcpy(void *dest, const void *src, size_t count)
>  {
> -	char *tmp = (char *) dest, *s = (char *) src;
> +	char *d8 = (char *)dest, *s8 = (char *)src;
> +	unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src;
>  
> +	/* if all data is aligned (common case), copy a word at a time */
> +	if ( (((int)dest | (int)src | count) & (sizeof(long) - 1)) == 0) {
> +		count /= sizeof(unsigned long);
> +		while (count--)
> +			*dl++ = *sl++;
> +		return dest;
> +	}
> +	/* else, use 1-byte copy */
>  	while (count--)
> -		*tmp++ = *s++;
> +		*d8++ = *s8++;
>  
>  	return dest;
>  }

Hi Alessandro,
No interest in the suggestion to not require count to be an exact
multiple of 4/8?  I don't think it would be that hard to update the
logic accordingly and this would let your code be utilized much more
often, especially if/when we run on a 64-bit machine.  Conceptually it
seems like a cleaner implementation too, but that's probably just my
preference:)

Best,
Peter



More information about the U-Boot mailing list