bdc76f
commit 5f1743d118047ff1fbefe713f2397090e0418deb
bdc76f
Author: Stefan Liebler <stli@linux.ibm.com>
bdc76f
Date:   Tue Dec 18 13:57:04 2018 +0100
bdc76f
bdc76f
    S390: Unify 31/64bit memset.
bdc76f
    
bdc76f
    The implementation of memset for s390-32 (31bit) and
bdc76f
    s390-64 (64bit) is nearly the same.
bdc76f
    This patch unifies it for maintability reasons.
bdc76f
    
bdc76f
    __memset_z10 and __memset_z196 differs between 31 and 64bit:
bdc76f
    -31bit needs .machinemode "zarch_nohighgprs" and llgfr   %r4,%r4
bdc76f
    -lr vs lgr and some other instructions:
bdc76f
    But lgr and co can be also used on 31bit as this ifunc variant
bdc76f
    is only called if we are on a zarch machine.
bdc76f
    
bdc76f
    __memset_default differs between 31 and 64bit:
bdc76f
    -Some 31bit vs 64bit instructions (e.g. ltr vs ltgr.
bdc76f
    Solved with 31/64 specific instruction macros).
bdc76f
    -The address of mvc instruction is setup in different ways
bdc76f
    (larl vs bras). Solved with #if defined __s390x__.
bdc76f
    
bdc76f
    Otherwise 31/64bit implementation has the same structure of the code.
bdc76f
    
bdc76f
    ChangeLog:
bdc76f
    
bdc76f
            * sysdeps/s390/s390-64/memset.S: Move to ...
bdc76f
            * sysdeps/s390/memset.S: ... here.
bdc76f
            Adjust to be usable for 31/64bit.
bdc76f
            * sysdeps/s390/s390-32/memset.S: Delete File.
bdc76f
            * sysdeps/s390/multiarch/Makefile (sysdep_routines): Add memset.
bdc76f
            * sysdeps/s390/s390-32/multiarch/Makefile (sysdep_routines):
bdc76f
            Remove memset.
bdc76f
            * sysdeps/s390/s390-64/multiarch/Makefile: Likewise.
bdc76f
            * sysdeps/s390/s390-64/multiarch/memset-s390x.S: Move to ...
bdc76f
            * sysdeps/s390/multiarch/memset-s390x.S: ... here.
bdc76f
            Adjust to be usable for 31/64bit.
bdc76f
            * sysdeps/s390/s390-32/multiarch/memset-s390.S: Delete File.
bdc76f
            * sysdeps/s390/s390-64/multiarch/memset.c: Move to ...
bdc76f
            * sysdeps/s390/multiarch/memset.c: ... here.
bdc76f
            * sysdeps/s390/s390-32/multiarch/memset.c: Delete File.
bdc76f
bdc76f
diff --git a/sysdeps/s390/s390-64/memset.S b/sysdeps/s390/memset.S
bdc76f
similarity index 58%
bdc76f
rename from sysdeps/s390/s390-64/memset.S
bdc76f
rename to sysdeps/s390/memset.S
bdc76f
index 8799c6592ce2dacf..72e7c5a42efbaf6c 100644
bdc76f
--- a/sysdeps/s390/s390-64/memset.S
bdc76f
+++ b/sysdeps/s390/memset.S
bdc76f
@@ -1,4 +1,4 @@
bdc76f
-/* Set a block of memory to some byte value.  64 bit S/390 version.
bdc76f
+/* Set a block of memory to some byte value.  31/64 bit S/390 version.
bdc76f
    Copyright (C) 2001-2018 Free Software Foundation, Inc.
bdc76f
    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
bdc76f
    This file is part of the GNU C Library.
bdc76f
@@ -28,33 +28,60 @@
bdc76f
 
bdc76f
        .text
bdc76f
 
bdc76f
+#if defined __s390x__
bdc76f
+# define LTGR	ltgr
bdc76f
+# define CGHI	cghi
bdc76f
+# define LGR	lgr
bdc76f
+# define AGHI	aghi
bdc76f
+# define BRCTG	brctg
bdc76f
+#else
bdc76f
+# define LTGR	ltr
bdc76f
+# define CGHI	chi
bdc76f
+# define LGR	lr
bdc76f
+# define AGHI	ahi
bdc76f
+# define BRCTG	brct
bdc76f
+#endif /* ! defined __s390x__  */
bdc76f
+
bdc76f
 #ifdef USE_MULTIARCH
