d8307d
commit 07be392807ac78330da90f01408aa7e042a97a88
d8307d
Author: Stefan Liebler <stli@linux.ibm.com>
d8307d
Date:   Tue Dec 18 13:57:05 2018 +0100
d8307d
d8307d
    S390: Implement bzero with memset.
d8307d
    
d8307d
    This patch removes the bzero s390 implementation with mvcle and
d8307d
    adds entry points for bzero in memset ifunc variants.
d8307d
    Therefore an ifunc resolver is implemented for bzero, too.
d8307d
    
d8307d
    ChangeLog:
d8307d
    
d8307d
            * sysdeps/s390/s390-32/bzero.S: Delete file.
d8307d
            * sysdeps/s390/s390-64/bzero.S: Likewise.
d8307d
            * sysdeps/s390/Makefile (sysdep_routines): Add bzero.
d8307d
            * sysdeps/s390/bzero.c: New file.
d8307d
            * sysdeps/s390/memset-z900.S: Add bzero entry points.
d8307d
            * sysdeps/s390/ifunc-memset.h: Add bzero function macros.
d8307d
            * sysdeps/s390/multiarch/ifunc-impl-list.c
d8307d
            (__libc_ifunc_impl_list): Add bzero ifunc variants.
d8307d
d8307d
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
d8307d
index 360838e172f4ca37..e40e5bd982e54d89 100644
d8307d
--- a/sysdeps/s390/Makefile
d8307d
+++ b/sysdeps/s390/Makefile
d8307d
@@ -31,5 +31,5 @@ sysdeps-gconv-modules = ../sysdeps/s390/gconv-modules
d8307d
 endif
d8307d
 
d8307d
 ifeq ($(subdir),string)
d8307d
-sysdep_routines += memset memset-z900
d8307d
+sysdep_routines += bzero memset memset-z900
d8307d
 endif
d8307d
diff --git a/sysdeps/s390/s390-32/bzero.S b/sysdeps/s390/bzero.c
d8307d
similarity index 52%
d8307d
rename from sysdeps/s390/s390-32/bzero.S
d8307d
rename to sysdeps/s390/bzero.c
d8307d
index 897aa2154a861b7f..9f8d95781bf2fb68 100644
d8307d
--- a/sysdeps/s390/s390-32/bzero.S
d8307d
+++ b/sysdeps/s390/bzero.c
d8307d
@@ -1,7 +1,6 @@
d8307d
-/* bzero -- set a block of memory to zero.  IBM S390 version
d8307d
+/* Multiple versions of bzero.
d8307d
+   Copyright (C) 2018 Free Software Foundation, Inc.
d8307d
    This file is part of the GNU C Library.
d8307d
-   Copyright (C) 2000-2018 Free Software Foundation, Inc.
d8307d
-   Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
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
@@ -17,26 +16,32 @@
d8307d
    License along with the GNU C Library; if not, see
d8307d
    <http://www.gnu.org/licenses/>.  */
d8307d
 
d8307d
-/*
d8307d
- * R2 = address to memory area
d8307d
- * R3 = number of bytes to fill
d8307d
- */
d8307d
-
d8307d
-#include "sysdep.h"
d8307d
-#include "asm-syntax.h"
d8307d
-
d8307d
-	.text
d8307d
-ENTRY(__bzero)
d8307d
-	ltr     %r3,%r3
d8307d
-	jz      .L1
d8307d
-	sr      %r1,%r1             # set pad byte to zero
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
-.L1:    br      %r14
d8307d
-END(__bzero)
d8307d
-
d8307d
-#ifndef NO_WEAK_ALIAS
d8307d
+#include <ifunc-memset.h>
d8307d
+#if HAVE_MEMSET_IFUNC
d8307d
+# include <string.h>
d8307d
+# include <ifunc-resolve.h>
d8307d
+
d8307d
+# if HAVE_MEMSET_Z900_G5
d8307d
+extern __typeof (__bzero) BZERO_Z900_G5 attribute_hidden;
d8307d
+# endif
d8307d
+
d8307d
+# if HAVE_MEMSET_Z10
d8307d
+extern __typeof (__bzero) BZERO_Z10 attribute_hidden;
d8307d
+# endif
d8307d
+
d8307d
+# if HAVE_MEMSET_Z196
d8307d
+extern __typeof (__bzero) BZERO_Z196 attribute_hidden;
d8307d
+# endif
d8307d
+
d8307d
+s390_libc_ifunc_expr (__bzero, __bzero,
d8307d
+		      ({
d8307d
+			s390_libc_ifunc_init ();
d8307d
+			(HAVE_MEMSET_Z196 && S390_IS_Z196 (stfle_bits))
d8307d
+			  ? BZERO_Z196
d8307d
+			  : (HAVE_MEMSET_Z10 && S390_IS_Z10 (stfle_bits))
d8307d
+			  ? BZERO_Z10
d8307d
+			  : BZERO_DEFAULT;
d8307d
+		      })
d8307d
+		      )
d8307d
 weak_alias (__bzero, bzero)
