bdc76f
commit 6c6b8c747096d74b900e2711b9b0d463677f6d31
bdc76f
Author: Stefan Liebler <stli@linux.ibm.com>
bdc76f
Date:   Tue Dec 18 13:57:05 2018 +0100
bdc76f
bdc76f
    S390: Unify 31/64bit memcmp.
bdc76f
    
bdc76f
    The implementation of memcmp for s390-32 (31bit) and
bdc76f
    s390-64 (64bit) is nearly the same.
bdc76f
    This patch unifies it for maintability reasons.
bdc76f
    
bdc76f
    __memcmp_z10 and __memcmp_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
    __memcmp_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/memcmp.S: Move to ...
bdc76f
            * sysdeps/s390/memcmp.S: ... here.
bdc76f
            Adjust to be usable for 31/64bit.
bdc76f
            * sysdeps/s390/s390-32/memcmp.S: Delete File.
bdc76f
            * sysdeps/s390/multiarch/Makefile (sysdep_routines): Add memcmp.
bdc76f
            * sysdeps/s390/s390-32/multiarch/Makefile (sysdep_routines):
bdc76f
            Remove memcmp.
bdc76f
            * sysdeps/s390/s390-64/multiarch/Makefile: Likewise.
bdc76f
            * sysdeps/s390/s390-64/multiarch/memcmp-s390x.S: Move to ...
bdc76f
            * sysdeps/s390/multiarch/memcmp-s390x.S: ... here.
bdc76f
            Adjust to be usable for 31/64bit.
bdc76f
            * sysdeps/s390/s390-32/multiarch/memcmp-s390.S: Delete File.
bdc76f
            * sysdeps/s390/s390-64/multiarch/memcmp.c: Move to ...
bdc76f
            * sysdeps/s390/multiarch/memcmp.c: ... here.
bdc76f
            * sysdeps/s390/s390-32/multiarch/memcmp.c: Delete File.
bdc76f
bdc76f
diff --git a/sysdeps/s390/s390-64/memcmp.S b/sysdeps/s390/memcmp.S
bdc76f
similarity index 60%
bdc76f
rename from sysdeps/s390/s390-64/memcmp.S
bdc76f
rename to sysdeps/s390/memcmp.S
bdc76f
index 005b19de45fcd883..751293a99e34f530 100644
bdc76f
--- a/sysdeps/s390/s390-64/memcmp.S
bdc76f
+++ b/sysdeps/s390/memcmp.S
bdc76f
@@ -1,4 +1,4 @@
bdc76f
-/* memcmp - compare two memory blocks.  64 bit S/390 version.
bdc76f
+/* memcmp - compare two memory blocks.  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
@@ -26,34 +26,62 @@
bdc76f
      %r4 = number of bytes to compare.  */
bdc76f
 
bdc76f
        .text
bdc76f
+#if defined __s390x__
bdc76f
+# define LTGR	ltgr
bdc76f
+# define AGHI	aghi
bdc76f
+# define BRCTG	brctg
bdc76f
+#else
bdc76f
+# define LTGR	ltr
bdc76f
+# define AGHI	ahi
bdc76f
+# define BRCTG	brct
bdc76f
+#endif /* ! defined __s390x__  */
bdc76f
+
bdc76f
 #ifdef USE_MULTIARCH
bdc76f
 ENTRY(__memcmp_default)
bdc76f
 #else
bdc76f
 ENTRY(memcmp)
bdc76f
 #endif
bdc76f
+#if defined __s390x__
bdc76f
 	.machine "z900"
bdc76f
-	ltgr    %r4,%r4
bdc76f
-	je      .L_Z900_4
bdc76f
-	aghi    %r4,-1
bdc76f
+#else
bdc76f
+	.machine "g5"
bdc76f
+	basr    %r5,0
bdc76f
+.L_Z900_G5_16:
bdc76f
+# define Z900_G5_EX_D .L_Z900_G5_15-.L_Z900_G5_16
bdc76f
+#endif /* ! defined __s390x__  */
bdc76f
+	LTGR    %r4,%r4
bdc76f
+	je      .L_Z900_G5_4
bdc76f
+	AGHI    %r4,-1
bdc76f
+#if defined __s390x__
bdc76f
 	srlg    %r1,%r4,8
