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