diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
index 239426d..9a16ce1 100644
--- a/sysdeps/s390/Makefile
+++ b/sysdeps/s390/Makefile
@@ -55,5 +55,6 @@ sysdep_routines += bzero memset memset-z900 \
strcspn strcspn-vx strcspn-c \
memchr memchr-vx memchr-z900 \
rawmemchr rawmemchr-vx rawmemchr-c \
- memccpy memccpy-vx memccpy-c
+ memccpy memccpy-vx memccpy-c \
+ memrchr memrchr-vx memrchr-c
endif
diff --git a/sysdeps/s390/ifunc-memrchr.h b/sysdeps/s390/ifunc-memrchr.h
new file mode 100644
index 0000000..9d80d55
--- /dev/null
+++ b/sysdeps/s390/ifunc-memrchr.h
@@ -0,0 +1,52 @@
+/* memrchr 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_MEMRCHR_IFUNC 1
+#else
+# define HAVE_MEMRCHR_IFUNC 0
+#endif
+
+#ifdef HAVE_S390_VX_ASM_SUPPORT
+# define HAVE_MEMRCHR_IFUNC_AND_VX_SUPPORT HAVE_MEMRCHR_IFUNC
+#else
+# define HAVE_MEMRCHR_IFUNC_AND_VX_SUPPORT 0
+#endif
+
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
+# define MEMRCHR_DEFAULT MEMRCHR_Z13
+# define HAVE_MEMRCHR_C 0
+# define HAVE_MEMRCHR_Z13 1
+#else
+# define MEMRCHR_DEFAULT MEMRCHR_C
+# define HAVE_MEMRCHR_C 1
+# define HAVE_MEMRCHR_Z13 HAVE_MEMRCHR_IFUNC_AND_VX_SUPPORT
+#endif
+
+#if HAVE_MEMRCHR_C
+# define MEMRCHR_C __memrchr_c
+#else
+# define MEMRCHR_C NULL
+#endif
+
+#if HAVE_MEMRCHR_Z13
+# define MEMRCHR_Z13 __memrchr_vx
+#else
+# define MEMRCHR_Z13 NULL
+#endif
diff --git a/sysdeps/s390/memrchr-c.c b/sysdeps/s390/memrchr-c.c
new file mode 100644
index 0000000..333c0fc
--- /dev/null
+++ b/sysdeps/s390/memrchr-c.c
@@ -0,0 +1,27 @@
+/* Default memrchr 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_MEMRCHR_C
+# if HAVE_MEMRCHR_IFUNC
+# define MEMRCHR MEMRCHR_C
+# endif
+
+# include
+#endif
diff --git a/sysdeps/s390/memrchr-vx.S b/sysdeps/s390/memrchr-vx.S
new file mode 100644
index 0000000..ba832f1
--- /dev/null
+++ b/sysdeps/s390/memrchr-vx.S
@@ -0,0 +1,168 @@
+/* Vector optimized 32/64 bit S/390 version of memrchr.
+ 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_MEMRCHR_Z13
+
+# include "sysdep.h"
+# include "asm-syntax.h"
+
+ .text
+
+/* void *memrchr (const void *s, int c, size_t n)
+ Scans memory for character c backwards
+ and returns pointer to first c.
+
+ Register usage:
+ -r0=tmp
+ -r1=tmp
+ -r2=s
+ -r3=c
+ -r4=n
+ -r5=s in loop
+
+ -v16=part of s
+ -v17=index of found c
+ -v18=c replicated
+ -v20=permute pattern
+*/
+ENTRY(MEMRCHR_Z13)
+ .machine "z13"
+ .machinemode "zarch_nohighgprs"
+
+# if !defined __s390x__
+ llgfr %r4,%r4
+# endif /* !defined __s390x__ */
+ clgije %r4,0,.Lnot_found
+
+ vlvgb %v18,%r3,0 /* Generate vector which elements are all c.
+ If c > 255, c will be truncated. */
+ vrepb %v18,%v18,0
+
+ llcr %r3,%r3 /* char c_char = (char) c. */
+
+ /* check byte n - 1. */
+ llc %r0,-1(%r4,%r2)
+ slgfi %r4,1
+ clrje %r0,%r3,.Lfound_end
+ jh .Lnot_found /* Return NULL if n is now 0. */
+
+ larl %r1,.Lpermute_mask /* Load permute mask. */
+ vl %v20,0(%r1)
+
+ /* check byte n - 2. */
+ llc %r0,-1(%r4,%r2)
+ slgfi %r4,1
+ clrje %r0,%r3,.Lfound_end
+ jh .Lnot_found /* Return NULL if n is now 0. */
+
+ clgijhe %r4,64,.Lloop64 /* If n >= 64 -> loop64. */
+
+.Llt64:
+ /* Process n < 64 bytes. */
+ clgijl %r4,16,.Llt16 /* Jump away if n < 16. */
+ aghi %r4,-16
+ vl %v16,0(%r4,%r2)
+ vfeebs %v17,%v16,%v18
+ jno .Lfound0
+ clgijl %r4,16,.Llt16
+ aghi %r4,-16
+ vl %v16,0(%r4,%r2)
+ vfeebs %v17,%v16,%v18
+ jno .Lfound0
+ clgijl %r4,16,.Llt16
+ aghi %r4,-16
+ vl %v16,0(%r4,%r2)
+ vfeebs %v17,%v16,%v18
+ jno .Lfound0
+.Llt16:
+ clgfi %r4,0 /* if remaining bytes == 0, return NULL. */
+ locghie %r2,0
+ ber %r14
+
+ aghi %r4,-1 /* vll needs highest index. */
+ vll %v16,%r4,0(%r2) /* Load remaining bytes. */
+
+ /* Right-shift of v16 to mask bytes after highest index. */
+ lhi %r0,15
+ slr %r0,%r4 /* Compute byte count for vector shift right. */
+ sll %r0,3 /* Convert to bit count. */
+ vlvgb %v17,%r0,7
+ vsrlb %v16,%v16,%v17 /* Vector shift right by byte by number of bytes
+ specified in bits 1-4 of byte 7 in v17. */
+ j .Lfound_permute
+
+.Lfound48:
+ aghi %r4,16
+.Lfound32:
+ aghi %r4,16
+.Lfound16:
+ aghi %r4,16
+.Lfound0:
+ la %r2,0(%r4,%r2) /* Set pointer to start of v16. */
+ lghi %r4,15 /* Set highest index in v16 to last index. */
+.Lfound_permute:
+ /* Search for a c in v16 in reversed byte order. v16 contains %r4 + 1
+ bytes. If v16 was not fully loaded, the bytes are already
+ right shifted, so that the bytes in v16 can simply be reversed. */
+ vperm %v16,%v16,%v16,%v20 /* Permute v16 to reversed order. */
+ vfeeb %v16,%v16,%v18 /* Find c in reversed v16. */
+ vlgvb %r1,%v16,7 /* Index of c or 16 if not found. */
+
+ /* Return NULL if there is no c in loaded bytes. */
+ clrjh %r1,%r4,.Lnot_found
+
+ slgr %r4,%r1
+.Lfound_end:
+ la %r2,0(%r4,%r2) /* Return pointer to c. */
+ br %r14
+
+.Lnot_found:
+ lghi %r2,0
+ br %r14
+
+.Lpermute_mask:
+ .byte 0x0F,0x0E,0x0D,0x0C,0x0B,0x0A,0x09,0x08
+ .byte 0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00
+
+.Lloop64:
+ aghi %r4,-64
+ vl %v16,48(%r4,%r2) /* Load 16bytes of memory area. */
+ vfeebs %v17,%v16,%v18 /* Find c. */
+ jno .Lfound48 /* Jump away if c was found. */
+ vl %v16,32(%r4,%r2)
+ vfeebs %v17,%v16,%v18
+ jno .Lfound32
+ vl %v16,16(%r4,%r2)
+ vfeebs %v17,%v16,%v18
+ jno .Lfound16
+ vl %v16,0(%r4,%r2)
+ vfeebs %v17,%v16,%v18
+ jno .Lfound0
+
+ clgijhe %r4,64,.Lloop64 /* If n >= 64 -> loop64. */
+ j .Llt64
+END(MEMRCHR_Z13)
+
+# if ! HAVE_MEMRCHR_IFUNC
+strong_alias (MEMRCHR_Z13, __memrchr)
+weak_alias (__memrchr, memrchr)
+# endif
+
+#endif /* HAVE_MEMRCHR_Z13 */
diff --git a/sysdeps/s390/memrchr.c b/sysdeps/s390/memrchr.c
new file mode 100644
index 0000000..d995e99
--- /dev/null
+++ b/sysdeps/s390/memrchr.c
@@ -0,0 +1,39 @@
+/* Multiple versions of memrchr.
+ 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_MEMRCHR_IFUNC
+# include
+# include
+
+# if HAVE_MEMRCHR_C
+extern __typeof (__memrchr) MEMRCHR_C attribute_hidden;
+# endif
+
+# if HAVE_MEMRCHR_Z13
+extern __typeof (__memrchr) MEMRCHR_Z13 attribute_hidden;
+# endif
+
+s390_libc_ifunc_expr (__memrchr, __memrchr,
+ (HAVE_MEMRCHR_Z13 && (hwcap & HWCAP_S390_VX))
+ ? MEMRCHR_Z13
+ : MEMRCHR_DEFAULT
+ )
+weak_alias (__memrchr, memrchr)
+#endif /* HAVE_MEMRCHR_IFUNC */
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
index d5a32fc..260b514 100644
--- a/sysdeps/s390/multiarch/Makefile
+++ b/sysdeps/s390/multiarch/Makefile
@@ -1,7 +1,3 @@
-ifeq ($(subdir),string)
-sysdep_routines += memrchr memrchr-vx memrchr-c
-endif
-
ifeq ($(subdir),wcsmbs)
sysdep_routines += wcslen wcslen-vx wcslen-c \
wcsnlen wcsnlen-vx wcsnlen-c \
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
index b891774..0f01b99 100644
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
@@ -45,6 +45,7 @@
#include
#include
#include
+#include
/* Maximum number of IFUNC implementations. */
#define MAX_IFUNC 3
@@ -411,6 +412,18 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
)
#endif /* HAVE_MEMCCPY_IFUNC */
+#if HAVE_MEMRCHR_IFUNC
+ IFUNC_IMPL (i, name, memrchr,
+# if HAVE_MEMRCHR_Z13
+ IFUNC_IMPL_ADD (array, i, memrchr,
+ dl_hwcap & HWCAP_S390_VX, MEMRCHR_Z13)
+# endif
+# if HAVE_MEMRCHR_C
+ IFUNC_IMPL_ADD (array, i, memrchr, 1, MEMRCHR_C)
+# endif
+ )
+#endif /* HAVE_MEMRCHR_IFUNC */
+
#ifdef HAVE_S390_VX_ASM_SUPPORT
# define IFUNC_VX_IMPL(FUNC) \
@@ -457,8 +470,6 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
IFUNC_VX_IMPL (wmemcmp);
- IFUNC_VX_IMPL (memrchr);
-
#endif /* HAVE_S390_VX_ASM_SUPPORT */
return i;
diff --git a/sysdeps/s390/multiarch/memrchr-c.c b/sysdeps/s390/multiarch/memrchr-c.c
deleted file mode 100644
index 1e3c914..0000000
--- a/sysdeps/s390/multiarch/memrchr-c.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Default memrchr 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 MEMRCHR __memrchr_c
-
-# include
-extern __typeof (__memrchr) __memrchr_c;
-# include
-#endif
diff --git a/sysdeps/s390/multiarch/memrchr-vx.S b/sysdeps/s390/multiarch/memrchr-vx.S
deleted file mode 100644
index 8e81f5e..0000000
--- a/sysdeps/s390/multiarch/memrchr-vx.S
+++ /dev/null
@@ -1,160 +0,0 @@
-/* Vector optimized 32/64 bit S/390 version of memrchr.
- 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 *memrchr (const void *s, int c, size_t n)
- Scans memory for character c backwards
- and returns pointer to first c.
-
- Register usage:
- -r0=tmp
- -r1=tmp
- -r2=s
- -r3=c
- -r4=n
- -r5=s in loop
-
- -v16=part of s
- -v17=index of found c
- -v18=c replicated
- -v20=permute pattern
-*/
-ENTRY(__memrchr_vx)
- .machine "z13"
- .machinemode "zarch_nohighgprs"
-
-# if !defined __s390x__
- llgfr %r4,%r4
-# endif /* !defined __s390x__ */
- clgije %r4,0,.Lnot_found
-
- vlvgb %v18,%r3,0 /* Generate vector which elements are all c.
- If c > 255, c will be truncated. */
- vrepb %v18,%v18,0
-
- llcr %r3,%r3 /* char c_char = (char) c. */
-
- /* check byte n - 1. */
- llc %r0,-1(%r4,%r2)
- slgfi %r4,1
- clrje %r0,%r3,.Lfound_end
- jh .Lnot_found /* Return NULL if n is now 0. */
-
- larl %r1,.Lpermute_mask /* Load permute mask. */
- vl %v20,0(%r1)
-
- /* check byte n - 2. */
- llc %r0,-1(%r4,%r2)
- slgfi %r4,1
- clrje %r0,%r3,.Lfound_end
- jh .Lnot_found /* Return NULL if n is now 0. */
-
- clgijhe %r4,64,.Lloop64 /* If n >= 64 -> loop64. */
-
-.Llt64:
- /* Process n < 64 bytes. */
- clgijl %r4,16,.Llt16 /* Jump away if n < 16. */
- aghi %r4,-16
- vl %v16,0(%r4,%r2)
- vfeebs %v17,%v16,%v18
- jno .Lfound0
- clgijl %r4,16,.Llt16
- aghi %r4,-16
- vl %v16,0(%r4,%r2)
- vfeebs %v17,%v16,%v18
- jno .Lfound0
- clgijl %r4,16,.Llt16
- aghi %r4,-16
- vl %v16,0(%r4,%r2)
- vfeebs %v17,%v16,%v18
- jno .Lfound0
-.Llt16:
- clgfi %r4,0 /* if remaining bytes == 0, return NULL. */
- locghie %r2,0
- ber %r14
-
- aghi %r4,-1 /* vll needs highest index. */
- vll %v16,%r4,0(%r2) /* Load remaining bytes. */
-
- /* Right-shift of v16 to mask bytes after highest index. */
- lhi %r0,15
- slr %r0,%r4 /* Compute byte count for vector shift right. */
- sll %r0,3 /* Convert to bit count. */
- vlvgb %v17,%r0,7
- vsrlb %v16,%v16,%v17 /* Vector shift right by byte by number of bytes
- specified in bits 1-4 of byte 7 in v17. */
- j .Lfound_permute
-
-.Lfound48:
- aghi %r4,16
-.Lfound32:
- aghi %r4,16
-.Lfound16:
- aghi %r4,16
-.Lfound0:
- la %r2,0(%r4,%r2) /* Set pointer to start of v16. */
- lghi %r4,15 /* Set highest index in v16 to last index. */
-.Lfound_permute:
- /* Search for a c in v16 in reversed byte order. v16 contains %r4 + 1
- bytes. If v16 was not fully loaded, the bytes are already
- right shifted, so that the bytes in v16 can simply be reversed. */
- vperm %v16,%v16,%v16,%v20 /* Permute v16 to reversed order. */
- vfeeb %v16,%v16,%v18 /* Find c in reversed v16. */
- vlgvb %r1,%v16,7 /* Index of c or 16 if not found. */
-
- /* Return NULL if there is no c in loaded bytes. */
- clrjh %r1,%r4,.Lnot_found
-
- slgr %r4,%r1
-.Lfound_end:
- la %r2,0(%r4,%r2) /* Return pointer to c. */
- br %r14
-
-.Lnot_found:
- lghi %r2,0
- br %r14
-
-.Lpermute_mask:
- .byte 0x0F,0x0E,0x0D,0x0C,0x0B,0x0A,0x09,0x08
- .byte 0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00
-
-.Lloop64:
- aghi %r4,-64
- vl %v16,48(%r4,%r2) /* Load 16bytes of memory area. */
- vfeebs %v17,%v16,%v18 /* Find c. */
- jno .Lfound48 /* Jump away if c was found. */
- vl %v16,32(%r4,%r2)
- vfeebs %v17,%v16,%v18
- jno .Lfound32
- vl %v16,16(%r4,%r2)
- vfeebs %v17,%v16,%v18
- jno .Lfound16
- vl %v16,0(%r4,%r2)
- vfeebs %v17,%v16,%v18
- jno .Lfound0
-
- clgijhe %r4,64,.Lloop64 /* If n >= 64 -> loop64. */
- j .Llt64
-END(__memrchr_vx)
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
diff --git a/sysdeps/s390/multiarch/memrchr.c b/sysdeps/s390/multiarch/memrchr.c
deleted file mode 100644
index 43a44ab..0000000
--- a/sysdeps/s390/multiarch/memrchr.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Multiple versions of memrchr.
- 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 (__memrchr)
-weak_alias (__memrchr, memrchr)
-
-#else
-# include
-#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)) */