bdc76f
-	ltgr    %r1,%r1
bdc76f
-	jne     .L_Z900_12
bdc76f
-.L_Z900_3:
bdc76f
-	larl    %r1,.L_Z900_15
bdc76f
-	ex      %r4,0(%r1)
bdc76f
-.L_Z900_4:
bdc76f
+	larl    %r5,.L_Z900_G5_15
bdc76f
+# define Z900_G5_EX_D 0
bdc76f
+#else
bdc76f
+	lr	%r1,%r4
bdc76f
+	srl	%r1,8
bdc76f
+#endif /* ! defined __s390x__  */
bdc76f
+	LTGR    %r1,%r1
bdc76f
+	jne     .L_Z900_G5_12
bdc76f
+.L_Z900_G5_3:
bdc76f
+	ex      %r4,Z900_G5_EX_D(%r5)
bdc76f
+.L_Z900_G5_4:
bdc76f
 	ipm     %r2
bdc76f
+#if defined __s390x__
bdc76f
 	sllg    %r2,%r2,34
bdc76f
 	srag    %r2,%r2,62
bdc76f
+#else
bdc76f
+	sll     %r2,2
bdc76f
+	sra     %r2,30
bdc76f
+#endif /* ! defined __s390x__  */
bdc76f
 	br      %r14
bdc76f
-.L_Z900_12:
bdc76f
+.L_Z900_G5_12:
bdc76f
 	clc     0(256,%r3),0(%r2)
bdc76f
-	jne     .L_Z900_4
bdc76f
+	jne     .L_Z900_G5_4
bdc76f
 	la      %r3,256(%r3)
bdc76f
 	la      %r2,256(%r2)
bdc76f
-	brctg   %r1,.L_Z900_12
bdc76f
-	j       .L_Z900_3
bdc76f
-.L_Z900_15:
bdc76f
+	BRCTG   %r1,.L_Z900_G5_12
bdc76f
+	j       .L_Z900_G5_3
bdc76f
+.L_Z900_G5_15:
bdc76f
 	clc     0(1,%r3),0(%r2)
bdc76f
 #ifdef USE_MULTIARCH
bdc76f
 END(__memcmp_default)
bdc76f
@@ -62,3 +90,7 @@ END(memcmp)
bdc76f
 libc_hidden_builtin_def (memcmp)
bdc76f
 weak_alias (memcmp, bcmp)
bdc76f
 #endif
bdc76f
+
bdc76f
+#undef LTGR
bdc76f
+#undef AGHI
bdc76f
+#undef BRCTG
bdc76f
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bdc76f
index c893ebc5659fd4ae..53dd8654d73677db 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
+		   memcmp memcmp-s390x
bdc76f
 endif
bdc76f
 
bdc76f
 ifeq ($(subdir),wcsmbs)
bdc76f
diff --git a/sysdeps/s390/s390-64/multiarch/memcmp-s390x.S b/sysdeps/s390/multiarch/memcmp-s390x.S
bdc76f
similarity index 89%
bdc76f
rename from sysdeps/s390/s390-64/multiarch/memcmp-s390x.S
bdc76f
rename to sysdeps/s390/multiarch/memcmp-s390x.S
bdc76f
index 35f9bf9cf72da503..6321737acec821ec 100644
bdc76f
--- a/sysdeps/s390/s390-64/multiarch/memcmp-s390x.S
bdc76f
+++ b/sysdeps/s390/multiarch/memcmp-s390x.S
bdc76f
@@ -1,4 +1,4 @@
bdc76f
-/* CPU specific memcmp implementations.  64 bit S/390 version.
bdc76f
+/* CPU specific memcmp implementations.  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(__memcmp_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
 	aghi    %r4,-1
bdc76f
@@ -64,6 +68,10 @@ END(__memcmp_z196)
bdc76f
 
bdc76f
 ENTRY(__memcmp_z10)
bdc76f
 	.machine "z10"
bdc76f
+	.machinemode "zarch_nohighgprs"
bdc76f
+# if !defined __s390x__
bdc76f
+	llgfr	%r4,%r4
bdc76f
+# endif /* !defined __s390x__  */
bdc76f
 	ltgr    %r4,%r4
bdc76f
 	je      .L_Z10_4
bdc76f
 	aghi    %r4,-1
