arrfab / rpms / glibc

Forked from rpms/glibc 4 years ago
Clone

Blame SOURCES/glibc-rh1268008-29.patch

147e83
From f34499b3a506359f84fcb63a125e44d4a8e4ee68 Mon Sep 17 00:00:00 2001
147e83
From: Stefan Liebler <stli@linux.vnet.ibm.com>
147e83
Date: Thu, 8 Oct 2015 13:23:50 +0200
147e83
Subject: [PATCH 29/30] S390: Optimize wmemcmp.
147e83
147e83
upstream-commit-id: f21216015b7395c535abc01b9585a1ae3ceaa132
147e83
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00086.html
147e83
147e83
This patch provides optimized version of wmemcmp with the z13 vector
147e83
instructions.
147e83
147e83
ChangeLog:
147e83
147e83
	* sysdeps/s390/multiarch/wmemcmp-c.c: New File.
147e83
	* sysdeps/s390/multiarch/wmemcmp-vx.S: Likewise.
147e83
	* sysdeps/s390/multiarch/wmemcmp.c: Likewise.
147e83
	* sysdeps/s390/multiarch/Makefile
147e83
	(sysdep_routines): Add wmemcmp functions.
147e83
	* sysdeps/s390/multiarch/ifunc-impl-list-common.c
147e83
	(__libc_ifunc_impl_list_common): Add ifunc test for wmemcmp.
147e83
	* benchtests/bench-wmemcmp.c: New File.
147e83
	* benchtests/Makefile (wcsmbs-bench): Add wmemcmp.
147e83
---
147e83
 benchtests/Makefile                      |   2 +-
147e83
 benchtests/bench-wmemcmp.c               |  20 +++++
147e83
 sysdeps/s390/multiarch/Makefile          |   3 +-
147e83
 sysdeps/s390/multiarch/ifunc-impl-list.c |   2 +
147e83
 sysdeps/s390/multiarch/wmemcmp-c.c       |  26 ++++++
147e83
 sysdeps/s390/multiarch/wmemcmp-vx.S      | 149 +++++++++++++++++++++++++++++++
147e83
 sysdeps/s390/multiarch/wmemcmp.c         |  27 ++++++
147e83
 7 files changed, 227 insertions(+), 2 deletions(-)
147e83
 create mode 100644 benchtests/bench-wmemcmp.c
147e83
 create mode 100644 sysdeps/s390/multiarch/wmemcmp-c.c
147e83
 create mode 100644 sysdeps/s390/multiarch/wmemcmp-vx.S
147e83
 create mode 100644 sysdeps/s390/multiarch/wmemcmp.c
147e83
147e83
diff --git a/benchtests/Makefile b/benchtests/Makefile
147e83
index b5edfdd..911b6df 100644
147e83
--- a/benchtests/Makefile
147e83
+++ b/benchtests/Makefile
147e83
@@ -40,7 +40,7 @@ string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
147e83
 		strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
147e83
 wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \
147e83
 		wcsncmp wcsncmp wcschr wcschrnul wcsrchr wcsspn wcspbrk wcscspn \
147e83
-		wmemchr wmemset
147e83
+		wmemchr wmemset wmemcmp
147e83
 string-bench-all := $(string-bench) ${wcsmbs-bench}
147e83
 
147e83
 stdlib-bench := strtod
147e83
diff --git a/benchtests/bench-wmemcmp.c b/benchtests/bench-wmemcmp.c
147e83
new file mode 100644
147e83
index 0000000..8b33f89
147e83
--- /dev/null
147e83
+++ b/benchtests/bench-wmemcmp.c
147e83
@@ -0,0 +1,20 @@
147e83
+/* Measure wmemcmp functions.
147e83
+   Copyright (C) 2015 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#define WIDE 1
147e83
+#include "bench-memcmp.c"
147e83
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
147e83
index eac88e0..929a545 100644
147e83
--- a/sysdeps/s390/multiarch/Makefile
147e83
+++ b/sysdeps/s390/multiarch/Makefile
147e83
@@ -38,5 +38,6 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \
147e83
 		   wcspbrk wcspbrk-vx wcspbrk-c \
147e83
 		   wcscspn wcscspn-vx wcscspn-c \
147e83
 		   wmemchr wmemchr-vx wmemchr-c \
147e83
-		   wmemset wmemset-vx wmemset-c
147e83
+		   wmemset wmemset-vx wmemset-c \
147e83
+		   wmemcmp wmemcmp-vx wmemcmp-c
147e83
 endif
147e83
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
147e83
index 44d534b..5ea258b 100644
147e83
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
147e83
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
147e83
@@ -135,6 +135,8 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
147e83
 
147e83
   IFUNC_VX_IMPL (wmemset);
147e83
 
147e83
+  IFUNC_VX_IMPL (wmemcmp);
147e83
+
147e83
 #endif /* HAVE_S390_VX_ASM_SUPPORT */
