public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Improve performance of strcat
@ 2014-08-07 13:28 Wilco Dijkstra
  2014-08-07 13:31 ` Adhemerval Zanella
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Wilco Dijkstra @ 2014-08-07 13:28 UTC (permalink / raw)
  To: libc-alpha

[-- Attachment #1: Type: text/plain, Size: 523 bytes --]

Hi,

This patch improves strcat performance by using strlen and strcpy. Strlen has a fast C
implementation, so this improves performance even on targets which don't have an optimized strlen
and strcpy - it is 25% faster in bench-strcat. On targets which don't provide an optimized strcat
but which do have an optimized strlen and strcpy, performance gain is > 2x.

OK for commit?

ChangeLog:
2014-08-07  Wilco Dijkstra <wdijkstr@arm.com>

	* string/strcat.c (strcat): Improve performance by using strlen/strcpy.

[-- Attachment #2: Improve-strcat-performance.txt --]
[-- Type: text/plain, Size: 796 bytes --]

---
 string/strcat.c |   21 +--------------------
 1 file changed, 1 insertion(+), 20 deletions(-)

diff --git a/string/strcat.c b/string/strcat.c
index 2cbe8b3..983d115 100644
--- a/string/strcat.c
+++ b/string/strcat.c
@@ -23,26 +23,7 @@
 char *
 strcat (char *dest, const char *src)
 {
-  char *s1 = dest;
-  const char *s2 = src;
-  char c;
-
-  /* Find the end of the string.  */
-  do
-    c = *s1++;
-  while (c != '\0');
-
-  /* Make S1 point before the next character, so we can increment
-     it while memory is read (wins on pipelined cpus).  */
-  s1 -= 2;
-
-  do
-    {
-      c = *s2++;
-      *++s1 = c;
-    }
-  while (c != '\0');
-
+  strcpy (dest + strlen (dest), src);
   return dest;
 }
 libc_hidden_builtin_def (strcat)
-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: [PATCH] Improve performance of strcat
@ 2014-08-07 13:58 Wilco Dijkstra
  0 siblings, 0 replies; 10+ messages in thread
From: Wilco Dijkstra @ 2014-08-07 13:58 UTC (permalink / raw)
  To: azanella; +Cc: libc-alpha

>> +  strcpy (dest + strlen (dest), src);
>
> Should it be __strcpy/__strlen ?

Not according to: https://sourceware.org/ml/libc-alpha/2014-04/msg00471.html



^ permalink raw reply	[flat|nested] 10+ messages in thread
* RE: [PATCH] Improve performance of strcat
@ 2014-09-10 15:32 Wilco Dijkstra
  0 siblings, 0 replies; 10+ messages in thread
From: Wilco Dijkstra @ 2014-09-10 15:32 UTC (permalink / raw)
  To: libc-alpha

Ping

> -----Original Message-----
> From: Wilco Dijkstra [mailto:wdijkstr@arm.com]
> Sent: 07 August 2014 14:28
> To: 'libc-alpha@sourceware.org'
> Subject: [PATCH] Improve performance of strcat
> 
> Hi,
> 
> This patch improves strcat performance by using strlen and strcpy. Strlen has a fast C
> implementation, so this improves performance even on targets which don't have an optimized
> strlen and strcpy - it is 25% faster in bench-strcat. On targets which don't provide an
> optimized strcat but which do have an optimized strlen and strcpy, performance gain is > 2x.
> 
> OK for commit?
> 
> ChangeLog:
> 2014-08-07  Wilco Dijkstra <wdijkstr@arm.com>
> 
> 	* string/strcat.c (strcat): Improve performance by using strlen/strcpy.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-09-12 11:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-07 13:28 [PATCH] Improve performance of strcat Wilco Dijkstra
2014-08-07 13:31 ` Adhemerval Zanella
2014-08-07 13:58   ` Joseph S. Myers
2014-09-10 17:24 ` Florian Weimer
2014-09-11 19:42 ` Carlos O'Donell
2014-09-12  5:19   ` Ondřej Bílka
2014-09-12 11:51     ` Wilco Dijkstra
2014-09-12 11:14   ` Wilco Dijkstra
2014-08-07 13:58 Wilco Dijkstra
2014-09-10 15:32 Wilco Dijkstra

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).