|
|
147e83 |
From b403bd489e63561185fda4d7d1de2b1f627608d9 Mon Sep 17 00:00:00 2001
|
|
|
147e83 |
From: Stefan Liebler <stli@linux.vnet.ibm.com>
|
|
|
147e83 |
Date: Thu, 8 Oct 2015 11:10:59 +0200
|
|
|
147e83 |
Subject: [PATCH 15/30] S390: Optimize stpncpy and wcpncpy.
|
|
|
147e83 |
|
|
|
147e83 |
upstream-commit-id: b3a0c176d1185621c4dd2bb3a51ec961bdb29123
|
|
|
147e83 |
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00158.html
|
|
|
147e83 |
|
|
|
147e83 |
This patch provides optimized versions of stpncpy and wcpncpy with the z13
|
|
|
147e83 |
vector instructions.
|
|
|
147e83 |
|
|
|
147e83 |
ChangeLog:
|
|
|
147e83 |
|
|
|
147e83 |
* sysdeps/s390/multiarch/stpncpy-c.c: New File.
|
|
|
147e83 |
* sysdeps/s390/multiarch/stpncpy-vx.S: Likewise.
|
|
|
147e83 |
* sysdeps/s390/multiarch/stpncpy.c: Likewise.
|
|
|
147e83 |
* sysdeps/s390/multiarch/wcpncpy-c.c: Likewise.
|
|
|
147e83 |
* sysdeps/s390/multiarch/wcpncpy-vx.S: Likewise.
|
|
|
147e83 |
* sysdeps/s390/multiarch/wcpncpy.c: Likewise.
|
|
|
147e83 |
* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add stpncpy and
|
|
|
147e83 |
wcpncpy functions.
|
|
|
147e83 |
* sysdeps/s390/multiarch/ifunc-impl-list.c
|
|
|
147e83 |
(__libc_ifunc_impl_list): Add ifunc test for stpncpy, wcpncpy.
|
|
|
147e83 |
* wcsmbs/wcpncpy.c: Use WCPNCPY if defined.
|
|
|
147e83 |
* string/test-stpncpy.c: Add wcpncpy support.
|
|
|
147e83 |
* wcsmbs/test-wcpncpy.c: New File.
|
|
|
147e83 |
* wcsmbs/Makefile (strop-tests): Add wcpncpy.
|
|
|
147e83 |
* benchtests/bench-stpncpy.c: Add wcpncpy support.
|
|
|
147e83 |
* benchtests/bench-wcpncpy.c: New File.
|
|
|
147e83 |
* benchtests/Makefile (wcsmbs-bench): Add wcpncpy.
|
|
|
147e83 |
---
|
|
|
147e83 |
benchtests/Makefile | 2 +-
|
|
|
147e83 |
benchtests/bench-stpncpy.c | 40 ++++--
|
|
|
147e83 |
benchtests/bench-wcpncpy.c | 20 +++
|
|
|
147e83 |
string/test-stpncpy.c | 40 ++++--
|
|
|
147e83 |
sysdeps/s390/multiarch/Makefile | 6 +-
|
|
|
147e83 |
sysdeps/s390/multiarch/ifunc-impl-list.c | 3 +
|
|
|
147e83 |
sysdeps/s390/multiarch/stpncpy-c.c | 28 ++++
|
|
|
147e83 |
sysdeps/s390/multiarch/stpncpy-vx.S | 200 ++++++++++++++++++++++++++++
|
|
|
147e83 |
sysdeps/s390/multiarch/stpncpy.c | 28 ++++
|
|
|
147e83 |
sysdeps/s390/multiarch/wcpncpy-c.c | 25 ++++
|
|
|
147e83 |
sysdeps/s390/multiarch/wcpncpy-vx.S | 222 +++++++++++++++++++++++++++++++
|
|
|
147e83 |
sysdeps/s390/multiarch/wcpncpy.c | 28 ++++
|
|
|
147e83 |
wcsmbs/Makefile | 2 +-
|
|
|
147e83 |
wcsmbs/test-wcpncpy-ifunc.c | 20 +++
|
|
|
147e83 |
wcsmbs/test-wcpncpy.c | 20 +++
|
|
|
147e83 |
wcsmbs/wcpncpy.c | 5 +
|
|
|
147e83 |
16 files changed, 663 insertions(+), 26 deletions(-)
|
|
|
147e83 |
create mode 100644 benchtests/bench-wcpncpy.c
|
|
|
147e83 |
create mode 100644 sysdeps/s390/multiarch/stpncpy-c.c
|
|
|
147e83 |
create mode 100644 sysdeps/s390/multiarch/stpncpy-vx.S
|
|
|
147e83 |
create mode 100644 sysdeps/s390/multiarch/stpncpy.c
|
|
|
147e83 |
create mode 100644 sysdeps/s390/multiarch/wcpncpy-c.c
|
|
|
147e83 |
create mode 100644 sysdeps/s390/multiarch/wcpncpy-vx.S
|
|
|
147e83 |
create mode 100644 sysdeps/s390/multiarch/wcpncpy.c
|
|
|
147e83 |
create mode 100644 wcsmbs/test-wcpncpy-ifunc.c
|
|
|
147e83 |
create mode 100644 wcsmbs/test-wcpncpy.c
|
|
|
147e83 |
|
|
|
147e83 |
diff --git a/benchtests/Makefile b/benchtests/Makefile
|
|
|
147e83 |
index f898258..dfab95f 100644
|
|
|
147e83 |
--- a/benchtests/Makefile
|
|
|
147e83 |
+++ b/benchtests/Makefile
|
|
|
147e83 |
@@ -38,7 +38,7 @@ string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
|
|
|
147e83 |
strcat strchr strchrnul strcmp strcpy strcspn strlen \
|
|
|
147e83 |
strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
|
|
|
147e83 |
strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
|
|
|
147e83 |
-wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy
|
|
|
147e83 |
+wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy
|
|
|
147e83 |
string-bench-all := $(string-bench) ${wcsmbs-bench}
|
|
|
147e83 |
|
|
|
147e83 |
stdlib-bench := strtod
|
|
|
147e83 |
diff --git a/benchtests/bench-stpncpy.c b/benchtests/bench-stpncpy.c
|
|
|
147e83 |
index 65ed800..e428102 100644
|
|
|
147e83 |
--- a/benchtests/bench-stpncpy.c
|
|
|
147e83 |
+++ b/benchtests/bench-stpncpy.c
|
|
|
147e83 |
@@ -18,18 +18,36 @@
|
|
|
147e83 |
|
|
|
147e83 |
#define STRNCPY_RESULT(dst, len, n) ((dst) + ((len) > (n) ? (n) : (len)))
|
|
|
147e83 |
#define TEST_MAIN
|
|
|
147e83 |
-#define TEST_NAME "stpncpy"
|
|
|
147e83 |
+#ifndef WIDE
|
|
|
147e83 |
+# define TEST_NAME "stpncpy"
|
|
|
147e83 |
+#else
|
|
|
147e83 |
+# define TEST_NAME "wcpncpy"
|
|
|
147e83 |
+#endif /* WIDE */
|
|
|
147e83 |
#include "bench-string.h"
|
|
|
147e83 |
+#ifndef WIDE
|
|
|
147e83 |
+# define CHAR char
|
|
|
147e83 |
+# define SIMPLE_STPNCPY simple_stpncpy
|
|
|
147e83 |
+# define STUPID_STPNCPY stupid_stpncpy
|
|
|
147e83 |
+# define STPNCPY stpncpy
|
|
|
147e83 |
+# define STRNLEN strnlen
|
|
|
147e83 |
+#else
|
|
|
147e83 |
+# include <wchar.h>
|
|
|
147e83 |
+# define CHAR wchar_t
|
|
|
147e83 |
+# define SIMPLE_STPNCPY simple_wcpncpy
|
|
|
147e83 |
+# define STUPID_STPNCPY stupid_wcpncpy
|
|
|
147e83 |
+# define STPNCPY wcpncpy
|
|
|
147e83 |
+# define STRNLEN wcsnlen
|
|
|
147e83 |
+#endif /* WIDE */
|
|
|
147e83 |
|
|
|
147e83 |
-char *simple_stpncpy (char *, const char *, size_t);
|
|
|
147e83 |
-char *stupid_stpncpy (char *, const char *, size_t);
|
|
|
147e83 |
+CHAR *SIMPLE_STPNCPY (CHAR *, const CHAR *, size_t);
|
|
|
147e83 |
+CHAR *STUPID_STPNCPY (CHAR *, const CHAR *, size_t);
|
|
|
147e83 |
|
|
|
147e83 |
-IMPL (stupid_stpncpy, 0)
|
|
|
147e83 |
-IMPL (simple_stpncpy, 0)
|
|
|
147e83 |
-IMPL (stpncpy, 1)
|
|
|
147e83 |
+IMPL (STUPID_STPNCPY, 0)
|
|
|
147e83 |
+IMPL (SIMPLE_STPNCPY, 0)
|
|
|
147e83 |
+IMPL (STPNCPY, 1)
|
|
|
147e83 |
|
|
|
147e83 |
-char *
|
|
|
147e83 |
-simple_stpncpy (char *dst, const char *src, size_t n)
|
|
|
147e83 |
+CHAR *
|
|
|
147e83 |
+SIMPLE_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
|
|
|
147e83 |
{
|
|
|
147e83 |
while (n--)
|
|
|
147e83 |
if ((*dst++ = *src++) == '\0')
|
|
|
147e83 |
@@ -43,10 +61,10 @@ simple_stpncpy (char *dst, const char *src, size_t n)
|
|
|
147e83 |
return dst;
|
|
|
147e83 |
}
|
|
|
147e83 |
|
|
|
147e83 |
-char *
|
|
|
147e83 |
-stupid_stpncpy (char *dst, const char *src, size_t n)
|
|
|
147e83 |
+CHAR *
|
|
|
147e83 |
+STUPID_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
|
|
|
147e83 |
{
|
|
|
147e83 |
- size_t nc = strnlen (src, n);
|
|
|
147e83 |
+ size_t nc = STRNLEN (src, n);
|
|
|
147e83 |
size_t i;
|
|
|
147e83 |
|
|
|
147e83 |
for (i = 0; i < nc; ++i)
|
|
|
147e83 |
diff --git a/benchtests/bench-wcpncpy.c b/benchtests/bench-wcpncpy.c
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..8aa529e
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/benchtests/bench-wcpncpy.c
|
|
|
147e83 |
@@ -0,0 +1,20 @@
|
|
|
147e83 |
+/* Measure wcpncpy 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-stpncpy.c"
|
|
|
147e83 |
diff --git a/string/test-stpncpy.c b/string/test-stpncpy.c
|
|
|
147e83 |
index 8647299..69c8181 100644
|
|
|
147e83 |
--- a/string/test-stpncpy.c
|
|
|
147e83 |
+++ b/string/test-stpncpy.c
|
|
|
147e83 |
@@ -19,18 +19,36 @@
|
|
|
147e83 |
|
|
|
147e83 |
#define STRNCPY_RESULT(dst, len, n) ((dst) + ((len) > (n) ? (n) : (len)))
|
|
|
147e83 |
#define TEST_MAIN
|
|
|
147e83 |
-#define TEST_NAME "stpncpy"
|
|
|
147e83 |
+#ifndef WIDE
|
|
|
147e83 |
+# define TEST_NAME "stpncpy"
|
|
|
147e83 |
+#else
|
|
|
147e83 |
+# define TEST_NAME "wcpncpy"
|
|
|
147e83 |
+#endif /* WIDE */
|
|
|
147e83 |
#include "test-string.h"
|
|
|
147e83 |
+#ifndef WIDE
|
|
|
147e83 |
+# define CHAR char
|
|
|
147e83 |
+# define SIMPLE_STPNCPY simple_stpncpy
|
|
|
147e83 |
+# define STUPID_STPNCPY stupid_stpncpy
|
|
|
147e83 |
+# define STPNCPY stpncpy
|
|
|
147e83 |
+# define STRNLEN strnlen
|
|
|
147e83 |
+#else
|
|
|
147e83 |
+# include <wchar.h>
|
|
|
147e83 |
+# define CHAR wchar_t
|
|
|
147e83 |
+# define SIMPLE_STPNCPY simple_wcpncpy
|
|
|
147e83 |
+# define STUPID_STPNCPY stupid_wcpncpy
|
|
|
147e83 |
+# define STPNCPY wcpncpy
|
|
|
147e83 |
+# define STRNLEN wcsnlen
|
|
|
147e83 |
+#endif /* WIDE */
|
|
|
147e83 |
|
|
|
147e83 |
-char *simple_stpncpy (char *, const char *, size_t);
|
|
|
147e83 |
-char *stupid_stpncpy (char *, const char *, size_t);
|
|
|
147e83 |
+CHAR *SIMPLE_STPNCPY (CHAR *, const CHAR *, size_t);
|
|
|
147e83 |
+CHAR *STUPID_STPNCPY (CHAR *, const CHAR *, size_t);
|
|
|
147e83 |
|
|
|
147e83 |
-IMPL (stupid_stpncpy, 0)
|
|
|
147e83 |
-IMPL (simple_stpncpy, 0)
|
|
|
147e83 |
-IMPL (stpncpy, 1)
|
|
|
147e83 |
+IMPL (STUPID_STPNCPY, 0)
|
|
|
147e83 |
+IMPL (SIMPLE_STPNCPY, 0)
|
|
|
147e83 |
+IMPL (STPNCPY, 1)
|
|
|
147e83 |
|
|
|
147e83 |
-char *
|
|
|
147e83 |
-simple_stpncpy (char *dst, const char *src, size_t n)
|
|
|
147e83 |
+CHAR *
|
|
|
147e83 |
+SIMPLE_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
|
|
|
147e83 |
{
|
|
|
147e83 |
while (n--)
|
|
|
147e83 |
if ((*dst++ = *src++) == '\0')
|
|
|
147e83 |
@@ -44,10 +62,10 @@ simple_stpncpy (char *dst, const char *src, size_t n)
|
|
|
147e83 |
return dst;
|
|
|
147e83 |
}
|
|
|
147e83 |
|
|
|
147e83 |
-char *
|
|
|
147e83 |
-stupid_stpncpy (char *dst, const char *src, size_t n)
|
|
|
147e83 |
+CHAR *
|
|
|
147e83 |
+STUPID_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
|
|
|
147e83 |
{
|
|
|
147e83 |
- size_t nc = strnlen (src, n);
|
|
|
147e83 |
+ size_t nc = STRNLEN (src, n);
|
|
|
147e83 |
size_t i;
|
|
|
147e83 |
|
|
|
147e83 |
for (i = 0; i < nc; ++i)
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
|
|
|
147e83 |
index 0dff2dc..98b588f 100644
|
|
|
147e83 |
--- a/sysdeps/s390/multiarch/Makefile
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/Makefile
|
|
|
147e83 |
@@ -3,7 +3,8 @@ sysdep_routines += strlen strlen-vx strlen-c \
|
|
|
147e83 |
strnlen strnlen-vx strnlen-c \
|
|
|
147e83 |
strcpy strcpy-vx \
|
|
|
147e83 |
stpcpy stpcpy-vx stpcpy-c \
|
|
|
147e83 |
- strncpy strncpy-vx
|
|
|
147e83 |
+ strncpy strncpy-vx \
|
|
|
147e83 |
+ stpncpy stpncpy-vx stpncpy-c
|
|
|
147e83 |
endif
|
|
|
147e83 |
|
|
|
147e83 |
ifeq ($(subdir),wcsmbs)
|
|
|
147e83 |
@@ -11,5 +12,6 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \
|
|
|
147e83 |
wcsnlen wcsnlen-vx wcsnlen-c \
|
|
|
147e83 |
wcscpy wcscpy-vx wcscpy-c \
|
|
|
147e83 |
wcpcpy wcpcpy-vx wcpcpy-c \
|
|
|
147e83 |
- wcsncpy wcsncpy-vx wcsncpy-c
|
|
|
147e83 |
+ wcsncpy wcsncpy-vx wcsncpy-c \
|
|
|
147e83 |
+ wcpncpy wcpncpy-vx wcpncpy-c
|
|
|
147e83 |
endif
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
|
|
|
147e83 |
index 940421d..ca69983 100644
|
|
|
147e83 |
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
|
|
|
147e83 |
@@ -94,6 +94,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
|
|
|
147e83 |
IFUNC_VX_IMPL (strncpy);
|
|
|
147e83 |
IFUNC_VX_IMPL (wcsncpy);
|
|
|
147e83 |
|
|
|
147e83 |
+ IFUNC_VX_IMPL (stpncpy);
|
|
|
147e83 |
+ IFUNC_VX_IMPL (wcpncpy);
|
|
|
147e83 |
+
|
|
|
147e83 |
#endif /* HAVE_S390_VX_ASM_SUPPORT */
|
|
|
147e83 |
|
|
|
147e83 |
return i;
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/stpncpy-c.c b/sysdeps/s390/multiarch/stpncpy-c.c
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..40dd8bd
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/stpncpy-c.c
|
|
|
147e83 |
@@ -0,0 +1,28 @@
|
|
|
147e83 |
+/* Default stpncpy 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 STPNCPY __stpncpy_c
|
|
|
147e83 |
+# ifdef SHARED
|
|
|
147e83 |
+# undef libc_hidden_def
|
|
|
147e83 |
+# define libc_hidden_def(name) \
|
|
|
147e83 |
+ __hidden_ver1 (__stpncpy_c, __GI___stpncpy, __stpncpy_c);
|
|
|
147e83 |
+# endif /* SHARED */
|
|
|
147e83 |
+
|
|
|
147e83 |
+# include <string/stpncpy.c>
|
|
|
147e83 |
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/stpncpy-vx.S b/sysdeps/s390/multiarch/stpncpy-vx.S
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..36f6b93
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/stpncpy-vx.S
|
|
|
147e83 |
@@ -0,0 +1,200 @@
|
|
|
147e83 |
+/* Vector optimized 32/64 bit S/390 version of stpncpy.
|
|
|
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 |
+/* char * stpncpy (char *dest, const char *src, size_t n)
|
|
|
147e83 |
+ Copies at most n characters of string src to dest
|
|
|
147e83 |
+ returning a pointer to its end or dest+n
|
|
|
147e83 |
+ if src is smaller than n.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ Register usage:
|
|
|
147e83 |
+ -%r0 = return value
|
|
|
147e83 |
+ -%r1 = zero byte index
|
|
|
147e83 |
+ -%r2 = curr dst pointer
|
|
|
147e83 |
+ -%r3 = curr src pointer
|
|
|
147e83 |
+ -%r4 = n
|
|
|
147e83 |
+ -%r5 = current_len
|
|
|
147e83 |
+ -%r6 = loaded bytes
|
|
|
147e83 |
+ -%r7 = border, tmp
|
|
|
147e83 |
+*/
|
|
|
147e83 |
+ENTRY(__stpncpy_vx)
|
|
|
147e83 |
+ .machine "z13"
|
|
|
147e83 |
+ .machinemode "zarch_nohighgprs"
|
|
|
147e83 |
+
|
|
|
147e83 |
+# if !defined __s390x__
|
|
|
147e83 |
+ llgfr %r4,%r4
|
|
|
147e83 |
+# endif /* !defined __s390x__ */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ clgfi %r4,0
|
|
|
147e83 |
+ ber %r14 /* Nothing to do, if n == 0. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ la %r0,0(%r4,%r2) /* Save destination pointer + n for return. */
|
|
|
147e83 |
+ vlvgp %v31,%r6,%r7 /* Save registers. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ vlbb %v16,0(%r3),6 /* Load s until next 4k-byte boundary. */
|
|
|
147e83 |
+ lcbb %r6,0(%r3),6 /* Get bytes to 4k-byte boundary or 16. */
|
|
|
147e83 |
+ llgfr %r6,%r6 /* Convert 32bit to 64bit. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ lghi %r5,0 /* current_len = 0. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ clgrjle %r4,%r6,.Lremaining_v16 /* If n <= loaded-bytes
|
|
|
147e83 |
+ -> process remaining. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* n > loaded-byte-count */
|
|
|
147e83 |
+ vfenezb %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
147e83 |
+ vlgvb %r1,%v17,7 /* Load zero index or 16 if not found. */
|
|
|
147e83 |
+ clrjl %r1,%r6,.Lfound_v16_store /* Found zero within loaded bytes,
|
|
|
147e83 |
+ copy and return. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Align s to 16 byte. */
|
|
|
147e83 |
+ risbgn %r7,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
|
|
|
147e83 |
+ lghi %r5,15 /* current_len = 15. */
|
|
|
147e83 |
+ slr %r5,%r7 /* Compute highest index to 16byte boundary. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Zero not found and n > loaded-byte-count. */
|
|
|
147e83 |
+ vstl %v16,%r5,0(%r2) /* Copy loaded characters - no zero. */
|
|
|
147e83 |
+ ahi %r5,1 /* Start loop at next character. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Now we are 16byte aligned, so we can load a full vreg
|
|
|
147e83 |
+ without page fault. */
|
|
|
147e83 |
+ lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */
|
|
|
147e83 |
+ aghi %r1,64
|
|
|
147e83 |
+ clgrjl %r1,%r4,.Lloop64
|
|
|
147e83 |
+
|
|
|
147e83 |
+ vl %v16,0(%r5,%r3) /* Load s. */
|
|
|
147e83 |
+ clgijl %r4,17,.Lremaining_v16 /* If n <= 16, process remaining
|
|
|
147e83 |
+ bytes. */
|
|
|
147e83 |
+.Llt64:
|
|
|
147e83 |
+ lgr %r7,%r4
|
|
|
147e83 |
+ slgfi %r7,16 /* border_len = n - 16. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ clgrjhe %r5,%r7,.Lremaining_v16 /* If current_len >= border
|
|
|
147e83 |
+ then process remaining bytes. */
|
|
|
147e83 |
+ vfenezbs %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
147e83 |
+ je .Lfound_v16 /* Jump away if zero was found. */
|
|
|
147e83 |
+ vl %v18,16(%r5,%r3) /* Load next part of s. */
|
|
|
147e83 |
+ vst %v16,0(%r5,%r2) /* Save previous part without zero to dst. */
|
|
|
147e83 |
+ aghi %r5,16
|
|
|
147e83 |
+
|
|
|
147e83 |
+ clgrjhe %r5,%r7,.Lremaining_v18
|
|
|
147e83 |
+ vfenezbs %v17,%v18,%v18
|
|
|
147e83 |
+ je .Lfound_v18
|
|
|
147e83 |
+ vl %v16,16(%r5,%r3)
|
|
|
147e83 |
+ vst %v18,0(%r5,%r2)
|
|
|
147e83 |
+ aghi %r5,16
|
|
|
147e83 |
+
|
|
|
147e83 |
+ clgrjhe %r5,%r7,.Lremaining_v16
|
|
|
147e83 |
+ vfenezbs %v17,%v16,%v16
|
|
|
147e83 |
+ je .Lfound_v16
|
|
|
147e83 |
+ vl %v18,16(%r5,%r3)
|
|
|
147e83 |
+ vst %v16,0(%r5,%r2)
|
|
|
147e83 |
+ aghi %r5,16
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lremaining_v18:
|
|
|
147e83 |
+ vlr %v16,%v18
|
|
|
147e83 |
+.Lremaining_v16:
|
|
|
147e83 |
+ /* v16 contains the remaining bytes [1...16].
|
|
|
147e83 |
+ Store remaining bytes and append string-termination. */
|
|
|
147e83 |
+ vfenezb %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
147e83 |
+ slgrk %r7,%r4,%r5 /* Remaining bytes = maxlen - current_len */
|
|
|
147e83 |
+ aghi %r7,-1 /* vstl needs highest index. */
|
|
|
147e83 |
+ la %r2,0(%r5,%r2) /* vstl has no index register. */
|
|
|
147e83 |
+ vlgvb %r1,%v17,7 /* Load zero index or 16 if not found. */
|
|
|
147e83 |
+ /* Zero in remaining bytes? -> jump away (zero-index <= max-index). */
|
|
|
147e83 |
+ clrjle %r1,%r7,.Lfound_v16_store
|
|
|
147e83 |
+ vstl %v16,%r7,0(%r2) /* Store remaining bytes without null
|
|
|
147e83 |
+ termination! */
|
|
|
147e83 |
+.Lend:
|
|
|
147e83 |
+ /* Restore saved registers. */
|
|
|
147e83 |
+ vlgvg %r6,%v31,0
|
|
|
147e83 |
+ vlgvg %r7,%v31,1
|
|
|
147e83 |
+ lgr %r2,%r0 /* Load saved dest-ptr. */
|
|
|
147e83 |
+ br %r14
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lfound_v16_32:
|
|
|
147e83 |
+ aghi %r5,32
|
|
|
147e83 |
+ j .Lfound_v16
|
|
|
147e83 |
+.Lfound_v18_48:
|
|
|
147e83 |
+ aghi %r5,32
|
|
|
147e83 |
+.Lfound_v18_16:
|
|
|
147e83 |
+ aghi %r5,16
|
|
|
147e83 |
+.Lfound_v18:
|
|
|
147e83 |
+ vlr %v16,%v18
|
|
|
147e83 |
+.Lfound_v16:
|
|
|
147e83 |
+ /* v16 contains a zero. Store remaining bytes to zero. current_len
|
|
|
147e83 |
+ has not reached border, thus checking for n is not needed! */
|
|
|
147e83 |
+ vlgvb %r1,%v17,7 /* Load byte index of zero. */
|
|
|
147e83 |
+ la %r2,0(%r5,%r2) /* vstl has no support for index-register. */
|
|
|
147e83 |
+.Lfound_v16_store:
|
|
|
147e83 |
+ vstl %v16,%r1,0(%r2) /* Copy characters including zero. */
|
|
|
147e83 |
+ /* Fill remaining bytes with zero - remaining count always > 0. */
|
|
|
147e83 |
+ algr %r5,%r1 /* Remaining bytes (=%r4) = ... */
|
|
|
147e83 |
+ slgr %r4,%r5 /* = maxlen - (currlen + zero_index + 1) */
|
|
|
147e83 |
+ la %r2,0(%r1,%r2) /* Pointer to zero. start filling beyond. */
|
|
|
147e83 |
+ lgr %r0,%r2 /* Save return-pointer to found zero. */
|
|
|
147e83 |
+ clgije %r4,1,.Lend /* Skip zero-filling, if found zero is last
|
|
|
147e83 |
+ possible character.
|
|
|
147e83 |
+ (1 is substracted from r4 below!). */
|
|
|
147e83 |
+ aghi %r4,-2 /* mvc with exrl needs count - 1.
|
|
|
147e83 |
+ (additional -1, see remaining bytes above) */
|
|
|
147e83 |
+ srlg %r6,%r4,8 /* Split into 256 byte blocks. */
|
|
|
147e83 |
+ ltgr %r6,%r6
|
|
|
147e83 |
+ je .Lzero_lt256
|
|
|
147e83 |
+.Lzero_loop256:
|
|
|
147e83 |
+ mvc 1(256,%r2),0(%r2) /* Fill 256 zeros at once. */
|
|
|
147e83 |
+ la %r2,256(%r2)
|
|
|
147e83 |
+ brctg %r6,.Lzero_loop256 /* Loop until all blocks are processed. */
|
|
|
147e83 |
+.Lzero_lt256:
|
|
|
147e83 |
+ exrl %r4,.Lmvc_lt256
|
|
|
147e83 |
+ j .Lend
|
|
|
147e83 |
+.Lmvc_lt256:
|
|
|
147e83 |
+ mvc 1(1,%r2),0(%r2)
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lloop64:
|
|
|
147e83 |
+ vl %v16,0(%r5,%r3)
|
|
|
147e83 |
+ vfenezbs %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
147e83 |
+ je .Lfound_v16 /* Jump away if zero was found. */
|
|
|
147e83 |
+ vl %v18,16(%r5,%r3) /* Load next part of s. */
|
|
|
147e83 |
+ vst %v16,0(%r5,%r2) /* Save previous part without zero to dst. */
|
|
|
147e83 |
+ vfenezbs %v17,%v18,%v18
|
|
|
147e83 |
+ je .Lfound_v18_16
|
|
|
147e83 |
+ vl %v16,32(%r5,%r3)
|
|
|
147e83 |
+ vst %v18,16(%r5,%r2)
|
|
|
147e83 |
+ vfenezbs %v17,%v16,%v16
|
|
|
147e83 |
+ je .Lfound_v16_32
|
|
|
147e83 |
+ vl %v18,48(%r5,%r3)
|
|
|
147e83 |
+ vst %v16,32(%r5,%r2)
|
|
|
147e83 |
+ vfenezbs %v17,%v18,%v18
|
|
|
147e83 |
+ je .Lfound_v18_48
|
|
|
147e83 |
+ vst %v18,48(%r5,%r2)
|
|
|
147e83 |
+
|
|
|
147e83 |
+ aghi %r5,64
|
|
|
147e83 |
+ lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */
|
|
|
147e83 |
+ aghi %r1,64
|
|
|
147e83 |
+ clgrjl %r1,%r4,.Lloop64
|
|
|
147e83 |
+
|
|
|
147e83 |
+ vl %v16,0(%r5,%r3) /* Load s. */
|
|
|
147e83 |
+ j .Llt64
|
|
|
147e83 |
+END(__stpncpy_vx)
|
|
|
147e83 |
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/stpncpy.c b/sysdeps/s390/multiarch/stpncpy.c
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..894a33b
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/stpncpy.c
|
|
|
147e83 |
@@ -0,0 +1,28 @@
|
|
|
147e83 |
+/* Multiple versions of stpncpy.
|
|
|
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 <string.h>
|
|
|
147e83 |
+# include <ifunc-resolve.h>
|
|
|
147e83 |
+
|
|
|
147e83 |
+s390_vx_libc_ifunc (__stpncpy)
|
|
|
147e83 |
+weak_alias (__stpncpy, stpncpy)
|
|
|
147e83 |
+
|
|
|
147e83 |
+#else
|
|
|
147e83 |
+# include <string/stpncpy.c>
|
|
|
147e83 |
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/wcpncpy-c.c b/sysdeps/s390/multiarch/wcpncpy-c.c
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..e49b2ef
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/wcpncpy-c.c
|
|
|
147e83 |
@@ -0,0 +1,25 @@
|
|
|
147e83 |
+/* Default wcsncpy 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 WCPNCPY __wcpncpy_c
|
|
|
147e83 |
+
|
|
|
147e83 |
+# include <wchar.h>
|
|
|
147e83 |
+extern __typeof (__wcpncpy) __wcpncpy_c;
|
|
|
147e83 |
+# include <wcsmbs/wcpncpy.c>
|
|
|
147e83 |
+#endif
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/wcpncpy-vx.S b/sysdeps/s390/multiarch/wcpncpy-vx.S
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..335ea58
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/wcpncpy-vx.S
|
|
|
147e83 |
@@ -0,0 +1,222 @@
|
|
|
147e83 |
+/* Vector optimized 32/64 bit S/390 version of wcpncpy.
|
|
|
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 |
+/* wchar_t * wcpncpy (wchar_t *dest, const wchar_t *src, size_t n)
|
|
|
147e83 |
+ Copies at most n characters of string src to dest
|
|
|
147e83 |
+ returning a pointer to its end or dest+n
|
|
|
147e83 |
+ if src is smaller than n.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ Register usage:
|
|
|
147e83 |
+ -%r0 = return value
|
|
|
147e83 |
+ -%r1 = zero byte index
|
|
|
147e83 |
+ -%r2 = curr dst pointer
|
|
|
147e83 |
+ -%r3 = curr src pointer
|
|
|
147e83 |
+ -%r4 = n
|
|
|
147e83 |
+ -%r5 = current_len
|
|
|
147e83 |
+ -%r6 = loaded bytes
|
|
|
147e83 |
+ -%r7 = border, tmp
|
|
|
147e83 |
+*/
|
|
|
147e83 |
+ENTRY(__wcpncpy_vx)
|
|
|
147e83 |
+ .machine "z13"
|
|
|
147e83 |
+ .machinemode "zarch_nohighgprs"
|
|
|
147e83 |
+
|
|
|
147e83 |
+# if !defined __s390x__
|
|
|
147e83 |
+ llgfr %r4,%r4
|
|
|
147e83 |
+# endif /* !defined __s390x__ */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ clgfi %r4,0
|
|
|
147e83 |
+ ber %r14 /* Nothing to do, if n == 0. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ vlbb %v16,0(%r3),6 /* Load s until next 4k-byte boundary. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ tmll %r3,3 /* Test if s is 4-byte aligned? */
|
|
|
147e83 |
+ jne .Lfallback /* And use common-code variant if not. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ vlvgp %v31,%r6,%r7 /* Save registers. */
|
|
|
147e83 |
+ lghi %r5,0 /* current_len = 0. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ lcbb %r6,0(%r3),6 /* Get bytes to 4k-byte boundary or 16. */
|
|
|
147e83 |
+ llgfr %r6,%r6 /* Convert 32bit to 64bit. */
|
|
|
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 |
+ la %r0,0(%r4,%r2) /* Save destination pointer + n for return. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ clgrjle %r4,%r6,.Lremaining_v16 /* If n <= loaded-bytes
|
|
|
147e83 |
+ -> process remaining. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* n > loaded-byte-count */
|
|
|
147e83 |
+ vfenezf %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
147e83 |
+ vlgvb %r1,%v17,7 /* Load zero index or 16 if not found. */
|
|
|
147e83 |
+ aghi %r1,3 /* Also copy remaining bytes of zero. */
|
|
|
147e83 |
+ clrjl %r1,%r6,.Lfound_v16_store /* Found zero within loaded bytes,
|
|
|
147e83 |
+ copy and return. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Align s to 16 byte. */
|
|
|
147e83 |
+ risbgn %r7,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
|
|
|
147e83 |
+ lghi %r5,15 /* current_len = 15. */
|
|
|
147e83 |
+ slr %r5,%r7 /* Compute highest index to 16byte boundary. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Zero not found and n > loaded-byte-count. */
|
|
|
147e83 |
+ vstl %v16,%r5,0(%r2) /* Copy loaded characters - no zero. */
|
|
|
147e83 |
+ ahi %r5,1 /* Start loop at next character. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Now we are 16byte aligned, so we can load a full vreg
|
|
|
147e83 |
+ without page fault. */
|
|
|
147e83 |
+ lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */
|
|
|
147e83 |
+ aghi %r1,64
|
|
|
147e83 |
+ clgrjl %r1,%r4,.Lloop64
|
|
|
147e83 |
+
|
|
|
147e83 |
+ vl %v16,0(%r5,%r3) /* Load s. */
|
|
|
147e83 |
+ clgijl %r4,17,.Lremaining_v16 /* If n <=16,
|
|
|
147e83 |
+ process remaining bytes. */
|
|
|
147e83 |
+.Llt64:
|
|
|
147e83 |
+ lgr %r7,%r4
|
|
|
147e83 |
+ slgfi %r7,16 /* border_len = n - 16. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ clgrjhe %r5,%r7,.Lremaining_v16 /* If current_len >= border
|
|
|
147e83 |
+ then process remaining bytes. */
|
|
|
147e83 |
+ vfenezfs %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
147e83 |
+ je .Lfound_v16 /* Jump away if zero was found. */
|
|
|
147e83 |
+ vl %v18,16(%r5,%r3) /* Load next part of s. */
|
|
|
147e83 |
+ vst %v16,0(%r5,%r2) /* Store previous part without zero to dst. */
|
|
|
147e83 |
+ aghi %r5,16
|
|
|
147e83 |
+
|
|
|
147e83 |
+ clgrjhe %r5,%r7,.Lremaining_v18
|
|
|
147e83 |
+ vfenezfs %v17,%v18,%v18
|
|
|
147e83 |
+ je .Lfound_v18
|
|
|
147e83 |
+ vl %v16,16(%r5,%r3)
|
|
|
147e83 |
+ vst %v18,0(%r5,%r2)
|
|
|
147e83 |
+ aghi %r5,16
|
|
|
147e83 |
+
|
|
|
147e83 |
+ clgrjhe %r5,%r7,.Lremaining_v16
|
|
|
147e83 |
+ vfenezfs %v17,%v16,%v16
|
|
|
147e83 |
+ je .Lfound_v16
|
|
|
147e83 |
+ vl %v18,16(%r5,%r3)
|
|
|
147e83 |
+ vst %v16,0(%r5,%r2)
|
|
|
147e83 |
+ aghi %r5,16
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lremaining_v18:
|
|
|
147e83 |
+ vlr %v16,%v18
|
|
|
147e83 |
+.Lremaining_v16:
|
|
|
147e83 |
+ /* v16 contains the remaining bytes [1...16].
|
|
|
147e83 |
+ Store remaining bytes and append string-termination. */
|
|
|
147e83 |
+ vfenezf %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
147e83 |
+ slgrk %r7,%r4,%r5 /* Remaining bytes = maxlen - current_len */
|
|
|
147e83 |
+ aghi %r7,-1 /* vstl needs highest index. */
|
|
|
147e83 |
+ la %r2,0(%r5,%r2) /* vstl has no index register. */
|
|
|
147e83 |
+ vlgvb %r1,%v17,7 /* Load zero index or 16 if not found. */
|
|
|
147e83 |
+ aghi %r1,3 /* Also copy remaining bytes of zero. */
|
|
|
147e83 |
+ /* Zero in remaining bytes? -> jump away (zero-index <= max-index). */
|
|
|
147e83 |
+ clrjle %r1,%r7,.Lfound_v16_store
|
|
|
147e83 |
+ vstl %v16,%r7,0(%r2) /* Store remaining bytes without null
|
|
|
147e83 |
+ termination! */
|
|
|
147e83 |
+.Lend:
|
|
|
147e83 |
+ /* Restore saved registers. */
|
|
|
147e83 |
+ vlgvg %r6,%v31,0
|
|
|
147e83 |
+ vlgvg %r7,%v31,1
|
|
|
147e83 |
+ lgr %r2,%r0 /* Load saved dest-ptr. */
|
|
|
147e83 |
+ br %r14
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lfound_v16_32:
|
|
|
147e83 |
+ aghi %r5,32
|
|
|
147e83 |
+ j .Lfound_v16
|
|
|
147e83 |
+.Lfound_v18_48:
|
|
|
147e83 |
+ aghi %r5,32
|
|
|
147e83 |
+.Lfound_v18_16:
|
|
|
147e83 |
+ aghi %r5,16
|
|
|
147e83 |
+.Lfound_v18:
|
|
|
147e83 |
+ vlr %v16,%v18
|
|
|
147e83 |
+.Lfound_v16:
|
|
|
147e83 |
+ /* v16 contains a zero. Store remaining bytes to zero. current_len
|
|
|
147e83 |
+ has not reached border, thus checking for n is not needed! */
|
|
|
147e83 |
+ vlgvb %r1,%v17,7 /* Load byte index of zero. */
|
|
|
147e83 |
+ la %r2,0(%r5,%r2) /* vstl has no support for index-register. */
|
|
|
147e83 |
+ aghi %r1,3 /* Also copy remaining bytes of zero. */
|
|
|
147e83 |
+.Lfound_v16_store:
|
|
|
147e83 |
+ vstl %v16,%r1,0(%r2) /* Copy characters including zero. */
|
|
|
147e83 |
+ /* Fill remaining bytes with zero - remaining byte count always > 0. */
|
|
|
147e83 |
+ algr %r5,%r1 /* Remaining bytes (=%r4) = ... */
|
|
|
147e83 |
+ slgr %r4,%r5 /* = n - (currlen + zero_index + 1) */
|
|
|
147e83 |
+ la %r2,0(%r1,%r2) /* Pointer to zero. start filling beyond. */
|
|
|
147e83 |
+ lay %r0,-3(%r2) /* Save return-pointer to found zero. */
|
|
|
147e83 |
+ clgije %r4,1,.Lend /* Skip zero-filling, if found-zero is last
|
|
|
147e83 |
+ possible character.
|
|
|
147e83 |
+ (1 is substracted from r4 below!). */
|
|
|
147e83 |
+ aghi %r4,-2 /* mvc with exrl needs count - 1.
|
|
|
147e83 |
+ (additional -1, see remaining bytes above) */
|
|
|
147e83 |
+ srlg %r6,%r4,8 /* Split into 256 byte blocks. */
|
|
|
147e83 |
+ ltgr %r6,%r6
|
|
|
147e83 |
+ je .Lzero_lt256
|
|
|
147e83 |
+.Lzero_loop256:
|
|
|
147e83 |
+ mvc 1(256,%r2),0(%r2) /* Fill 256 zeros at once. */
|
|
|
147e83 |
+ la %r2,256(%r2)
|
|
|
147e83 |
+ brctg %r6,.Lzero_loop256 /* Loop until all blocks are processed. */
|
|
|
147e83 |
+.Lzero_lt256:
|
|
|
147e83 |
+ exrl %r4,.Lmvc_lt256
|
|
|
147e83 |
+ j .Lend
|
|
|
147e83 |
+.Lmvc_lt256:
|
|
|
147e83 |
+ mvc 1(1,%r2),0(%r2)
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Find zero in 16byte aligned loop. */
|
|
|
147e83 |
+.Lloop64:
|
|
|
147e83 |
+ vl %v16,0(%r5,%r3)
|
|
|
147e83 |
+ vfenezfs %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
147e83 |
+ je .Lfound_v16 /* Jump away if zero was found. */
|
|
|
147e83 |
+ vl %v18,16(%r5,%r3) /* Load next part of s. */
|
|
|
147e83 |
+ vst %v16,0(%r5,%r2) /* Store previous part without zero to dst. */
|
|
|
147e83 |
+ vfenezfs %v17,%v18,%v18
|
|
|
147e83 |
+ je .Lfound_v18_16
|
|
|
147e83 |
+ vl %v16,32(%r5,%r3)
|
|
|
147e83 |
+ vst %v18,16(%r5,%r2)
|
|
|
147e83 |
+ vfenezfs %v17,%v16,%v16
|
|
|
147e83 |
+ je .Lfound_v16_32
|
|
|
147e83 |
+ vl %v18,48(%r5,%r3)
|
|
|
147e83 |
+ vst %v16,32(%r5,%r2)
|
|
|
147e83 |
+ vfenezfs %v17,%v18,%v18
|
|
|
147e83 |
+ je .Lfound_v18_48
|
|
|
147e83 |
+ vst %v18,48(%r5,%r2)
|
|
|
147e83 |
+
|
|
|
147e83 |
+ aghi %r5,64
|
|
|
147e83 |
+ lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */
|
|
|
147e83 |
+ aghi %r1,64
|
|
|
147e83 |
+ clgrjl %r1,%r4,.Lloop64
|
|
|
147e83 |
+
|
|
|
147e83 |
+ vl %v16,0(%r5,%r3) /* Load s. */
|
|
|
147e83 |
+ j .Llt64
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lfallback:
|
|
|
147e83 |
+ jg __wcpncpy_c
|
|
|
147e83 |
+END(__wcpncpy_vx)
|
|
|
147e83 |
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/wcpncpy.c b/sysdeps/s390/multiarch/wcpncpy.c
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..3db7b8b
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/wcpncpy.c
|
|
|
147e83 |
@@ -0,0 +1,28 @@
|
|
|
147e83 |
+/* Multiple versions of wcpncpy.
|
|
|
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_ifunc (__wcpncpy)
|
|
|
147e83 |
+weak_alias (__wcpncpy, wcpncpy)
|
|
|
147e83 |
+
|
|
|
147e83 |
+#else
|
|
|
147e83 |
+# include <wcsmbs/wcpncpy.c>
|
|
|
147e83 |
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
|
|
|
147e83 |
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
|
|
|
147e83 |
index c26ab0c..89b5b3b 100644
|
|
|
147e83 |
--- a/wcsmbs/Makefile
|
|
|
147e83 |
+++ b/wcsmbs/Makefile
|
|
|
147e83 |
@@ -42,7 +42,7 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
|
|
|
147e83 |
mbrtoc16 c16rtomb
|
|
|
147e83 |
|
|
|
147e83 |
strop-tests := wcscmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen \
|
|
|
147e83 |
- wcpcpy wcsncpy
|
|
|
147e83 |
+ wcpcpy wcsncpy wcpncpy
|
|
|
147e83 |
tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \
|
|
|
147e83 |
tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2 \
|
|
|
147e83 |
tst-c16c32-1 wcsatcliff $(addprefix test-,$(strop-tests))
|
|
|
147e83 |
diff --git a/wcsmbs/test-wcpncpy-ifunc.c b/wcsmbs/test-wcpncpy-ifunc.c
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..0685487
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/wcsmbs/test-wcpncpy-ifunc.c
|
|
|
147e83 |
@@ -0,0 +1,20 @@
|
|
|
147e83 |
+/* Test and measure IFUNC implementations of wcpncpy function.
|
|
|
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 TEST_IFUNC 1
|
|
|
147e83 |
+#include "test-wcpncpy.c"
|
|
|
147e83 |
diff --git a/wcsmbs/test-wcpncpy.c b/wcsmbs/test-wcpncpy.c
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..de302b4
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/wcsmbs/test-wcpncpy.c
|
|
|
147e83 |
@@ -0,0 +1,20 @@
|
|
|
147e83 |
+/* Test wcpncpy 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 "../string/test-stpncpy.c"
|
|
|
147e83 |
diff --git a/wcsmbs/wcpncpy.c b/wcsmbs/wcpncpy.c
|
|
|
147e83 |
index 2fab857..6337a87 100644
|
|
|
147e83 |
--- a/wcsmbs/wcpncpy.c
|
|
|
147e83 |
+++ b/wcsmbs/wcpncpy.c
|
|
|
147e83 |
@@ -18,6 +18,9 @@
|
|
|
147e83 |
|
|
|
147e83 |
#include <wchar.h>
|
|
|
147e83 |
|
|
|
147e83 |
+#ifdef WCPNCPY
|
|
|
147e83 |
+# define __wcpncpy WCPNCPY
|
|
|
147e83 |
+#endif
|
|
|
147e83 |
|
|
|
147e83 |
/* Copy no more than N wide-characters of SRC to DEST, returning the
|
|
|
147e83 |
address of the last character written into DEST. */
|
|
|
147e83 |
@@ -82,4 +85,6 @@ __wcpncpy (dest, src, n)
|
|
|
147e83 |
return dest - 1;
|
|
|
147e83 |
}
|
|
|
147e83 |
|
|
|
147e83 |
+#ifndef WCPNCPY
|
|
|
147e83 |
weak_alias (__wcpncpy, wcpncpy)
|
|
|
147e83 |
+#endif
|
|
|
147e83 |
--
|
|
|
147e83 |
2.3.0
|
|
|
147e83 |
|