public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Wilco Dijkstra" <wdijkstr@arm.com>
To: <libc-alpha@sourceware.org>
Subject: RE: [PATCH][PING] Improve stpncpy performance
Date: Mon, 06 Jul 2015 11:29:00 -0000	[thread overview]
Message-ID: <000301d0b7df$02f253d0$08d6fb70$@com> (raw)
In-Reply-To: 

> Wilco wrote:
> ping
> 
> > > -----Original Message-----
> > > From: Wilco Dijkstra [mailto:wdijkstr@arm.com]
> > > Sent: 12 January 2015 15:09
> > > To: 'libc-alpha@sourceware.org'
> > > Subject: [PATCH] Improve stpncpy performance
> > >
> > > Like strncpy, this patch improves stpncpy performance by using strnlen/memcpy/memset
> rather
> > > than a byte loop. Performance on bench-stpncpy is ~2x faster on average.
> > >
> > > ChangeLog:
> > >
> > > 2015-01-12 Wilco Dijkstra wdijkstr@arm.com
> > >
> > > 	* string/stpncpy.c (stpncpy): Improve performance using
> > > 	__strnlen/memcpy/memset.
> > >
> > > ---
> > >  string/stpncpy.c | 59 ++++++--------------------------------------------------
> > >  1 file changed, 6 insertions(+), 53 deletions(-)
> > >
> > > diff --git a/string/stpncpy.c b/string/stpncpy.c
> > > index fad747e..50521aa 100644
> > > --- a/string/stpncpy.c
> > > +++ b/string/stpncpy.c
> > > @@ -15,7 +15,7 @@
> > >     License along with the GNU C Library; if not, see
> > >     <http://www.gnu.org/licenses/>.  */
> > >
> > > -/* This is almost copied from strncpy.c, written by Torbjorn Granlund.  */
> > > +#include <stddef.h>
> > >
> > >  #ifdef HAVE_CONFIG_H
> > >  # include <config.h>
> > > @@ -41,59 +41,12 @@ weak_alias (__stpncpy, stpncpy)
> > >  char *
> > >  STPNCPY (char *dest, const char *src, size_t n)
> > >  {
> > > -  char c;
> > > -  char *s = dest;
> > > -
> > > -  if (n >= 4)
> > > -    {
> > > -      size_t n4 = n >> 2;
> > > -
> > > -      for (;;)
> > > -	{
> > > -	  c = *src++;
> > > -	  *dest++ = c;
> > > -	  if (c == '\0')
> > > -	    break;
> > > -	  c = *src++;
> > > -	  *dest++ = c;
> > > -	  if (c == '\0')
> > > -	    break;
> > > -	  c = *src++;
> > > -	  *dest++ = c;
> > > -	  if (c == '\0')
> > > -	    break;
> > > -	  c = *src++;
> > > -	  *dest++ = c;
> > > -	  if (c == '\0')
> > > -	    break;
> > > -	  if (--n4 == 0)
> > > -	    goto last_chars;
> > > -	}
> > > -      n -= dest - s;
> > > -      goto zero_fill;
> > > -    }
> > > -
> > > - last_chars:
> > > -  n &= 3;
> > > -  if (n == 0)
> > > +  size_t size = __strnlen (src, n);
> > > +  memcpy (dest, src, size);
> > > +  dest += size;
> > > +  if (size == n)
> > >      return dest;
> > > -
> > > -  for (;;)
> > > -    {
> > > -      c = *src++;
> > > -      --n;
> > > -      *dest++ = c;
> > > -      if (c == '\0')
> > > -	break;
> > > -      if (n == 0)
> > > -	return dest;
> > > -    }
> > > -
> > > - zero_fill:
> > > -  while (n-- > 0)
> > > -    dest[n] = '\0';
> > > -
> > > -  return dest - 1;
> > > +  return memset (dest, '\0', n - size);
> > >  }
> > >  #ifdef weak_alias
> > >  libc_hidden_def (__stpncpy)
> > > --
> > > 1.9.1



             reply	other threads:[~2015-07-06 11:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-06 11:29 Wilco Dijkstra [this message]
2015-07-09 13:21 ` Ondřej Bílka
2015-07-09 15:02   ` Wilco Dijkstra
2015-08-12 20:57     ` Ondřej Bílka
2015-08-19 16:15       ` Wilco Dijkstra

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='000301d0b7df$02f253d0$08d6fb70$@com' \
    --to=wdijkstr@arm.com \
    --cc=libc-alpha@sourceware.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).