All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alessandro Rubini <rubini-list@gnudd.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V3 2/3] lib_generic memset: fill one word at a time if	possible
Date: Fri, 9 Oct 2009 11:12:32 +0200	[thread overview]
Message-ID: <20091009091232.GA3836@mail.gnudd.com> (raw)

From: Alessandro Rubini <rubini@unipv.it>

If the destination is aligned, fill ulong values until possible.
Then fill remaining part by bytes.

Signed-off-by: Alessandro Rubini <rubini@unipv.it>
Acked-by: Andrea Gallo <andrea.gallo@stericsson.com>
---
 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;
+	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) {
+		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;
 }
-- 
1.5.6.5

             reply	other threads:[~2009-10-09  9:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-09  9:12 Alessandro Rubini [this message]
2009-10-10  6:23 ` [U-Boot] [PATCH V3 2/3] lib_generic memset: fill one word at a time if possible Chris Moore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091009091232.GA3836@mail.gnudd.com \
    --to=rubini-list@gnudd.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.