bdc76f
diff --git a/sysdeps/s390/s390-32/multiarch/memcmp.c b/sysdeps/s390/multiarch/memcmp.c
bdc76f
similarity index 100%
bdc76f
rename from sysdeps/s390/s390-32/multiarch/memcmp.c
bdc76f
rename to sysdeps/s390/multiarch/memcmp.c
bdc76f
diff --git a/sysdeps/s390/s390-32/memcmp.S b/sysdeps/s390/s390-32/memcmp.S
bdc76f
deleted file mode 100644
bdc76f
index f9ad0bc745daf05f..0000000000000000
bdc76f
--- a/sysdeps/s390/s390-32/memcmp.S
bdc76f
+++ /dev/null
bdc76f
@@ -1,66 +0,0 @@
bdc76f
-/* memcmp - compare two memory blocks.  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 first memory area
bdc76f
-     %r3 = address of second memory area
bdc76f
-     %r4 = number of bytes to compare.  */
bdc76f
-
bdc76f
-       .text
bdc76f
-#ifdef USE_MULTIARCH
bdc76f
-ENTRY(__memcmp_default)
bdc76f
-#else
bdc76f
-ENTRY(memcmp)
bdc76f
-#endif
bdc76f
-	.machine "g5"
bdc76f
-	basr    %r5,0
bdc76f
-.L_G5_16:
bdc76f
-	ltr     %r4,%r4
bdc76f
-	je      .L_G5_4
bdc76f
-	ahi     %r4,-1
bdc76f
-	lr      %r1,%r4
bdc76f
-	srl     %r1,8
bdc76f
-	ltr     %r1,%r1
bdc76f
-	jne     .L_G5_12
bdc76f
-	ex      %r4,.L_G5_17-.L_G5_16(%r5)
bdc76f
-.L_G5_4:
bdc76f
-	ipm     %r2
bdc76f
-	sll     %r2,2
bdc76f
-	sra     %r2,30
bdc76f
-	br      %r14
bdc76f
-.L_G5_12:
bdc76f
-	clc     0(256,%r3),0(%r2)
bdc76f
-	jne     .L_G5_4
bdc76f
-	la      %r3,256(%r3)
bdc76f
-	la      %r2,256(%r2)
bdc76f
-	brct    %r1,.L_G5_12
bdc76f
-	ex      %r4,.L_G5_17-.L_G5_16(%r5)
bdc76f
-	j       .L_G5_4
bdc76f
-.L_G5_17:
bdc76f
-	clc     0(1,%r3),0(%r2)
bdc76f
-#ifdef USE_MULTIARCH
bdc76f
-END(__memcmp_default)
bdc76f
-#else
bdc76f
-END(memcmp)
bdc76f
-libc_hidden_builtin_def (memcmp)
bdc76f
-weak_alias(memcmp, bcmp)
bdc76f
-#endif
bdc76f
diff --git a/sysdeps/s390/s390-32/multiarch/Makefile b/sysdeps/s390/s390-32/multiarch/Makefile
bdc76f
index 4b11e28656ac19ab..82a7492eb8436479 100644
bdc76f
--- a/sysdeps/s390/s390-32/multiarch/Makefile
bdc76f
+++ b/sysdeps/s390/s390-32/multiarch/Makefile
bdc76f
@@ -1,3 +1,3 @@
bdc76f
 ifeq ($(subdir),string)
bdc76f
-sysdep_routines += memcpy memcpy-s390 memcmp memcmp-s390
bdc76f
+sysdep_routines += memcpy memcpy-s390
bdc76f
 endif