bdc76f
 ENTRY(__memset_default)
bdc76f
 #else
bdc76f
 ENTRY(memset)
bdc76f
 #endif
bdc76f
+#if defined __s390x__
bdc76f
 	.machine "z900"
bdc76f
-	ltgr    %r4,%r4
bdc76f
-	je      .L_Z900_4
bdc76f
+#else
bdc76f
+	.machine "g5"
bdc76f
+#endif /* ! defined __s390x__  */
bdc76f
+	LTGR    %r4,%r4
bdc76f
+	je      .L_Z900_G5_4
bdc76f
 	stc     %r3,0(%r2)
bdc76f
-	cghi    %r4,1
bdc76f
-	lgr     %r1,%r2
bdc76f
-	je      .L_Z900_4
bdc76f
-	aghi    %r4,-2
bdc76f
+	CGHI    %r4,1
bdc76f
+	LGR     %r1,%r2
bdc76f
+	je      .L_Z900_G5_4
bdc76f
+	AGHI    %r4,-2
bdc76f
+#if defined __s390x__
bdc76f
+	larl    %r5,.L_Z900_G5_18
bdc76f
 	srlg    %r3,%r4,8
bdc76f
-	ltgr    %r3,%r3
bdc76f
-	jne     .L_Z900_14
bdc76f
-.L_Z900_3:
bdc76f
-	larl    %r3,.L_Z900_18
bdc76f
-	ex      %r4,0(%r3)
bdc76f
-.L_Z900_4:
bdc76f
+# define Z900_G5_EX_D 0
bdc76f
+#else
bdc76f
+	basr    %r5,0
bdc76f
+.L_Z900_G5_19:
bdc76f
+# define Z900_G5_EX_D .L_Z900_G5_18-.L_Z900_G5_19
bdc76f
+	lr      %r3,%r4
bdc76f
+	srl     %r3,8
bdc76f
+#endif /* ! defined __s390x__  */
bdc76f
+	LTGR    %r3,%r3
bdc76f
+	jne     .L_Z900_G5_14
bdc76f
+.L_Z900_G5_3:
bdc76f
+	ex      %r4,Z900_G5_EX_D(%r5)
bdc76f
+.L_Z900_G5_4:
bdc76f
 	br      %r14
bdc76f
-.L_Z900_14:
bdc76f
+.L_Z900_G5_14:
bdc76f
 	mvc     1(256,%r1),0(%r1)
bdc76f
 	la      %r1,256(%r1)
bdc76f
-	brctg   %r3,.L_Z900_14
bdc76f
-	j       .L_Z900_3
bdc76f
-.L_Z900_18:
bdc76f
+	BRCTG   %r3,.L_Z900_G5_14
bdc76f
+	j       .L_Z900_G5_3
bdc76f
+.L_Z900_G5_18:
bdc76f
 	mvc     1(1,%r1),0(%r1)
bdc76f
 #ifdef USE_MULTIARCH
bdc76f
 END(__memset_default)
bdc76f
@@ -62,3 +89,9 @@ END(__memset_default)
bdc76f
 END(memset)
bdc76f
 libc_hidden_builtin_def (memset)
bdc76f
 #endif
bdc76f
+
bdc76f
+#undef LTGR
bdc76f
+#undef CGHI
bdc76f
+#undef LGR
bdc76f
+#undef AGHI
bdc76f
+#undef BRCTG
bdc76f
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bdc76f
index c893ebc5659fd4ae..93ad21bfa2686ee5 100644
bdc76f
--- a/sysdeps/s390/multiarch/Makefile
bdc76f
+++ b/sysdeps/s390/multiarch/Makefile
bdc76f
@@ -19,7 +19,8 @@ sysdep_routines += strlen strlen-vx strlen-c \
bdc76f
 		   rawmemchr rawmemchr-vx rawmemchr-c \
