This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
RE: [PATCH] Inline mempcpy
- From: "Wilco Dijkstra" <wdijkstr at arm dot com>
- To: "'Joseph Myers'" <joseph at codesourcery dot com>
- Cc: 'Ondřej Bílka' <neleai at seznam dot cz>, <libc-alpha at sourceware dot org>, "'Carlos O'Donell'" <carlos at redhat dot com>, <munroesj at linux dot vnet dot ibm dot com>
- Date: Wed, 20 May 2015 12:53:24 +0100
- Subject: RE: [PATCH] Inline mempcpy
- Authentication-results: sourceware.org; auth=none
- References: <A610E03AD50BFC4D95529A36D37FA55E769A83F7F7 at GEORGE dot Emea dot Arm dot com> <000201d0915f$87bb15d0$97314170$ at com> <alpine dot DEB dot 2 dot 10 dot 1505181152420 dot 4225 at digraph dot polyomino dot org dot uk> <000301d09180$ef6e9eb0$ce4bdc10$ at com> <alpine dot DEB dot 2 dot 10 dot 1505181700040 dot 20209 at digraph dot polyomino dot org dot uk>
> Joseph Myers wrote:
> On Mon, 18 May 2015, Wilco Dijkstra wrote:
>
> This seems plausible, subject to getting per-architecture agreement (for
> each architecture with mempcpy.S) on whether to define
> _HAVE_STRING_ARCH_mempcpy. Although there may be the question of whether
> __extern_always_inline should be defined at all for !__GNUC_PREREQ (3,2)
> (i.e. when the always_inline attribute isn't supported).
It would be good to fix the *always_inline defines, but I for now I've added
an extra check for __GNUC_PREREQ (3,2) to be sure we don't fail to inline on
really old GCCs. So here's the actual patch - I've disabled inlining for SPARC,
and from previous comments it seems people prefer the inline mempcpy on x64/x86
and PPC (I've included the maintainers for those arches to agree/veto).
OK for commit?
Wilco
ChangeLog:
2015-05-20 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.
---
string/string.h | 19 +++++++++++++++++++
sysdeps/sparc/bits/string.h | 3 +++
2 files changed, 22 insertions(+)
diff --git a/string/string.h b/string/string.h
index 54a4d39..3ab7103 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 36fbb4c..4eb9447 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
--
1.9.1