arrfab / rpms / glibc

Forked from rpms/glibc 4 years ago
Clone

Blame SOURCES/glibc-rh1268008-11.patch

147e83
From 1a569200bc2875ffc474587fb6ec599aac4bad9b Mon Sep 17 00:00:00 2001
147e83
From: Stefan Liebler <stli@linux.vnet.ibm.com>
147e83
Date: Thu, 8 Oct 2015 10:56:59 +0200
147e83
Subject: [PATCH 11/30] S390: Optimize strnlen and wcsnlen.
147e83
147e83
upstream-commit-id: fcf40ebe2682fd65d64f94d69a3df798960cf1b7
147e83
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00082.html
147e83
147e83
This patch provides optimized versions of strnlen and wcsnlen with the z13
147e83
vector instructions.
147e83
147e83
ChangeLog:
147e83
147e83
	* sysdeps/s390/multiarch/strnlen-c.c: New File.
147e83
	* sysdeps/s390/multiarch/strnlen-vx.S: Likewise.
147e83
	* sysdeps/s390/multiarch/strnlen.c: Likewise.
147e83
	* sysdeps/s390/multiarch/wcsnlen-c.c: Likewise.
147e83
	* sysdeps/s390/multiarch/wcsnlen-vx.S: Likewise.
147e83
	* sysdeps/s390/multiarch/wcsnlen.c: Likewise.
147e83
	* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add strnlen and
147e83
	wcsnlen functions.
147e83
	* sysdeps/s390/multiarch/ifunc-impl-list.c
147e83
	(__libc_ifunc_impl_list): Add ifunc test for strnlen, wcsnlen.
147e83
	* wcsmbs/wcsnlen.c: Use WCSNLEN if defined.
147e83
	* string/test-strnlen.c: Add wcsnlen support.
147e83
	* wcsmbs/test-wcsnlen.c: New File.
147e83
	* wcsmbs/Makefile (strop-tests): Add wcsnlen.
147e83
	* benchtests/bench-strnlen.c: Add wcsnlen support.
147e83
	* benchtests/bench-wcsnlen.c: New File.
147e83
	* benchtests/Makefile (wcsmbs-bench): Add wcsnlen.
147e83
---
147e83
 benchtests/Makefile                      |   2 +-
147e83
 benchtests/bench-strnlen.c               |  73 +++++++++------
147e83
 benchtests/bench-wcsnlen.c               |  20 ++++
147e83
 string/test-strnlen.c                    |  87 +++++++++++-------
147e83
 sysdeps/s390/multiarch/Makefile          |   6 +-
147e83
 sysdeps/s390/multiarch/ifunc-impl-list.c |   3 +
147e83
 sysdeps/s390/multiarch/strnlen-c.c       |  28 ++++++
147e83
 sysdeps/s390/multiarch/strnlen-vx.S      | 134 +++++++++++++++++++++++++++
147e83
 sysdeps/s390/multiarch/strnlen.c         |  29 ++++++
147e83
 sysdeps/s390/multiarch/wcsnlen-c.c       |  25 +++++
147e83
 sysdeps/s390/multiarch/wcsnlen-vx.S      | 151 +++++++++++++++++++++++++++++++
147e83
 sysdeps/s390/multiarch/wcsnlen.c         |  28 ++++++
147e83
 wcsmbs/Makefile                          |   2 +-
147e83
 wcsmbs/test-wcsnlen-ifunc.c              |  20 ++++
147e83
 wcsmbs/test-wcsnlen.c                    |  20 ++++
147e83
 wcsmbs/wcsnlen.c                         |   7 +-
147e83
 16 files changed, 571 insertions(+), 64 deletions(-)
147e83
 create mode 100644 benchtests/bench-wcsnlen.c
147e83
 create mode 100644 sysdeps/s390/multiarch/strnlen-c.c
147e83
 create mode 100644 sysdeps/s390/multiarch/strnlen-vx.S
147e83
 create mode 100644 sysdeps/s390/multiarch/strnlen.c
147e83
 create mode 100644 sysdeps/s390/multiarch/wcsnlen-c.c
147e83
 create mode 100644 sysdeps/s390/multiarch/wcsnlen-vx.S
147e83
 create mode 100644 sysdeps/s390/multiarch/wcsnlen.c
147e83
 create mode 100644 wcsmbs/test-wcsnlen-ifunc.c
147e83
 create mode 100644 wcsmbs/test-wcsnlen.c
147e83
147e83
diff --git a/benchtests/Makefile b/benchtests/Makefile
147e83
index 09ab87f..7bb2eef 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
147e83
+wcsmbs-bench := wcslen wcsnlen
147e83
 string-bench-all := $(string-bench) ${wcsmbs-bench}
147e83
 
147e83
 stdlib-bench := strtod
147e83
diff --git a/benchtests/bench-strnlen.c b/benchtests/bench-strnlen.c
147e83
index 793f9be..cbdce75 100644
147e83
--- a/benchtests/bench-strnlen.c
147e83
+++ b/benchtests/bench-strnlen.c
147e83
@@ -1,5 +1,5 @@
147e83
 /* Measure strlen functions.
147e83
-   Copyright (C) 2013 Free Software Foundation, Inc.
147e83
+   Copyright (C) 2013-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
@@ -17,17 +17,36 @@
147e83
    <http://www.gnu.org/licenses/>.  */
147e83
 
147e83
 #define TEST_MAIN
147e83
-#define TEST_NAME "strnlen"
147e83
+#ifndef WIDE
147e83
+# define TEST_NAME "strnlen"
147e83
+#else
147e83
+# define TEST_NAME "wcsnlen"
147e83
+#endif /* WIDE */
147e83
 #include "bench-string.h"
147e83
 
147e83
-typedef size_t (*proto_t) (const char *, size_t);
147e83
-size_t simple_strnlen (const char *, size_t);
147e83
-
147e83
-IMPL (simple_strnlen, 0)
147e83
-IMPL (strnlen, 1)
147e83
+#ifndef WIDE
147e83
+# define STRNLEN strnlen
147e83
+# define CHAR char
147e83
+# define BIG_CHAR CHAR_MAX
147e83
+# define MIDDLE_CHAR 127
147e83
+# define SIMPLE_STRNLEN simple_strnlen
147e83
+#else
147e83
+# include <wchar.h>
147e83
+# define STRNLEN wcsnlen
147e83
+# define CHAR wchar_t
147e83
+# define BIG_CHAR WCHAR_MAX
147e83
+# define MIDDLE_CHAR 1121
147e83
+# define SIMPLE_STRNLEN simple_wcsnlen
147e83
+#endif /* WIDE */
147e83
+
147e83
+typedef size_t (*proto_t) (const CHAR *, size_t);
147e83
+size_t SIMPLE_STRNLEN (const CHAR *, size_t);
147e83
+
147e83
+IMPL (SIMPLE_STRNLEN, 0)
147e83
+IMPL (STRNLEN, 1)
147e83
 
147e83
 size_t
147e83
-simple_strnlen (const char *s, size_t maxlen)
147e83
+SIMPLE_STRNLEN (const CHAR *s, size_t maxlen)
147e83
 {
147e83
   size_t i;
147e83
 
147e83
@@ -36,7 +55,7 @@ simple_strnlen (const char *s, size_t maxlen)
147e83
 }
147e83
 
147e83
 static void
147e83
-do_one_test (impl_t *impl, const char *s, size_t maxlen, size_t exp_len)
147e83
+do_one_test (impl_t *impl, const CHAR *s, size_t maxlen, size_t exp_len)
147e83
 {
147e83
   size_t len = CALL (impl, s, maxlen), i, iters = INNER_LOOP_ITERS;
147e83
   timing_t start, stop, cur;
147e83
@@ -66,18 +85,20 @@ do_test (size_t align, size_t len, size_t maxlen, int max_char)
147e83
 {
147e83
   size_t i;
147e83
 
147e83
-  align &= 7;
147e83
-  if (align + len >= page_size)
147e83
+  align &= 63;
147e83
+  if ((align + len) * sizeof (CHAR) >= page_size)
147e83
     return;
147e83
 
147e83
+  CHAR *buf = (CHAR *) (buf1);
147e83
+
147e83
   for (i = 0; i < len; ++i)
147e83
-    buf1[align + i] = 1 + 7 * i % max_char;
147e83
-  buf1[align + len] = 0;
147e83
+    buf[align + i] = 1 + 7 * i % max_char;
147e83
+  buf[align + len] = 0;
147e83
 
147e83
   printf ("Length %4zd, alignment %2zd:", len, align);
147e83
 
147e83
   FOR_EACH_IMPL (impl, 0)
147e83
-    do_one_test (impl, (char *) (buf1 + align), maxlen, MIN (len, maxlen));
147e83
+    do_one_test (impl, (CHAR *) (buf + align), maxlen, MIN (len, maxlen));
147e83
 
147e83
   putchar ('\n');
147e83
 }
147e83
@@ -96,34 +117,34 @@ test_main (void)
147e83
 
147e83
   for (i = 1; i < 8; ++i)
147e83
     {
147e83
-      do_test (0, i, i - 1, 127);
147e83
-      do_test (0, i, i, 127);
147e83
-      do_test (0, i, i + 1, 127);
147e83
+      do_test (0, i, i - 1, MIDDLE_CHAR);
147e83
+      do_test (0, i, i, MIDDLE_CHAR);
147e83
+      do_test (0, i, i + 1, MIDDLE_CHAR);
147e83
     }
147e83
 
147e83
   for (i = 1; i < 8; ++i)
147e83
     {
147e83
-      do_test (i, i, i - 1, 127);
147e83
-      do_test (i, i, i, 127);
147e83
-      do_test (i, i, i + 1, 127);
147e83
+      do_test (i, i, i - 1, MIDDLE_CHAR);
147e83
+      do_test (i, i, i, MIDDLE_CHAR);
147e83
+      do_test (i, i, i + 1, MIDDLE_CHAR);
147e83
     }
147e83
 
147e83
   for (i = 2; i <= 10; ++i)
147e83
     {
147e83
-      do_test (0, 1 << i, 5000, 127);
147e83
-      do_test (1, 1 << i, 5000, 127);
147e83
+      do_test (0, 1 << i, 5000, MIDDLE_CHAR);
147e83
+      do_test (1, 1 << i, 5000, MIDDLE_CHAR);
147e83
     }
147e83
 
147e83
   for (i = 1; i < 8; ++i)
147e83
-    do_test (0, i, 5000, 255);
147e83
+    do_test (0, i, 5000, BIG_CHAR);
147e83
 
147e83
   for (i = 1; i < 8; ++i)
147e83
-    do_test (i, i, 5000, 255);
147e83
+    do_test (i, i, 5000, BIG_CHAR);
147e83
 
147e83
   for (i = 2; i <= 10; ++i)
147e83
     {
147e83
-      do_test (0, 1 << i, 5000, 255);
147e83
-      do_test (1, 1 << i, 5000, 255);
147e83
+      do_test (0, 1 << i, 5000, BIG_CHAR);
147e83
+      do_test (1, 1 << i, 5000, BIG_CHAR);
147e83
     }
147e83
 
147e83
   return ret;
147e83
diff --git a/benchtests/bench-wcsnlen.c b/benchtests/bench-wcsnlen.c
147e83
new file mode 100644
147e83
index 0000000..2b5a51c
147e83
--- /dev/null
147e83
+++ b/benchtests/bench-wcsnlen.c
147e83
@@ -0,0 +1,20 @@
147e83
+/* Measure wcsnlen 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-strnlen.c"
147e83
diff --git a/string/test-strnlen.c b/string/test-strnlen.c
147e83
index ae959bf..43db896 100644
147e83
--- a/string/test-strnlen.c
147e83
+++ b/string/test-strnlen.c
147e83
@@ -1,5 +1,5 @@
147e83
 /* Test and measure strlen functions.
147e83
-   Copyright (C) 1999-2012 Free Software Foundation, Inc.
147e83
+   Copyright (C) 1999-2015 Free Software Foundation, Inc.
147e83
    This file is part of the GNU C Library.
147e83
    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
147e83
 
147e83
@@ -18,17 +18,36 @@
147e83
    <http://www.gnu.org/licenses/>.  */
147e83
 
147e83
 #define TEST_MAIN
147e83
-#define TEST_NAME "strnlen"
147e83
+#ifndef WIDE
147e83
+# define TEST_NAME "strnlen"
147e83
+#else
147e83
+# define TEST_NAME "wcsnlen"
147e83
+#endif /* !WIDE */
147e83
 #include "test-string.h"
147e83
 
147e83
-typedef size_t (*proto_t) (const char *, size_t);
147e83
-size_t simple_strnlen (const char *, size_t);
147e83
-
147e83
-IMPL (simple_strnlen, 0)
147e83
-IMPL (strnlen, 1)
147e83
+#ifndef WIDE
147e83
+# define STRNLEN strnlen
147e83
+# define CHAR char
147e83
+# define BIG_CHAR CHAR_MAX
147e83
+# define MIDDLE_CHAR 127
147e83
+# define SIMPLE_STRNLEN simple_strnlen
147e83
+#else
147e83
+# include <wchar.h>
147e83
+# define STRNLEN wcsnlen
147e83
+# define CHAR wchar_t
147e83
+# define BIG_CHAR WCHAR_MAX
147e83
+# define MIDDLE_CHAR 1121
147e83
+# define SIMPLE_STRNLEN simple_wcsnlen
147e83
+#endif /* !WIDE */
147e83
+
147e83
+typedef size_t (*proto_t) (const CHAR *, size_t);
147e83
+size_t SIMPLE_STRNLEN (const CHAR *, size_t);
147e83
+
147e83
+IMPL (SIMPLE_STRNLEN, 0)
147e83
+IMPL (STRNLEN, 1)
147e83
 
147e83
 size_t
147e83
-simple_strnlen (const char *s, size_t maxlen)
147e83
+SIMPLE_STRNLEN (const CHAR *s, size_t maxlen)
147e83
 {
147e83
   size_t i;
147e83
 
147e83
@@ -37,7 +56,7 @@ simple_strnlen (const char *s, size_t maxlen)
147e83
 }
147e83
 
147e83
 static void
147e83
-do_one_test (impl_t *impl, const char *s, size_t maxlen, size_t exp_len)
147e83
+do_one_test (impl_t *impl, const CHAR *s, size_t maxlen, size_t exp_len)
147e83
 {
147e83
   size_t len = CALL (impl, s, maxlen);
147e83
   if (len != exp_len)
147e83
@@ -54,23 +73,25 @@ do_test (size_t align, size_t len, size_t maxlen, int max_char)
147e83
 {
147e83
   size_t i;
147e83
 
147e83
-  align &= 7;
147e83
-  if (align + len >= page_size)
147e83
+  align &= 63;
147e83
+  if ((align + len) * sizeof (CHAR) >= page_size)
147e83
     return;
147e83
 
147e83
+  CHAR *buf = (CHAR *) (buf1);
147e83
+
147e83
   for (i = 0; i < len; ++i)
147e83
-    buf1[align + i] = 1 + 7 * i % max_char;
147e83
-  buf1[align + len] = 0;
147e83
+    buf[align + i] = 1 + 7 * i % max_char;
147e83
+  buf[align + len] = 0;
147e83
 
147e83
   FOR_EACH_IMPL (impl, 0)
147e83
-    do_one_test (impl, (char *) (buf1 + align), maxlen, MIN (len, maxlen));
147e83
+    do_one_test (impl, (CHAR *) (buf + align), maxlen, MIN (len, maxlen));
147e83
 }
147e83
 
147e83
 static void
147e83
 do_random_tests (void)
147e83
 {
147e83
   size_t i, j, n, align, len;
147e83
-  unsigned char *p = buf1 + page_size - 512;
147e83
+  CHAR *p = (CHAR *) (buf1 + page_size - 512 * sizeof (CHAR));
147e83
 
147e83
   for (n = 0; n < ITERATIONS; n++)
147e83
     {
147e83
@@ -97,25 +118,25 @@ do_random_tests (void)
147e83
       FOR_EACH_IMPL (impl, 1)
147e83
 	{
147e83
 	  if (len > 0
147e83
-	      && CALL (impl, (char *) (p + align), len - 1) != len - 1)
147e83
+	      && CALL (impl, (CHAR *) (p + align), len - 1) != len - 1)
147e83
 	    {
147e83
 	      error (0, 0, "Iteration %zd (limited) - wrong result in function %s (%zd) %zd != %zd, p %p",
147e83
 		     n, impl->name, align,
147e83
-		     CALL (impl, (char *) (p + align), len - 1), len - 1, p);
147e83
+		     CALL (impl, (CHAR *) (p + align), len - 1), len - 1, p);
147e83
 	      ret = 1;
147e83
 	    }
147e83
-	  if (CALL (impl, (char *) (p + align), len) != len)
147e83
+	  if (CALL (impl, (CHAR *) (p + align), len) != len)
147e83
 	    {
147e83
 	      error (0, 0, "Iteration %zd (exact) - wrong result in function %s (%zd) %zd != %zd, p %p",
147e83
 		     n, impl->name, align,
147e83
-		     CALL (impl, (char *) (p + align), len), len, p);
147e83
+		     CALL (impl, (CHAR *) (p + align), len), len, p);
147e83
 	      ret = 1;
147e83
 	    }
147e83
-	  if (CALL (impl, (char *) (p + align), len + 1) != len)
147e83
+	  if (CALL (impl, (CHAR *) (p + align), len + 1) != len)
147e83
 	    {
147e83
 	      error (0, 0, "Iteration %zd (long) - wrong result in function %s (%zd) %zd != %zd, p %p",
147e83
 		     n, impl->name, align,
147e83
-		     CALL (impl, (char *) (p + align), len + 1), len, p);
147e83
+		     CALL (impl, (CHAR *) (p + align), len + 1), len, p);
147e83
 	      ret = 1;
147e83
 	    }
147e83
 	}
