about summary refs log tree commit diff
path: root/string/test-strnlen.c
diff options
context:
space:
mode:
authorStefan Liebler <stli@linux.vnet.ibm.com>2015-08-26 10:26:20 +0200
committerAndreas Krebbel <krebbel@linux.vnet.ibm.com>2015-08-26 10:26:20 +0200
commitfcf40ebe2682fd65d64f94d69a3df798960cf1b7 (patch)
tree45b1b3ea6b9a5105a81ca6d7fe351b79a9042eb6 /string/test-strnlen.c
parent9472f35a0a6dbbda82ce103aaf0f5013f5d46e34 (diff)
downloadglibc-fcf40ebe2682fd65d64f94d69a3df798960cf1b7.tar.gz
glibc-fcf40ebe2682fd65d64f94d69a3df798960cf1b7.tar.xz
glibc-fcf40ebe2682fd65d64f94d69a3df798960cf1b7.zip
S390: Optimize strnlen and wcsnlen.
This patch provides optimized versions of strnlen and wcsnlen with the z13
vector instructions.

ChangeLog:

	* sysdeps/s390/multiarch/strnlen-c.c: New File.
	* sysdeps/s390/multiarch/strnlen-vx.S: Likewise.
	* sysdeps/s390/multiarch/strnlen.c: Likewise.
	* sysdeps/s390/multiarch/wcsnlen-c.c: Likewise.
	* sysdeps/s390/multiarch/wcsnlen-vx.S: Likewise.
	* sysdeps/s390/multiarch/wcsnlen.c: Likewise.
	* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add strnlen and
	wcsnlen functions.
	* sysdeps/s390/multiarch/ifunc-impl-list.c
	(__libc_ifunc_impl_list): Add ifunc test for strnlen, wcsnlen.
	* wcsmbs/wcsnlen.c: Use WCSNLEN if defined.
	* string/test-strnlen.c: Add wcsnlen support.
	* wcsmbs/test-wcsnlen.c: New File.
	* wcsmbs/Makefile (strop-tests): Add wcsnlen.
	* benchtests/bench-strnlen.c: Add wcsnlen support.
	* benchtests/bench-wcsnlen.c: New File.
	* benchtests/Makefile (wcsmbs-bench): Add wcsnlen.
Diffstat (limited to 'string/test-strnlen.c')
-rw-r--r--string/test-strnlen.c87
1 files changed, 54 insertions, 33 deletions
diff --git a/string/test-strnlen.c b/string/test-strnlen.c
index 96797e156b..8d35cacb61 100644
--- a/string/test-strnlen.c
+++ b/string/test-strnlen.c
@@ -1,4 +1,4 @@
-/* Test and measure strlen functions.
+/* Test strlen functions.
    Copyright (C) 1999-2015 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
@@ -18,17 +18,36 @@
    <http://www.gnu.org/licenses/>.  */
 
 #define TEST_MAIN
-#define TEST_NAME "strnlen"
+#ifndef WIDE
+# define TEST_NAME "strnlen"
+#else
+# define TEST_NAME "wcsnlen"
+#endif /* !WIDE */
 #include "test-string.h"
 
-typedef size_t (*proto_t) (const char *, size_t);
-size_t simple_strnlen (const char *, size_t);
-
-IMPL (simple_strnlen, 0)
-IMPL (strnlen, 1)
+#ifndef WIDE
+# define STRNLEN strnlen
+# define CHAR char
+# define BIG_CHAR CHAR_MAX
+# define MIDDLE_CHAR 127
+# define SIMPLE_STRNLEN simple_strnlen
+#else
+# include <wchar.h>
+# define STRNLEN wcsnlen
+# define CHAR wchar_t
+# define BIG_CHAR WCHAR_MAX
+# define MIDDLE_CHAR 1121
+# define SIMPLE_STRNLEN simple_wcsnlen
+#endif /* !WIDE */
+
+typedef size_t (*proto_t) (const CHAR *, size_t);
+size_t SIMPLE_STRNLEN (const CHAR *, size_t);
+
+IMPL (SIMPLE_STRNLEN, 0)
+IMPL (STRNLEN, 1)
 
 size_t
-simple_strnlen (const char *s, size_t maxlen)
+SIMPLE_STRNLEN (const CHAR *s, size_t maxlen)
 {
   size_t i;
 
@@ -37,7 +56,7 @@ simple_strnlen (const char *s, size_t maxlen)
 }
 
 static void
