From mboxrd@z Thu Jan 1 00:00:00 1970 From: Chris Moore Date: Sat, 10 Oct 2009 08:23:43 +0200 Subject: [U-Boot] [PATCH V3 2/3] lib_generic memset: fill one word at a time if possible In-Reply-To: <20091009091232.GA3836@mail.gnudd.com> References: <20091009091232.GA3836@mail.gnudd.com> Message-ID: <4AD0286E.8030508@free.fr> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Similar remarks to those for memcpy : Alessandro Rubini a ?crit : > From: Alessandro Rubini > > If the destination is aligned, fill ulong values until possible. > Then fill remaining part by bytes. > > Signed-off-by: Alessandro Rubini > Acked-by: Andrea Gallo > --- > lib_generic/string.c | 22 +++++++++++++++++++--- > 1 files changed, 19 insertions(+), 3 deletions(-) > > diff --git a/lib_generic/string.c b/lib_generic/string.c > index 9bee79b..1575c63 100644 > --- a/lib_generic/string.c > +++ b/lib_generic/string.c > @@ -403,10 +403,26 @@ char *strswab(const char *s) > */ > void * memset(void * s,int c,size_t count) > { > - char *xs = (char *) s; > - > + unsigned long *sl = (unsigned long *) s; > Nitpick: Cast ? + unsigned long *sl = s; > + unsigned long cl = 0; > + char *s8; > + int i; > + > + /* do it one word at a time (32 bits or 64 bits) while possible */ > + if ( ((count | (ulong)s) & (sizeof(*sl) - 1)) == 0) { > Remove count from or. + if (((ulong)s & (sizeof(*sl) - 1)) == 0) { > + for (i=0; i Nitpick: for LK spaces around operators are preferred but I am not sure for U-Boot. + for (i = 0; i < sizeof(*sl); ++i) { > + cl <<= 8; > + cl |= c & 0xff; > + } > + while (count >= sizeof(*sl)) { > + *sl++ = cl; > + count -= sizeof(*sl); > + } > + } > + /* fill 8 bits at a time */ > + s8 = (char *)sl; > while (count--) > - *xs++ = c; > + *s8++ = c; > > return s; > } > Cheers, Chris