u-boot-boun...@lists.denx.de wrote on 10/10/2009 11:51:16:
> From: > > Alessandro Rubini <rubini-l...@gnudd.com> > > To: > > u-boot@lists.denx.de > > Cc: > > stericsson_nomadik_li...@list.st.com, andrea.ga...@stericsson.com > > Date: > > 10/10/2009 11:51 > > Subject: > > [U-Boot] [PATCH V4 2/3] lib_generic memset: fill one word at a time if > possible > > Sent by: > > u-boot-boun...@lists.denx.de > > From: Alessandro Rubini <rub...@unipv.it> > > If the destination is aligned, fill ulong values until possible. > Then fill remaining part by byte. > > Signed-off-by: Alessandro Rubini <rub...@unipv.it> > Acked-by: Andrea Gallo <andrea.ga...@stericsson.com> > Acked-by: Mike Frysinger <vap...@gentoo.org> > --- > 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 61a45dc..b375b81 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; > + unsigned long cl = 0; > + char *s8; > + int i; > + > + /* do it one word at a time (32 bits or 64 bits) while possible */ > + if ( ((ulong)s & (sizeof(*sl) - 1)) == 0) { > + for (i = 0; i < sizeof(*sl); i++) { > + cl <<= 8; > + cl |= c & 0xff; > + } > + while (count >= sizeof(*sl)) { > + *sl++ = cl; > + count -= sizeof(*sl); > + } The above while can be slow if not the complier manages to turn into: for(wc = count / sizeof(*sl); wc; --wc) { *sl++ = cl; } count = count & (sizeof(*sl)-1); even better would be: for(--sl, wc = count / sizeof(*sl); wc; --wc) { *++sl = cl; } ++sl; count = count & (sizeof(*sl)-1); for those arch's that can do pre inc and load/store in one instruction. Just figured I should mention it. _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot