Message ID | 001f01d03004$e05abdb0$a1103910$@com |
---|---|
State | Committed |
Headers |
Received: (qmail 31457 invoked by alias); 14 Jan 2015 14:18:31 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <libc-alpha.sourceware.org> List-Unsubscribe: <mailto:libc-alpha-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:libc-alpha-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 31289 invoked by uid 89); 14 Jan 2015 14:18:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com From: "Wilco Dijkstra" <wdijkstr@arm.com> To: <libc-alpha@sourceware.org> Subject: [PATCH] Improve memccpy performance Date: Wed, 14 Jan 2015 14:17:49 -0000 Message-ID: <001f01d03004$e05abdb0$a1103910$@com> MIME-Version: 1.0 X-MC-Unique: 115011414175608301 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable |
Commit Message
Wilco Dijkstra
Jan. 14, 2015, 2:17 p.m. UTC
Improve memccpy performance by using memchr/memcpy rather than a byte loop. Overall performance on bench-memccpy is > 2x faster when using the C implementation of memchr and an optimized memcpy. ChangeLog: 2015-01-14 Wilco Dijkstra wdijkstr@arm.com * string/memccpy.c (memccpy): Improve performance using memchr/memcpy. --- string/memccpy.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
Comments
> + return memcpy (dest, src, n) + n;
Use __mempcpy here.
On 14/01/15 18:14, Roland McGrath wrote: >> + return memcpy (dest, src, n) + n; > > Use __mempcpy here. > That will be worse if mempcpy just calls memcpy; which is what the C library implementation does. R.
> Richard Earnshaw wrote: > On 14/01/15 18:14, Roland McGrath wrote: > >> + return memcpy (dest, src, n) + n; > > > > Use __mempcpy here. > > > That will be worse if mempcpy just calls memcpy; which is what the C > library implementation does. If GLIBC inlines mempcpy like I proposed then it would be reasonable to use mempcpy here as it results in exactly the same code. Wilco
ping > Wilco Dijkstra wrote: > > Wilco Dijkstra wrote: > > > Richard Earnshaw wrote: > > > On 14/01/15 18:14, Roland McGrath wrote: > > > >> + return memcpy (dest, src, n) + n; > > > > > > > > Use __mempcpy here. > > > > > > > That will be worse if mempcpy just calls memcpy; which is what the C > > > library implementation does. > > > > If GLIBC inlines mempcpy like I proposed then it would be reasonable > > to use mempcpy here as it results in exactly the same code. > > So, OK for trunk with __mempcpy like below? > > --- > string/memccpy.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/string/memccpy.c b/string/memccpy.c > index 70ee2ae..d4146f9 100644 > --- a/string/memccpy.c > +++ b/string/memccpy.c > @@ -26,15 +26,15 @@ > void * > __memccpy (void *dest, const void *src, int c, size_t n) > { > - const char *s = src; > - char *d = dest; > - const char x = c; > - size_t i = n; > + void *p = memchr (src, c, n); > > - while (i-- > 0) > - if ((*d++ = *s++) == x) > - return d; > + if (p != NULL) > + { > + n = p - src + 1; > + return __mempcpy (dest, src, n); > + } > > + memcpy (dest, src, n); > return NULL; > } > > -- > 1.9.1
On Wed, Apr 15, 2015 at 01:31:30PM +0100, Wilco Dijkstra wrote: > ping > > > Wilco Dijkstra wrote: > > > Wilco Dijkstra wrote: > > > > Richard Earnshaw wrote: > > > > On 14/01/15 18:14, Roland McGrath wrote: > > > > >> + return memcpy (dest, src, n) + n; > > > > > > > > > > Use __mempcpy here. > > > > > > > > > That will be worse if mempcpy just calls memcpy; which is what the C > > > > library implementation does. > > > > > > If GLIBC inlines mempcpy like I proposed then it would be reasonable > > > to use mempcpy here as it results in exactly the same code. > > > > So, OK for trunk with __mempcpy like below? > > > > --- > > string/memccpy.c | 14 +++++++------- > > 1 file changed, 7 insertions(+), 7 deletions(-) > > > > diff --git a/string/memccpy.c b/string/memccpy.c > > index 70ee2ae..d4146f9 100644 > > --- a/string/memccpy.c > > +++ b/string/memccpy.c > > @@ -26,15 +26,15 @@ > > void * > > __memccpy (void *dest, const void *src, int c, size_t n) > > { > > - const char *s = src; > > - char *d = dest; > > - const char x = c; > > - size_t i = n; > > + void *p = memchr (src, c, n); > > > > - while (i-- > 0) > > - if ((*d++ = *s++) == x) > > - return d; > > + if (p != NULL) > > + { > > + n = p - src + 1; > > + return __mempcpy (dest, src, n); > > + } > > > > + memcpy (dest, src, n); > > return NULL; > > } > > > > -- > > 1.9.1 ok for me.
> Wilco Dijkstra wrote: > ping > > > Wilco Dijkstra wrote: > > > Wilco Dijkstra wrote: > > > > Richard Earnshaw wrote: > > > > On 14/01/15 18:14, Roland McGrath wrote: > > > > >> + return memcpy (dest, src, n) + n; > > > > > > > > > > Use __mempcpy here. > > > > > > > > > That will be worse if mempcpy just calls memcpy; which is what the C > > > > library implementation does. > > > > > > If GLIBC inlines mempcpy like I proposed then it would be reasonable > > > to use mempcpy here as it results in exactly the same code. > > > > So, OK for trunk with __mempcpy like below? > > > > --- > > string/memccpy.c | 14 +++++++------- > > 1 file changed, 7 insertions(+), 7 deletions(-) > > > > diff --git a/string/memccpy.c b/string/memccpy.c > > index 70ee2ae..d4146f9 100644 > > --- a/string/memccpy.c > > +++ b/string/memccpy.c > > @@ -26,15 +26,15 @@ > > void * > > __memccpy (void *dest, const void *src, int c, size_t n) > > { > > - const char *s = src; > > - char *d = dest; > > - const char x = c; > > - size_t i = n; > > + void *p = memchr (src, c, n); > > > > - while (i-- > 0) > > - if ((*d++ = *s++) == x) > > - return d; > > + if (p != NULL) > > + { > > + n = p - src + 1; > > + return __mempcpy (dest, src, n); > > + } > > > > + memcpy (dest, src, n); > > return NULL; > > } > > > > -- > > 1.9.1
diff --git a/string/memccpy.c b/string/memccpy.c index 70ee2ae..d4146f9 100644 --- a/string/memccpy.c +++ b/string/memccpy.c @@ -26,15 +26,15 @@ void * __memccpy (void *dest, const void *src, int c, size_t n) { - const char *s = src; - char *d = dest; - const char x = c; - size_t i = n; + void *p = memchr (src, c, n); - while (i-- > 0) - if ((*d++ = *s++) == x) - return d; + if (p != NULL) + { + n = p - src + 1; + return memcpy (dest, src, n) + n; + } + memcpy (dest, src, n); return NULL; }