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