|
|
00db10 |
From 130a0ae7cad6bc7a2d102624027a1d8de19cc3b3 Mon Sep 17 00:00:00 2001
|
|
|
00db10 |
From: Stefan Liebler <stli@linux.vnet.ibm.com>
|
|
|
00db10 |
Date: Thu, 8 Oct 2015 13:21:11 +0200
|
|
|
00db10 |
Subject: [PATCH 27/30] S390: Optimize memccpy.
|
|
|
00db10 |
|
|
|
00db10 |
upstream-commit-id: 9b593dc3055d44a4179c03050be58a437ae385a1
|
|
|
00db10 |
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00100.html
|
|
|
00db10 |
|
|
|
00db10 |
This patch provides optimized versions of memccpy with the z13 vector
|
|
|
00db10 |
instructions.
|
|
|
00db10 |
|
|
|
00db10 |
ChangeLog:
|
|
|
00db10 |
|
|
|
00db10 |
* sysdeps/s390/multiarch/memccpy-c.c: New File.
|
|
|
00db10 |
* sysdeps/s390/multiarch/memccpy-vx.S: Likewise.
|
|
|
00db10 |
* sysdeps/s390/multiarch/memccpy.c: Likewise.
|
|
|
00db10 |
* sysdeps/s390/multiarch/Makefile
|
|
|
00db10 |
(sysdep_routines): Add memccpy functions.
|
|
|
00db10 |
* sysdeps/s390/multiarch/ifunc-impl-list-common.c
|
|
|
00db10 |
(__libc_ifunc_impl_list_common): Add ifunc test for memccpy.
|
|
|
00db10 |
* string/memccpy.c: Use MEMCCPY if defined.
|
|
|
00db10 |
---
|
|
|
00db10 |
string/memccpy.c | 4 +
|
|
|
00db10 |
sysdeps/s390/multiarch/Makefile | 3 +-
|
|
|
00db10 |
sysdeps/s390/multiarch/ifunc-impl-list.c | 2 +
|
|
|
00db10 |
sysdeps/s390/multiarch/memccpy-c.c | 27 ++++++
|
|
|
00db10 |
sysdeps/s390/multiarch/memccpy-vx.S | 156 +++++++++++++++++++++++++++++++
|
|
|
00db10 |
sysdeps/s390/multiarch/memccpy.c | 28 ++++++
|
|
|
00db10 |
6 files changed, 219 insertions(+), 1 deletion(-)
|
|
|
00db10 |
create mode 100644 sysdeps/s390/multiarch/memccpy-c.c
|
|
|
00db10 |
create mode 100644 sysdeps/s390/multiarch/memccpy-vx.S
|
|
|
00db10 |
create mode 100644 sysdeps/s390/multiarch/memccpy.c
|
|
|
00db10 |
|
|
|
00db10 |
diff --git a/string/memccpy.c b/string/memccpy.c
|
|
|
00db10 |
index a8649ff..78c13b6 100644
|
|
|
00db10 |
--- a/string/memccpy.c
|
|
|
00db10 |
+++ b/string/memccpy.c
|
|
|
00db10 |
@@ -20,6 +20,10 @@
|
|
|
00db10 |
#undef __memccpy
|
|
|
00db10 |
#undef memccpy
|
|
|
00db10 |
|
|
|
00db10 |
+#ifdef MEMCCPY
|
|
|
00db10 |
+# define __memccpy MEMCCPY
|
|
|
00db10 |
+#endif
|
|
|
00db10 |
+
|
|
|
00db10 |
/* Copy no more than N bytes of SRC to DEST, stopping when C is found.
|
|
|
00db10 |
Return the position in DEST one byte past where C was copied, or
|
|
|
00db10 |
NULL if C was not found in the first N bytes of SRC. */
|
|
|
00db10 |
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
|
|
|
00db10 |
index 4a04c34..87dff0f 100644
|
|
|
00db10 |
--- a/sysdeps/s390/multiarch/Makefile
|
|
|
00db10 |
+++ b/sysdeps/s390/multiarch/Makefile
|
|
|
00db10 |
@@ -16,7 +16,8 @@ sysdep_routines += strlen strlen-vx strlen-c \
|
|
|
00db10 |
strpbrk strpbrk-vx strpbrk-c \
|
|
|
00db10 |
strcspn strcspn-vx strcspn-c \
|
|
|
00db10 |
memchr memchr-vx \
|
|
|
00db10 |
- rawmemchr rawmemchr-vx rawmemchr-c
|
|
|
00db10 |
+ rawmemchr rawmemchr-vx rawmemchr-c \
|
|
|
00db10 |
+ memccpy memccpy-vx memccpy-c
|
|
|
00db10 |
endif
|
|
|
00db10 |
|
|
|
00db10 |
ifeq ($(subdir),wcsmbs)
|
|
|
00db10 |
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
|
|
|
00db10 |
index d4c7c0d..c90fb6b 100644
|
|
|
00db10 |
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
|
|
|
00db10 |
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
|
|
|
00db10 |
@@ -131,6 +131,8 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
|
|
|
00db10 |
IFUNC_VX_IMPL (wmemchr);
|
|
|
00db10 |
IFUNC_VX_IMPL (rawmemchr);
|
|
|
00db10 |
|
|
|
00db10 |
+ IFUNC_VX_IMPL (memccpy);
|
|
|
00db10 |
+
|
|
|
00db10 |
#endif /* HAVE_S390_VX_ASM_SUPPORT */
|
|
|
00db10 |
|
|
|
00db10 |
return i;
|
|
|
00db10 |
diff --git a/sysdeps/s390/multiarch/memccpy-c.c b/sysdeps/s390/multiarch/memccpy-c.c
|
|
|
00db10 |
new file mode 100644
|
|
|
00db10 |
index 0000000..4d07b63
|
|
|
00db10 |
--- /dev/null
|
|
|
00db10 |
+++ b/sysdeps/s390/multiarch/memccpy-c.c
|
|
|
00db10 |
@@ -0,0 +1,27 @@
|
|
|
00db10 |
+/* Default memccpy implementation for S/390.
|
|
|
00db10 |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
00db10 |
+ This file is part of the GNU C Library.
|
|
|
00db10 |
+
|
|
|
00db10 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
00db10 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
00db10 |
+ License as published by the Free Software Foundation; either
|
|
|
00db10 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
00db10 |
+
|
|
|
00db10 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
00db10 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
00db10 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
00db10 |
+ Lesser General Public License for more details.
|
|
|
00db10 |
+
|
|
|
00db10 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
00db10 |
+ License along with the GNU C Library; if not, see
|
|
|
00db10 |
+ <http://www.gnu.org/licenses/>. */
|
|
|
00db10 |
+
|
|
|
00db10 |
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
|
|
|
00db10 |
+# define MEMCCPY __memccpy_c
|
|
|
00db10 |
+# undef weak_alias
|
|
|
00db10 |
+# define weak_alias(a, b)
|
|
|
00db10 |
+
|
|
|
00db10 |
+# include <string.h>
|
|
|
00db10 |
+extern __typeof (__memccpy) __memccpy_c;
|
|
|
00db10 |
+# include <string/memccpy.c>
|
|
|
00db10 |
+#endif
|
|
|
00db10 |
diff --git a/sysdeps/s390/multiarch/memccpy-vx.S b/sysdeps/s390/multiarch/memccpy-vx.S
|
|
|
00db10 |
new file mode 100644
|
|
|
00db10 |
index 0000000..b1dc69c
|
|
|
00db10 |
--- /dev/null
|
|
|
00db10 |
+++ b/sysdeps/s390/multiarch/memccpy-vx.S
|
|
|
00db10 |
@@ -0,0 +1,156 @@
|
|
|
00db10 |
+/* Vector optimized 32/64 bit S/390 version of memccpy.
|
|
|
00db10 |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
00db10 |
+ This file is part of the GNU C Library.
|
|
|
00db10 |
+
|
|
|
00db10 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
00db10 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
00db10 |
+ License as published by the Free Software Foundation; either
|
|
|
00db10 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
00db10 |
+
|
|
|
00db10 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
00db10 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
00db10 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
00db10 |
+ Lesser General Public License for more details.
|
|
|
00db10 |
+
|
|
|
00db10 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
00db10 |
+ License along with the GNU C Library; if not, see
|
|
|
00db10 |
+ <http://www.gnu.org/licenses/>. */
|
|
|
00db10 |
+
|
|
|
00db10 |
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
|
|
|
00db10 |
+
|
|
|
00db10 |
+# include "sysdep.h"
|
|
|
00db10 |
+# include "asm-syntax.h"
|
|
|
00db10 |
+
|
|
|
00db10 |
+ .text
|
|
|
00db10 |
+
|
|
|
00db10 |
+/* void *memccpy (void * dest, const void *src, int c, size_t n)
|
|
|
00db10 |
+ Copies no more than n bytes from src to dest,
|
|
|
00db10 |
+ stopping when the character c is found
|
|
|
00db10 |
+ and returns pointer next to c in dest or null if c not found.
|
|
|
00db10 |
+
|
|
|
00db10 |
+ Register usage:
|
|
|
00db10 |
+ -r0=tmp
|
|
|
00db10 |
+ -r1=tmp
|
|
|
00db10 |
+ -r2=dest
|
|
|
00db10 |
+ -r3=src
|
|
|
00db10 |
+ -r4=c
|
|
|
00db10 |
+ -r5=n
|
|
|
00db10 |
+ -r6=current_len
|
|
|
00db10 |
+ -v16=part of s
|
|
|
00db10 |
+ -v17=index of found c
|
|
|
00db10 |
+ -v18=c replicated
|
|
|
00db10 |
+ -v19=part #2 of s
|
|
|
00db10 |
+ -v31=save area for r6
|
|
|
00db10 |
+*/
|
|
|
00db10 |
+ENTRY(__memccpy_vx)
|
|
|
00db10 |
+ .machine "z13"
|
|
|
00db10 |
+ .machinemode "zarch_nohighgprs"
|
|
|
00db10 |
+
|
|
|
00db10 |
+# if !defined __s390x__
|
|
|
00db10 |
+ llgfr %r5,%r5
|
|
|
00db10 |
+# endif /* !defined __s390x__ */
|
|
|
00db10 |
+
|
|
|
00db10 |
+ vlvgp %v31,%r6,%r7 /* Save registers. */
|
|
|
00db10 |
+ clgije %r5,0,.Lnf_end /* If len == 0 then exit. */
|
|
|
00db10 |
+
|
|
|
00db10 |
+ vlbb %v16,0(%r3),6 /* Load s until next 4k-byte boundary. */
|
|
|
00db10 |
+ lcbb %r0,0(%r3),6 /* Get bytes to 4k-byte boundary or 16. */
|
|
|
00db10 |
+ llgfr %r0,%r0 /* Convert 32bit to 64bit. */
|
|
|
00db10 |
+
|
|
|
00db10 |
+ vlvgb %v18,%r4,0 /* Generate vector which elements are all c.
|
|
|
00db10 |
+ if c > 255, c will be truncated. */
|
|
|
00db10 |
+ vrepb %v18,%v18,0
|
|
|
00db10 |
+ lghi %r6,0 /* current_len = 0. */
|
|
|
00db10 |
+
|
|
|
00db10 |
+ clgrjle %r5,%r0,.Lremaining_v16 /* If maxlen <= loaded-bytes
|
|
|
00db10 |
+ -> Process remaining. */
|
|
|
00db10 |
+
|
|
|
00db10 |
+ vfeebs %v17,%v16,%v18 /* Find c. */
|
|
|
00db10 |
+ vlgvb %r1,%v17,7 /* Load byte index of c. */
|
|
|
00db10 |
+ clgrjl %r1,%r0,.Lfound_v16 /* Found c is within loaded bytes. */
|
|
|
00db10 |
+
|
|
|
00db10 |
+ /* Align s to 16 byte. */
|
|
|
00db10 |
+ risbgn %r1,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
|
|
|
00db10 |
+ lghi %r6,15 /* current_len = 15. */
|
|
|
00db10 |
+ slr %r6,%r1 /* Compute highest index to 16byte boundary. */
|
|
|
00db10 |
+
|
|
|
00db10 |
+ vstl %v16,%r6,0(%r2) /* Store prcessed bytes */
|
|
|
00db10 |
+ ahi %r6,1
|
|
|
00db10 |
+
|
|
|
00db10 |
+.Lpreloop1:
|
|
|
00db10 |
+ /* Now we are 16byte aligned, so we can load
|
|
|
00db10 |
+ a full vreg without page fault. */
|
|
|
00db10 |
+ vl %v16,0(%r6,%r3) /* Load s. */
|
|
|
00db10 |
+ clgijl %r5,17,.Lremaining_v16 /* If n <= 16,
|
|
|
00db10 |
+ process remaining bytes. */
|
|
|
00db10 |
+ lgr %r7,%r5
|
|
|
00db10 |
+ slgfi %r7,16 /* border_len = n - 16. */
|
|
|
00db10 |
+ j .Lloop1
|
|
|
00db10 |
+
|
|
|
00db10 |
+.Lloop2:
|
|
|
00db10 |
+ vl %v16,16(%r6,%r3)
|
|
|
00db10 |
+ vst %v19,0(%r6,%r2)
|
|
|
00db10 |
+ aghi %r6,16
|
|
|
00db10 |
+
|
|
|
00db10 |
+.Lloop1:
|
|
|
00db10 |
+ clgrjhe %r6,%r7,.Lremaining_v16 /* If current_len >= border
|
|
|
00db10 |
+ then process remaining bytes. */
|
|
|
00db10 |
+ vfeebs %v17,%v16,%v18 /* Find c. */
|
|
|
00db10 |
+ jl .Lfound_v16 /* Jump away if c was found. */
|
|
|
00db10 |
+ vl %v19,16(%r6,%r3) /* Load next s part. */
|
|
|
00db10 |
+ vst %v16,0(%r6,%r2) /* Store previous part without c. */
|
|
|
00db10 |
+ aghi %r6,16
|
|
|
00db10 |
+
|
|
|
00db10 |
+ clgrjhe %r6,%r7,.Lremaining_v19
|
|
|
00db10 |
+ vfeebs %v17,%v19,%v18
|
|
|
00db10 |
+ jl .Lfound_v19
|
|
|
00db10 |
+ vl %v16,16(%r6,%r3)
|
|
|
00db10 |
+ vst %v19,0(%r6,%r2)
|
|
|
00db10 |
+ aghi %r6,16
|
|
|
00db10 |
+
|
|
|
00db10 |
+ clgrjhe %r6,%r7,.Lremaining_v16
|
|
|
00db10 |
+ vfeebs %v17,%v16,%v18
|
|
|
00db10 |
+ jl .Lfound_v16
|
|
|
00db10 |
+ vl %v19,16(%r6,%r3)
|
|
|
00db10 |
+ vst %v16,0(%r6,%r2)
|
|
|
00db10 |
+ aghi %r6,16
|
|
|
00db10 |
+
|
|
|
00db10 |
+ clgrjhe %r6,%r7,.Lremaining_v19
|
|
|
00db10 |
+ vfeebs %v17,%v19,%v18
|
|
|
00db10 |
+ jo .Lloop2
|
|
|
00db10 |
+
|
|
|
00db10 |
+.Lfound_v19:
|
|
|
00db10 |
+ vlr %v16,%v19
|
|
|
00db10 |
+.Lfound_v16:
|
|
|
00db10 |
+ /* v16 contains c. Store remaining bytes to c. currlen hasnĀ“t
|
|
|
00db10 |
+ reached border, thus checking for maxlen is not needed! */
|
|
|
00db10 |
+ vlgvb %r1,%v17,7 /* Load byte index of c. */
|
|
|
00db10 |
+ la %r2,0(%r6,%r2) /* vstl has no support for index-register. */
|
|
|
00db10 |
+.Lfound_v16_store:
|
|
|
00db10 |
+ vstl %v16,%r1,0(%r2) /* Copy bytes including c. */
|
|
|
00db10 |
+ la %r2,1(%r1,%r2) /* Return pointer next to c in dest. */
|
|
|
00db10 |
+ vlgvg %r6,%v31,0
|
|
|
00db10 |
+ vlgvg %r7,%v31,1
|
|
|
00db10 |
+ br %r14
|
|
|
00db10 |
+
|
|
|
00db10 |
+.Lremaining_v19:
|
|
|
00db10 |
+ vlr %v16,%v19
|
|
|
00db10 |
+.Lremaining_v16:
|
|
|
00db10 |
+ /* v16 contains the remaining bytes [1...16].
|
|
|
00db10 |
+ Check and store remaining bytes. */
|
|
|
00db10 |
+ vfeebs %v17,%v16,%v18
|
|
|
00db10 |
+ slgrk %r7,%r5,%r6 /* Remaining bytes = maxlen - current_len. */
|
|
|
00db10 |
+ aghi %r7,-1 /* vstl needs highest index. */
|
|
|
00db10 |
+ la %r2,0(%r6,%r2) /* vstl has no index register. */
|
|
|
00db10 |
+ vlgvb %r1,%v17,7 /* Load index of c or 16 if not found. */
|
|
|
00db10 |
+ /* c in remaining bytes? -> Jump away (c-index <= max-index) */
|
|
|
00db10 |
+ clrjle %r1,%r7,.Lfound_v16_store
|
|
|
00db10 |
+ vstl %v16,%r7,0(%r2) /* Store remaining bytes. */
|
|
|
00db10 |
+
|
|
|
00db10 |
+.Lnf_end:
|
|
|
00db10 |
+ vlgvg %r6,%v31,0
|
|
|
00db10 |
+ vlgvg %r7,%v31,1
|
|
|
00db10 |
+ lghi %r2,0 /* Return null. */
|
|
|
00db10 |
+ br %r14
|
|
|
00db10 |
+END(__memccpy_vx)
|
|
|
00db10 |
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
|
|
|
00db10 |
diff --git a/sysdeps/s390/multiarch/memccpy.c b/sysdeps/s390/multiarch/memccpy.c
|
|
|
00db10 |
new file mode 100644
|
|
|
00db10 |
index 0000000..746bc25
|
|
|
00db10 |
--- /dev/null
|
|
|
00db10 |
+++ b/sysdeps/s390/multiarch/memccpy.c
|
|
|
00db10 |
@@ -0,0 +1,28 @@
|
|
|
00db10 |
+/* Multiple versions of memccpy.
|
|
|
00db10 |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
00db10 |
+ This file is part of the GNU C Library.
|
|
|
00db10 |
+
|
|
|
00db10 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
00db10 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
00db10 |
+ License as published by the Free Software Foundation; either
|
|
|
00db10 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
00db10 |
+
|
|
|
00db10 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
00db10 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
00db10 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
00db10 |
+ Lesser General Public License for more details.
|
|
|
00db10 |
+
|
|
|
00db10 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
00db10 |
+ License along with the GNU C Library; if not, see
|
|
|
00db10 |
+ <http://www.gnu.org/licenses/>. */
|
|
|
00db10 |
+
|
|
|
00db10 |
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
|
|
|
00db10 |
+# include <string.h>
|
|
|
00db10 |
+# include <ifunc-resolve.h>
|
|
|
00db10 |
+
|
|
|
00db10 |
+s390_vx_libc_ifunc (__memccpy)
|
|
|
00db10 |
+weak_alias (__memccpy, memccpy)
|
|
|
00db10 |
+
|
|
|
00db10 |
+#else
|
|
|
00db10 |
+# include <string/memccpy.c>
|
|
|
00db10 |
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
|
|
|
00db10 |
--
|
|
|
00db10 |
2.3.0
|
|
|
00db10 |
|