diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
index 9b38b46..239426d 100644
--- a/sysdeps/s390/Makefile
+++ b/sysdeps/s390/Makefile
@@ -54,5 +54,6 @@ sysdep_routines += bzero memset memset-z900 \
strpbrk strpbrk-vx strpbrk-c \
strcspn strcspn-vx strcspn-c \
memchr memchr-vx memchr-z900 \
- rawmemchr rawmemchr-vx rawmemchr-c
+ rawmemchr rawmemchr-vx rawmemchr-c \
+ memccpy memccpy-vx memccpy-c
endif
diff --git a/sysdeps/s390/ifunc-memccpy.h b/sysdeps/s390/ifunc-memccpy.h
new file mode 100644
index 0000000..8f7a1d0
--- /dev/null
+++ b/sysdeps/s390/ifunc-memccpy.h
@@ -0,0 +1,52 @@
+/* memccpy variant information on S/390 version.
+ Copyright (C) 2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ . */
+
+#if defined USE_MULTIARCH && IS_IN (libc) \
+ && ! defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
+# define HAVE_MEMCCPY_IFUNC 1
+#else
+# define HAVE_MEMCCPY_IFUNC 0
+#endif
+
+#ifdef HAVE_S390_VX_ASM_SUPPORT
+# define HAVE_MEMCCPY_IFUNC_AND_VX_SUPPORT HAVE_MEMCCPY_IFUNC
+#else
+# define HAVE_MEMCCPY_IFUNC_AND_VX_SUPPORT 0
+#endif
+
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
+# define MEMCCPY_DEFAULT MEMCCPY_Z13
+# define HAVE_MEMCCPY_C 0
+# define HAVE_MEMCCPY_Z13 1
+#else
+# define MEMCCPY_DEFAULT MEMCCPY_C
+# define HAVE_MEMCCPY_C 1
+# define HAVE_MEMCCPY_Z13 HAVE_MEMCCPY_IFUNC_AND_VX_SUPPORT
+#endif
+
+#if HAVE_MEMCCPY_C
+# define MEMCCPY_C __memccpy_c
+#else
+# define MEMCCPY_C NULL
+#endif
+
+#if HAVE_MEMCCPY_Z13
+# define MEMCCPY_Z13 __memccpy_vx
+#else
+# define MEMCCPY_Z13 NULL
+#endif
diff --git a/sysdeps/s390/memccpy-c.c b/sysdeps/s390/memccpy-c.c
new file mode 100644
index 0000000..2b2f81e
--- /dev/null
+++ b/sysdeps/s390/memccpy-c.c
@@ -0,0 +1,29 @@
+/* Default memccpy implementation for S/390.
+ Copyright (C) 2015-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ . */
+
+#include
+
+#if HAVE_MEMCCPY_C
+# if HAVE_MEMCCPY_IFUNC
+# define MEMCCPY MEMCCPY_C
+# undef weak_alias
+# define weak_alias(a, b)
+#endif
+
+# include
+#endif
diff --git a/sysdeps/s390/memccpy-vx.S b/sysdeps/s390/memccpy-vx.S
new file mode 100644
index 0000000..44f7bc5
--- /dev/null
+++ b/sysdeps/s390/memccpy-vx.S
@@ -0,0 +1,164 @@
+/* Vector optimized 32/64 bit S/390 version of memccpy.
+ Copyright (C) 2015-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ . */
+
+#include
+
+#if HAVE_MEMCCPY_Z13
+
+# include "sysdep.h"
+# include "asm-syntax.h"
+
+ .text
+
+/* void *memccpy (void * dest, const void *src, int c, size_t n)
+ Copies no more than n bytes from src to dest,
+ stopping when the character c is found
+ and returns pointer next to c in dest or null if c not found.
+
+ Register usage:
+ -r0=tmp
+ -r1=tmp
+ -r2=dest
+ -r3=src
+ -r4=c
+ -r5=n
+ -r6=current_len
+ -v16=part of s
+ -v17=index of found c
+ -v18=c replicated
+ -v19=part #2 of s
+ -v31=save area for r6
+*/
+ENTRY(MEMCCPY_Z13)
+ .machine "z13"
+ .machinemode "zarch_nohighgprs"
+
+# if !defined __s390x__
+ llgfr %r5,%r5
+# endif /* !defined __s390x__ */
+
+ vlvgp %v31,%r6,%r7 /* Save registers. */
+ clgije %r5,0,.Lnf_end /* If len == 0 then exit. */
+
+ vlbb %v16,0(%r3),6 /* Load s until next 4k-byte boundary. */
+ lcbb %r0,0(%r3),6 /* Get bytes to 4k-byte boundary or 16. */
+ llgfr %r0,%r0 /* Convert 32bit to 64bit. */
+
+ vlvgb %v18,%r4,0 /* Generate vector which elements are all c.
+ if c > 255, c will be truncated. */
+ vrepb %v18,%v18,0
+ lghi %r6,0 /* current_len = 0. */
+
+ clgrjle %r5,%r0,.Lremaining_v16 /* If maxlen <= loaded-bytes
+ -> Process remaining. */
+
+ vfeebs %v17,%v16,%v18 /* Find c. */
+ vlgvb %r1,%v17,7 /* Load byte index of c. */
+ clgrjl %r1,%r0,.Lfound_v16 /* Found c is within loaded bytes. */
+
+ /* Align s to 16 byte. */
+ risbgn %r1,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
+ lghi %r6,15 /* current_len = 15. */
+ slr %r6,%r1 /* Compute highest index to 16byte boundary. */
+
+ vstl %v16,%r6,0(%r2) /* Store prcessed bytes */
+ ahi %r6,1
+
+.Lpreloop1:
+ /* Now we are 16byte aligned, so we can load
+ a full vreg without page fault. */
+ vl %v16,0(%r6,%r3) /* Load s. */
+ clgijl %r5,17,.Lremaining_v16 /* If n <= 16,
+ process remaining bytes. */
+ lgr %r7,%r5
+ slgfi %r7,16 /* border_len = n - 16. */
+ j .Lloop1
+
+.Lloop2:
+ vl %v16,16(%r6,%r3)
+ vst %v19,0(%r6,%r2)
+ aghi %r6,16
+
+.Lloop1:
+ clgrjhe %r6,%r7,.Lremaining_v16 /* If current_len >= border
+ then process remaining bytes. */
+ vfeebs %v17,%v16,%v18 /* Find c. */
+ jl .Lfound_v16 /* Jump away if c was found. */
+ vl %v19,16(%r6,%r3) /* Load next s part. */
+ vst %v16,0(%r6,%r2) /* Store previous part without c. */
+ aghi %r6,16
+
+ clgrjhe %r6,%r7,.Lremaining_v19
+ vfeebs %v17,%v19,%v18
+ jl .Lfound_v19
+ vl %v16,16(%r6,%r3)
+ vst %v19,0(%r6,%r2)
+ aghi %r6,16
+
+ clgrjhe %r6,%r7,.Lremaining_v16
+ vfeebs %v17,%v16,%v18
+ jl .Lfound_v16
+ vl %v19,16(%r6,%r3)
+ vst %v16,0(%r6,%r2)
+ aghi %r6,16
+
+ clgrjhe %r6,%r7,.Lremaining_v19
+ vfeebs %v17,%v19,%v18
+ jo .Lloop2
+
+.Lfound_v19:
+ vlr %v16,%v19
+.Lfound_v16:
+ /* v16 contains c. Store remaining bytes to c. currlen hasn´t
+ reached border, thus checking for maxlen is not needed! */
+ vlgvb %r1,%v17,7 /* Load byte index of c. */
+ la %r2,0(%r6,%r2) /* vstl has no support for index-register. */
+.Lfound_v16_store:
+ vstl %v16,%r1,0(%r2) /* Copy bytes including c. */
+ la %r2,1(%r1,%r2) /* Return pointer next to c in dest. */
+ vlgvg %r6,%v31,0
+ vlgvg %r7,%v31,1
+ br %r14
+
+.Lremaining_v19:
+ vlr %v16,%v19
+.Lremaining_v16:
+ /* v16 contains the remaining bytes [1...16].
+ Check and store remaining bytes. */
+ vfeebs %v17,%v16,%v18
+ slgrk %r7,%r5,%r6 /* Remaining bytes = maxlen - current_len. */
+ aghi %r7,-1 /* vstl needs highest index. */
+ la %r2,0(%r6,%r2) /* vstl has no index register. */
+ vlgvb %r1,%v17,7 /* Load index of c or 16 if not found. */
+ /* c in remaining bytes? -> Jump away (c-index <= max-index) */
+ clrjle %r1,%r7,.Lfound_v16_store
+ vstl %v16,%r7,0(%r2) /* Store remaining bytes. */
+
+.Lnf_end:
+ vlgvg %r6,%v31,0
+ vlgvg %r7,%v31,1
+ lghi %r2,0 /* Return null. */
+ br %r14
+END(MEMCCPY_Z13)
+
+# if ! HAVE_MEMCCPY_IFUNC
+strong_alias (MEMCCPY_Z13, __memccpy)
+weak_alias (__memccpy, memccpy)
+# endif
+
+#endif /* HAVE_MEMCCPY_Z13 */
diff --git a/sysdeps/s390/memccpy.c b/sysdeps/s390/memccpy.c
new file mode 100644
index 0000000..bcfeb31
--- /dev/null
+++ b/sysdeps/s390/memccpy.c
@@ -0,0 +1,39 @@
+/* Multiple versions of memccpy.
+ Copyright (C) 2015-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ . */
+
+#include
+
+#if HAVE_MEMCCPY_IFUNC
+# include
+# include
+
+# if HAVE_MEMCCPY_C
+extern __typeof (__memccpy) MEMCCPY_C attribute_hidden;
+# endif
+
+# if HAVE_MEMCCPY_Z13
+extern __typeof (__memccpy) MEMCCPY_Z13 attribute_hidden;
+# endif
+
+s390_libc_ifunc_expr (__memccpy, __memccpy,
+ (HAVE_MEMCCPY_Z13 && (hwcap & HWCAP_S390_VX))
+ ? MEMCCPY_Z13
+ : MEMCCPY_DEFAULT
+ )
+weak_alias (__memccpy, memccpy)
+#endif /* HAVE_MEMCCPY_IFUNC */
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
index ac6cfcf..d5a32fc 100644
--- a/sysdeps/s390/multiarch/Makefile
+++ b/sysdeps/s390/multiarch/Makefile
@@ -1,6 +1,5 @@
ifeq ($(subdir),string)
-sysdep_routines += memccpy memccpy-vx memccpy-c \
- memrchr memrchr-vx memrchr-c
+sysdep_routines += memrchr memrchr-vx memrchr-c
endif
ifeq ($(subdir),wcsmbs)
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
index bf3b40e..b891774 100644
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
@@ -44,6 +44,7 @@
#include
#include
#include
+#include
/* Maximum number of IFUNC implementations. */
#define MAX_IFUNC 3
@@ -398,6 +399,18 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
)
#endif /* HAVE_RAWMEMCHR_IFUNC */
+#if HAVE_MEMCCPY_IFUNC
+ IFUNC_IMPL (i, name, memccpy,
+# if HAVE_MEMCCPY_Z13
+ IFUNC_IMPL_ADD (array, i, memccpy,
+ dl_hwcap & HWCAP_S390_VX, MEMCCPY_Z13)
+# endif
+# if HAVE_MEMCCPY_C
+ IFUNC_IMPL_ADD (array, i, memccpy, 1, MEMCCPY_C)
+# endif
+ )
+#endif /* HAVE_MEMCCPY_IFUNC */
+
#ifdef HAVE_S390_VX_ASM_SUPPORT
# define IFUNC_VX_IMPL(FUNC) \
@@ -440,8 +453,6 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
IFUNC_VX_IMPL (wmemchr);
- IFUNC_VX_IMPL (memccpy);
-
IFUNC_VX_IMPL (wmemset);
IFUNC_VX_IMPL (wmemcmp);
diff --git a/sysdeps/s390/multiarch/memccpy-c.c b/sysdeps/s390/multiarch/memccpy-c.c
deleted file mode 100644
index 1f4c548..0000000
--- a/sysdeps/s390/multiarch/memccpy-c.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Default memccpy implementation for S/390.
- Copyright (C) 2015-2018 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- . */
-
-#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
-# define MEMCCPY __memccpy_c
-
-# include
-extern __typeof (__memccpy) __memccpy_c;
-# include
-#endif
diff --git a/sysdeps/s390/multiarch/memccpy-vx.S b/sysdeps/s390/multiarch/memccpy-vx.S
deleted file mode 100644
index 150aa0e..0000000
--- a/sysdeps/s390/multiarch/memccpy-vx.S
+++ /dev/null
@@ -1,156 +0,0 @@
-/* Vector optimized 32/64 bit S/390 version of memccpy.
- Copyright (C) 2015-2018 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- . */
-
-#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
-
-# include "sysdep.h"
-# include "asm-syntax.h"
-
- .text
-
-/* void *memccpy (void * dest, const void *src, int c, size_t n)
- Copies no more than n bytes from src to dest,
- stopping when the character c is found
- and returns pointer next to c in dest or null if c not found.
-
- Register usage:
- -r0=tmp
- -r1=tmp
- -r2=dest
- -r3=src
- -r4=c
- -r5=n
- -r6=current_len
- -v16=part of s
- -v17=index of found c
- -v18=c replicated
- -v19=part #2 of s
- -v31=save area for r6
-*/
-ENTRY(__memccpy_vx)
- .machine "z13"
- .machinemode "zarch_nohighgprs"
-
-# if !defined __s390x__
- llgfr %r5,%r5
-# endif /* !defined __s390x__ */
-
- vlvgp %v31,%r6,%r7 /* Save registers. */
- clgije %r5,0,.Lnf_end /* If len == 0 then exit. */
-
- vlbb %v16,0(%r3),6 /* Load s until next 4k-byte boundary. */
- lcbb %r0,0(%r3),6 /* Get bytes to 4k-byte boundary or 16. */
- llgfr %r0,%r0 /* Convert 32bit to 64bit. */
-
- vlvgb %v18,%r4,0 /* Generate vector which elements are all c.
- if c > 255, c will be truncated. */
- vrepb %v18,%v18,0
- lghi %r6,0 /* current_len = 0. */
-
- clgrjle %r5,%r0,.Lremaining_v16 /* If maxlen <= loaded-bytes
- -> Process remaining. */
-
- vfeebs %v17,%v16,%v18 /* Find c. */
- vlgvb %r1,%v17,7 /* Load byte index of c. */
- clgrjl %r1,%r0,.Lfound_v16 /* Found c is within loaded bytes. */
-
- /* Align s to 16 byte. */
- risbgn %r1,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
- lghi %r6,15 /* current_len = 15. */
- slr %r6,%r1 /* Compute highest index to 16byte boundary. */
-
- vstl %v16,%r6,0(%r2) /* Store prcessed bytes */
- ahi %r6,1
-
-.Lpreloop1:
- /* Now we are 16byte aligned, so we can load
- a full vreg without page fault. */
- vl %v16,0(%r6,%r3) /* Load s. */
- clgijl %r5,17,.Lremaining_v16 /* If n <= 16,
- process remaining bytes. */
- lgr %r7,%r5
- slgfi %r7,16 /* border_len = n - 16. */
- j .Lloop1
-
-.Lloop2:
- vl %v16,16(%r6,%r3)
- vst %v19,0(%r6,%r2)
- aghi %r6,16
-
-.Lloop1:
- clgrjhe %r6,%r7,.Lremaining_v16 /* If current_len >= border
- then process remaining bytes. */
- vfeebs %v17,%v16,%v18 /* Find c. */
- jl .Lfound_v16 /* Jump away if c was found. */
- vl %v19,16(%r6,%r3) /* Load next s part. */
- vst %v16,0(%r6,%r2) /* Store previous part without c. */
- aghi %r6,16
-
- clgrjhe %r6,%r7,.Lremaining_v19
- vfeebs %v17,%v19,%v18
- jl .Lfound_v19
- vl %v16,16(%r6,%r3)
- vst %v19,0(%r6,%r2)
- aghi %r6,16
-
- clgrjhe %r6,%r7,.Lremaining_v16
- vfeebs %v17,%v16,%v18
- jl .Lfound_v16
- vl %v19,16(%r6,%r3)
- vst %v16,0(%r6,%r2)
- aghi %r6,16
-
- clgrjhe %r6,%r7,.Lremaining_v19
- vfeebs %v17,%v19,%v18
- jo .Lloop2
-
-.Lfound_v19:
- vlr %v16,%v19
-.Lfound_v16:
- /* v16 contains c. Store remaining bytes to c. currlen hasn´t
- reached border, thus checking for maxlen is not needed! */
- vlgvb %r1,%v17,7 /* Load byte index of c. */
- la %r2,0(%r6,%r2) /* vstl has no support for index-register. */
-.Lfound_v16_store:
- vstl %v16,%r1,0(%r2) /* Copy bytes including c. */
- la %r2,1(%r1,%r2) /* Return pointer next to c in dest. */
- vlgvg %r6,%v31,0
- vlgvg %r7,%v31,1
- br %r14
-
-.Lremaining_v19:
- vlr %v16,%v19
-.Lremaining_v16:
- /* v16 contains the remaining bytes [1...16].
- Check and store remaining bytes. */
- vfeebs %v17,%v16,%v18
- slgrk %r7,%r5,%r6 /* Remaining bytes = maxlen - current_len. */
- aghi %r7,-1 /* vstl needs highest index. */
- la %r2,0(%r6,%r2) /* vstl has no index register. */
- vlgvb %r1,%v17,7 /* Load index of c or 16 if not found. */
- /* c in remaining bytes? -> Jump away (c-index <= max-index) */
- clrjle %r1,%r7,.Lfound_v16_store
- vstl %v16,%r7,0(%r2) /* Store remaining bytes. */
-
-.Lnf_end:
- vlgvg %r6,%v31,0
- vlgvg %r7,%v31,1
- lghi %r2,0 /* Return null. */
- br %r14
-END(__memccpy_vx)
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
diff --git a/sysdeps/s390/multiarch/memccpy.c b/sysdeps/s390/multiarch/memccpy.c
deleted file mode 100644
index 30aae82..0000000
--- a/sysdeps/s390/multiarch/memccpy.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Multiple versions of memccpy.
- Copyright (C) 2015-2018 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- . */
-
-#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
-# include
-# include
-
-s390_vx_libc_ifunc (__memccpy)
-weak_alias (__memccpy, memccpy)
-
-#else
-# include
-#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)) */