bdc76f
diff --git a/sysdeps/s390/s390-32/multiarch/memcmp-s390.S b/sysdeps/s390/s390-32/multiarch/memcmp-s390.S
bdc76f
deleted file mode 100644
bdc76f
index e53b508c98bebeba..0000000000000000
bdc76f
--- a/sysdeps/s390/s390-32/multiarch/memcmp-s390.S
bdc76f
+++ /dev/null
bdc76f
@@ -1,107 +0,0 @@
bdc76f
-/* CPU specific memcmp implementations.  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 first memory area
bdc76f
-     %r3 = address of second memory area
bdc76f
-     %r4 = number of bytes to compare.  */
bdc76f
-
bdc76f
-       .text
bdc76f
-
bdc76f
-#if IS_IN (libc)
bdc76f
-
bdc76f
-ENTRY(__memcmp_z196)
bdc76f
-	.machine "z196"
bdc76f
-	.machinemode "zarch_nohighgprs"
bdc76f
-	ltr     %r4,%r4
bdc76f
-	je      .L_Z196_4
bdc76f
-	ahi     %r4,-1
bdc76f
-	srlk    %r1,%r4,8
bdc76f
-	ltr     %r1,%r1
bdc76f
-	jne     .L_Z196_2
bdc76f
-.L_Z196_3:
bdc76f
-	exrl    %r4,.L_Z196_14
bdc76f
-.L_Z196_4:
bdc76f
-	ipm     %r2
bdc76f
-	sll     %r2,2
bdc76f
-	sra     %r2,30
bdc76f
-	br      %r14
bdc76f
-.L_Z196_17:
bdc76f
-	la      %r3,256(%r3)
bdc76f
-	la      %r2,256(%r2)
bdc76f
-	ahi     %r1,-1
bdc76f
-	je      .L_Z196_3
bdc76f
-.L_Z196_2:
bdc76f
-	pfd     1,512(%r3)
bdc76f
-	pfd     1,512(%r2)
bdc76f
-	clc     0(256,%r3),0(%r2)
bdc76f
-	je      .L_Z196_17
bdc76f
-	ipm     %r2
bdc76f
-	sll     %r2,2
bdc76f
-	sra     %r2,30
bdc76f
-	br      %r14
bdc76f
-.L_Z196_14:
bdc76f
-	clc     0(1,%r3),0(%r2)
bdc76f
-END(__memcmp_z196)
bdc76f
-
bdc76f
-ENTRY(__memcmp_z10)
bdc76f
-	.machine "z10"
bdc76f
-	.machinemode "zarch_nohighgprs"
bdc76f
-	ltr     %r4,%r4
bdc76f
-	je      .L_Z10_4
bdc76f
-	ahi     %r4,-1
bdc76f
-	lr      %r1,%r4
bdc76f
-	srl     %r1,8
bdc76f
-	cijlh   %r1,0,.L_Z10_12
bdc76f
-.L_Z10_3:
bdc76f
-	exrl    %r4,.L_Z10_15
bdc76f
-.L_Z10_4:
bdc76f
-	ipm     %r2
bdc76f
-	sll     %r2,2
bdc76f
-	sra     %r2,30
bdc76f
-	br      %r14
bdc76f
-.L_Z10_12:
bdc76f
-	pfd     1,512(%r3)
bdc76f
-	pfd     1,512(%r2)
bdc76f
-	clc     0(256,%r3),0(%r2)
bdc76f
-	jne     .L_Z10_4
bdc76f
-	la      %r3,256(%r3)
bdc76f
-	la      %r2,256(%r2)
bdc76f
-	brct    %r1,.L_Z10_12
bdc76f
-	j       .L_Z10_3
bdc76f
-.L_Z10_15:
bdc76f
-	clc     0(1,%r3),0(%r2)
bdc76f
-END(__memcmp_z10)
bdc76f
-
bdc76f
-#endif /* IS_IN (libc) */
bdc76f
-
bdc76f
-#include "../memcmp.S"
bdc76f
-
bdc76f
-#if !IS_IN (libc)
bdc76f
-.globl   memcmp
bdc76f
-.set     memcmp,__memcmp_default
bdc76f
-.weak    bcmp
bdc76f
-.set	 bcmp,__memcmp_default
bdc76f
-#elif defined SHARED && IS_IN (libc)
bdc76f
-.globl   __GI_memcmp
bdc76f
-.set     __GI_memcmp,__memcmp_default
bdc76f
-#endif
bdc76f
diff --git a/sysdeps/s390/s390-64/multiarch/Makefile b/sysdeps/s390/s390-64/multiarch/Makefile
bdc76f
index e4870c7ee177ad0d..8a043e3327a1527a 100644
bdc76f
--- a/sysdeps/s390/s390-64/multiarch/Makefile
bdc76f
+++ b/sysdeps/s390/s390-64/multiarch/Makefile
bdc76f
@@ -1,3 +1,3 @@
bdc76f
 ifeq ($(subdir),string)
bdc76f
-sysdep_routines += memcpy memcpy-s390x memcmp memcmp-s390x
bdc76f
+sysdep_routines += memcpy memcpy-s390x
bdc76f
 endif
bdc76f
diff --git a/sysdeps/s390/s390-64/multiarch/memcmp.c b/sysdeps/s390/s390-64/multiarch/memcmp.c
bdc76f
deleted file mode 100644
bdc76f
index 1e6f31806e172d7d..0000000000000000
bdc76f
--- a/sysdeps/s390/s390-64/multiarch/memcmp.c
bdc76f
+++ /dev/null
bdc76f
@@ -1,27 +0,0 @@
bdc76f
-/* Multiple versions of memcmp.
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 memcmp __redirect_memcmp
bdc76f
-# include <string.h>
bdc76f
-# undef memcmp
bdc76f
-# include <ifunc-resolve.h>
bdc76f
-
bdc76f
-s390_libc_ifunc (__redirect_memcmp, __memcmp, memcmp)
bdc76f
-weak_alias (memcmp, bcmp);
bdc76f
-#endif