public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Wilco Dijkstra" <wdijkstr@arm.com>
To: "'Rich Felker'" <dalias@libc.org>, "Florian Weimer" <fweimer@redhat.com>
Cc: <azanella@linux.vnet.ibm.com>, <libc-alpha@sourceware.org>
Subject: RE: [PATCH] Improve performance of strncpy
Date: Wed, 10 Sep 2014 18:25:00 -0000	[thread overview]
Message-ID: <001701cfcd24$953292b0$bf97b810$@com> (raw)
In-Reply-To: <20140910180144.GK23797@brightrain.aerifal.cx>

> Rich Felker wrote:
> On Wed, Sep 10, 2014 at 07:34:40PM +0200, Florian Weimer wrote:
> > On 09/10/2014 05:21 PM, Wilco Dijkstra wrote:
> > >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?
> >
> > I think you could simplify it down to strnlen, memcpy, and memset.
> 
> I don't think that's an improvement, at least not in the general case.
> It involves iterating twice over the source string, which for long
> strings could mean blowing the whole cache twice and fetching from
> main memory twice. There's a good reason that string operations are
> usually implemented to perform the copy and length computation
> together in a single pass.
> 
> Rich

Few strings will be larger than the typical L1 size of 32KB. You're right
that it is best to do a single pass in a highly optimized implementation.
However the issue is that the C versions are so slow that even doing 2
passes will be significantly faster due to processing 8 bytes at a time - 
likely even if much larger than L1 (I'll check that).

The goal of these patches is to ensure the C string routines are quite
competitive out of the box, and benefit further when you add a few highly
optimized routines (eg. strlen/strcpy). That means new targets are not
forced to add optimized versions of all of the string routines in order to
get decent performance (as unfortunately is the case today).

Wilco


  reply	other threads:[~2014-09-10 18:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
  -- strict thread matches above, loose matches on Subject: below --
2014-10-24 15:56 Wilco Dijkstra
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
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='001701cfcd24$953292b0$bf97b810$@com' \
    --to=wdijkstr@arm.com \
    --cc=azanella@linux.vnet.ibm.com \
    --cc=dalias@libc.org \
    --cc=fweimer@redhat.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).