about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWilco Dijkstra <wdijkstr@arm.com>2015-08-05 15:58:15 +0100
committerWilco Dijkstra <wdijkstr@arm.com>2015-08-05 16:24:04 +0100
commit05a910f7b420c2b831f35ba90e61c80f001c0606 (patch)
treeea10fa59974d0e2e3b5f43d490aca37bc2b787ad
parentf29ac72effae859140bb0d7fffdb1e6cef0ffed0 (diff)
downloadglibc-05a910f7b420c2b831f35ba90e61c80f001c0606.tar.gz
glibc-05a910f7b420c2b831f35ba90e61c80f001c0606.tar.xz
glibc-05a910f7b420c2b831f35ba90e61c80f001c0606.zip
Improve performance of mempcpy by inlining and using memcpy. Enable
this for all targets except sparc which has an optimized mempcpy
implementation.
-rw-r--r--ChangeLog6
-rw-r--r--string/string.h19
-rw-r--r--sysdeps/sparc/bits/string.h3
3 files changed, 28 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 65592c3e80..4a45eed6d3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2015-08-05  Wilco Dijkstra  <wdijkstr@arm.com>
 
+	* string/string.h: (mempcpy): Redirect to __mempcpy_inline.
+	(__mempcpy): Likewise.  (__mempcpy_inline): New inline function.
+	* sysdeps/sparc/bits/string.h: (_HAVE_STRING_ARCH_mempcpy): Define.
+
+2015-08-05  Wilco Dijkstra  <wdijkstr@arm.com>
+
 	* string/memccpy.c (memccpy):
 	Improve performance by using memchr/memcpy/__mempcpy.
 
diff --git a/string/string.h b/string/string.h
index 54a4d39a53..3ab71038ee 100644
--- a/string/string.h
+++ b/string/string.h
@@ -636,6 +636,25 @@ extern char *basename (const char *__filename) __THROW __nonnull ((1));
 # endif
 #endif
 
+#if defined __USE_GNU && defined __OPTIMIZE__ \
+    && defined __extern_always_inline && __GNUC_PREREQ (3,2)
+# if !defined _FORCE_INLINES && !defined _HAVE_STRING_ARCH_mempcpy
+
+#undef mempcpy
+#undef __mempcpy
+#define mempcpy(dest, src, n) __mempcpy_inline (dest, src, n)
+#define __mempcpy(dest, src, n) __mempcpy_inline (dest, src, n)
+
+__extern_always_inline void *
+__mempcpy_inline (void *__restrict __dest,
+		  const void *__restrict __src, size_t __n)
+{
+  return (char *) memcpy (__dest, __src, __n) + __n;
+}
+
+# endif
+#endif
+
 __END_DECLS
 
 #endif /* string.h  */
diff --git a/sysdeps/sparc/bits/string.h b/sysdeps/sparc/bits/string.h
index 36fbb4c847..4eb94473fb 100644
--- a/sysdeps/sparc/bits/string.h
+++ b/sysdeps/sparc/bits/string.h
@@ -26,3 +26,6 @@
 /* sparc32 and sparc64 strchr(x, '\0') perform better than
    __rawmemchr(x, '\0').  */
 #define _HAVE_STRING_ARCH_strchr 1
+
+/* Don't inline mempcpy into memcpy as sparc has an optimized mempcpy.  */
+#define _HAVE_STRING_ARCH_mempcpy 1