147e83
 
147e83
   return i;
147e83
diff --git a/sysdeps/s390/multiarch/wmemcmp-c.c b/sysdeps/s390/multiarch/wmemcmp-c.c
147e83
new file mode 100644
147e83
index 0000000..b43e5d4
147e83
--- /dev/null
147e83
+++ b/sysdeps/s390/multiarch/wmemcmp-c.c
147e83
@@ -0,0 +1,26 @@
147e83
+/* Default wmemcmp implementation for S/390.
147e83
+   Copyright (C) 2015 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
147e83
+# define WMEMCMP  __wmemcmp_c
147e83
+
147e83
+# include <wchar.h>
147e83
+extern __typeof (wmemcmp) __wmemcmp_c;
147e83
+
147e83
+# include <wcsmbs/wmemcmp.c>
147e83
+#endif
147e83
diff --git a/sysdeps/s390/multiarch/wmemcmp-vx.S b/sysdeps/s390/multiarch/wmemcmp-vx.S
147e83
new file mode 100644
147e83
index 0000000..b509bef
147e83
--- /dev/null
147e83
+++ b/sysdeps/s390/multiarch/wmemcmp-vx.S
147e83
@@ -0,0 +1,149 @@
147e83
+/* Vector Optimized 32/64 bit S/390 version of wmemcmp.
147e83
+   Copyright (C) 2015 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
147e83
+
147e83
+# include "sysdep.h"
147e83
+# include "asm-syntax.h"
147e83
+
147e83
+	.text
147e83
+
147e83
+/* int wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n)
147e83
+   Compare at most n characters of two wchar_t-arrays.
147e83
+
147e83
+   Register usage:
147e83
+   -r0=tmp
147e83
+   -r1=number of blocks
147e83
+   -r2=s1
147e83
+   -r3=s2
147e83
+   -r4=n
147e83
+   -r5=current_len
147e83
+   -v16=part of s1
147e83
+   -v17=part of s2
147e83
+   -v18=index of unequal
147e83
+*/
147e83
+ENTRY(__wmemcmp_vx)
147e83
+	.machine "z13"
147e83
+	.machinemode "zarch_nohighgprs"
147e83
+
147e83
+# if !defined __s390x__
147e83
+	llgfr	%r4,%r4
147e83
+# endif /* !defined __s390x__ */
147e83
+	clgije	%r4,0,.Lend_equal /* Nothing to do if n == 0.  */
147e83
+
147e83
+	/* Check range of maxlen and convert to byte-count.  */
147e83
+# ifdef __s390x__
147e83
+	tmhh	%r4,49152	/* Test bit 0 or 1 of maxlen.  */
147e83
+	lghi	%r1,-4		/* Max byte-count is 18446744073709551612.  */
147e83
+# else
147e83
+	tmlh	%r4,49152	/* Test bit 0 or 1 of maxlen.  */
147e83
+	llilf	%r1,4294967292	/* Max byte-count is 4294967292.  */
147e83
+# endif /* !__s390x__ */
147e83
+	sllg	%r4,%r4,2	/* Convert character-count to byte-count.  */
147e83
+	locgrne	%r4,%r1		/* Use max byte-count, if bit 0/1 was one.  */
147e83
+
147e83
+	lghi	%r5,0		/* current_len = 0.  */
147e83
+
147e83
+	clgijh	%r4,16,.Lgt16
147e83
+
147e83
+.Lremaining:
147e83
+	aghi	%r4,-1		/* vstl needs highest index.  */
147e83
+	vll	%v16,%r4,0(%r2)
147e83
+	vll	%v17,%r4,0(%r3)
147e83
+	vfenef	%v18,%v16,%v17	/* Compare not equal.  */
147e83
+	vlgvb	%r1,%v18,7	/* Load unequal index or 16 if not found.  */
147e83
+	clrj	%r1,%r4,12,.Lfound2 /* r1 <= r4 -> unequal within loaded
147e83
+					bytes.  */
147e83
+
147e83
+.Lend_equal:
147e83
+	lghi	%r2,0
147e83
+	br	%r14
147e83
+
147e83
+.Lfound:
147e83
+	/* vfenezf found an unequal element or zero.
147e83
+	   This instruction compares unsigned words, but wchar_t is signed.
147e83
+	   Thus we have to compare the found element again.  */
147e83
+	vlgvb	%r1,%v18,7	/* Extract not equal byte-index.  */
147e83
+.Lfound2:
147e83
+	srl	%r1,2		/* And convert it to character-index.  */
147e83
+	vlgvf	%r0,%v16,0(%r1)	/* Load character-values.  */
147e83
+	vlgvf	%r1,%v17,0(%r1)
147e83
+	cr	%r0,%r1
147e83
+	je	.Lend_equal
147e83
+	lghi	%r2,1
147e83
+	lghi	%r1,-1
147e83
+	locgrl	%r2,%r1
147e83
+	br	%r14
147e83
+
147e83
+.Lgt16:
147e83
+	clgijh	%r4,64,.Lpreloop64
147e83
+
147e83
+.Lpreloop16:
147e83
+	srlg	%r1,%r4,4	/* Split into 16byte blocks */
147e83
+.Lloop16:
147e83
+	vl	%v16,0(%r5,%r2)
147e83
+	vl	%v17,0(%r5,%r3)
147e83
+	aghi	%r5,16
147e83
+	vfenefs	%v18,%v16,%v17	/* Compare not equal.  */
147e83
+	jno	.Lfound
147e83
+	brctg	%r1,.Lloop16	/* Loop until all blocks are processed.  */
147e83
+
147e83
+	llgfr	%r4,%r4
147e83
+	nilf	%r4,15		/* Get remaining bytes */
147e83
+	locgre	%r2,%r4
147e83
+	ber	%r14
147e83
+	la	%r2,0(%r5,%r2)
147e83
+	la	%r3,0(%r5,%r3)
147e83
+	j	.Lremaining
147e83
+
147e83
+.Lpreloop64:
147e83
+	srlg	%r1,%r4,6	/* Split into 64byte blocks */
147e83
+.Lloop64:
147e83
+	vl	%v16,0(%r5,%r2)
147e83
+	vl	%v17,0(%r5,%r3)
147e83
+	vfenefs	%v18,%v16,%v17	/* Compare not equal.  */
147e83
+	jno	.Lfound
147e83
+
147e83
+	vl	%v16,16(%r5,%r2)
147e83
+	vl	%v17,16(%r5,%r3)
147e83
+	vfenefs	%v18,%v16,%v17
147e83
+	jno	.Lfound
147e83
+
147e83
+	vl	%v16,32(%r5,%r2)
147e83
+	vl	%v17,32(%r5,%r3)
147e83
+	vfenefs	%v18,%v16,%v17
147e83
+	jno	.Lfound
147e83
+
147e83
+	vl	%v16,48(%r5,%r2)
147e83
+	vl	%v17,48(%r5,%r3)
147e83
+	aghi	%r5,64
147e83
+	vfenefs	%v18,%v16,%v17
147e83
+	jno	.Lfound
147e83
+
147e83
+	brctg	%r1,.Lloop64	/* Loop until all blocks are processed.  */
147e83
+
147e83
+	llgfr	%r4,%r4
147e83
+	nilf	%r4,63		/* Get remaining bytes */
147e83
+	locgre	%r2,%r4
147e83
+	ber	%r14
147e83
+	clgijh	%r4,16,.Lpreloop16
147e83
+	la	%r2,0(%r5,%r2)
147e83
+	la	%r3,0(%r5,%r3)
147e83
+	j	.Lremaining
147e83
+END(__wmemcmp_vx)
147e83
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
147e83
diff --git a/sysdeps/s390/multiarch/wmemcmp.c b/sysdeps/s390/multiarch/wmemcmp.c
147e83
new file mode 100644
147e83
index 0000000..24a57e9
147e83
--- /dev/null
147e83
+++ b/sysdeps/s390/multiarch/wmemcmp.c
147e83
@@ -0,0 +1,27 @@
147e83
+/* Multiple versions of wmemcmp.
147e83
+   Copyright (C) 2015 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
147e83
+# include <wchar.h>
147e83
+# include <ifunc-resolve.h>
147e83
+
147e83
+s390_vx_libc_ifunc2 (__wmemcmp, wmemcmp)
147e83
+
147e83
+#else
147e83
+# include <wcsmbs/wmemcmp.c>
147e83
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
147e83
-- 
147e83
2.3.0
147e83