@@ -37,7 +37,7 @@ string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \
strcoll
wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \
- wcscmp wcsncmp wcschr wcschrnul
+ wcscmp wcsncmp wcschr wcschrnul wcsrchr
string-bench-all := $(string-bench) ${wcsmbs-bench}
# We have to generate locales
new file mode 100644
@@ -0,0 +1,20 @@
+/* Measure wcsrchr functions.
+ Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#define WIDE 1
+#include "bench-strrchr.c"
@@ -10,7 +10,8 @@ sysdep_routines += strlen strlen-vx strlen-c \
strcmp strcmp-vx \
strncmp strncmp-vx strncmp-c \
strchr strchr-vx strchr-c \
- strchrnul strchrnul-vx strchrnul-c
+ strchrnul strchrnul-vx strchrnul-c \
+ strrchr strrchr-vx strrchr-c
endif
ifeq ($(subdir),wcsmbs)
@@ -25,5 +26,6 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \
wcscmp wcscmp-vx wcscmp-c \
wcsncmp wcsncmp-vx wcsncmp-c \
wcschr wcschr-vx wcschr-c \
- wcschrnul wcschrnul-vx wcschrnul-c
+ wcschrnul wcschrnul-vx wcschrnul-c \
+ wcsrchr wcsrchr-vx wcsrchr-c
endif
@@ -115,6 +115,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
IFUNC_VX_IMPL (strchrnul);
IFUNC_VX_IMPL (wcschrnul);
+ IFUNC_VX_IMPL (strrchr);
+ IFUNC_VX_IMPL (wcsrchr);
+
#endif /* HAVE_S390_VX_ASM_SUPPORT */
return i;
new file mode 100644
@@ -0,0 +1,29 @@
+/* Default strrchr implementation for S/390.
+ Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
+# define STRRCHR __strrchr_c
+# undef weak_alias
+# ifdef SHARED
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name) \
+ __hidden_ver1 (__strrchr_c, __GI_strrchr, __strrchr_c);
+# endif /* SHARED */
+
+# include <string/strrchr.c>
+#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
new file mode 100644
@@ -0,0 +1,133 @@
+/* Vector optimized 32/64 bit S/390 version of strrchr.
+ Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
+
+# include "sysdep.h"
+# include "asm-syntax.h"
+
+ .text
+
+/* char *strrchr (const char *s, int c)
+ Locate the last character c in string.
+
+ Register usage:
+ -r0=tmp
+ -r1=pointer to last occurence of c or NULL if not found.
+ -r2=s
+ -r3=c
+ -r4=tmp
+ -r5=current_len
+ -v16=part of s
+ -v17=index of found element
+ -v18=replicated c
+*/
+ENTRY(__strrchr_vx)
+ .machine "z13"
+ .machinemode "zarch_nohighgprs"
+
+ vlvgb %v18,%r3,0 /* Generate vector which elements are all c.
+ if c > 255, c will be truncated. */
+ lghi %r5,0 /* current_len = 0. */
+ vrepb %v18,%v18,0
+ lghi %r1,0 /* Zero out return pointer. */
+
+ /* Align s to 16byte */
+ risbg %r0,%r2,60,128+63,0 /* Test if s is aligned and
+ %r0 = bits 60-63 'and' 15. */
+ je .Lloop1 /* If s is aligned, loop aligned. */
+ lghi %r4,15
+ slr %r4,%r0 /* Compute highest index to load (15-x). */
+ vll %v16,%r4,0(%r2) /* Load up to 16 byte boundary (vll needs
+ highest index, remaining bytes are 0). */
+ ahi %r4,1 /* Work with loaded byte count. */
+ j .Llt16
+
+ /* Process s in a 16byte aligned loop. */
+.Lloop2:
+ aghi %r5,16
+.Lloop1:
+ vl %v16,0(%r5,%r2) /* Load s. */
+ vfeezbs %v17,%v16,%v18 /* Find element equal with zero search. */
+ jno .Lfound_from_loop /* Found c/zero (cc=0|1|2). */
+ vl %v16,16(%r5,%r2)
+ aghi %r5,16
+ vfeezbs %v17,%v16,%v18
+ jno .Lfound_from_loop
+ vl %v16,16(%r5,%r2)
+ aghi %r5,16
+ vfeezbs %v17,%v16,%v18
+ jno .Lfound_from_loop
+ vl %v16,16(%r5,%r2)
+ aghi %r5,16
+ vfeezbs %v17,%v16,%v18
+ jo .Lloop2 /* No character and no zero -> loop. */
+
+
+.Lfound_from_loop:
+ vlgvb %r0,%v17,7 /* Load byte index of character. */
+ lghi %r4,16 /* Byte count in v16 is 16. */
+.Lfound:
+ /* Found c/zero in loaded bytes,
+ in %r0 is found index. */
+ je .Lzero /* Found zero, but no c before -> end. */
+
+.Lcharacter:
+ /* Found character. */
+ algr %r5,%r0
+ la %r1,0(%r5,%r2) /* Store found character pointer. */
+ aghi %r0,1 /* Start next search behind found character. */
+ aghi %r5,1 /* Start next search behind found character. */
+ clrje %r0,%r4,.Lloop1 /* Found character was the last loaded byte,
+ so load next 16bytes aligned and
+ loop until end of string. */
+ /* Shift left processed bytes in vector register
+ and process remaining bytes without load */
+ slr %r4,%r0 /* Calculate remaining number of bytes =
+ loaded byte count - (found-index + 1) */
+ sll %r0,3 /* Compute byte count for vector shift left. */
+ vlvgb %v17,%r0,7
+ vslb %v16,%v16,%v17 /* Vector shift left by byte by number of bytes
+ specified in bits 1-4 of byte 7 in v17. */
+
+.Llt16:
+ /* Loaded only 1...15bytes in v16. */
+ vfeezbs %v17,%v16,%v18
+ vlgvb %r0,%v17,7 /* Load byte index of zero (cc not changed) */
+ clrjl %r0,%r4,.Lfound /* %r0<%r4 => found c/zero in loaded bytes. */
+ /* Found something behind loaded bytes or found nothing -> ignore. */
+ algfr %r5,%r4 /* Add loaded byte count to current len. */
+ /* One aligned vr is fully processed, so we are now aligned, too. */
+ j .Lloop1 /* Loop without adding 16. */
+
+
+.Lzero:
+ llgcr %r3,%r3 /* char c_char = (char) c; */
+ clije %r3,0,.Lzero2 /* Found zero and c is zero. */
+ /* Return %r1: null if character not found
+ or last stored character pointer. */
+ lgr %r2,%r1
+ br %r14
+
+.Lzero2:
+ /* Searched c is zero, so return pointer to \0 instead of NULL. */
+ algr %r5,%r0 /* Add loaded byte index of zero. */
+ la %r2,0(%r5,%r2) /* Store last zero as return pointer. */
+ br %r14
+END(__strrchr_vx)
+#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
new file mode 100644
@@ -0,0 +1,28 @@
+/* Multiple versions of strrchr.
+ Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
+# include <string.h>
+# include <ifunc-resolve.h>
+
+s390_vx_libc_ifunc2 (__strrchr, strrchr)
+weak_alias (strrchr, rindex)
+
+#else
+# include <string/strrchr.c>
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)) */
new file mode 100644
@@ -0,0 +1,25 @@
+/* Default wcsrchr implementation for S/390.
+ Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
+# define WCSRCHR __wcsrchr_c
+
+# include <wchar.h>
+extern __typeof (wcsrchr) __wcsrchr_c;
+# include <wcsmbs/wcsrchr.c>
+#endif
new file mode 100644
@@ -0,0 +1,135 @@
+/* Vector optimized 32/64 bit S/390 version of wcsrchr.
+ Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
+
+# include "sysdep.h"
+# include "asm-syntax.h"
+
+ .text
+
+/* wchar_t *wcsrchr (const wchar_t *s, wchar_t c)
+ Locate the last character c in string.
+
+ Register usage:
+ -r0=tmp
+ -r1=pointer to last occurence of c or NULL if not found.
+ -r2=s
+ -r3=c
+ -r4=tmp
+ -r5=current_len
+ -v16=part of s
+ -v17=index of found element
+ -v18=replicated c
+*/
+ENTRY(__wcsrchr_vx)
+ .machine "z13"
+ .machinemode "zarch_nohighgprs"
+
+ vlvgf %v18,%r3,0 /* Generate vector which elements are all c. */
+ lghi %r5,0 /* current_len = 0. */
+ vrepf %v18,%v18,0
+ lghi %r1,0 /* Zero out return pointer. */
+
+ /* Align s to 16byte */
+ risbg %r0,%r2,60,128+63,0 /* Test if s is aligned and
+ %r0 = bits 60-63 'and' 15. */
+ je .Lloop1 /* If s is aligned, loop aligned. */
+ tmll %r2,3 /* Test if s is 4-byte aligned? */
+ jne .Lfallback /* And use common-code variant if not. */
+ lghi %r4,15
+ slr %r4,%r0 /* Compute highest index to load (15-x). */
+ vll %v16,%r4,0(%r2) /* Load up to 16byte boundary (vll needs
+ highest index, remaining bytes are 0). */
+ ahi %r4,1 /* Work with loaded byte count. */
+ j .Llt16
+
+ /* Process s in a 16byte aligned loop. */
+.Lloop2:
+ aghi %r5,16
+.Lloop1:
+ vl %v16,0(%r5,%r2) /* Load s. */
+ vfeezfs %v17,%v16,%v18 /* Find element equal with zero search. */
+ jno .Lfound_from_loop /* Found c/zero (cc=0|1|2). */
+ vl %v16,16(%r5,%r2)
+ aghi %r5,16
+ vfeezfs %v17,%v16,%v18
+ jno .Lfound_from_loop
+ vl %v16,16(%r5,%r2)
+ aghi %r5,16
+ vfeezfs %v17,%v16,%v18
+ jno .Lfound_from_loop
+ vl %v16,16(%r5,%r2)
+ aghi %r5,16
+ vfeezfs %v17,%v16,%v18
+ jo .Lloop2 /* No character and no zero -> loop. */
+
+
+.Lfound_from_loop:
+ vlgvb %r0,%v17,7 /* Load byte index of character. */
+ lghi %r4,16 /* Byte count in v16 is 16. */
+.Lfound:
+ /* Found c/zero in loaded bytes,
+ in %r0 is found index. */
+ je .Lzero /* Found zero, but no c before -> end. */
+
+.Lcharacter:
+ /* Found character. */
+ algr %r5,%r0
+ la %r1,0(%r5,%r2) /* Store found character pointer. */
+ aghi %r0,4 /* Start next search behind found character. */
+ aghi %r5,4 /* Start next search behind found character. */
+ clrje %r0,%r4,.Lloop1 /* Found character was the last loaded byte,
+ so load next 16bytes aligned and
+ loop until end of string. */
+ /* Shift left processed bytes in vector register
+ and process remaining bytes without load */
+ slr %r4,%r0 /* Calculate remaining number of bytes =
+ loaded byte count - (found-index + 4) */
+ sll %r0,3 /* Compute byte count for vector shift left. */
+ vlvgb %v17,%r0,7
+ vslb %v16,%v16,%v17 /* Vector shift left by byte by number of bytes
+ specified in bits 1-4 of byte 7 in v17. */
+
+.Llt16:
+ /* Loaded only 1...15bytes in v16. */
+ vfeezfs %v17,%v16,%v18
+ vlgvb %r0,%v17,7 /* Load byte index of zero (cc not changed) */
+ clrjl %r0,%r4,.Lfound /* %r0<%r4 => found c/zero in loaded bytes. */
+ /* Found something behind loaded bytes or found nothing -> ignore. */
+ algfr %r5,%r4 /* Add loaded byte count to current_len. */
+ /* One aligned vreg is fully processed, so we are now aligned, too. */
+ j .Lloop1 /* Loop without adding 16. */
+
+
+.Lzero:
+ clije %r3,0,.Lzero2 /* Found zero and c is zero. */
+ /* Return %r1: null if character not found
+ or last stored character pointer. */
+ lgr %r2,%r1
+ br %r14
+
+.Lzero2:
+ /* Searched c is zero, so return pointer to \0 instead of NULL. */
+ algr %r5,%r0 /* Add loaded byte index of zero. */
+ la %r2,0(%r5,%r2) /* Store last zero as return pointer. */
+ br %r14
+.Lfallback:
+ jg __wcsrchr_c
+END(__wcsrchr_vx)
+#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
new file mode 100644
@@ -0,0 +1,27 @@
+/* Multiple versions of wcsrchr.
+ Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
+# include <wchar.h>
+# include <ifunc-resolve.h>
+
+s390_vx_libc_ifunc2 (__wcsrchr, wcsrchr)
+
+#else
+# include <wcsmbs/wcsrchr.c>
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)) */