bdc76f
 		   memccpy memccpy-vx memccpy-c \
bdc76f
 		   memrchr memrchr-vx memrchr-c \
bdc76f
-		   mempcpy
bdc76f
+		   mempcpy \
bdc76f
+		   memset memset-s390x
bdc76f
 endif
bdc76f
 
bdc76f
 ifeq ($(subdir),wcsmbs)
bdc76f
diff --git a/sysdeps/s390/s390-64/multiarch/memset-s390x.S b/sysdeps/s390/multiarch/memset-s390x.S
bdc76f
similarity index 90%
bdc76f
rename from sysdeps/s390/s390-64/multiarch/memset-s390x.S
bdc76f
rename to sysdeps/s390/multiarch/memset-s390x.S
bdc76f
index 0c5aaef34fdf47e6..aca3ac3fda1dd228 100644
bdc76f
--- a/sysdeps/s390/s390-64/multiarch/memset-s390x.S
bdc76f
+++ b/sysdeps/s390/multiarch/memset-s390x.S
bdc76f
@@ -1,4 +1,4 @@
bdc76f
-/* Set a block of memory to some byte value.  64 bit S/390 version.
bdc76f
+/* Set a block of memory to some byte value.  31/64 bit S/390 version.
bdc76f
    Copyright (C) 2012-2018 Free Software Foundation, Inc.
bdc76f
    This file is part of the GNU C Library.
bdc76f
 
bdc76f
@@ -31,6 +31,10 @@
bdc76f
 
bdc76f
 ENTRY(__memset_z196)
bdc76f
 	.machine "z196"
bdc76f
+	.machinemode "zarch_nohighgprs"
bdc76f
+# if !defined __s390x__
bdc76f
+	llgfr	%r4,%r4
bdc76f
+# endif /* !defined __s390x__  */
bdc76f
 	ltgr    %r4,%r4
bdc76f
 	je      .L_Z196_4
bdc76f
 	stc     %r3,0(%r2)
bdc76f
@@ -61,6 +65,10 @@ END(__memset_z196)
bdc76f
 
bdc76f
 ENTRY(__memset_z10)
bdc76f
 	.machine "z10"
bdc76f
+	.machinemode "zarch_nohighgprs"
bdc76f
+# if !defined __s390x__
bdc76f
+	llgfr	%r4,%r4
bdc76f
+# endif /* !defined __s390x__  */
bdc76f
 	cgije   %r4,0,.L_Z10_4
bdc76f
 	stc     %r3,0(%r2)
bdc76f
 	lgr     %r1,%r2
