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