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