bdc76f
diff --git a/sysdeps/s390/s390-32/multiarch/memset.c b/sysdeps/s390/multiarch/memset.c
bdc76f
similarity index 100%
bdc76f
rename from sysdeps/s390/s390-32/multiarch/memset.c
bdc76f
rename to sysdeps/s390/multiarch/memset.c
bdc76f
diff --git a/sysdeps/s390/s390-32/memset.S b/sysdeps/s390/s390-32/memset.S
bdc76f
deleted file mode 100644
bdc76f
index 57f08e1cae1abd01..0000000000000000
bdc76f
--- a/sysdeps/s390/s390-32/memset.S
bdc76f
+++ /dev/null
bdc76f
@@ -1,65 +0,0 @@
bdc76f
-/* Set a block of memory to some byte value.  For IBM S390
bdc76f
-   Copyright (C) 2012-2018 Free Software Foundation, Inc.
bdc76f
-   This file is part of the GNU C Library.
bdc76f
-
bdc76f
-   The GNU C Library is free software; you can redistribute it and/or
bdc76f
-   modify it under the terms of the GNU Lesser General Public
bdc76f
-   License as published by the Free Software Foundation; either
bdc76f
-   version 2.1 of the License, or (at your option) any later version.
bdc76f
-
bdc76f
-   The GNU C Library is distributed in the hope that it will be useful,
bdc76f
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
bdc76f
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bdc76f
-   Lesser General Public License for more details.
bdc76f
-
bdc76f
-   You should have received a copy of the GNU Lesser General Public
bdc76f
-   License along with the GNU C Library; if not, see
bdc76f
-   <http://www.gnu.org/licenses/>.  */
bdc76f
-
bdc76f
-
bdc76f
-#include "sysdep.h"
bdc76f
-#include "asm-syntax.h"
bdc76f
-
bdc76f
-/* INPUT PARAMETERS
bdc76f
-     %r2 = address to memory area
bdc76f
-     %r3 = byte to fill memory with
bdc76f
-     %r4 = number of bytes to fill.  */
bdc76f
-
bdc76f
-       .text
bdc76f
-
bdc76f
-#ifdef USE_MULTIARCH
bdc76f
-ENTRY(__memset_default)
bdc76f
-#else
bdc76f
-ENTRY(memset)
bdc76f
-#endif
bdc76f
-	.machine "g5"
bdc76f
-	basr    %r5,0
bdc76f
-.L_G5_19:
bdc76f
-	ltr     %r4,%r4
bdc76f
-	je      .L_G5_4
bdc76f
-	stc     %r3,0(%r2)
bdc76f
-	chi     %r4,1
bdc76f
-	lr      %r1,%r2
bdc76f
-	je      .L_G5_4
bdc76f
-	ahi     %r4,-2
bdc76f
-	lr      %r3,%r4
bdc76f
-	srl     %r3,8
bdc76f
-	ltr     %r3,%r3
bdc76f
-	jne     .L_G5_14
bdc76f
-	ex      %r4,.L_G5_20-.L_G5_19(%r5)
bdc76f
-.L_G5_4:
bdc76f
-	br      %r14
bdc76f
-.L_G5_14:
bdc76f
-	mvc     1(256,%r1),0(%r1)
bdc76f
-	la      %r1,256(%r1)
bdc76f
-	brct    %r3,.L_G5_14
bdc76f
-	ex      %r4,.L_G5_20-.L_G5_19(%r5)
bdc76f
-	j       .L_G5_4
bdc76f
-.L_G5_20:
bdc76f
-	mvc     1(1,%r1),0(%r1)
bdc76f
-#ifdef USE_MULTIARCH
bdc76f
-END(__memset_default)
bdc76f
-#else
bdc76f
-END(memset)
bdc76f
-libc_hidden_builtin_def (memset)
bdc76f
-#endif
bdc76f
diff --git a/sysdeps/s390/s390-32/multiarch/Makefile b/sysdeps/s390/s390-32/multiarch/Makefile
bdc76f
index f8aee14bbd4736ad..4b11e28656ac19ab 100644
bdc76f
--- a/sysdeps/s390/s390-32/multiarch/Makefile
bdc76f
+++ b/sysdeps/s390/s390-32/multiarch/Makefile
bdc76f
@@ -1,4 +1,3 @@
bdc76f
 ifeq ($(subdir),string)
bdc76f
-sysdep_routines += memset memset-s390 memcpy memcpy-s390 \
bdc76f
-		   memcmp memcmp-s390
bdc76f
+sysdep_routines += memcpy memcpy-s390 memcmp memcmp-s390
bdc76f
 endif
