|
|
bca718 |
From 74fa8494fa732a0bd63b14b60ea0f1e542e0cee6 Mon Sep 17 00:00:00 2001
|
|
|
bca718 |
From: Stefan Liebler <stli@linux.vnet.ibm.com>
|
|
|
bca718 |
Date: Thu, 8 Oct 2015 11:09:04 +0200
|
|
|
bca718 |
Subject: [PATCH 14/30] S390: Optimize strncpy and wcsncpy.
|
|
|
bca718 |
|
|
|
bca718 |
upstream-commit-id: d183b96ee6dc694e95f212c9272a178163351b19
|
|
|
bca718 |
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00160.html
|
|
|
bca718 |
|
|
|
bca718 |
This patch provides optimized versions of strncpy and wcsncpy with the z13
|
|
|
bca718 |
vector instructions.
|
|
|
bca718 |
|
|
|
bca718 |
ChangeLog:
|
|
|
bca718 |
|
|
|
bca718 |
* sysdeps/s390/multiarch/strncpy-vx.S: New File.
|
|
|
bca718 |
* sysdeps/s390/multiarch/strncpy.c: Likewise.
|
|
|
bca718 |
* sysdeps/s390/multiarch/wcsncpy-c.c: Likewise.
|
|
|
bca718 |
* sysdeps/s390/multiarch/wcsncpy-vx.S: Likewise.
|
|
|
bca718 |
* sysdeps/s390/multiarch/wcsncpy.c: Likewise.
|
|
|
bca718 |
* sysdeps/s390/s390-32/multiarch/strncpy.c: Likewise.
|
|
|
bca718 |
* sysdeps/s390/s390-64/multiarch/strncpy.c: Likewise.
|
|
|
bca718 |
* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add strncpy and
|
|
|
bca718 |
wcsncpy functions.
|
|
|
bca718 |
* wcsmbs/wcsncpy.c: Use WCSNCPY if defined.
|
|
|
bca718 |
* sysdeps/s390/multiarch/ifunc-impl-list.c
|
|
|
bca718 |
(__libc_ifunc_impl_list): Add ifunc test for strncpy, wcsncpy.
|
|
|
bca718 |
* string/test-strncpy.c: Add wcsncpy support.
|
|
|
bca718 |
* wcsmbs/test-wcsncpy.c: New File.
|
|
|
bca718 |
* wcsmbs/Makefile (strop-tests): Add wcsncpy.
|
|
|
bca718 |
* benchtests/bench-strncpy.c: Add wcsncpy support.
|
|
|
bca718 |
* benchtests/bench-wcsncpy.c: New File.
|
|
|
bca718 |
* benchtests/Makefile (wcsmbs-bench): Add wcsncpy
|
|
|
bca718 |
---
|
|
|
bca718 |
benchtests/Makefile | 2 +-
|
|
|
bca718 |
benchtests/bench-strncpy.c | 108 ++++++++++-----
|
|
|
bca718 |
benchtests/bench-wcsncpy.c | 20 +++
|
|
|
bca718 |
string/test-strncpy.c | 129 +++++++++++-------
|
|
|
bca718 |
sysdeps/s390/multiarch/Makefile | 6 +-
|
|
|
bca718 |
sysdeps/s390/multiarch/ifunc-impl-list.c | 3 +
|
|
|
bca718 |
sysdeps/s390/multiarch/strncpy-vx.S | 207 ++++++++++++++++++++++++++++
|
|
|
bca718 |
sysdeps/s390/multiarch/strncpy.c | 24 ++++
|
|
|
bca718 |
sysdeps/s390/multiarch/wcsncpy-c.c | 25 ++++
|
|
|
bca718 |
sysdeps/s390/multiarch/wcsncpy-vx.S | 223 +++++++++++++++++++++++++++++++
|
|
|
bca718 |
sysdeps/s390/multiarch/wcsncpy.c | 28 ++++
|
|
|
bca718 |
sysdeps/s390/s390-32/multiarch/strncpy.c | 21 +++
|
|
|
bca718 |
sysdeps/s390/s390-64/multiarch/strncpy.c | 21 +++
|
|
|
bca718 |
wcsmbs/Makefile | 2 +-
|
|
|
bca718 |
wcsmbs/test-wcsncpy-ifunc.c | 20 +++
|
|
|
bca718 |
wcsmbs/test-wcsncpy.c | 20 +++
|
|
|
bca718 |
wcsmbs/wcsncpy.c | 5 +
|
|
|
bca718 |
17 files changed, 778 insertions(+), 86 deletions(-)
|
|
|
bca718 |
create mode 100644 benchtests/bench-wcsncpy.c
|
|
|
bca718 |
create mode 100644 sysdeps/s390/multiarch/strncpy-vx.S
|
|
|
bca718 |
create mode 100644 sysdeps/s390/multiarch/strncpy.c
|
|
|
bca718 |
create mode 100644 sysdeps/s390/multiarch/wcsncpy-c.c
|
|
|
bca718 |
create mode 100644 sysdeps/s390/multiarch/wcsncpy-vx.S
|
|
|
bca718 |
create mode 100644 sysdeps/s390/multiarch/wcsncpy.c
|
|
|
bca718 |
create mode 100644 sysdeps/s390/s390-32/multiarch/strncpy.c
|
|
|
bca718 |
create mode 100644 sysdeps/s390/s390-64/multiarch/strncpy.c
|
|
|
bca718 |
create mode 100644 wcsmbs/test-wcsncpy-ifunc.c
|
|
|
bca718 |
create mode 100644 wcsmbs/test-wcsncpy.c
|
|
|
bca718 |
|
|
|
bca718 |
diff --git a/benchtests/Makefile b/benchtests/Makefile
|
|
|
bca718 |
index 1b491c6..f898258 100644
|
|
|
bca718 |
--- a/benchtests/Makefile
|
|
|
bca718 |
+++ b/benchtests/Makefile
|
|
|
bca718 |
@@ -38,7 +38,7 @@ string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
|
|
|
bca718 |
strcat strchr strchrnul strcmp strcpy strcspn strlen \
|
|
|
bca718 |
strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
|
|
|
bca718 |
strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
|
|
|
bca718 |
-wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy
|
|
|
bca718 |
+wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy
|
|
|
bca718 |
string-bench-all := $(string-bench) ${wcsmbs-bench}
|
|
|
bca718 |
|
|
|
bca718 |
stdlib-bench := strtod
|
|
|
bca718 |
diff --git a/benchtests/bench-strncpy.c b/benchtests/bench-strncpy.c
|
|
|
bca718 |
index 645925b..2cfd56a 100644
|
|
|
bca718 |
--- a/benchtests/bench-strncpy.c
|
|
|
bca718 |
+++ b/benchtests/bench-strncpy.c
|
|
|
bca718 |
@@ -1,5 +1,5 @@
|
|
|
bca718 |
/* Measure strncpy functions.
|
|
|
bca718 |
- Copyright (C) 2013 Free Software Foundation, Inc.
|
|
|
bca718 |
+ Copyright (C) 2013-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 |
@@ -16,23 +16,56 @@
|
|
|
bca718 |
License along with the GNU C Library; if not, see
|
|
|
bca718 |
<http://www.gnu.org/licenses/>. */
|
|
|
bca718 |
|
|
|
bca718 |
+#ifdef WIDE
|
|
|
bca718 |
+# include <wchar.h>
|
|
|
bca718 |
+# define CHAR wchar_t
|
|
|
bca718 |
+# define UCHAR wchar_t
|
|
|
bca718 |
+# define BIG_CHAR WCHAR_MAX
|
|
|
bca718 |
+# define SMALL_CHAR 1273
|
|
|
bca718 |
+# define MEMCMP wmemcmp
|
|
|
bca718 |
+# define MEMSET wmemset
|
|
|
bca718 |
+# define STRNLEN wcsnlen
|
|
|
bca718 |
+#else
|
|
|
bca718 |
+# define CHAR char
|
|
|
bca718 |
+# define UCHAR unsigned char
|
|
|
bca718 |
+# define BIG_CHAR CHAR_MAX
|
|
|
bca718 |
+# define SMALL_CHAR 127
|
|
|
bca718 |
+# define MEMCMP memcmp
|
|
|
bca718 |
+# define MEMSET memset
|
|
|
bca718 |
+# define STRNLEN strnlen
|
|
|
bca718 |
+#endif /* !WIDE */
|
|
|
bca718 |
+
|
|
|
bca718 |
#ifndef STRNCPY_RESULT
|
|
|
bca718 |
# define STRNCPY_RESULT(dst, len, n) dst
|
|
|
bca718 |
# define TEST_MAIN
|
|
|
bca718 |
-# define TEST_NAME "strncpy"
|
|
|
bca718 |
+# ifndef WIDE
|
|
|
bca718 |
+# define TEST_NAME "strncpy"
|
|
|
bca718 |
+# else
|
|
|
bca718 |
+# define TEST_NAME "wcsncpy"
|
|
|
bca718 |
+# endif /* WIDE */
|
|
|
bca718 |
# include "bench-string.h"
|
|
|
bca718 |
|
|
|
bca718 |
-char *simple_strncpy (char *, const char *, size_t);
|
|
|
bca718 |
-char *stupid_strncpy (char *, const char *, size_t);
|
|
|
bca718 |
-
|
|
|
bca718 |
-IMPL (stupid_strncpy, 0)
|
|
|
bca718 |
-IMPL (simple_strncpy, 0)
|
|
|
bca718 |
-IMPL (strncpy, 1)
|
|
|
bca718 |
-
|
|
|
bca718 |
-char *
|
|
|
bca718 |
-simple_strncpy (char *dst, const char *src, size_t n)
|
|
|
bca718 |
+# ifndef WIDE
|
|
|
bca718 |
+# define SIMPLE_STRNCPY simple_strncpy
|
|
|
bca718 |
+# define STUPID_STRNCPY stupid_strncpy
|
|
|
bca718 |
+# define STRNCPY strncpy
|
|
|
bca718 |
+# else
|
|
|
bca718 |
+# define SIMPLE_STRNCPY simple_wcsncpy
|
|
|
bca718 |
+# define STUPID_STRNCPY stupid_wcsncpy
|
|
|
bca718 |
+# define STRNCPY wcsncpy
|
|
|
bca718 |
+# endif /* WIDE */
|
|
|
bca718 |
+
|
|
|
bca718 |
+CHAR *SIMPLE_STRNCPY (CHAR *, const CHAR *, size_t);
|
|
|
bca718 |
+CHAR *STUPID_STRNCPY (CHAR *, const CHAR *, size_t);
|
|
|
bca718 |
+
|
|
|
bca718 |
+IMPL (STUPID_STRNCPY, 0)
|
|
|
bca718 |
+IMPL (SIMPLE_STRNCPY, 0)
|
|
|
bca718 |
+IMPL (STRNCPY, 1)
|
|
|
bca718 |
+
|
|
|
bca718 |
+CHAR *
|
|
|
bca718 |
+SIMPLE_STRNCPY (CHAR *dst, const CHAR *src, size_t n)
|
|
|
bca718 |
{
|
|
|
bca718 |
- char *ret = dst;
|
|
|
bca718 |
+ CHAR *ret = dst;
|
|
|
bca718 |
while (n--)
|
|
|
bca718 |
if ((*dst++ = *src++) == '\0')
|
|
|
bca718 |
{
|
|
|
bca718 |
@@ -43,10 +76,10 @@ simple_strncpy (char *dst, const char *src, size_t n)
|
|
|
bca718 |
return ret;
|
|
|
bca718 |
}
|
|
|
bca718 |
|
|
|
bca718 |
-char *
|
|
|
bca718 |
-stupid_strncpy (char *dst, const char *src, size_t n)
|
|
|
bca718 |
+CHAR *
|
|
|
bca718 |
+STUPID_STRNCPY (CHAR *dst, const CHAR *src, size_t n)
|
|
|
bca718 |
{
|
|
|
bca718 |
- size_t nc = strnlen (src, n);
|
|
|
bca718 |
+ size_t nc = STRNLEN (src, n);
|
|
|
bca718 |
size_t i;
|
|
|
bca718 |
|
|
|
bca718 |
for (i = 0; i < nc; ++i)
|
|
|
bca718 |
@@ -55,12 +88,12 @@ stupid_strncpy (char *dst, const char *src, size_t n)
|
|
|
bca718 |
dst[i] = '\0';
|
|
|
bca718 |
return dst;
|
|
|
bca718 |
}
|
|
|
bca718 |
-#endif
|
|
|
bca718 |
+#endif /* !STRNCPY_RESULT */
|
|
|
bca718 |
|
|
|
bca718 |
-typedef char *(*proto_t) (char *, const char *, size_t);
|
|
|
bca718 |
+typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t);
|
|
|
bca718 |
|
|
|
bca718 |
static void
|
|
|
bca718 |
-do_one_test (impl_t *impl, char *dst, const char *src, size_t len, size_t n)
|
|
|
bca718 |
+do_one_test (impl_t *impl, CHAR *dst, const CHAR *src, size_t len, size_t n)
|
|
|
bca718 |
{
|
|
|
bca718 |
size_t i, iters = INNER_LOOP_ITERS;
|
|
|
bca718 |
timing_t start, stop, cur;
|
|
|
bca718 |
@@ -73,7 +106,7 @@ do_one_test (impl_t *impl, char *dst, const char *src, size_t len, size_t n)
|
|
|
bca718 |
return;
|
|
|
bca718 |
}
|
|
|
bca718 |
|
|
|
bca718 |
- if (memcmp (dst, src, len > n ? n : len) != 0)
|
|
|
bca718 |
+ if (memcmp (dst, src, (len > n ? n : len) * sizeof (CHAR)) != 0)
|
|
|
bca718 |
{
|
|
|
bca718 |
error (0, 0, "Wrong result in function %s", impl->name);
|
|
|
bca718 |
ret = 1;
|
|
|
bca718 |
@@ -109,23 +142,24 @@ static void
|
|
|
bca718 |
do_test (size_t align1, size_t align2, size_t len, size_t n, int max_char)
|
|
|
bca718 |
{
|
|
|
bca718 |
size_t i;
|
|
|
bca718 |
- char *s1, *s2;
|
|
|
bca718 |
+ CHAR *s1, *s2;
|
|
|
bca718 |
|
|
|
bca718 |
align1 &= 7;
|
|
|
bca718 |
- if (align1 + len >= page_size)
|
|
|
bca718 |
+ if ((align1 + len) * sizeof (CHAR) >= page_size)
|
|
|
bca718 |
return;
|
|
|
bca718 |
|
|
|
bca718 |
align2 &= 7;
|
|
|
bca718 |
- if (align2 + len >= page_size)
|
|
|
bca718 |
+ if ((align2 + len) * sizeof (CHAR) >= page_size)
|
|
|
bca718 |
return;
|
|
|
bca718 |
|
|
|
bca718 |
- s1 = (char *) (buf1 + align1);
|
|
|
bca718 |
- s2 = (char *) (buf2 + align2);
|
|
|
bca718 |
+ s1 = (CHAR *) (buf1 + align1);
|
|
|
bca718 |
+ s2 = (CHAR *) (buf2 + align2);
|
|
|
bca718 |
|
|
|
bca718 |
for (i = 0; i < len; ++i)
|
|
|
bca718 |
s1[i] = 32 + 23 * i % (max_char - 32);
|
|
|
bca718 |
s1[len] = 0;
|
|
|
bca718 |
- for (i = len + 1; i + align1 < page_size && i < len + 64; ++i)
|
|
|
bca718 |
+ for (i = len + 1; (i + align1) * sizeof (CHAR) < page_size && i < len + 64;
|
|
|
bca718 |
+ ++i)
|
|
|
bca718 |
s1[i] = 32 + 32 * i % (max_char - 32);
|
|
|
bca718 |
|
|
|
bca718 |
printf ("Length %4zd, n %4zd, alignment %2zd/%2zd:", len, n, align1, align2);
|
|
|
bca718 |
@@ -150,22 +184,22 @@ test_main (void)
|
|
|
bca718 |
|
|
|
bca718 |
for (i = 1; i < 8; ++i)
|
|
|
bca718 |
{
|
|
|
bca718 |
- do_test (i, i, 16, 16, 127);
|
|
|
bca718 |
- do_test (i, i, 16, 16, 255);
|
|
|
bca718 |
- do_test (i, 2 * i, 16, 16, 127);
|
|
|
bca718 |
- do_test (2 * i, i, 16, 16, 255);
|
|
|
bca718 |
- do_test (8 - i, 2 * i, 1 << i, 2 << i, 127);
|
|
|
bca718 |
- do_test (2 * i, 8 - i, 2 << i, 1 << i, 127);
|
|
|
bca718 |
- do_test (8 - i, 2 * i, 1 << i, 2 << i, 255);
|
|
|
bca718 |
- do_test (2 * i, 8 - i, 2 << i, 1 << i, 255);
|
|
|
bca718 |
+ do_test (i, i, 16, 16, SMALL_CHAR);
|
|
|
bca718 |
+ do_test (i, i, 16, 16, BIG_CHAR);
|
|
|
bca718 |
+ do_test (i, 2 * i, 16, 16, SMALL_CHAR);
|
|
|
bca718 |
+ do_test (2 * i, i, 16, 16, BIG_CHAR);
|
|
|
bca718 |
+ do_test (8 - i, 2 * i, 1 << i, 2 << i, SMALL_CHAR);
|
|
|
bca718 |
+ do_test (2 * i, 8 - i, 2 << i, 1 << i, SMALL_CHAR);
|
|
|
bca718 |
+ do_test (8 - i, 2 * i, 1 << i, 2 << i, BIG_CHAR);
|
|
|
bca718 |
+ do_test (2 * i, 8 - i, 2 << i, 1 << i, BIG_CHAR);
|
|
|
bca718 |
}
|
|
|
bca718 |
|
|
|
bca718 |
for (i = 1; i < 8; ++i)
|
|
|
bca718 |
{
|
|
|
bca718 |
- do_test (0, 0, 4 << i, 8 << i, 127);
|
|
|
bca718 |
- do_test (0, 0, 16 << i, 8 << i, 127);
|
|
|
bca718 |
- do_test (8 - i, 2 * i, 4 << i, 8 << i, 127);
|
|
|
bca718 |
- do_test (8 - i, 2 * i, 16 << i, 8 << i, 127);
|
|
|
bca718 |
+ do_test (0, 0, 4 << i, 8 << i, SMALL_CHAR);
|
|
|
bca718 |
+ do_test (0, 0, 16 << i, 8 << i, SMALL_CHAR);
|
|
|
bca718 |
+ do_test (8 - i, 2 * i, 4 << i, 8 << i, SMALL_CHAR);
|
|
|
bca718 |
+ do_test (8 - i, 2 * i, 16 << i, 8 << i, SMALL_CHAR);
|
|
|
bca718 |
}
|
|
|
bca718 |
|
|
|
bca718 |
return ret;
|
|
|
bca718 |
diff --git a/benchtests/bench-wcsncpy.c b/benchtests/bench-wcsncpy.c
|
|
|
bca718 |
new file mode 100644
|
|
|
bca718 |
index 0000000..d6f63c9
|
|
|
bca718 |
--- /dev/null
|
|
|
bca718 |
+++ b/benchtests/bench-wcsncpy.c
|
|
|
bca718 |
@@ -0,0 +1,20 @@
|
|
|
bca718 |
+/* Measure wcsncpy 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-strncpy.c"
|
|
|
bca718 |
diff --git a/string/test-strncpy.c b/string/test-strncpy.c
|
|
|
bca718 |
index a623093..bdccc98 100644
|
|
|
bca718 |
--- a/string/test-strncpy.c
|
|
|
bca718 |
+++ b/string/test-strncpy.c
|
|
|
bca718 |
@@ -17,23 +17,56 @@
|
|
|
bca718 |
License along with the GNU C Library; if not, see
|
|
|
bca718 |
<http://www.gnu.org/licenses/>. */
|
|
|
bca718 |
|
|
|
bca718 |
+#ifdef WIDE
|
|
|
bca718 |
+# include <wchar.h>
|
|
|
bca718 |
+# define CHAR wchar_t
|
|
|
bca718 |
+# define UCHAR wchar_t
|
|
|
bca718 |
+# define BIG_CHAR WCHAR_MAX
|
|
|
bca718 |
+# define SMALL_CHAR 1273
|
|
|
bca718 |
+# define MEMCMP wmemcmp
|
|
|
bca718 |
+# define MEMSET wmemset
|
|
|
bca718 |
+# define STRNLEN wcsnlen
|
|
|
bca718 |
+#else
|
|
|
bca718 |
+# define CHAR char
|
|
|
bca718 |
+# define UCHAR unsigned char
|
|
|
bca718 |
+# define BIG_CHAR CHAR_MAX
|
|
|
bca718 |
+# define SMALL_CHAR 127
|
|
|
bca718 |
+# define MEMCMP memcmp
|
|
|
bca718 |
+# define MEMSET memset
|
|
|
bca718 |
+# define STRNLEN strnlen
|
|
|
bca718 |
+#endif /* !WIDE */
|
|
|
bca718 |
+
|
|
|
bca718 |
+
|
|
|
bca718 |
#ifndef STRNCPY_RESULT
|
|
|
bca718 |
# define STRNCPY_RESULT(dst, len, n) dst
|
|
|
bca718 |
# define TEST_MAIN
|
|
|
bca718 |
-# define TEST_NAME "strncpy"
|
|
|
bca718 |
+# ifndef WIDE
|
|
|
bca718 |
+# define TEST_NAME "strncpy"
|
|
|
bca718 |
+# else
|
|
|
bca718 |
+# define TEST_NAME "wcsncpy"
|
|
|
bca718 |
+# endif /* WIDE */
|
|
|
bca718 |
# include "test-string.h"
|
|
|
bca718 |
+# ifndef WIDE
|
|
|
bca718 |
+# define SIMPLE_STRNCPY simple_strncpy
|
|
|
bca718 |
+# define STUPID_STRNCPY stupid_strncpy
|
|
|
bca718 |
+# define STRNCPY strncpy
|
|
|
bca718 |
+# else
|
|
|
bca718 |
+# define SIMPLE_STRNCPY simple_wcsncpy
|
|
|
bca718 |
+# define STUPID_STRNCPY stupid_wcsncpy
|
|
|
bca718 |
+# define STRNCPY wcsncpy
|
|
|
bca718 |
+# endif /* WIDE */
|
|
|
bca718 |
|
|
|
bca718 |
-char *simple_strncpy (char *, const char *, size_t);
|
|
|
bca718 |
-char *stupid_strncpy (char *, const char *, size_t);
|
|
|
bca718 |
+CHAR *SIMPLE_STRNCPY (CHAR *, const CHAR *, size_t);
|
|
|
bca718 |
+CHAR *STUPID_STRNCPY (CHAR *, const CHAR *, size_t);
|
|
|
bca718 |
|
|
|
bca718 |
-IMPL (stupid_strncpy, 0)
|
|
|
bca718 |
-IMPL (simple_strncpy, 0)
|
|
|
bca718 |
-IMPL (strncpy, 1)
|
|
|
bca718 |
+IMPL (STUPID_STRNCPY, 0)
|
|
|
bca718 |
+IMPL (SIMPLE_STRNCPY, 0)
|
|
|
bca718 |
+IMPL (STRNCPY, 1)
|
|
|
bca718 |
|
|
|
bca718 |
-char *
|
|
|
bca718 |
-simple_strncpy (char *dst, const char *src, size_t n)
|
|
|
bca718 |
+CHAR *
|
|
|
bca718 |
+SIMPLE_STRNCPY (CHAR *dst, const CHAR *src, size_t n)
|
|
|
bca718 |
{
|
|
|
bca718 |
- char *ret = dst;
|
|
|
bca718 |
+ CHAR *ret = dst;
|
|
|
bca718 |
while (n--)
|
|
|
bca718 |
if ((*dst++ = *src++) == '\0')
|
|
|
bca718 |
{
|
|
|
bca718 |
@@ -44,10 +77,10 @@ simple_strncpy (char *dst, const char *src, size_t n)
|
|
|
bca718 |
return ret;
|
|
|
bca718 |
}
|
|
|
bca718 |
|
|
|
bca718 |
-char *
|
|
|
bca718 |
-stupid_strncpy (char *dst, const char *src, size_t n)
|
|
|
bca718 |
+CHAR *
|
|
|
bca718 |
+STUPID_STRNCPY (CHAR *dst, const CHAR *src, size_t n)
|
|
|
bca718 |
{
|
|
|
bca718 |
- size_t nc = strnlen (src, n);
|
|
|
bca718 |
+ size_t nc = STRNLEN (src, n);
|
|
|
bca718 |
size_t i;
|
|
|
bca718 |
|
|
|
bca718 |
for (i = 0; i < nc; ++i)
|
|
|
bca718 |
@@ -56,12 +89,12 @@ stupid_strncpy (char *dst, const char *src, size_t n)
|
|
|
bca718 |
dst[i] = '\0';
|
|
|
bca718 |
return dst;
|
|
|
bca718 |
}
|
|
|
bca718 |
-#endif
|
|
|
bca718 |
+#endif /* !STRNCPY_RESULT */
|
|
|
bca718 |
|
|
|
bca718 |
-typedef char *(*proto_t) (char *, const char *, size_t);
|
|
|
bca718 |
+typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t);
|
|
|
bca718 |
|
|
|
bca718 |
static void
|
|
|
bca718 |
-do_one_test (impl_t *impl, char *dst, const char *src, size_t len, size_t n)
|
|
|
bca718 |
+do_one_test (impl_t *impl, CHAR *dst, const char *src, size_t len, size_t n)
|
|
|
bca718 |
{
|
|
|
bca718 |
if (CALL (impl, dst, src, n) != STRNCPY_RESULT (dst, len, n))
|
|
|
bca718 |
{
|
|
|
bca718 |
@@ -71,7 +104,7 @@ do_one_test (impl_t *impl, char *dst, const char *src, size_t len, size_t n)
|
|
|
bca718 |
return;
|
|
|
bca718 |
}
|
|
|
bca718 |
|
|
|
bca718 |
- if (memcmp (dst, src, len > n ? n : len) != 0)
|
|
|
bca718 |
+ if (memcmp (dst, src, (len > n ? n : len) * sizeof (CHAR)) != 0)
|
|
|
bca718 |
{
|
|
|
bca718 |
error (0, 0, "Wrong result in function %s", impl->name);
|
|
|
bca718 |
ret = 1;
|
|
|
bca718 |
@@ -96,23 +129,26 @@ static void
|
|
|
bca718 |
do_test (size_t align1, size_t align2, size_t len, size_t n, int max_char)
|
|
|
bca718 |
{
|
|
|
bca718 |
size_t i;
|
|
|
bca718 |
- char *s1, *s2;
|
|
|
bca718 |
+ CHAR *s1, *s2;
|
|
|
bca718 |
|
|
|
bca718 |
+/* For wcsncpy: align1 and align2 here mean alignment not in bytes,
|
|
|
bca718 |
+ but in wchar_ts, in bytes it will equal to align * (sizeof (wchar_t)). */
|
|
|
bca718 |
align1 &= 7;
|
|
|
bca718 |
- if (align1 + len >= page_size)
|
|
|
bca718 |
+ if ((align1 + len) * sizeof (CHAR) >= page_size)
|
|
|
bca718 |
return;
|
|
|
bca718 |
|
|
|
bca718 |
align2 &= 7;
|
|
|
bca718 |
- if (align2 + len >= page_size)
|
|
|
bca718 |
+ if ((align2 + len) * sizeof (CHAR) >= page_size)
|
|
|
bca718 |
return;
|
|
|
bca718 |
|
|
|
bca718 |
- s1 = (char *) (buf1 + align1);
|
|
|
bca718 |
- s2 = (char *) (buf2 + align2);
|
|
|
bca718 |
+ s1 = (CHAR *) (buf1) + align1;
|
|
|
bca718 |
+ s2 = (CHAR *) (buf2) + align2;
|
|
|
bca718 |
|
|
|
bca718 |
for (i = 0; i < len; ++i)
|
|
|
bca718 |
s1[i] = 32 + 23 * i % (max_char - 32);
|
|
|
bca718 |
s1[len] = 0;
|
|
|
bca718 |
- for (i = len + 1; i + align1 < page_size && i < len + 64; ++i)
|
|
|
bca718 |
+ for (i = len + 1; (i + align1) * sizeof (CHAR) < page_size && i < len + 64;
|
|
|
bca718 |
+ ++i)
|
|
|
bca718 |
s1[i] = 32 + 32 * i % (max_char - 32);
|
|
|
bca718 |
|
|
|
bca718 |
FOR_EACH_IMPL (impl, 0)
|
|
|
bca718 |
@@ -123,12 +159,16 @@ static void
|
|
|
bca718 |
do_random_tests (void)
|
|
|
bca718 |
{
|
|
|
bca718 |
size_t i, j, n, align1, align2, len, size, mode;
|
|
|
bca718 |
- unsigned char *p1 = buf1 + page_size - 512;
|
|
|
bca718 |
- unsigned char *p2 = buf2 + page_size - 512;
|
|
|
bca718 |
- unsigned char *res;
|
|
|
bca718 |
+ UCHAR *p1 = (UCHAR *) (buf1 + page_size) - 512;
|
|
|
bca718 |
+ UCHAR *p2 = (UCHAR *) (buf2 + page_size) - 512;
|
|
|
bca718 |
+ UCHAR *res;
|
|
|
bca718 |
|
|
|
bca718 |
for (n = 0; n < ITERATIONS; n++)
|
|
|
bca718 |
{
|
|
|
bca718 |
+ /* For wcsncpy: align1 and align2 here mean align not in bytes,
|
|
|
bca718 |
+ but in wchar_ts, in bytes it will equal to align * (sizeof
|
|
|
bca718 |
+ (wchar_t)). */
|
|
|
bca718 |
+
|
|
|
bca718 |
mode = random ();
|
|
|
bca718 |
if (mode & 1)
|
|
|
bca718 |
{
|
|
|
bca718 |
@@ -166,7 +206,7 @@ do_random_tests (void)
|
|
|
bca718 |
{
|
|
|
bca718 |
size = random () & 511;
|
|
|
bca718 |
if (size + j > 512)
|
|
|
bca718 |
- size = 512 - j - (random() & 31);
|
|
|
bca718 |
+ size = 512 - j - (random () & 31);
|
|
|
bca718 |
}
|
|
|
bca718 |
else
|
|
|
bca718 |
size = 512 - j;
|
|
|
bca718 |
@@ -182,18 +222,17 @@ do_random_tests (void)
|
|
|
bca718 |
p1[i] = 0;
|
|
|
bca718 |
else
|
|
|
bca718 |
{
|
|
|
bca718 |
- p1[i] = random () & 255;
|
|
|
bca718 |
+ p1[i] = random () & BIG_CHAR;
|
|
|
bca718 |
if (i >= align1 && i < len + align1 && !p1[i])
|
|
|
bca718 |
- p1[i] = (random () & 127) + 3;
|
|
|
bca718 |
+ p1[i] = (random () & SMALL_CHAR) + 3;
|
|
|
bca718 |
}
|
|
|
bca718 |
}
|
|
|
bca718 |
|
|
|
bca718 |
FOR_EACH_IMPL (impl, 1)
|
|
|
bca718 |
{
|
|
|
bca718 |
- memset (p2 - 64, '\1', 512 + 64);
|
|
|
bca718 |
- res = (unsigned char *) CALL (impl,
|
|
|
bca718 |
- (char *) (p2 + align2),
|
|
|
bca718 |
- (char *) (p1 + align1), size);
|
|
|
bca718 |
+ MEMSET (p2 - 64, '\1', 512 + 64);
|
|
|
bca718 |
+ res = (UCHAR *) CALL (impl, (CHAR *) (p2 + align2),
|
|
|
bca718 |
+ (CHAR *) (p1 + align1), size);
|
|
|
bca718 |
if (res != STRNCPY_RESULT (p2 + align2, len, size))
|
|
|
bca718 |
{
|
|
|
bca718 |
error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %zd, %zd) %p != %p",
|
|
|
bca718 |
@@ -235,7 +274,7 @@ do_random_tests (void)
|
|
|
bca718 |
j = len + 1;
|
|
|
bca718 |
if (size < j)
|
|
|
bca718 |
j = size;
|
|
|
bca718 |
- if (memcmp (p1 + align1, p2 + align2, j))
|
|
|
bca718 |
+ if (MEMCMP (p1 + align1, p2 + align2, j))
|
|
|
bca718 |
{
|
|
|
bca718 |
error (0, 0, "Iteration %zd - different strings, %s (%zd, %zd, %zd)",
|
|
|
bca718 |
n, impl->name, align1, align2, len);
|
|
|
bca718 |
@@ -259,22 +298,22 @@ test_main (void)
|
|
|
bca718 |
|
|
|
bca718 |
for (i = 1; i < 8; ++i)
|
|
|
bca718 |
{
|
|
|
bca718 |
- do_test (i, i, 16, 16, 127);
|
|
|
bca718 |
- do_test (i, i, 16, 16, 255);
|
|
|
bca718 |
- do_test (i, 2 * i, 16, 16, 127);
|
|
|
bca718 |
- do_test (2 * i, i, 16, 16, 255);
|
|
|
bca718 |
- do_test (8 - i, 2 * i, 1 << i, 2 << i, 127);
|
|
|
bca718 |
- do_test (2 * i, 8 - i, 2 << i, 1 << i, 127);
|
|
|
bca718 |
- do_test (8 - i, 2 * i, 1 << i, 2 << i, 255);
|
|
|
bca718 |
- do_test (2 * i, 8 - i, 2 << i, 1 << i, 255);
|
|
|
bca718 |
+ do_test (i, i, 16, 16, SMALL_CHAR);
|
|
|
bca718 |
+ do_test (i, i, 16, 16, BIG_CHAR);
|
|
|
bca718 |
+ do_test (i, 2 * i, 16, 16, SMALL_CHAR);
|
|
|
bca718 |
+ do_test (2 * i, i, 16, 16, BIG_CHAR);
|
|
|
bca718 |
+ do_test (8 - i, 2 * i, 1 << i, 2 << i, SMALL_CHAR);
|
|
|
bca718 |
+ do_test (2 * i, 8 - i, 2 << i, 1 << i, SMALL_CHAR);
|
|
|
bca718 |
+ do_test (8 - i, 2 * i, 1 << i, 2 << i, BIG_CHAR);
|
|
|
bca718 |
+ do_test (2 * i, 8 - i, 2 << i, 1 << i, BIG_CHAR);
|
|
|
bca718 |
}
|
|
|
bca718 |
|
|
|
bca718 |
for (i = 1; i < 8; ++i)
|
|
|
bca718 |
{
|
|
|
bca718 |
- do_test (0, 0, 4 << i, 8 << i, 127);
|
|
|
bca718 |
- do_test (0, 0, 16 << i, 8 << i, 127);
|
|
|
bca718 |
- do_test (8 - i, 2 * i, 4 << i, 8 << i, 127);
|
|
|
bca718 |
- do_test (8 - i, 2 * i, 16 << i, 8 << i, 127);
|
|
|
bca718 |
+ do_test (0, 0, 4 << i, 8 << i, SMALL_CHAR);
|
|
|
bca718 |
+ do_test (0, 0, 16 << i, 8 << i, SMALL_CHAR);
|
|
|
bca718 |
+ do_test (8 - i, 2 * i, 4 << i, 8 << i, SMALL_CHAR);
|
|
|
bca718 |
+ do_test (8 - i, 2 * i, 16 << i, 8 << i, SMALL_CHAR);
|
|
|
bca718 |
}
|
|
|
bca718 |
|
|
|
bca718 |
do_random_tests ();
|
|
|
bca718 |
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
|
|
|
bca718 |
index 5b57342..0dff2dc 100644
|
|
|
bca718 |
--- a/sysdeps/s390/multiarch/Makefile
|
|
|
bca718 |
+++ b/sysdeps/s390/multiarch/Makefile
|
|
|
bca718 |
@@ -2,12 +2,14 @@ ifeq ($(subdir),string)
|
|
|
bca718 |
sysdep_routines += strlen strlen-vx strlen-c \
|
|
|
bca718 |
strnlen strnlen-vx strnlen-c \
|
|
|
bca718 |
strcpy strcpy-vx \
|
|
|
bca718 |
- stpcpy stpcpy-vx stpcpy-c
|
|
|
bca718 |
+ stpcpy stpcpy-vx stpcpy-c \
|
|
|
bca718 |
+ strncpy strncpy-vx
|
|
|
bca718 |
endif
|
|
|
bca718 |
|
|
|
bca718 |
ifeq ($(subdir),wcsmbs)
|
|
|
bca718 |
sysdep_routines += wcslen wcslen-vx wcslen-c \
|
|
|
bca718 |
wcsnlen wcsnlen-vx wcsnlen-c \
|
|
|
bca718 |
wcscpy wcscpy-vx wcscpy-c \
|
|
|
bca718 |
- wcpcpy wcpcpy-vx wcpcpy-c
|
|
|
bca718 |
+ wcpcpy wcpcpy-vx wcpcpy-c \
|
|
|
bca718 |
+ wcsncpy wcsncpy-vx wcsncpy-c
|
|
|
bca718 |
endif
|
|
|
bca718 |
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
|
|
|
bca718 |
index a402301..940421d 100644
|
|
|
bca718 |
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
|
|
|
bca718 |
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
|
|
|
bca718 |
@@ -91,6 +91,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
|
|
|
bca718 |
IFUNC_VX_IMPL (stpcpy);
|
|
|
bca718 |
IFUNC_VX_IMPL (wcpcpy);
|
|
|
bca718 |
|
|
|
bca718 |
+ IFUNC_VX_IMPL (strncpy);
|
|
|
bca718 |
+ IFUNC_VX_IMPL (wcsncpy);
|
|
|
bca718 |
+
|
|
|
bca718 |
#endif /* HAVE_S390_VX_ASM_SUPPORT */
|
|
|
bca718 |
|
|
|
bca718 |
return i;
|
|
|
bca718 |
diff --git a/sysdeps/s390/multiarch/strncpy-vx.S b/sysdeps/s390/multiarch/strncpy-vx.S
|
|
|
bca718 |
new file mode 100644
|
|
|
bca718 |
index 0000000..c18b9b7
|
|
|
bca718 |
--- /dev/null
|
|
|
bca718 |
+++ b/sysdeps/s390/multiarch/strncpy-vx.S
|
|
|
bca718 |
@@ -0,0 +1,207 @@
|
|
|
bca718 |
+/* Vector optimized 32/64 bit S/390 version of strncpy.
|
|
|
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 |
+/* char * strncpy (const char *dest, const char *src, size_t n)
|
|
|
bca718 |
+ Copy at most n characters of string src to dest.
|
|
|
bca718 |
+
|
|
|
bca718 |
+ Register usage:
|
|
|
bca718 |
+ -r0=dest pointer for return
|
|
|
bca718 |
+ -r1=tmp, zero byte index
|
|
|
bca718 |
+ -r2=dest
|
|
|
bca718 |
+ -r3=src
|
|
|
bca718 |
+ -r4=n
|
|
|
bca718 |
+ -r5=current_len
|
|
|
bca718 |
+ -r6=tmp, loaded bytes
|
|
|
bca718 |
+ -r7=tmp, border
|
|
|
bca718 |
+ -v16=part of src
|
|
|
bca718 |
+ -v17=index of zero
|
|
|
bca718 |
+ -v18=part of src
|
|
|
bca718 |
+ -v31=register save area for r6, r7
|
|
|
bca718 |
+*/
|
|
|
bca718 |
+ENTRY(__strncpy_vx)
|
|
|
bca718 |
+ .machine "z13"
|
|
|
bca718 |
+ .machinemode "zarch_nohighgprs"
|
|
|
bca718 |
+
|
|
|
bca718 |
+# if !defined __s390x__
|
|
|
bca718 |
+ llgfr %r4,%r4
|
|
|
bca718 |
+# endif /* !defined __s390x__ */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ clgfi %r4,0
|
|
|
bca718 |
+ ber %r14 /* Nothing to do, if n == 0. */
|
|
|
bca718 |
+ lgr %r0,%r2 /* Save destination pointer for return. */
|
|
|
bca718 |
+ vlvgp %v31,%r6,%r7 /* Save registers. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ vlbb %v16,0(%r3),6 /* Load s until next 4k-byte boundary. */
|
|
|
bca718 |
+ lcbb %r6,0(%r3),6 /* Get bytes to 4k-byte boundary or 16. */
|
|
|
bca718 |
+ llgfr %r6,%r6 /* Convert 32bit to 64bit. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ lghi %r5,0 /* current_len = 0. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ clgrjle %r4,%r6,.Lremaining_v16 /* If n <= loaded-bytes
|
|
|
bca718 |
+ -> process remaining. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ /* n > loaded-byte-count. */
|
|
|
bca718 |
+ vfenezb %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
bca718 |
+ vlgvb %r1,%v17,7 /* Load zero index or 16 if not found. */
|
|
|
bca718 |
+ clrjl %r1,%r6,.Lfound_v16_store /* Found zero within loaded bytes,
|
|
|
bca718 |
+ copy and return. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ /* Align s to 16 byte. */
|
|
|
bca718 |
+ risbgn %r7,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
|
|
|
bca718 |
+ lghi %r5,15 /* current_len = 15. */
|
|
|
bca718 |
+ slr %r5,%r7 /* Compute highest index to 16byte boundary. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ /* Zero not found and n > loaded-byte-count. */
|
|
|
bca718 |
+ vstl %v16,%r5,0(%r2) /* Copy loaded characters - no zero. */
|
|
|
bca718 |
+ ahi %r5,1 /* Start loop at next character. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ /* Now we are 16byte aligned, so we can load
|
|
|
bca718 |
+ a full vreg without page fault. */
|
|
|
bca718 |
+ lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */
|
|
|
bca718 |
+ aghi %r1,64
|
|
|
bca718 |
+ clgrjl %r1,%r4,.Lloop64
|
|
|
bca718 |
+
|
|
|
bca718 |
+ vl %v16,0(%r5,%r3) /* Load s. */
|
|
|
bca718 |
+ clgijl %r4,17,.Lremaining_v16 /* If n <= 16, process remaining
|
|
|
bca718 |
+ bytes. */
|
|
|
bca718 |
+.Llt64:
|
|
|
bca718 |
+ lgr %r7,%r4
|
|
|
bca718 |
+ slgfi %r7,16 /* border_len = n - 16. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ clgrjhe %r5,%r7,.Lremaining_v16 /* If current_len >= border
|
|
|
bca718 |
+ then process remaining bytes. */
|
|
|
bca718 |
+ vfenezbs %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
bca718 |
+ je .Lfound_v16 /* Jump away if zero was found. */
|
|
|
bca718 |
+ vl %v18,16(%r5,%r3) /* Load next part of s. */
|
|
|
bca718 |
+ vst %v16,0(%r5,%r2) /* Store previous part without zero to dst. */
|
|
|
bca718 |
+ aghi %r5,16
|
|
|
bca718 |
+
|
|
|
bca718 |
+ clgrjhe %r5,%r7,.Lremaining_v18
|
|
|
bca718 |
+ vfenezbs %v17,%v18,%v18
|
|
|
bca718 |
+ je .Lfound_v18
|
|
|
bca718 |
+ vl %v16,16(%r5,%r3)
|
|
|
bca718 |
+ vst %v18,0(%r5,%r2)
|
|
|
bca718 |
+ aghi %r5,16
|
|
|
bca718 |
+
|
|
|
bca718 |
+ clgrjhe %r5,%r7,.Lremaining_v16
|
|
|
bca718 |
+ vfenezbs %v17,%v16,%v16
|
|
|
bca718 |
+ je .Lfound_v16
|
|
|
bca718 |
+ vl %v18,16(%r5,%r3)
|
|
|
bca718 |
+ vst %v16,0(%r5,%r2)
|
|
|
bca718 |
+ aghi %r5,16
|
|
|
bca718 |
+
|
|
|
bca718 |
+.Lremaining_v18:
|
|
|
bca718 |
+ vlr %v16,%v18
|
|
|
bca718 |
+.Lremaining_v16:
|
|
|
bca718 |
+ /* v16 contains the remaining bytes [1...16].
|
|
|
bca718 |
+ Store remaining bytes and append string-termination. */
|
|
|
bca718 |
+ vfenezb %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
bca718 |
+ slgrk %r7,%r4,%r5 /* Remaining bytes = maxlen - current_len. */
|
|
|
bca718 |
+ aghi %r7,-1 /* vstl needs highest index. */
|
|
|
bca718 |
+ la %r2,0(%r5,%r2) /* vstl has no index register. */
|
|
|
bca718 |
+ vlgvb %r1,%v17,7 /* Load zero index or 16 if not found. */
|
|
|
bca718 |
+ /* Zero in remaining bytes? -> jump away (zero-index < max-index)
|
|
|
bca718 |
+ Do not jump away if zero-index == max-index,
|
|
|
bca718 |
+ but simply copy zero with vstl below. */
|
|
|
bca718 |
+ clrjl %r1,%r7,.Lfound_v16_store
|
|
|
bca718 |
+ vstl %v16,%r7,0(%r2) /* Store remaining bytes without null
|
|
|
bca718 |
+ termination!. */
|
|
|
bca718 |
+.Lend:
|
|
|
bca718 |
+ /* Restore saved registers. */
|
|
|
bca718 |
+ vlgvg %r6,%v31,0
|
|
|
bca718 |
+ vlgvg %r7,%v31,1
|
|
|
bca718 |
+ lgr %r2,%r0 /* Load saved dest-ptr. */
|
|
|
bca718 |
+ br %r14
|
|
|
bca718 |
+
|
|
|
bca718 |
+
|
|
|
bca718 |
+.Lfound_v16_32:
|
|
|
bca718 |
+ aghi %r5,32
|
|
|
bca718 |
+ j .Lfound_v16
|
|
|
bca718 |
+.Lfound_v18_48:
|
|
|
bca718 |
+ aghi %r5,32
|
|
|
bca718 |
+.Lfound_v18_16:
|
|
|
bca718 |
+ aghi %r5,16
|
|
|
bca718 |
+.Lfound_v18:
|
|
|
bca718 |
+ vlr %v16,%v18
|
|
|
bca718 |
+.Lfound_v16:
|
|
|
bca718 |
+ /* v16 contains a zero. Store remaining bytes to zero. current_len
|
|
|
bca718 |
+ has not reached border, thus checking for n is not needed! */
|
|
|
bca718 |
+ vlgvb %r1,%v17,7 /* Load byte index of zero. */
|
|
|
bca718 |
+ la %r2,0(%r5,%r2) /* vstl has no support for index-register. */
|
|
|
bca718 |
+.Lfound_v16_store:
|
|
|
bca718 |
+ vstl %v16,%r1,0(%r2) /* Copy characters including zero. */
|
|
|
bca718 |
+ /* Fill remaining bytes with zero - remaining count always > 0. */
|
|
|
bca718 |
+ algr %r5,%r1 /* Remaining bytes (=%r4) = ... */
|
|
|
bca718 |
+ slgr %r4,%r5 /* = n - (current_len + zero_index + 1). */
|
|
|
bca718 |
+ la %r2,0(%r1,%r2) /* Pointer to zero. start filling beyond. */
|
|
|
bca718 |
+ aghi %r4,-2 /* mvc with exrl needs count - 1.
|
|
|
bca718 |
+ (additional -1, see remaining bytes above) */
|
|
|
bca718 |
+ srlg %r6,%r4,8 /* Split into 256 byte blocks. */
|
|
|
bca718 |
+ ltgr %r6,%r6
|
|
|
bca718 |
+ je .Lzero_lt256
|
|
|
bca718 |
+.Lzero_loop256:
|
|
|
bca718 |
+ mvc 1(256,%r2),0(%r2) /* Fill 256 zeros at once. */
|
|
|
bca718 |
+ la %r2,256(%r2)
|
|
|
bca718 |
+ brctg %r6,.Lzero_loop256 /* Loop until all blocks are processed. */
|
|
|
bca718 |
+.Lzero_lt256:
|
|
|
bca718 |
+ exrl %r4,.Lmvc_lt256
|
|
|
bca718 |
+ j .Lend
|
|
|
bca718 |
+.Lmvc_lt256:
|
|
|
bca718 |
+ mvc 1(1,%r2),0(%r2)
|
|
|
bca718 |
+
|
|
|
bca718 |
+.Lloop64:
|
|
|
bca718 |
+ vl %v16,0(%r5,%r3) /* Load s. */
|
|
|
bca718 |
+ vfenezbs %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
bca718 |
+ je .Lfound_v16 /* Jump away if zero was found. */
|
|
|
bca718 |
+ vl %v18,16(%r5,%r3) /* Load next part of s. */
|
|
|
bca718 |
+ vst %v16,0(%r5,%r2) /* Store previous part without zero to dst. */
|
|
|
bca718 |
+ vfenezbs %v17,%v18,%v18
|
|
|
bca718 |
+ je .Lfound_v18_16
|
|
|
bca718 |
+ vl %v16,32(%r5,%r3)
|
|
|
bca718 |
+ vst %v18,16(%r5,%r2)
|
|
|
bca718 |
+ vfenezbs %v17,%v16,%v16
|
|
|
bca718 |
+ je .Lfound_v16_32
|
|
|
bca718 |
+ vl %v18,48(%r5,%r3)
|
|
|
bca718 |
+ vst %v16,32(%r5,%r2)
|
|
|
bca718 |
+ vfenezbs %v17,%v18,%v18
|
|
|
bca718 |
+ je .Lfound_v18_48
|
|
|
bca718 |
+ vst %v18,48(%r5,%r2)
|
|
|
bca718 |
+
|
|
|
bca718 |
+ aghi %r5,64
|
|
|
bca718 |
+ lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */
|
|
|
bca718 |
+ aghi %r1,64
|
|
|
bca718 |
+ clgrjl %r1,%r4,.Lloop64
|
|
|
bca718 |
+
|
|
|
bca718 |
+ vl %v16,0(%r5,%r3) /* Load s. */
|
|
|
bca718 |
+ j .Llt64
|
|
|
bca718 |
+END(__strncpy_vx)
|
|
|
bca718 |
+
|
|
|
bca718 |
+# define strncpy __strncpy_c
|
|
|
bca718 |
+# undef libc_hidden_builtin_def
|
|
|
bca718 |
+# define libc_hidden_builtin_def(name) strong_alias(__strncpy_c, __GI_strncpy)
|
|
|
bca718 |
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
|
|
|
bca718 |
+
|
|
|
bca718 |
+/* Include strncpy-implementation in s390-32/s390-64 subdirectory. */
|
|
|
bca718 |
+#include <strncpy.S>
|
|
|
bca718 |
diff --git a/sysdeps/s390/multiarch/strncpy.c b/sysdeps/s390/multiarch/strncpy.c
|
|
|
bca718 |
new file mode 100644
|
|
|
bca718 |
index 0000000..0b0c308
|
|
|
bca718 |
--- /dev/null
|
|
|
bca718 |
+++ b/sysdeps/s390/multiarch/strncpy.c
|
|
|
bca718 |
@@ -0,0 +1,24 @@
|
|
|
bca718 |
+/* Multiple versions of strncpy.
|
|
|
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 <string.h>
|
|
|
bca718 |
+# include <ifunc-resolve.h>
|
|
|
bca718 |
+
|
|
|
bca718 |
+s390_vx_libc_ifunc2 (__strncpy, strncpy)
|
|
|
bca718 |
+#endif
|
|
|
bca718 |
diff --git a/sysdeps/s390/multiarch/wcsncpy-c.c b/sysdeps/s390/multiarch/wcsncpy-c.c
|
|
|
bca718 |
new file mode 100644
|
|
|
bca718 |
index 0000000..a46e4ac
|
|
|
bca718 |
--- /dev/null
|
|
|
bca718 |
+++ b/sysdeps/s390/multiarch/wcsncpy-c.c
|
|
|
bca718 |
@@ -0,0 +1,25 @@
|
|
|
bca718 |
+/* Default wcsncpy 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 WCSNCPY __wcsncpy_c
|
|
|
bca718 |
+
|
|
|
bca718 |
+# include <wchar.h>
|
|
|
bca718 |
+extern __typeof (__wcsncpy) __wcsncpy_c;
|
|
|
bca718 |
+# include <wcsmbs/wcsncpy.c>
|
|
|
bca718 |
+#endif
|
|
|
bca718 |
diff --git a/sysdeps/s390/multiarch/wcsncpy-vx.S b/sysdeps/s390/multiarch/wcsncpy-vx.S
|
|
|
bca718 |
new file mode 100644
|
|
|
bca718 |
index 0000000..072a2d4
|
|
|
bca718 |
--- /dev/null
|
|
|
bca718 |
+++ b/sysdeps/s390/multiarch/wcsncpy-vx.S
|
|
|
bca718 |
@@ -0,0 +1,223 @@
|
|
|
bca718 |
+/* Vector optimized 32/64 bit S/390 version of wcsncpy.
|
|
|
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 |
+/* wchar_t *wcsncpy (const wchar_t *dest, const wchar_t *src, size_t n)
|
|
|
bca718 |
+ Copy at most n characters of string src to dest.
|
|
|
bca718 |
+
|
|
|
bca718 |
+ Register usage:
|
|
|
bca718 |
+ -r0=dest pointer for return
|
|
|
bca718 |
+ -r1=tmp, zero byte index
|
|
|
bca718 |
+ -r2=dest
|
|
|
bca718 |
+ -r3=src
|
|
|
bca718 |
+ -r4=n
|
|
|
bca718 |
+ -r5=current_len
|
|
|
bca718 |
+ -r6=tmp, loaded bytes
|
|
|
bca718 |
+ -r7=tmp, border
|
|
|
bca718 |
+ -v16=part of src
|
|
|
bca718 |
+ -v17=index of zero
|
|
|
bca718 |
+ -v18=part of src
|
|
|
bca718 |
+ -v31=register save area for r6, r7
|
|
|
bca718 |
+*/
|
|
|
bca718 |
+ENTRY(__wcsncpy_vx)
|
|
|
bca718 |
+ .machine "z13"
|
|
|
bca718 |
+ .machinemode "zarch_nohighgprs"
|
|
|
bca718 |
+
|
|
|
bca718 |
+# if !defined __s390x__
|
|
|
bca718 |
+ llgfr %r4,%r4
|
|
|
bca718 |
+# endif /* !defined __s390x__ */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ clgfi %r4,0
|
|
|
bca718 |
+ ber %r14 /* Nothing to do, if n == 0. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ vlbb %v16,0(%r3),6 /* Load s until next 4k-byte boundary. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ tmll %r3,3 /* Test if s is 4-byte aligned? */
|
|
|
bca718 |
+ jne .Lfallback /* And use common-code variant if not. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ vlvgp %v31,%r6,%r7 /* Save registers. */
|
|
|
bca718 |
+ lgr %r0,%r2 /* Save destination pointer for return. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ lcbb %r6,0(%r3),6 /* Get bytes to 4k-byte boundary or 16. */
|
|
|
bca718 |
+ llgfr %r6,%r6 /* Convert 32bit to 64bit. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ lghi %r5,0 /* current_len = 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 n. */
|
|
|
bca718 |
+ lghi %r1,-4 /* Max byte-count is 18446744073709551612. */
|
|
|
bca718 |
+# else
|
|
|
bca718 |
+ tmlh %r4,49152 /* Test bit 0 or 1 of n. */
|
|
|
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 |
+ clgrjle %r4,%r6,.Lremaining_v16 /* If n <= loaded-bytes
|
|
|
bca718 |
+ -> process remaining. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ /* n > loaded-byte-count. */
|
|
|
bca718 |
+ vfenezf %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
bca718 |
+ vlgvb %r1,%v17,7 /* Load zero index or 16 if not found. */
|
|
|
bca718 |
+ aghi %r1,3 /* Also copy remaining bytes of zero. */
|
|
|
bca718 |
+ clrjl %r1,%r6,.Lfound_v16_store /* Found zero within loaded bytes,
|
|
|
bca718 |
+ copy and return. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ /* Align s to 16 byte. */
|
|
|
bca718 |
+ risbgn %r7,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
|
|
|
bca718 |
+ lghi %r5,15 /* current_len = 15. */
|
|
|
bca718 |
+ slr %r5,%r7 /* Compute highest index to 16byte boundary. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ /* Zero not found and n > loaded-byte-count. */
|
|
|
bca718 |
+ vstl %v16,%r5,0(%r2) /* Copy loaded characters - no zero. */
|
|
|
bca718 |
+ ahi %r5,1 /* Start loop at next character. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ /* Now we are 16byte aligned, so we can load
|
|
|
bca718 |
+ a full vreg without page fault. */
|
|
|
bca718 |
+ lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */
|
|
|
bca718 |
+ aghi %r1,64
|
|
|
bca718 |
+ clgrjl %r1,%r4,.Lloop64
|
|
|
bca718 |
+
|
|
|
bca718 |
+ vl %v16,0(%r5,%r3) /* Load s. */
|
|
|
bca718 |
+ clgijl %r4,17,.Lremaining_v16 /* If n <=16, process remaining
|
|
|
bca718 |
+ bytes. */
|
|
|
bca718 |
+.Llt64:
|
|
|
bca718 |
+ lgr %r7,%r4
|
|
|
bca718 |
+ slgfi %r7,16 /* border_len = maxlen - 16. */
|
|
|
bca718 |
+
|
|
|
bca718 |
+ clgrjhe %r5,%r7,.Lremaining_v16 /* If current_len >= border
|
|
|
bca718 |
+ then process remaining bytes. */
|
|
|
bca718 |
+ vfenezfs %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
bca718 |
+ je .Lfound_v16 /* Jump away if zero was found. */
|
|
|
bca718 |
+ vl %v18,16(%r5,%r3) /* Load next part of s. */
|
|
|
bca718 |
+ vst %v16,0(%r5,%r2) /* Store previous part without zero to dst. */
|
|
|
bca718 |
+ aghi %r5,16
|
|
|
bca718 |
+
|
|
|
bca718 |
+ clgrjhe %r5,%r7,.Lremaining_v18
|
|
|
bca718 |
+ vfenezfs %v17,%v18,%v18
|
|
|
bca718 |
+ je .Lfound_v18
|
|
|
bca718 |
+ vl %v16,16(%r5,%r3)
|
|
|
bca718 |
+ vst %v18,0(%r5,%r2)
|
|
|
bca718 |
+ aghi %r5,16
|
|
|
bca718 |
+
|
|
|
bca718 |
+ clgrjhe %r5,%r7,.Lremaining_v16
|
|
|
bca718 |
+ vfenezfs %v17,%v16,%v16
|
|
|
bca718 |
+ je .Lfound_v16
|
|
|
bca718 |
+ vl %v18,16(%r5,%r3)
|
|
|
bca718 |
+ vst %v16,0(%r5,%r2)
|
|
|
bca718 |
+ aghi %r5,16
|
|
|
bca718 |
+
|
|
|
bca718 |
+.Lremaining_v18:
|
|
|
bca718 |
+ vlr %v16,%v18
|
|
|
bca718 |
+.Lremaining_v16:
|
|
|
bca718 |
+ /* v16 contains the remaining bytes [1...16].
|
|
|
bca718 |
+ Store remaining bytes and append string-termination. */
|
|
|
bca718 |
+ vfenezf %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
bca718 |
+ slgrk %r7,%r4,%r5 /* Remaining bytes = maxlen - current_len. */
|
|
|
bca718 |
+ aghi %r7,-1 /* vstl needs highest index. */
|
|
|
bca718 |
+ la %r2,0(%r5,%r2) /* vstl has no index register. */
|
|
|
bca718 |
+ vlgvb %r1,%v17,7 /* Load zero index or 16 if not found. */
|
|
|
bca718 |
+ aghi %r1,3 /* Also copy remaining bytes of zero. */
|
|
|
bca718 |
+ /* Zero in remaining bytes? -> jump away (zero-index < max-index)
|
|
|
bca718 |
+ Do not jump away if zero-index == max-index,
|
|
|
bca718 |
+ but simply copy zero with vstl below. */
|
|
|
bca718 |
+ clrjl %r1,%r7,.Lfound_v16_store
|
|
|
bca718 |
+ vstl %v16,%r7,0(%r2) /* Store remaining bytes without null
|
|
|
bca718 |
+ termination!. */
|
|
|
bca718 |
+.Lend:
|
|
|
bca718 |
+ /* Restore saved registers. */
|
|
|
bca718 |
+ vlgvg %r6,%v31,0
|
|
|
bca718 |
+ vlgvg %r7,%v31,1
|
|
|
bca718 |
+ lgr %r2,%r0 /* Load saved dest-ptr. */
|
|
|
bca718 |
+ br %r14
|
|
|
bca718 |
+
|
|
|
bca718 |
+.Lfound_v16_32:
|
|
|
bca718 |
+ aghi %r5,32
|
|
|
bca718 |
+ j .Lfound_v16
|
|
|
bca718 |
+.Lfound_v18_48:
|
|
|
bca718 |
+ aghi %r5,32
|
|
|
bca718 |
+.Lfound_v18_16:
|
|
|
bca718 |
+ aghi %r5,16
|
|
|
bca718 |
+.Lfound_v18:
|
|
|
bca718 |
+ vlr %v16,%v18
|
|
|
bca718 |
+.Lfound_v16:
|
|
|
bca718 |
+ /* v16 contains a zero. Store remaining bytes to zero. current_len
|
|
|
bca718 |
+ has not reached border, thus checking for n is not needed! */
|
|
|
bca718 |
+ vlgvb %r1,%v17,7 /* Load byte index of zero. */
|
|
|
bca718 |
+ la %r2,0(%r5,%r2) /* vstl has no support for index-register. */
|
|
|
bca718 |
+ aghi %r1,3 /* Also copy remaining bytes of zero. */
|
|
|
bca718 |
+.Lfound_v16_store:
|
|
|
bca718 |
+ vstl %v16,%r1,0(%r2) /* Copy characters including zero. */
|
|
|
bca718 |
+ /* Fill remaining bytes with zero - remaining count always > 0. */
|
|
|
bca718 |
+ algr %r5,%r1 /* Remaining bytes (=%r4) = ... */
|
|
|
bca718 |
+ slgr %r4,%r5 /* = maxlen - (currlen + zero_index + 1). */
|
|
|
bca718 |
+ la %r2,0(%r1,%r2) /* Pointer to zero. start filling beyond. */
|
|
|
bca718 |
+ aghi %r4,-2 /* mvc with exrl needs count - 1.
|
|
|
bca718 |
+ (additional -1, see remaining bytes above) */
|
|
|
bca718 |
+ srlg %r6,%r4,8 /* Split into 256 byte blocks. */
|
|
|
bca718 |
+ ltgr %r6,%r6
|
|
|
bca718 |
+ je .Lzero_lt256
|
|
|
bca718 |
+.Lzero_loop256:
|
|
|
bca718 |
+ mvc 1(256,%r2),0(%r2) /* Fill 256 zeros at once. */
|
|
|
bca718 |
+ la %r2,256(%r2)
|
|
|
bca718 |
+ brctg %r6,.Lzero_loop256 /* Loop until all blocks are processed. */
|
|
|
bca718 |
+.Lzero_lt256:
|
|
|
bca718 |
+ exrl %r4,.Lmvc_lt256
|
|
|
bca718 |
+ j .Lend
|
|
|
bca718 |
+.Lmvc_lt256:
|
|
|
bca718 |
+ mvc 1(1,%r2),0(%r2)
|
|
|
bca718 |
+
|
|
|
bca718 |
+ /* Find zero in 16byte aligned loop. */
|
|
|
bca718 |
+.Lloop64:
|
|
|
bca718 |
+ vl %v16,0(%r5,%r3) /* Load s. */
|
|
|
bca718 |
+ vfenezfs %v17,%v16,%v16 /* Find element not equal with zero search. */
|
|
|
bca718 |
+ je .Lfound_v16 /* Jump away if zero was found. */
|
|
|
bca718 |
+ vl %v18,16(%r5,%r3) /* Load next part of s. */
|
|
|
bca718 |
+ vst %v16,0(%r5,%r2) /* Store previous part without zero to dst. */
|
|
|
bca718 |
+ vfenezfs %v17,%v18,%v18
|
|
|
bca718 |
+ je .Lfound_v18_16
|
|
|
bca718 |
+ vl %v16,32(%r5,%r3)
|
|
|
bca718 |
+ vst %v18,16(%r5,%r2)
|
|
|
bca718 |
+ vfenezfs %v17,%v16,%v16
|
|
|
bca718 |
+ je .Lfound_v16_32
|
|
|
bca718 |
+ vl %v18,48(%r5,%r3)
|
|
|
bca718 |
+ vst %v16,32(%r5,%r2)
|
|
|
bca718 |
+ vfenezfs %v17,%v18,%v18
|
|
|
bca718 |
+ je .Lfound_v18_48
|
|
|
bca718 |
+ vst %v18,48(%r5,%r2)
|
|
|
bca718 |
+
|
|
|
bca718 |
+ aghi %r5,64
|
|
|
bca718 |
+ lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */
|
|
|
bca718 |
+ aghi %r1,64
|
|
|
bca718 |
+ clgrjl %r1,%r4,.Lloop64
|
|
|
bca718 |
+
|
|
|
bca718 |
+ vl %v16,0(%r5,%r3) /* Load s. */
|
|
|
bca718 |
+ j .Llt64
|
|
|
bca718 |
+
|
|
|
bca718 |
+.Lfallback:
|
|
|
bca718 |
+ jg __wcsncpy_c
|
|
|
bca718 |
+END(__wcsncpy_vx)
|
|
|
bca718 |
+
|
|
|
bca718 |
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
|
|
|
bca718 |
diff --git a/sysdeps/s390/multiarch/wcsncpy.c b/sysdeps/s390/multiarch/wcsncpy.c
|
|
|
bca718 |
new file mode 100644
|
|
|
bca718 |
index 0000000..99aa344
|
|
|
bca718 |
--- /dev/null
|
|
|
bca718 |
+++ b/sysdeps/s390/multiarch/wcsncpy.c
|
|
|
bca718 |
@@ -0,0 +1,28 @@
|
|
|
bca718 |
+/* Multiple versions of wcsncpy.
|
|
|
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_ifunc (__wcsncpy)
|
|
|
bca718 |
+weak_alias (__wcsncpy, wcsncpy)
|
|
|
bca718 |
+
|
|
|
bca718 |
+#else
|
|
|
bca718 |
+# include <wcsmbs/wcsncpy.c>
|
|
|
bca718 |
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
|
|
|
bca718 |
diff --git a/sysdeps/s390/s390-32/multiarch/strncpy.c b/sysdeps/s390/s390-32/multiarch/strncpy.c
|
|
|
bca718 |
new file mode 100644
|
|
|
bca718 |
index 0000000..bc9c336
|
|
|
bca718 |
--- /dev/null
|
|
|
bca718 |
+++ b/sysdeps/s390/s390-32/multiarch/strncpy.c
|
|
|
bca718 |
@@ -0,0 +1,21 @@
|
|
|
bca718 |
+/* Multiple versions of strncpy.
|
|
|
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 |
+/* This wrapper-file is needed, because otherwise file
|
|
|
bca718 |
+ sysdeps/s390/s390-[32|64]/strncpy.S will be used. */
|
|
|
bca718 |
+#include <sysdeps/s390/multiarch/strncpy.c>
|
|
|
bca718 |
diff --git a/sysdeps/s390/s390-64/multiarch/strncpy.c b/sysdeps/s390/s390-64/multiarch/strncpy.c
|
|
|
bca718 |
new file mode 100644
|
|
|
bca718 |
index 0000000..bc9c336
|
|
|
bca718 |
--- /dev/null
|
|
|
bca718 |
+++ b/sysdeps/s390/s390-64/multiarch/strncpy.c
|
|
|
bca718 |
@@ -0,0 +1,21 @@
|
|
|
bca718 |
+/* Multiple versions of strncpy.
|
|
|
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 |
+/* This wrapper-file is needed, because otherwise file
|
|
|
bca718 |
+ sysdeps/s390/s390-[32|64]/strncpy.S will be used. */
|
|
|
bca718 |
+#include <sysdeps/s390/multiarch/strncpy.c>
|
|
|
bca718 |
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
|
|
|
bca718 |
index 3b91b6d..c26ab0c 100644
|
|
|
bca718 |
--- a/wcsmbs/Makefile
|
|
|
bca718 |
+++ b/wcsmbs/Makefile
|
|
|
bca718 |
@@ -42,7 +42,7 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
|
|
|
bca718 |
mbrtoc16 c16rtomb
|
|
|
bca718 |
|
|
|
bca718 |
strop-tests := wcscmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen \
|
|
|
bca718 |
- wcpcpy
|
|
|
bca718 |
+ wcpcpy wcsncpy
|
|
|
bca718 |
tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \
|
|
|
bca718 |
tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2 \
|
|
|
bca718 |
tst-c16c32-1 wcsatcliff $(addprefix test-,$(strop-tests))
|
|
|
bca718 |
diff --git a/wcsmbs/test-wcsncpy-ifunc.c b/wcsmbs/test-wcsncpy-ifunc.c
|
|
|
bca718 |
new file mode 100644
|
|
|
bca718 |
index 0000000..0141b38
|
|
|
bca718 |
--- /dev/null
|
|
|
bca718 |
+++ b/wcsmbs/test-wcsncpy-ifunc.c
|
|
|
bca718 |
@@ -0,0 +1,20 @@
|
|
|
bca718 |
+/* Test and measure IFUNC implementations of wcsncpy function.
|
|
|
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 TEST_IFUNC 1
|
|
|
bca718 |
+#include "test-wcsncpy.c"
|
|
|
bca718 |
diff --git a/wcsmbs/test-wcsncpy.c b/wcsmbs/test-wcsncpy.c
|
|
|
bca718 |
new file mode 100644
|
|
|
bca718 |
index 0000000..27de6f8
|
|
|
bca718 |
--- /dev/null
|
|
|
bca718 |
+++ b/wcsmbs/test-wcsncpy.c
|
|
|
bca718 |
@@ -0,0 +1,20 @@
|
|
|
bca718 |
+/* Test wcsncpy 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 "../string/test-strncpy.c"
|
|
|
bca718 |
diff --git a/wcsmbs/wcsncpy.c b/wcsmbs/wcsncpy.c
|
|
|
bca718 |
index f134c36..2e3cebe 100644
|
|
|
bca718 |
--- a/wcsmbs/wcsncpy.c
|
|
|
bca718 |
+++ b/wcsmbs/wcsncpy.c
|
|
|
bca718 |
@@ -18,6 +18,9 @@
|
|
|
bca718 |
|
|
|
bca718 |
#include <wchar.h>
|
|
|
bca718 |
|
|
|
bca718 |
+#ifdef WCSNCPY
|
|
|
bca718 |
+# define __wcsncpy WCSNCPY
|
|
|
bca718 |
+#endif
|
|
|
bca718 |
|
|
|
bca718 |
/* Copy no more than N wide-characters of SRC to DEST. */
|
|
|
bca718 |
wchar_t *
|
|
|
bca718 |
@@ -83,4 +86,6 @@ __wcsncpy (dest, src, n)
|
|
|
bca718 |
|
|
|
bca718 |
return s;
|
|
|
bca718 |
}
|
|
|
bca718 |
+#ifndef WCSNCPY
|
|
|
bca718 |
weak_alias (__wcsncpy, wcsncpy)
|
|
|
bca718 |
+#endif
|
|
|
bca718 |
--
|
|
|
bca718 |
2.3.0
|
|
|
bca718 |
|