From: "Wilco Dijkstra" <wdijkstr@arm.com>
To: <azanella@linux.vnet.ibm.com>
Cc: <libc-alpha@sourceware.org>
Subject: RE: [PATCH] Improve performance of strncpy
Date: Fri, 24 Oct 2014 15:56:00 -0000 [thread overview]
Message-ID: <001a01cfefa3$0fb21330$2f163990$@com> (raw)
In-Reply-To:
Ping (there was some further discussion but I don't see an OK for this patch)
> -----Original Message-----
> From: Wilco Dijkstra [mailto:wdijkstr@arm.com]
> Sent: 10 September 2014 16:22
> To: 'azanella@linux.vnet.ibm.com'
> Cc: 'libc-alpha@sourceware.org'
> Subject: RE: [PATCH] Improve performance of strncpy
>
> Adhemerval Zanella wrote:
> > Hi, the patch looks ok. I also pushed a similar modification for powerpc based on same idea.
>
> > zero_fill:
> > - do
> > - *++s1 = '\0';
> > - while (--n > 0);
> > + if (n >= 8)
> > + memset (s1 + 1, '\0', n);
> > + else
> > + do
> > + *++s1 = '\0';
> > + while (--n > 0);
>
> > I wonder if this test is really worth, my opinion is just to keep it simple
> > and just call memset on both 'goto' in loop and after 'last_chars'.
>
> Yes, you're right, I timed it and there is actually little difference, while
> the code is now even simpler. New version below (not attaching results in bad
> characters due to various mail servers changing line endings).
>
> OK for commit?
>
> ---
> string/strncpy.c | 14 +++++---------
> 1 file changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/string/strncpy.c b/string/strncpy.c
> index 0915e03..d5fa5be 100644
> --- a/string/strncpy.c
> +++ b/string/strncpy.c
> @@ -57,10 +57,10 @@ STRNCPY (char *s1, const char *s2, size_t n)
> if (--n4 == 0)
> goto last_chars;
> }
> - n = n - (s1 - s) - 1;
> - if (n == 0)
> - return s;
> - goto zero_fill;
> + s1++;
> + n = n - (s1 - s);
> + memset (s1, '\0', n);
> + return s;
> }
>
> last_chars:
> @@ -77,11 +77,7 @@ STRNCPY (char *s1, const char *s2, size_t n)
> }
> while (c != '\0');
>
> - zero_fill:
> - do
> - *++s1 = '\0';
> - while (--n > 0);
> -
> + memset (s1 + 1, '\0', n);
> return s;
> }
> libc_hidden_builtin_def (strncpy)
> --
> 1.7.9.5
next reply other threads:[~2014-10-24 15:56 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-24 15:56 Wilco Dijkstra [this message]
2014-11-23 16:52 ` Ondřej Bílka
2014-11-27 19:20 ` Wilco Dijkstra
2014-11-27 20:51 ` Ondřej Bílka
-- strict thread matches above, loose matches on Subject: below --
2014-09-10 15:21 Wilco Dijkstra
2014-09-10 17:34 ` Florian Weimer
2014-09-10 18:02 ` Rich Felker
2014-09-10 18:25 ` Wilco Dijkstra
2014-09-11 19:37 ` Wilco Dijkstra
2014-09-12 6:22 ` Ondřej Bílka
2014-09-12 11:04 ` Wilco Dijkstra
2014-09-10 18:09 ` Wilco Dijkstra
2014-08-20 12:44 Wilco Dijkstra
2014-08-22 12:02 ` Adhemerval Zanella
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='001a01cfefa3$0fb21330$2f163990$@com' \
--to=wdijkstr@arm.com \
--cc=azanella@linux.vnet.ibm.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).