bdc76f
diff --git a/sysdeps/s390/s390-32/multiarch/memset-s390.S b/sysdeps/s390/s390-32/multiarch/memset-s390.S
bdc76f
deleted file mode 100644
bdc76f
index b092073d6bef6b56..0000000000000000
bdc76f
--- a/sysdeps/s390/s390-32/multiarch/memset-s390.S
bdc76f
+++ /dev/null
bdc76f
@@ -1,116 +0,0 @@
bdc76f
-/* Set a block of memory to some byte value.  32 bit S/390 version.
bdc76f
-   Copyright (C) 2012-2018 Free Software Foundation, Inc.
bdc76f
-   This file is part of the GNU C Library.
bdc76f
-
bdc76f
-   The GNU C Library is free software; you can redistribute it and/or
bdc76f
-   modify it under the terms of the GNU Lesser General Public
bdc76f
-   License as published by the Free Software Foundation; either
bdc76f
-   version 2.1 of the License, or (at your option) any later version.
bdc76f
-
bdc76f
-   The GNU C Library is distributed in the hope that it will be useful,
bdc76f
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
bdc76f
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bdc76f
-   Lesser General Public License for more details.
bdc76f
-
bdc76f
-   You should have received a copy of the GNU Lesser General Public
bdc76f
-   License along with the GNU C Library; if not, see
bdc76f
-   <http://www.gnu.org/licenses/>.  */
bdc76f
-
bdc76f
-
bdc76f
-#include "sysdep.h"
bdc76f
-#include "asm-syntax.h"
bdc76f
-
bdc76f
-/* INPUT PARAMETERS
bdc76f
-     %r2 = address of memory area
bdc76f
-     %r3 = byte to fill memory with
bdc76f
-     %r4 = number of bytes to fill.  */
bdc76f
-
bdc76f
-       .text
bdc76f
-
bdc76f
-#if IS_IN (libc)
bdc76f
-
bdc76f
-ENTRY(__memset_z196)
bdc76f
-	.machine "z196"
bdc76f
-	.machinemode "zarch_nohighgprs"
bdc76f
-	llgfr   %r4,%r4
bdc76f
-	ltgr    %r4,%r4
bdc76f
-	je      .L_Z196_4
bdc76f
-	stc     %r3,0(%r2)
bdc76f
-	lr      %r1,%r2
bdc76f
-	cghi    %r4,1
bdc76f
-	je      .L_Z196_4
bdc76f
-	aghi    %r4,-2
bdc76f
-	srlg    %r5,%r4,8
bdc76f
-	ltgr    %r5,%r5
bdc76f
-	jne     .L_Z196_1
bdc76f
-.L_Z196_3:
bdc76f
-	exrl    %r4,.L_Z196_17
bdc76f
-.L_Z196_4:
bdc76f
-	br      %r14
bdc76f
-.L_Z196_1:
bdc76f
-	cgfi	%r5,1048576
bdc76f
-	jh	__memset_mvcle	   # Switch to mvcle for >256MB
bdc76f
-.L_Z196_2:
bdc76f
-	pfd     2,1024(%r1)
bdc76f
-	mvc     1(256,%r1),0(%r1)
bdc76f
-	aghi    %r5,-1
bdc76f
-	la      %r1,256(%r1)
bdc76f
-	jne     .L_Z196_2
bdc76f
-	j       .L_Z196_3
bdc76f
-.L_Z196_17:
bdc76f
-	mvc     1(1,%r1),0(%r1)
bdc76f
-END(__memset_z196)
bdc76f
-
bdc76f
-ENTRY(__memset_z10)
bdc76f
-	.machine "z10"
bdc76f
-	.machinemode "zarch_nohighgprs"
bdc76f
-	llgfr   %r4,%r4
bdc76f
-	cgije   %r4,0,.L_Z10_4
bdc76f
-	stc     %r3,0(%r2)
bdc76f
-	lr      %r1,%r2
bdc76f
-	cgije   %r4,1,.L_Z10_4
bdc76f
-	aghi    %r4,-2
bdc76f
-	srlg    %r5,%r4,8
bdc76f
-	cgijlh  %r5,0,.L_Z10_15
bdc76f
-.L_Z10_3:
bdc76f
-	exrl    %r4,.L_Z10_18
bdc76f
-.L_Z10_4:
bdc76f
-	br      %r14
bdc76f
-.L_Z10_15:
bdc76f
-	cgfi	%r5,163840          # Switch to mvcle for >40MB
bdc76f
-	jh	__memset_mvcle
bdc76f
-.L_Z10_14:
bdc76f
-	pfd     2,1024(%r1)
bdc76f
-	mvc     1(256,%r1),0(%r1)
bdc76f
-	la      %r1,256(%r1)
bdc76f
-	brctg   %r5,.L_Z10_14
bdc76f
-	j       .L_Z10_3
bdc76f
-.L_Z10_18:
bdc76f
-	mvc     1(1,%r1),0(%r1)
bdc76f
-END(__memset_z10)
bdc76f
-
bdc76f
-ENTRY(__memset_mvcle)
bdc76f
-	ahi	%r4,2               # take back the change done by the caller
bdc76f
-	lr      %r0,%r2             # save source address
bdc76f
-	lr      %r1,%r3             # move pad byte to R1
bdc76f
-	lr      %r3,%r4
bdc76f
-	sr      %r4,%r4             # no source for MVCLE, only a pad byte
bdc76f
-	sr      %r5,%r5
bdc76f
-.L0:    mvcle   %r2,%r4,0(%r1)      # thats it, MVCLE is your friend
bdc76f
-	jo      .L0
bdc76f
-	lr      %r2,%r0             # return value is source address
bdc76f
-.L1:
bdc76f
-	br      %r14
bdc76f
-END(__memset_mvcle)
bdc76f
-
bdc76f
-#endif /* IS_IN (libc) */
bdc76f
-
bdc76f
-#include "../memset.S"
bdc76f
-
bdc76f
-#if !IS_IN (libc)
bdc76f
-.globl   memset
bdc76f
-.set     memset,__memset_default
bdc76f
-#elif defined SHARED && IS_IN (libc)
bdc76f
-.globl   __GI_memset
bdc76f
-.set     __GI_memset,__memset_default
bdc76f
-#endif
bdc76f
diff --git a/sysdeps/s390/s390-64/multiarch/Makefile b/sysdeps/s390/s390-64/multiarch/Makefile
bdc76f
index 91053b536420aabb..e4870c7ee177ad0d 100644
bdc76f
--- a/sysdeps/s390/s390-64/multiarch/Makefile
bdc76f
+++ b/sysdeps/s390/s390-64/multiarch/Makefile
bdc76f
@@ -1,4 +1,3 @@
bdc76f
 ifeq ($(subdir),string)
