diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile index fdfd1c6..f9a7127 100644 --- a/sysdeps/s390/Makefile +++ b/sysdeps/s390/Makefile @@ -76,5 +76,6 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \ wcsspn wcsspn-vx wcsspn-c \ wcspbrk wcspbrk-vx wcspbrk-c \ wcscspn wcscspn-vx wcscspn-c \ - wmemchr wmemchr-vx wmemchr-c + wmemchr wmemchr-vx wmemchr-c \ + wmemset wmemset-vx wmemset-c endif diff --git a/sysdeps/s390/ifunc-wmemset.h b/sysdeps/s390/ifunc-wmemset.h new file mode 100644 index 0000000..c9d1d17 --- /dev/null +++ b/sysdeps/s390/ifunc-wmemset.h @@ -0,0 +1,53 @@ +/* wmemset 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_WMEMSET_IFUNC 1 +#else +# define HAVE_WMEMSET_IFUNC 0 +#endif + +#ifdef HAVE_S390_VX_ASM_SUPPORT +# define HAVE_WMEMSET_IFUNC_AND_VX_SUPPORT HAVE_WMEMSET_IFUNC +#else +# define HAVE_WMEMSET_IFUNC_AND_VX_SUPPORT 0 +#endif + +#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT +# define WMEMSET_DEFAULT WMEMSET_Z13 +/* The z13 ifunc variant is using the common code variant as fallback! */ +# define HAVE_WMEMSET_C 1 +# define HAVE_WMEMSET_Z13 1 +#else +# define WMEMSET_DEFAULT WMEMSET_C +# define HAVE_WMEMSET_C 1 +# define HAVE_WMEMSET_Z13 HAVE_WMEMSET_IFUNC_AND_VX_SUPPORT +#endif + +#if HAVE_WMEMSET_C +# define WMEMSET_C __wmemset_c +#else +# define WMEMSET_C NULL +#endif + +#if HAVE_WMEMSET_Z13 +# define WMEMSET_Z13 __wmemset_vx +#else +# define WMEMSET_Z13 NULL +#endif diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile index 92e28dc..cc6dd7a 100644 --- a/sysdeps/s390/multiarch/Makefile +++ b/sysdeps/s390/multiarch/Makefile @@ -1,6 +1,5 @@ ifeq ($(subdir),wcsmbs) -sysdep_routines += wmemset wmemset-vx wmemset-c \ - wmemcmp wmemcmp-vx wmemcmp-c +sysdep_routines += wmemcmp wmemcmp-vx wmemcmp-c endif ifeq ($(subdir),iconvdata) diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c index b5f55de..7040959 100644 --- a/sysdeps/s390/multiarch/ifunc-impl-list.c +++ b/sysdeps/s390/multiarch/ifunc-impl-list.c @@ -63,6 +63,7 @@ #include #include #include +#include /* Maximum number of IFUNC implementations. */ #define MAX_IFUNC 3 @@ -645,6 +646,18 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, ) #endif /* HAVE_WMEMCHR_IFUNC */ +#if HAVE_WMEMSET_IFUNC + IFUNC_IMPL (i, name, wmemset, +# if HAVE_WMEMSET_Z13 + IFUNC_IMPL_ADD (array, i, wmemset, + dl_hwcap & HWCAP_S390_VX, WMEMSET_Z13) +# endif +# if HAVE_WMEMSET_C + IFUNC_IMPL_ADD (array, i, wmemset, 1, WMEMSET_C) +# endif + ) +#endif /* HAVE_WMEMSET_IFUNC */ + #ifdef HAVE_S390_VX_ASM_SUPPORT # define IFUNC_VX_IMPL(FUNC) \ @@ -653,8 +666,6 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, __##FUNC##_vx) \ IFUNC_IMPL_ADD (array, i, FUNC, 1, __##FUNC##_c)) - IFUNC_VX_IMPL (wmemset); - IFUNC_VX_IMPL (wmemcmp); #endif /* HAVE_S390_VX_ASM_SUPPORT */ diff --git a/sysdeps/s390/multiarch/wmemset-c.c b/sysdeps/s390/multiarch/wmemset-c.c deleted file mode 100644 index 1969cf9..0000000 --- a/sysdeps/s390/multiarch/wmemset-c.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Default wmemset 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 WMEMSET __wmemset_c - -# include -extern __typeof (__wmemset) __wmemset_c; -# undef weak_alias -# define weak_alias(name, alias) -# ifdef SHARED -# undef libc_hidden_def -# define libc_hidden_def(name) \ - __hidden_ver1 (__wmemset_c, __GI___wmemset, __wmemset_c); -# undef libc_hidden_weak -# define libc_hidden_weak(name) \ - strong_alias (__wmemset_c, __wmemset_c_1); \ - __hidden_ver1 (__wmemset_c_1, __GI_wmemset, __wmemset_c_1); -# endif /* SHARED */ - -# include -#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */ diff --git a/sysdeps/s390/multiarch/wmemset-vx.S b/sysdeps/s390/multiarch/wmemset-vx.S deleted file mode 100644 index 0c2f633..0000000 --- a/sysdeps/s390/multiarch/wmemset-vx.S +++ /dev/null @@ -1,142 +0,0 @@ -/* Vector Optimized 32/64 bit S/390 version of wmemset. - 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 - -/* wchar_t *wmemset(wchar_t *dest, wchar_t wc, size_t n) - Fill an array of wide-characters with a constant wide character - and returns dest. - - Register usage: - -r0=tmp - -r1=tmp - -r2=dest or current-pointer - -r3=wc - -r4=n - -r5=tmp - -v16=replicated wc - -v17,v18,v19=copy of v16 for vstm - -v31=saved dest for return -*/ -ENTRY(__wmemset_vx) - .machine "z13" - .machinemode "zarch_nohighgprs" - -# if !defined __s390x__ - llgfr %r4,%r4 -# endif /* !defined __s390x__ */ - - vlvgg %v31,%r2,0 /* Save destination pointer for return. */ - clgije %r4,0,.Lend - - vlvgf %v16,%r3,0 /* Generate vector with wchar_t wc. */ - vrepf %v16,%v16,0 - - /* Check range of maxlen and convert to byte-count. */ -# ifdef __s390x__ - tmhh %r4,49152 /* Test bit 0 or 1 of maxlen. */ - lghi %r5,-4 /* Max byte-count is 18446744073709551612. */ -# else - tmlh %r4,49152 /* Test bit 0 or 1 of maxlen. */ - llilf %r5,4294967292 /* Max byte-count is 4294967292. */ -# endif /* !__s390x__ */ - sllg %r4,%r4,2 /* Convert character-count to byte-count. */ - locgrne %r4,%r5 /* Use max byte-count, if bit 0/1 was one. */ - - /* Align dest to 16 byte. */ - risbg %r0,%r2,60,128+63,0 /* Test if s is aligned and - %r3 = bits 60-63 'and' 15. */ - je .Lpreloop /* 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 %r1,16 - slr %r1,%r0 /* Compute byte count to load (16-x). */ - clgr %r1,%r4 - locgrh %r1,%r4 /* min (byte count, n) */ - aghik %r5,%r1,-1 /* vstl needs highest index. */ - vstl %v16,%r5,0(%r2) /* Store remaining bytes. */ - clgrje %r1,%r4,.Lend /* Return if n bytes where set. */ - slgr %r4,%r1 /* Compute remaining byte count. */ - la %r2,0(%r1,%r2) - -.Lpreloop: - /* Now we are 16-byte aligned. */ - clgijl %r4,17,.Lremaining - srlg %r1,%r4,8 /* Split into 256byte blocks */ - clgije %r1,0,.Lpreloop64 - vlr %v17,%v16 - vlr %v18,%v16 - vlr %v19,%v16 - -.Lloop256: - vstm %v16,%v19,0(%r2) - vstm %v16,%v19,64(%r2) - vstm %v16,%v19,128(%r2) - vstm %v16,%v19,192(%r2) - la %r2,256(%r2) - brctg %r1,.Lloop256 /* Loop until all blocks are processed. */ - - llgfr %r4,%r4 - nilf %r4,255 /* Get remaining bytes */ - je .Lend /* Skip store remaining bytes if zero. */ - -.Lpreloop64: - clgijl %r4,17,.Lremaining - clgijl %r4,33,.Lpreloop16 - srlg %r1,%r4,5 /* Split into 32byte blocks */ - -.Lloop32: - vst %v16,0(%r2) - vst %v16,16(%r2) - la %r2,32(%r2) - brctg %r1,.Lloop32 /* Loop until all blocks are processed. */ - - llgfr %r4,%r4 - nilf %r4,31 /* Get remaining bytes */ - je .Lend /* Skip store remaining bytes if zero. */ - -.Lpreloop16: - clgijl %r4,17,.Lremaining - srlg %r1,%r4,4 /* Split into 16byte blocks */ - -.Lloop16: - vst %v16,0(%r2) - la %r2,16(%r2) - brctg %r1,.Lloop16 /* Loop until all blocks are processed. */ - - llgfr %r4,%r4 - nilf %r4,15 /* Get remaining bytes */ - je .Lend /* Skip store remaining bytes if zero. */ - -.Lremaining: - aghi %r4,-1 /* vstl needs highest index. */ - vstl %v16,%r4,0(%r2) - -.Lend: - vlgvg %r2,%v31,0 /* Load saved dest for return value. */ - br %r14 -.Lfallback: - srlg %r4,%r4,2 /* Convert byte-count to character-count. */ - jg __wmemset_c -END(__wmemset_vx) -#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */ diff --git a/sysdeps/s390/multiarch/wmemset.c b/sysdeps/s390/multiarch/wmemset.c deleted file mode 100644 index 149b481..0000000 --- a/sysdeps/s390/multiarch/wmemset.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Multiple versions of wmemset. - 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 wmemset __redirect_wmemset -# define __wmemset __redirect___wmemset -# include -# undef wmemset -# undef __wmemset -# include - -s390_vx_libc_ifunc_redirected (__redirect___wmemset, __wmemset) -weak_alias (__wmemset, wmemset) - -#else -# include -#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)) */ diff --git a/sysdeps/s390/wmemset-c.c b/sysdeps/s390/wmemset-c.c new file mode 100644 index 0000000..01e6254 --- /dev/null +++ b/sysdeps/s390/wmemset-c.c @@ -0,0 +1,44 @@ +/* Default wmemset 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_WMEMSET_C +# if HAVE_WMEMSET_IFUNC || HAVE_WMEMSET_Z13 +# define WMEMSET WMEMSET_C + +# undef weak_alias +# define weak_alias(name, alias) + +# if defined SHARED && IS_IN (libc) +# undef libc_hidden_weak +# define libc_hidden_weak(name) +# undef libc_hidden_def +# if ! defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT +# define libc_hidden_def(name) \ + __hidden_ver1 (__wmemset_c, __GI_wmemset, __wmemset_c) __attribute__((weak)); \ + strong_alias (__wmemset_c, __wmemset_c_1); \ + __hidden_ver1 (__wmemset_c_1, __GI___wmemset, __wmemset_c_1); +# else +# define libc_hidden_def(name) +# endif +# endif +# endif + +# include +#endif diff --git a/sysdeps/s390/wmemset-vx.S b/sysdeps/s390/wmemset-vx.S new file mode 100644 index 0000000..4b6050b --- /dev/null +++ b/sysdeps/s390/wmemset-vx.S @@ -0,0 +1,154 @@ +/* Vector Optimized 32/64 bit S/390 version of wmemset. + 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_WMEMSET_Z13 + +# include "sysdep.h" +# include "asm-syntax.h" + + .text + +/* wchar_t *wmemset(wchar_t *dest, wchar_t wc, size_t n) + Fill an array of wide-characters with a constant wide character + and returns dest. + + Register usage: + -r0=tmp + -r1=tmp + -r2=dest or current-pointer + -r3=wc + -r4=n + -r5=tmp + -v16=replicated wc + -v17,v18,v19=copy of v16 for vstm + -v31=saved dest for return +*/ +ENTRY(WMEMSET_Z13) + .machine "z13" + .machinemode "zarch_nohighgprs" + +# if !defined __s390x__ + llgfr %r4,%r4 +# endif /* !defined __s390x__ */ + + vlvgg %v31,%r2,0 /* Save destination pointer for return. */ + clgije %r4,0,.Lend + + vlvgf %v16,%r3,0 /* Generate vector with wchar_t wc. */ + vrepf %v16,%v16,0 + + /* Check range of maxlen and convert to byte-count. */ +# ifdef __s390x__ + tmhh %r4,49152 /* Test bit 0 or 1 of maxlen. */ + lghi %r5,-4 /* Max byte-count is 18446744073709551612. */ +# else + tmlh %r4,49152 /* Test bit 0 or 1 of maxlen. */ + llilf %r5,4294967292 /* Max byte-count is 4294967292. */ +# endif /* !__s390x__ */ + sllg %r4,%r4,2 /* Convert character-count to byte-count. */ + locgrne %r4,%r5 /* Use max byte-count, if bit 0/1 was one. */ + + /* Align dest to 16 byte. */ + risbg %r0,%r2,60,128+63,0 /* Test if s is aligned and + %r3 = bits 60-63 'and' 15. */ + je .Lpreloop /* 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 %r1,16 + slr %r1,%r0 /* Compute byte count to load (16-x). */ + clgr %r1,%r4 + locgrh %r1,%r4 /* min (byte count, n) */ + aghik %r5,%r1,-1 /* vstl needs highest index. */ + vstl %v16,%r5,0(%r2) /* Store remaining bytes. */ + clgrje %r1,%r4,.Lend /* Return if n bytes where set. */ + slgr %r4,%r1 /* Compute remaining byte count. */ + la %r2,0(%r1,%r2) + +.Lpreloop: + /* Now we are 16-byte aligned. */ + clgijl %r4,17,.Lremaining + srlg %r1,%r4,8 /* Split into 256byte blocks */ + clgije %r1,0,.Lpreloop64 + vlr %v17,%v16 + vlr %v18,%v16 + vlr %v19,%v16 + +.Lloop256: + vstm %v16,%v19,0(%r2) + vstm %v16,%v19,64(%r2) + vstm %v16,%v19,128(%r2) + vstm %v16,%v19,192(%r2) + la %r2,256(%r2) + brctg %r1,.Lloop256 /* Loop until all blocks are processed. */ + + llgfr %r4,%r4 + nilf %r4,255 /* Get remaining bytes */ + je .Lend /* Skip store remaining bytes if zero. */ + +.Lpreloop64: + clgijl %r4,17,.Lremaining + clgijl %r4,33,.Lpreloop16 + srlg %r1,%r4,5 /* Split into 32byte blocks */ + +.Lloop32: + vst %v16,0(%r2) + vst %v16,16(%r2) + la %r2,32(%r2) + brctg %r1,.Lloop32 /* Loop until all blocks are processed. */ + + llgfr %r4,%r4 + nilf %r4,31 /* Get remaining bytes */ + je .Lend /* Skip store remaining bytes if zero. */ + +.Lpreloop16: + clgijl %r4,17,.Lremaining + srlg %r1,%r4,4 /* Split into 16byte blocks */ + +.Lloop16: + vst %v16,0(%r2) + la %r2,16(%r2) + brctg %r1,.Lloop16 /* Loop until all blocks are processed. */ + + llgfr %r4,%r4 + nilf %r4,15 /* Get remaining bytes */ + je .Lend /* Skip store remaining bytes if zero. */ + +.Lremaining: + aghi %r4,-1 /* vstl needs highest index. */ + vstl %v16,%r4,0(%r2) + +.Lend: + vlgvg %r2,%v31,0 /* Load saved dest for return value. */ + br %r14 +.Lfallback: + srlg %r4,%r4,2 /* Convert byte-count to character-count. */ + jg WMEMSET_C +END(WMEMSET_Z13) + +# if ! HAVE_WMEMSET_IFUNC +strong_alias (WMEMSET_Z13, __wmemset) +weak_alias (__wmemset, wmemset) +# endif + +# if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT \ + && defined SHARED && IS_IN (libc) +strong_alias (WMEMSET_Z13, __GI___wmemset) +weak_alias (WMEMSET_Z13, __GI_wmemset) +# endif +#endif diff --git a/sysdeps/s390/wmemset.c b/sysdeps/s390/wmemset.c new file mode 100644 index 0000000..6118754 --- /dev/null +++ b/sysdeps/s390/wmemset.c @@ -0,0 +1,43 @@ +/* Multiple versions of wmemset. + 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_WMEMSET_IFUNC +# define wmemset __redirect_wmemset +# define __wmemset __redirect___wmemset +# include +# undef wmemset +# undef __wmemset +# include + +# if HAVE_WMEMSET_C +extern __typeof (__redirect___wmemset) WMEMSET_C attribute_hidden; +# endif + +# if HAVE_WMEMSET_Z13 +extern __typeof (__redirect___wmemset) WMEMSET_Z13 attribute_hidden; +# endif + +s390_libc_ifunc_expr (__redirect___wmemset, __wmemset, + (HAVE_WMEMSET_Z13 && (hwcap & HWCAP_S390_VX)) + ? WMEMSET_Z13 + : WMEMSET_DEFAULT + ) +weak_alias (__wmemset, wmemset) +#endif