-do_one_test (impl_t *impl, const char *s, size_t maxlen, size_t exp_len)
+do_one_test (impl_t *impl, const CHAR *s, size_t maxlen, size_t exp_len)
 {
   size_t len = CALL (impl, s, maxlen);
   if (len != exp_len)
@@ -54,23 +73,25 @@ do_test (size_t align, size_t len, size_t maxlen, int max_char)
 {
   size_t i;
 
-  align &= 7;
-  if (align + len >= page_size)
+  align &= 63;
+  if ((align + len) * sizeof (CHAR) >= page_size)
     return;
 
+  CHAR *buf = (CHAR *) (buf1);
+
   for (i = 0; i < len; ++i)
-    buf1[align + i] = 1 + 7 * i % max_char;
-  buf1[align + len] = 0;
+    buf[align + i] = 1 + 11111 * i % max_char;
+  buf[align + len] = 0;
 
   FOR_EACH_IMPL (impl, 0)
-    do_one_test (impl, (char *) (buf1 + align), maxlen, MIN (len, maxlen));
+    do_one_test (impl, (CHAR *) (buf + align), maxlen, MIN (len, maxlen));
 }
 
 static void
 do_random_tests (void)
 {
   size_t i, j, n, align, len;
-  unsigned char *p = buf1 + page_size - 512;
+  CHAR *p = (CHAR *) (buf1 + page_size - 512 * sizeof (CHAR));
 
   for (n = 0; n < ITERATIONS; n++)
     {
@@ -97,25 +118,25 @@ do_random_tests (void)
       FOR_EACH_IMPL (impl, 1)
 	{
 	  if (len > 0
-	      && CALL (impl, (char *) (p + align), len - 1) != len - 1)
+	      && CALL (impl, (CHAR *) (p + align), len - 1) != len - 1)
 	    {
 	      error (0, 0, "Iteration %zd (limited) - wrong result in function %s (%zd) %zd != %zd, p %p",
 		     n, impl->name, align,
-		     CALL (impl, (char *) (p + align), len - 1), len - 1, p);
+		     CALL (impl, (CHAR *) (p + align), len - 1), len - 1, p);
 	      ret = 1;
 	    }
-	  if (CALL (impl, (char *) (p + align), len) != len)
+	  if (CALL (impl, (CHAR *) (p + align), len) != len)
 	    {
 	      error (0, 0, "Iteration %zd (exact) - wrong result in function %s (%zd) %zd != %zd, p %p",
 		     n, impl->name, align,
-		     CALL (impl, (char *) (p + align), len), len, p);
+		     CALL (impl, (CHAR *) (p + align), len), len, p);
 	      ret = 1;
 	    }
-	  if (CALL (impl, (char *) (p + align), len + 1) != len)
+	  if (CALL (impl, (CHAR *) (p + align), len + 1) != len)
 	    {
 	      error (0, 0, "Iteration %zd (long) - wrong result in function %s (%zd) %zd != %zd, p %p",
 		     n, impl->name, align,
-		     CALL (impl, (char *) (p + align), len + 1), len, p);
+		     CALL (impl, (CHAR *) (p + align), len + 1), len, p);
 	      ret = 1;
 	    }
 	}
@@ -136,34 +157,34 @@ test_main (void)
 
   for (i = 1; i < 8; ++i)
     {
-      do_test (0, i, i - 1, 127);
-      do_test (0, i, i, 127);
-      do_test (0, i, i + 1, 127);
+      do_test (0, i, i - 1, MIDDLE_CHAR);
+      do_test (0, i, i, MIDDLE_CHAR);
+      do_test (0, i, i + 1, MIDDLE_CHAR);
     }
 
   for (i = 1; i < 8; ++i)
     {
-      do_test (i, i, i - 1, 127);
-      do_test (i, i, i, 127);
-      do_test (i, i, i + 1, 127);
+      do_test (i, i, i - 1, MIDDLE_CHAR);
+      do_test (i, i, i, MIDDLE_CHAR);
+      do_test (i, i, i + 1, MIDDLE_CHAR);
     }
 
   for (i = 2; i <= 10; ++i)
     {
-      do_test (0, 1 << i, 5000, 127);
-      do_test (1, 1 << i, 5000, 127);
+      do_test (0, 1 << i, 5000, MIDDLE_CHAR);
+      do_test (1, 1 << i, 5000, MIDDLE_CHAR);
     }
 
   for (i = 1; i < 8; ++i)
-    do_test (0, i, 5000, 255);
+    do_test (0, i, 5000, BIG_CHAR);
 
   for (i = 1; i < 8; ++i)
-    do_test (i, i, 5000, 255);
+    do_test (i, i, 5000, BIG_CHAR);
 
   for (i = 2; i <= 10; ++i)
     {
-      do_test (0, 1 << i, 5000, 255);
-      do_test (1, 1 << i, 5000, 255);
+      do_test (0, 1 << i, 5000, BIG_CHAR);
+      do_test (1, 1 << i, 5000, BIG_CHAR);
     }
 
   do_random_tests ();