bdc76f
-sysdep_routines += memset memset-s390x memcpy memcpy-s390x \
bdc76f
-		   memcmp memcmp-s390x
bdc76f
+sysdep_routines += memcpy memcpy-s390x memcmp memcmp-s390x
bdc76f
 endif
bdc76f
diff --git a/sysdeps/s390/s390-64/multiarch/memset.c b/sysdeps/s390/s390-64/multiarch/memset.c
bdc76f
deleted file mode 100644
bdc76f
index 760b3e9df201b8b4..0000000000000000
bdc76f
--- a/sysdeps/s390/s390-64/multiarch/memset.c
bdc76f
+++ /dev/null
bdc76f
@@ -1,26 +0,0 @@
bdc76f
-/* Multiple versions of memset.
bdc76f
-   Copyright (C) 2015-2018 Free Software Foundation, Inc.
bdc76f
-   This file is part of the GNU C Library.
bdc76f
-
bdc76f
-   The GNU C Library is free software; you can redistribute it and/or
bdc76f
-   modify it under the terms of the GNU Lesser General Public
bdc76f
-   License as published by the Free Software Foundation; either
bdc76f
-   version 2.1 of the License, or (at your option) any later version.
bdc76f
-
bdc76f
-   The GNU C Library is distributed in the hope that it will be useful,
bdc76f
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
bdc76f
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bdc76f
-   Lesser General Public License for more details.
bdc76f
-
bdc76f
-   You should have received a copy of the GNU Lesser General Public
bdc76f
-   License along with the GNU C Library; if not, see
bdc76f
-   <http://www.gnu.org/licenses/>.  */
bdc76f
-
bdc76f
-#if IS_IN (libc)
bdc76f
-# define memset __redirect_memset
bdc76f
-# include <string.h>
bdc76f
-# undef memset
bdc76f
-# include <ifunc-resolve.h>
bdc76f
-
bdc76f
-s390_libc_ifunc (__redirect_memset, __memset, memset)
bdc76f
-#endif