147e83
@@ -136,34 +157,34 @@ test_main (void)
147e83
 
147e83
   for (i = 1; i < 8; ++i)
147e83
     {
147e83
-      do_test (0, i, i - 1, 127);
147e83
-      do_test (0, i, i, 127);
147e83
-      do_test (0, i, i + 1, 127);
147e83
+      do_test (0, i, i - 1, MIDDLE_CHAR);
147e83
+      do_test (0, i, i, MIDDLE_CHAR);
147e83
+      do_test (0, i, i + 1, MIDDLE_CHAR);
147e83
     }
147e83
 
147e83
   for (i = 1; i < 8; ++i)
147e83
     {
147e83
-      do_test (i, i, i - 1, 127);
147e83
-      do_test (i, i, i, 127);
147e83
-      do_test (i, i, i + 1, 127);
147e83
+      do_test (i, i, i - 1, MIDDLE_CHAR);
147e83
+      do_test (i, i, i, MIDDLE_CHAR);
147e83
+      do_test (i, i, i + 1, MIDDLE_CHAR);
147e83
     }
147e83
 
147e83
   for (i = 2; i <= 10; ++i)
147e83
     {
147e83
-      do_test (0, 1 << i, 5000, 127);
147e83
-      do_test (1, 1 << i, 5000, 127);
147e83
+      do_test (0, 1 << i, 5000, MIDDLE_CHAR);
147e83
+      do_test (1, 1 << i, 5000, MIDDLE_CHAR);
147e83
     }
147e83
 
147e83
   for (i = 1; i < 8; ++i)
147e83
-    do_test (0, i, 5000, 255);
147e83
+    do_test (0, i, 5000, BIG_CHAR);
147e83
 
147e83
   for (i = 1; i < 8; ++i)
147e83
-    do_test (i, i, 5000, 255);
147e83
+    do_test (i, i, 5000, BIG_CHAR);
147e83
 
