[U-Boot] [PATCH V2 2/3] memset: fill one word at a time if possible

Wolfgang Denk wd at denx.de
Thu Oct 8 22:46:18 CEST 2009


Dear Alessandro Rubini,

In message <f6eaf0a025bdc32019286a66bf10cc2184f00995.1255000877.git.rubini@ unipv.it> you wrote:
...
>  void * memset(void * s,int c,size_t count)
>  {
>  	char *xs = (char *) s;
> -
> +	unsigned long *sl = (unsigned long *) s;
> +	unsigned long cl = 0;
> +	int i;

Same changes as suggested for the memcpy() patch go here:

> +	/* 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);

delete this;

> +		for (i=0; i<sizeof(long); ++i) {
> +			cl <<= 8;
> +			cl |= c & 0xff;
> +		}
> +		while (count--)
> +			*sl++ = cl;

and make this

		while (count) {
			*sl++ = cl;
			count -= sizeof(long);
		}

> +		return s;

delete this, too.

> +	}
> +	/* else, fill 8 bits at a time */

Delete the comment, too.

>  	while (count--)
>  		*xs++ = c;

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
"One lawyer can steal more than a hundred men with guns."
- The Godfather


More information about the U-Boot mailing list