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

Chris Moore moore at free.fr
Thu Oct 8 07:23:05 CEST 2009


Alessandro Rubini a écrit :
> 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 |   11 ++++++++++-
>  1 files changed, 10 insertions(+), 1 deletions(-)
>
> diff --git a/lib_generic/string.c b/lib_generic/string.c
> index 181eda6..fdccab6 100644
> --- a/lib_generic/string.c
> +++ b/lib_generic/string.c
> @@ -449,7 +449,16 @@ char * bcopy(const char * src, char * dest, int count)
>  void * memcpy(void * dest,const void *src,size_t count)
>  {
>  	char *tmp = (char *) dest, *s = (char *) src;
> +	u32 *d32 = (u32 *)dest, *s32 = (u32 *) src;
>  
> +	/* if both are aligned, use 32-bit copy */
> +	if ( (((int)dest & 3) | ((int)src & 3) | (count & 3)) == 0 ) {
>   

This can be factorized as (a & 3) | (b & 3) | (c & 3) is equivalent to 
(a | b | c) & 3.
GCC is pretty smart but I doubt that it will pick this up :(

> +		count /= 4;
> +		while (count--)
> +			*d32++ = *s32++;
> +		return dest;
> +	}
> +	/* else, use 1-byte copy */
>  	while (count--)
>  		*tmp++ = *s++;
>  
>   

Cheers,
Chris



More information about the U-Boot mailing list