147e83
   for (i = 2; i <= 10; ++i)
147e83
     {
147e83
-      do_test (0, 1 << i, 5000, 255);
147e83
-      do_test (1, 1 << i, 5000, 255);
147e83
+      do_test (0, 1 << i, 5000, BIG_CHAR);
147e83
+      do_test (1, 1 << i, 5000, BIG_CHAR);
147e83
     }
147e83
 
147e83
   do_random_tests ();
147e83
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
147e83
index 3a98098..3397f24 100644
147e83
--- a/sysdeps/s390/multiarch/Makefile
147e83
+++ b/sysdeps/s390/multiarch/Makefile
147e83
@@ -1,7 +1,9 @@
147e83
 ifeq ($(subdir),string)
147e83
-sysdep_routines += strlen strlen-vx strlen-c
147e83
+sysdep_routines += strlen strlen-vx strlen-c \
147e83
+		   strnlen strnlen-vx strnlen-c
147e83
 endif
147e83
 
147e83
 ifeq ($(subdir),wcsmbs)
147e83
-sysdep_routines += wcslen wcslen-vx wcslen-c
147e83
+sysdep_routines += wcslen wcslen-vx wcslen-c \
147e83
+		   wcsnlen wcsnlen-vx wcsnlen-c
147e83
 endif
147e83
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
147e83
index e9639ef..bc17c59 100644
147e83
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
147e83
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
147e83
@@ -82,6 +82,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
147e83
   IFUNC_VX_IMPL (strlen);
147e83
   IFUNC_VX_IMPL (wcslen);
147e83
 
147e83
+  IFUNC_VX_IMPL (strnlen);
147e83
+  IFUNC_VX_IMPL (wcsnlen);
147e83
+
147e83
 #endif /* HAVE_S390_VX_ASM_SUPPORT */
147e83
 
147e83
   return i;