d8307d
 #endif
d8307d
diff --git a/sysdeps/s390/ifunc-memset.h b/sysdeps/s390/ifunc-memset.h
d8307d
index 9a13b1001fed9979..32bc155f7e79fa26 100644
d8307d
--- a/sysdeps/s390/ifunc-memset.h
d8307d
+++ b/sysdeps/s390/ifunc-memset.h
d8307d
@@ -25,16 +25,19 @@
d8307d
 
d8307d
 #if defined HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
d8307d
 # define MEMSET_DEFAULT		MEMSET_Z196
d8307d
+# define BZERO_DEFAULT		BZERO_Z196
d8307d
 # define HAVE_MEMSET_Z900_G5	0
d8307d
 # define HAVE_MEMSET_Z10	0
d8307d
 # define HAVE_MEMSET_Z196	1
d8307d
 #elif defined HAVE_S390_MIN_Z10_ZARCH_ASM_SUPPORT
d8307d
 # define MEMSET_DEFAULT		MEMSET_Z10
d8307d
+# define BZERO_DEFAULT		BZERO_Z10
d8307d
 # define HAVE_MEMSET_Z900_G5	0
d8307d
 # define HAVE_MEMSET_Z10	1
d8307d
 # define HAVE_MEMSET_Z196	HAVE_MEMSET_IFUNC
d8307d
 #else
d8307d
 # define MEMSET_DEFAULT		MEMSET_Z900_G5
d8307d
+# define BZERO_DEFAULT		BZERO_Z900_G5
d8307d
 # define HAVE_MEMSET_Z900_G5	1
d8307d
 # define HAVE_MEMSET_Z10	HAVE_MEMSET_IFUNC
d8307d
 # define HAVE_MEMSET_Z196	HAVE_MEMSET_IFUNC
d8307d
@@ -48,18 +51,24 @@
d8307d
 
d8307d
 #if HAVE_MEMSET_Z900_G5
d8307d
 # define MEMSET_Z900_G5		__memset_default
d8307d
+# define BZERO_Z900_G5		__bzero_default
d8307d
 #else
d8307d
 # define MEMSET_Z900_G5		NULL
d8307d
+# define BZERO_Z900_G5		NULL
d8307d
 #endif
d8307d
 
d8307d
 #if HAVE_MEMSET_Z10
d8307d
 # define MEMSET_Z10		__memset_z10
d8307d
+# define BZERO_Z10		__bzero_z10
d8307d
 #else
d8307d
 # define MEMSET_Z10		NULL
d8307d
+# define BZERO_Z10		NULL
d8307d
 #endif
d8307d
 
d8307d
 #if HAVE_MEMSET_Z196
d8307d
 # define MEMSET_Z196		__memset_z196
d8307d
+# define BZERO_Z196		__bzero_z196
d8307d
 #else
d8307d
 # define MEMSET_Z196		NULL
d8307d
+# define BZERO_Z196		NULL
d8307d
 #endif
d8307d
diff --git a/sysdeps/s390/memset-z900.S b/sysdeps/s390/memset-z900.S
d8307d
index eaf13402bd3e251d..bfc659ae0b029eb4 100644
d8307d
--- a/sysdeps/s390/memset-z900.S
d8307d
+++ b/sysdeps/s390/memset-z900.S
d8307d
@@ -22,10 +22,14 @@
d8307d
 #include "asm-syntax.h"
d8307d
 #include <ifunc-memset.h>
d8307d
 
d8307d
-/* INPUT PARAMETERS
d8307d
+/* INPUT PARAMETERS - MEMSET
d8307d
      %r2 = address of memory area
d8307d
      %r3 = byte to fill memory with
d8307d
-     %r4 = number of bytes to fill.  */
d8307d
+     %r4 = number of bytes to fill.
d8307d
+
d8307d
+   INPUT PARAMETERS - BZERO
d8307d
+     %r2 = address of memory area
d8307d
+     %r3 = number of bytes to fill.  */
d8307d
 
d8307d
        .text
d8307d
 
d8307d
@@ -44,7 +48,14 @@
d8307d
 #  define BRCTG	brct
d8307d
 # endif /* ! defined __s390x__  */
d8307d
 
d8307d
+ENTRY(BZERO_Z900_G5)
d8307d
+	LGR	%r4,%r3
d8307d
+	xr	%r3,%r3
d8307d
+	j	.L_Z900_G5_start
d8307d
+END(BZERO_Z900_G5)
d8307d
+
d8307d
 ENTRY(MEMSET_Z900_G5)
d8307d
+.L_Z900_G5_start:
d8307d
 #if defined __s390x__
d8307d
 	.machine "z900"
d8307d
 #else
d8307d
@@ -90,7 +101,16 @@ END(MEMSET_Z900_G5)
d8307d
 #endif /*  HAVE_MEMSET_Z900_G5  */
d8307d
 
d8307d
 #if HAVE_MEMSET_Z10