147e83
diff --git a/sysdeps/s390/multiarch/strnlen-c.c b/sysdeps/s390/multiarch/strnlen-c.c
147e83
new file mode 100644
147e83
index 0000000..50fc688
147e83
--- /dev/null
147e83
+++ b/sysdeps/s390/multiarch/strnlen-c.c
147e83
@@ -0,0 +1,28 @@
147e83
+/* Default strnlen 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 STRNLEN  __strnlen_c
147e83
+# ifdef SHARED
147e83
+#  undef libc_hidden_def
147e83
+#  define libc_hidden_def(name)					\
147e83
+  __hidden_ver1 (__strnlen_c, __GI_strnlen, __strnlen_c);
147e83
+# endif /* SHARED */
147e83
+
147e83
+# include <string/strnlen.c>
147e83
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
147e83
diff --git a/sysdeps/s390/multiarch/strnlen-vx.S b/sysdeps/s390/multiarch/strnlen-vx.S
147e83
new file mode 100644
147e83
index 0000000..8c15621
147e83
--- /dev/null
147e83
+++ b/sysdeps/s390/multiarch/strnlen-vx.S
147e83
@@ -0,0 +1,134 @@
147e83
+/* Vector optimized 32/64 bit S/390 version of strnlen.
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
+/* size_t strnlen (const char *s, size_t maxlen)
147e83
+   Returns the number of characters in s or at most maxlen.
147e83
+
147e83
+   Register usage:
147e83
+   -r1=tmp
147e83
+   -r2=address of string
147e83
+   -r3=maxlen (number of characters to be read)
147e83
+   -r4=tmp
147e83
+   -r5=current_len and return_value
147e83
+   -v16=part of s
147e83
+*/
147e83
+ENTRY(__strnlen_vx)
147e83
+	.machine "z13"
147e83
+	.machinemode "zarch_nohighgprs"
147e83
+
147e83
+# if !defined __s390x__
147e83
+	llgfr	%r3,%r3
147e83
+# endif /* !defined __s390x__ */
147e83
+
147e83
+	clgfi	%r3,0		/* if maxlen == 0, return 0.  */
147e83
+	locgre	%r2,%r3
147e83
+	ber	%r14
147e83
+
147e83
+	vlbb	%v16,0(%r2),6	/* Load s until next 4k-byte boundary.  */
147e83
+	lcbb	%r1,0(%r2),6	/* Get bytes to 4k-byte boundary or 16.  */
147e83
+	llgfr	%r1,%r1		/* Convert 32bit to 64bit.  */
147e83
+
147e83
+	vfenezb	%v16,%v16,%v16	/* Find element not equal with zero search.  */
147e83
+	clgr	%r1,%r3
147e83
+	locgrh	%r1,%r3		/* loaded_byte_count
147e83
+				   = min (loaded_byte_count, maxlen)  */
147e83
+
147e83
+	vlgvb	%r5,%v16,7	/* Load zero index or 16 if not found.  */
147e83
+	clr	%r5,%r1		/* If found zero within loaded bytes?  */
147e83
+	locgrl	%r2,%r5		/* Then copy return value.  */
147e83
+	blr	%r14		/* And return.  */
147e83
+
147e83
+	clgr	%r1,%r3		/* If loaded_byte_count == maxlen?  */
147e83
+	locgre	%r2,%r3		/* Then copy return value.  */
147e83
+	ber	%r14		/* And return.  */
147e83
+
147e83
+	/* Align s to 16 byte.  */
147e83
+	risbgn	%r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
147e83
+	lghi	%r5,16		/* current_len = 16.  */
147e83
+	slr	%r5,%r4		/* Compute bytes to 16bytes boundary.  */
147e83
+
147e83
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
147e83
+	aghi	%r1,64
147e83
+	clgrjl	%r1,%r3,.Lloop64
147e83
+
147e83
+	/* Find zero in max 64byte with aligned s.  */
147e83
+.Llt64:
147e83
+	vl	%v16,0(%r5,%r2) /* Load s.  */
147e83
+	vfenezbs %v16,%v16,%v16	/* Find element not equal with zero search.  */
147e83
+	je	.Lfound		/* Jump away if zero was found.  */
147e83
+	aghi	%r5,16
147e83
+	clgrjhe	%r5,%r3,.Lfound /* current_len >= maxlen -> end.  */
147e83
+	vl	%v16,0(%r5,%r2)
147e83
+	vfenezbs %v16,%v16,%v16
147e83
+	je	.Lfound
147e83
+	aghi	%r5,16
147e83
+	clgrjhe	%r5,%r3,.Lfound
147e83
+	vl	%v16,0(%r5,%r2)
147e83
+	vfenezbs %v16,%v16,%v16
147e83
+	je	.Lfound
147e83
+	aghi	%r5,16
147e83
+	clgrjhe	%r5,%r3,.Lfound
147e83
+	vl	%v16,0(%r5,%r2)
147e83
+	vfenezbs %v16,%v16,%v16
147e83
+	j	.Lfound
147e83
+
147e83
+.Lfound48:
147e83
+	aghi	%r5,16
147e83
+.Lfound32:
147e83
+	aghi	%r5,16
147e83
+.Lfound16:
147e83
+	aghi	%r5,16
147e83
+.Lfound:
147e83
+	vlgvb	%r4,%v16,7	/* Load byte index of zero or 16 if no zero.  */
147e83
+	algr	%r5,%r4
147e83
+
147e83
+	clgr	%r5,%r3
147e83
+	locgrh	%r5,%r3		/* Return min (current_len, maxlen).  */
147e83
+	lgr	%r2,%r5
147e83
+	br	%r14
147e83
+
147e83
+	/* Find zero in 16 byte aligned loop.  */
147e83
+.Lloop64:
147e83
+	vl	%v16,0(%r5,%r2) /* Load s.  */
147e83
+	vfenezbs %v16,%v16,%v16	/* Find element not equal with zero search.  */
147e83
+	je	.Lfound		/* Jump away if zero was found.  */
147e83
+	vl	%v16,16(%r5,%r2)
147e83
+	vfenezbs %v16,%v16,%v16
147e83
+	je	.Lfound16
147e83
+	vl	%v16,32(%r5,%r2)
147e83
+	vfenezbs %v16,%v16,%v16
147e83
+	je	.Lfound32
147e83
+	vl	%v16,48(%r5,%r2)
147e83
+	vfenezbs %v16,%v16,%v16
147e83
+	je	.Lfound48
147e83
+
147e83
+	aghi	%r5,64
147e83
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
147e83
+	aghi	%r1,64
147e83
+	clgrjl	%r1,%r3,.Lloop64
147e83
+
147e83
+	j	.Llt64
147e83
+END(__strnlen_vx)
147e83
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
147e83
diff --git a/sysdeps/s390/multiarch/strnlen.c b/sysdeps/s390/multiarch/strnlen.c
147e83
new file mode 100644
147e83
index 0000000..f036fcd
147e83
--- /dev/null
147e83
+++ b/sysdeps/s390/multiarch/strnlen.c
147e83
@@ -0,0 +1,29 @@
147e83
+/* Multiple versions of strnlen.
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 (__strnlen)
147e83
+weak_alias (__strnlen, strnlen)
147e83
+libc_hidden_def (strnlen)
147e83
+
147e83
+#else
147e83
+# include <string/strnlen.c>
147e83
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
147e83
diff --git a/sysdeps/s390/multiarch/wcsnlen-c.c b/sysdeps/s390/multiarch/wcsnlen-c.c
147e83
new file mode 100644
147e83
index 0000000..6d8b537
147e83
--- /dev/null
147e83
+++ b/sysdeps/s390/multiarch/wcsnlen-c.c
147e83
@@ -0,0 +1,25 @@
147e83
+/* Default wcsnlen 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 WCSNLEN  __wcsnlen_c
147e83
+
147e83
+# include <wchar.h>
147e83
+extern __typeof (__wcsnlen) __wcsnlen_c;
147e83
+# include <wcsmbs/wcsnlen.c>
147e83
+#endif
147e83
diff --git a/sysdeps/s390/multiarch/wcsnlen-vx.S b/sysdeps/s390/multiarch/wcsnlen-vx.S
147e83
new file mode 100644
147e83
index 0000000..8c21630
147e83
--- /dev/null
147e83
+++ b/sysdeps/s390/multiarch/wcsnlen-vx.S
147e83
@@ -0,0 +1,151 @@
147e83
+/* Vector optimized 32/64 bit S/390 version of wcsnlen.
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
+/* size_t wcsnlen (const wchar_t *s, size_t maxlen)
147e83
+   Returns the number of characters in s or at most maxlen.
147e83
+
147e83
+   Register usage:
147e83
+   -r1=tmp
147e83
+   -r2=address of string
147e83
+   -r3=maxlen (number of characters to be read)
147e83
+   -r4=tmp
147e83
+   -r5=current_len and return_value
147e83
+   -v16=part of s
147e83
+*/
147e83
+ENTRY(__wcsnlen_vx)
147e83
+
147e83
+	.machine "z13"
147e83
+	.machinemode "zarch_nohighgprs"
147e83
+
147e83
+# if !defined __s390x__
147e83
+	llgfr	%r3,%r3
147e83
+# endif /* !defined __s390x__ */
147e83
+
147e83
+	clgfi	%r3,0		/* if maxlen == 0, return 0.  */
147e83
+	locgre	%r2,%r3
147e83
+	ber	%r14
147e83
+
147e83
+	vlbb	%v16,0(%r2),6	/* Load s until next 4k-byte boundary.  */
147e83
+	lcbb	%r1,0(%r2),6	/* Get bytes to 4k-byte boundary or 16.  */
147e83
+	llgfr	%r1,%r1		/* Convert 32bit to 64bit.  */
147e83
+
147e83
+	tmll	%r2,3		/* Test if s is 4-byte aligned?  */
147e83
+	jne	.Lfallback	/* And use common-code variant if not.  */
147e83
+
147e83
+	/* Check range of maxlen and convert to byte-count.  */
147e83
+# ifdef __s390x__
147e83
+	tmhh	%r3,49152	/* Test bit 0 or 1 of maxlen.  */
147e83
+	lghi	%r4,-4		/* Max byte-count is 18446744073709551612.  */
147e83
+# else
147e83
+	tmlh	%r3,49152	/* Test bit 0 or 1 of maxlen.  */
147e83
+	llilf	%r4,4294967292	/* Max byte-count is 4294967292.  */
147e83
+# endif /* !__s390x__ */
147e83
+	sllg	%r3,%r3,2	/* Convert character-count to byte-count.  */
147e83
+	locgrne	%r3,%r4		/* Use max byte-count, if bit 0/1 was one.  */
147e83
+
147e83
+	vfenezf	%v16,%v16,%v16	/* Find element not equal with zero search.  */
147e83
+	clgr	%r1,%r3
147e83
+	locgrh	%r1,%r3		/* loaded_byte_count
147e83
+				   = min (loaded_byte_count, maxlen)  */
147e83
+
147e83
+	vlgvb	%r5,%v16,7	/* Load zero index or 16 if not found.  */
147e83
+	clrjl	%r5,%r1,.Lend	/* Found zero within loaded bytes -> return.  */
147e83
+
147e83
+	clgr	%r1,%r3		/* If loaded_byte_count == maxlen -> end.  */
147e83
+	locgre	%r5,%r3
147e83
+	je	.Lend
147e83
+
147e83
+	/* Align s to 16 byte.  */
147e83
+	risbgn	%r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
147e83
+	lghi	%r5,16		/* current_len = 16.  */
147e83
+	slr	%r5,%r4		/* Compute bytes to 16bytes boundary.  */
147e83
+
147e83
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
147e83
+	aghi	%r1,64
147e83
+	clgrjl	%r1,%r3,.Lloop64
147e83
+
147e83
+	/* Find zero in max 64byte with aligned s.  */
147e83
+.Llt64:
147e83
+	vl	%v16,0(%r5,%r2)	/* Load s.  */
147e83
+	vfenezfs %v16,%v16,%v16	/* Find element not equal with zero search.  */
147e83
+	je	.Lfound		/* Jump away if zero was found.  */
147e83
+	aghi	%r5,16
147e83
+	clgrjhe	%r5,%r3,.Lfound /* If current_len >= maxlen -> end.  */
147e83
+	vl	%v16,0(%r5,%r2)
147e83
+	vfenezfs %v16,%v16,%v16
147e83
+	je	.Lfound
147e83
+	aghi	%r5,16
147e83
+	clgrjhe	%r5,%r3,.Lfound
147e83
+	vl	%v16,0(%r5,%r2)
147e83
+	vfenezfs %v16,%v16,%v16
147e83
+	je	.Lfound
147e83
+	aghi	%r5,16
147e83
+	clgrjhe	%r5,%r3,.Lfound
147e83
+	vl	%v16,0(%r5,%r2)
147e83
+	vfenezfs %v16,%v16,%v16
147e83
+	j	.Lfound
147e83
+
147e83
+.Lfound48:
147e83
+	aghi	%r5,16
147e83
+.Lfound32:
147e83
+	aghi	%r5,16
147e83
+.Lfound16:
147e83
+	aghi	%r5,16
147e83
+.Lfound:
147e83
+	vlgvb	%r4,%v16,7	/* Load byte index of zero or 16 if no zero.  */
147e83
+	algr	%r5,%r4
147e83
+
147e83
+	clgr	%r5,%r3
147e83
+	locgrh	%r5,%r3		/* Return min (current_len, maxlen).  */
147e83
+.Lend:
147e83
+	srlg	%r2,%r5,2	/* Convert byte-count to character-count.  */
147e83
+	br	%r14
147e83
+
147e83
+	/* Find zero in 16byte aligned loop.  */
147e83
+.Lloop64:
147e83
+	vl	%v16,0(%r5,%r2)	/* Load s.  */
147e83
+	vfenezfs %v16,%v16,%v16	/* Find element not equal with zero search.  */
147e83
+	je	.Lfound		/* Jump away if zero was found.  */
147e83
+	vl	%v16,16(%r5,%r2)
147e83
+	vfenezfs %v16,%v16,%v16
147e83
+	je	.Lfound16
147e83
+	vl	%v16,32(%r5,%r2)
147e83
+	vfenezfs %v16,%v16,%v16
147e83
+	je	.Lfound32
147e83
+	vl	%v16,48(%r5,%r2)
147e83
+	vfenezfs %v16,%v16,%v16
147e83
+	je	.Lfound48
147e83
+
147e83
+	aghi	%r5,64
147e83
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
147e83
+	aghi	%r1,64
147e83
+	clgrjl	%r1,%r3,.Lloop64
147e83
+
147e83
+	j	.Llt64
147e83
+
147e83
+.Lfallback:
147e83
+	jg	__wcsnlen_c
147e83
+END(__wcsnlen_vx)
147e83
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
147e83
diff --git a/sysdeps/s390/multiarch/wcsnlen.c b/sysdeps/s390/multiarch/wcsnlen.c
147e83
new file mode 100644
147e83
index 0000000..fbb0cab
147e83
--- /dev/null
147e83
+++ b/sysdeps/s390/multiarch/wcsnlen.c
147e83
@@ -0,0 +1,28 @@
147e83
+/* Multiple versions of wcsnlen.
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 (__wcsnlen)
147e83
+weak_alias (__wcsnlen, wcsnlen)
147e83
+
147e83
+#else
147e83
+# include <wcsmbs/wcsnlen.c>
147e83
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
147e83
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
147e83
index 54994e2..ec0b050 100644
147e83
--- a/wcsmbs/Makefile
147e83
+++ b/wcsmbs/Makefile
147e83
@@ -41,7 +41,7 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
147e83
 	    isoc99_swscanf isoc99_vswscanf \
147e83
 	    mbrtoc16 c16rtomb
147e83
 
147e83
-strop-tests :=  wcscmp wmemcmp wcslen wcschr wcsrchr wcscpy
147e83
+strop-tests :=  wcscmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen
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-wcsnlen-ifunc.c b/wcsmbs/test-wcsnlen-ifunc.c
147e83
new file mode 100644
147e83
index 0000000..8aa528e
147e83
--- /dev/null
147e83
+++ b/wcsmbs/test-wcsnlen-ifunc.c
147e83
@@ -0,0 +1,20 @@
147e83
+/* Test and measure IFUNC implementations of wcsnlen 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-wcsnlen.c"
147e83
diff --git a/wcsmbs/test-wcsnlen.c b/wcsmbs/test-wcsnlen.c
147e83
new file mode 100644
147e83
index 0000000..262ab30
147e83
--- /dev/null
147e83
+++ b/wcsmbs/test-wcsnlen.c
147e83
@@ -0,0 +1,20 @@
147e83
+/* Test wcsnlen 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 WIDE 1
147e83
+#include "../string/test-strnlen.c"
147e83
diff --git a/wcsmbs/wcsnlen.c b/wcsmbs/wcsnlen.c
147e83
index dff1b45..e803920 100644
147e83
--- a/wcsmbs/wcsnlen.c
147e83
+++ b/wcsmbs/wcsnlen.c
147e83
@@ -18,8 +18,11 @@
147e83
 
147e83
 #include <wchar.h>
147e83
 
147e83
+#ifdef WCSNLEN
147e83
+# define __wcsnlen WCSNLEN
147e83
+#endif
147e83
 
147e83
-/* Copy SRC to DEST.  */
147e83
+/* Return length of string S at most maxlen.  */
147e83
 size_t
147e83
 __wcsnlen (s, maxlen)
147e83
      const wchar_t *s;
147e83
@@ -44,4 +47,6 @@ __wcsnlen (s, maxlen)
147e83
 
147e83
   return len;
147e83
 }
147e83
+#ifndef WCSNLEN
147e83
 weak_alias (__wcsnlen, wcsnlen)
147e83
+#endif
147e83
-- 
147e83
2.3.0
147e83