d8307d
+ENTRY(BZERO_Z10)
d8307d
+	.machine "z10"
d8307d
+	.machinemode "zarch_nohighgprs"
d8307d
+	lgr	%r4,%r3
d8307d
+	xr	%r3,%r3
d8307d
+	j	.L_Z10_start
d8307d
+END(BZERO_Z10)
d8307d
+
d8307d
 ENTRY(MEMSET_Z10)
d8307d
+.L_Z10_start:
d8307d
 	.machine "z10"
d8307d
 	.machinemode "zarch_nohighgprs"
d8307d
 # if !defined __s390x__
d8307d
@@ -122,7 +142,16 @@ END(MEMSET_Z10)
d8307d
 #endif /* HAVE_MEMSET_Z10  */
d8307d
 
d8307d
 #if HAVE_MEMSET_Z196
d8307d
+ENTRY(BZERO_Z196)
d8307d
+	.machine "z196"
d8307d
+	.machinemode "zarch_nohighgprs"
d8307d
+	lgr	%r4,%r3
d8307d
+	xr	%r3,%r3
d8307d
+	j	.L_Z196_start
d8307d
+END(BZERO_Z196)
d8307d
+
d8307d
 ENTRY(MEMSET_Z196)
d8307d
+.L_Z196_start:
d8307d
 	.machine "z196"
d8307d
 	.machinemode "zarch_nohighgprs"
d8307d
 # if !defined __s390x__
d8307d
@@ -177,6 +206,10 @@ END(__memset_mvcle)
d8307d
 /* If we don't use ifunc, define an alias for memset here.
d8307d
    Otherwise see sysdeps/s390/memset.c.  */
d8307d
 strong_alias (MEMSET_DEFAULT, memset)
d8307d
+/* Same for bzero.  If ifunc is used, see
d8307d
+   sysdeps/s390/bzero.c.  */
d8307d
+strong_alias (BZERO_DEFAULT, __bzero)
d8307d
+weak_alias (__bzero, bzero)
d8307d
 #endif
d8307d
 
d8307d
 #if defined SHARED && IS_IN (libc)
d8307d
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
d8307d
index 2f671eac1f4f1ffd..253f36045b57cc3c 100644
d8307d
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
d8307d
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
d8307d
@@ -59,6 +59,21 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
d8307d
 # endif
d8307d
 # if HAVE_MEMSET_Z900_G5
d8307d
 	      IFUNC_IMPL_ADD (array, i, memset, 1, MEMSET_Z900_G5)
d8307d
+# endif
d8307d
+	      )
d8307d
+
d8307d
+  /* Note: bzero is implemented in memset.  */
d8307d
+  IFUNC_IMPL (i, name, bzero,
d8307d
+# if HAVE_MEMSET_Z196
d8307d
+	      IFUNC_IMPL_ADD (array, i, bzero,
d8307d
+			      S390_IS_Z196 (stfle_bits), BZERO_Z196)
d8307d
+# endif
d8307d
+# if HAVE_MEMSET_Z10
d8307d
+	      IFUNC_IMPL_ADD (array, i, bzero,
d8307d
+			      S390_IS_Z10 (stfle_bits), BZERO_Z10)
d8307d
+# endif
d8307d
+# if HAVE_MEMSET_Z900_G5
d8307d
+	      IFUNC_IMPL_ADD (array, i, bzero, 1, BZERO_Z900_G5)
d8307d
 # endif
d8307d
 	      )
d8307d
 #endif /* HAVE_MEMSET_IFUNC */
d8307d
diff --git a/sysdeps/s390/s390-64/bzero.S b/sysdeps/s390/s390-64/bzero.S
d8307d
deleted file mode 100644
d8307d
index b3216652985cc239..0000000000000000
d8307d
--- a/sysdeps/s390/s390-64/bzero.S
d8307d
+++ /dev/null
d8307d
@@ -1,41 +0,0 @@
d8307d
-/* bzero -- set a block of memory to zero.  64 bit S/390 version.
d8307d
-   This file is part of the GNU C Library.
d8307d
-   Copyright (C) 2001-2018 Free Software Foundation, Inc.
d8307d
-   Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
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
-/* INPUT PARAMETERS
d8307d
-     %r2 = address of memory area
d8307d
-     %r3 = number of bytes to fill.  */
d8307d
-
d8307d
-#include "sysdep.h"
d8307d
-#include "asm-syntax.h"
d8307d
-
d8307d
-	.text
d8307d
-ENTRY(__bzero)
d8307d
-	ltgr	%r3,%r3
d8307d
-	jz	.L1
d8307d
-	sgr	%r1,%r1		    # set pad byte to zero
d8307d
-	sgr	%r4,%r4		    # no source for MVCLE, only a pad byte
d8307d
-	sgr	%r5,%r5
d8307d
-.L0:	mvcle	%r2,%r4,0(%r1)	    # thats it, MVCLE is your friend
d8307d
-	jo	.L0
d8307d
-.L1:	br	%r14
d8307d
-END(__bzero)
d8307d
-
d8307d
-#ifndef NO_WEAK_ALIAS
d8307d
-weak_alias (__bzero, bzero)
d8307d
-#endif