about summary refs log tree commit diff
path: root/benchtests/bench-strspn.c
diff options
context:
space:
mode:
authorStefan Liebler <stli@linux.vnet.ibm.com>2015-08-26 10:26:24 +0200
committerAndreas Krebbel <krebbel@linux.vnet.ibm.com>2015-08-26 10:26:24 +0200
commitf1ffad98be7ec4111fbd1cd1f58f3e3343257519 (patch)
tree37bf3ccd97d9ff61a4cdfcfb1256b370175aa9a2 /benchtests/bench-strspn.c
parentf40132d4bda984479bac89dfcd6968e9ff56e088 (diff)
downloadglibc-f1ffad98be7ec4111fbd1cd1f58f3e3343257519.tar.gz
glibc-f1ffad98be7ec4111fbd1cd1f58f3e3343257519.tar.xz
glibc-f1ffad98be7ec4111fbd1cd1f58f3e3343257519.zip
S390: Optimize strspn and wcsspn.
This patch provides optimized versions of strspn and wcsspn with the z13
vector instructions.

ChangeLog:

	* sysdeps/s390/multiarch/strspn-c.c: New File.
	* sysdeps/s390/multiarch/strspn-vx.S: Likewise.
	* sysdeps/s390/multiarch/strspn.c: Likewise.
	* sysdeps/s390/multiarch/wcsspn-c.c: Likewise.
	* sysdeps/s390/multiarch/wcsspn-vx.S: Likewise.
	* sysdeps/s390/multiarch/wcsspn.c: Likewise.
	* wcsmbs/wcsspn.c: Use WCSSPN if defined.
	* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add strspn and
	wcsspn functions.
	* sysdeps/s390/multiarch/ifunc-impl-list.c
	(__libc_ifunc_impl_list): Add ifunc test for strspn, wcsspn.
	* string/test-strspn.c: Add wcsspn support.
	* wcsmbs/test-wcsspn.c: New File.
	* wcsmbs/Makefile (strop-tests): Add wcsspn.
	* benchtests/bench-strspn.c: Add wcsspn support.
	* benchtests/bench-wcsspn.c: New File.
	* benchtests/Makefile (wcsmbs-bench): Add wcsspn.
Diffstat (limited to 'benchtests/bench-strspn.c')
-rw-r--r--benchtests/bench-strspn.c73
1 files changed, 49 insertions, 24 deletions
diff --git a/benchtests/bench-strspn.c b/benchtests/bench-strspn.c
index 6061f2b5ce..88192dd4c2 100644
--- a/benchtests/bench-strspn.c
+++ b/benchtests/bench-strspn.c
@@ -17,22 +17,47 @@
    <http://www.gnu.org/licenses/>.  */
 
 #define TEST_MAIN
-#define TEST_NAME "strspn"
+#ifndef WIDE
+# define TEST_NAME "strspn"
+#else
+# define TEST_NAME "wcsspn"
+#endif /* WIDE */
 #include "bench-string.h"
 
-typedef size_t (*proto_t) (const char *, const char *);
-size_t simple_strspn (const char *, const char *);
-size_t stupid_strspn (const char *, const char *);
-
-IMPL (stupid_strspn, 0)
-IMPL (simple_strspn, 0)
-IMPL (strspn, 1)
+#ifndef WIDE
+# define STRSPN strspn
+# define CHAR char
+# define SIMPLE_STRSPN simple_strspn
+# define STUPID_STRSPN stupid_strspn
+# define STRLEN strlen
+# define STRCHR strchr
+# define BIG_CHAR CHAR_MAX
+# define SMALL_CHAR 127
+#else
+# include <wchar.h>
+# define STRSPN wcsspn
+# define CHAR wchar_t
+# define SIMPLE_STRSPN simple_wcsspn
+# define STUPID_STRSPN stupid_wcsspn
+# define STRLEN wcslen
+# define STRCHR wcschr
+# define BIG_CHAR WCHAR_MAX
+# define SMALL_CHAR 1273
+#endif /* WIDE */
+
+typedef size_t (*proto_t) (const CHAR *, const CHAR *);
+size_t SIMPLE_STRSPN (const CHAR *, const CHAR *);
+size_t STUPID_STRSPN (const CHAR *, const CHAR *);
+
+IMPL (STUPID_STRSPN, 0)
+IMPL (SIMPLE_STRSPN, 0)
+IMPL (STRSPN, 1)
 
 size_t
-simple_strspn (const char *s, const char *acc)
+SIMPLE_STRSPN (const CHAR *s, const CHAR *acc)
 {
-  const char *r, *str = s;
-  char c;
+  const CHAR *r, *str = s;
+  CHAR c;
 
   while ((c = *s++) != '\0')
     {
@@ -46,9 +71,9 @@ simple_strspn (const char *s, const char *acc)
 }
 
 size_t
-stupid_strspn (const char *s, const char *acc)
+STUPID_STRSPN (const CHAR *s, const CHAR *acc)
 {
-  size_t ns = strlen (s), nacc = strlen (acc);
+  size_t ns = STRLEN (s), nacc = STRLEN (acc);
   size_t i, j;
 
   for (i = 0; i < ns; ++i)
@@ -63,7 +88,7 @@ stupid_strspn (const char *s, const char *acc)
 }
 
 static void
-do_one_test (impl_t *impl, const char *s, const char *acc, size_t exp_res)
+do_one_test (impl_t *impl, const CHAR *s, const CHAR *acc, size_t exp_res)
 {
   size_t res = CALL (impl, s, acc), i, iters = INNER_LOOP_ITERS;
   timing_t start, stop, cur;
@@ -92,34 +117,34 @@ static void
 do_test (size_t align, size_t pos, size_t len)
 {
   size_t i;
-  char *acc, *s;
+  CHAR *acc, *s;
 
   align &= 7;
-  if (align + pos + 10 >= page_size || len > 240 || ! len)
+  if ((align + pos + 10) * sizeof (CHAR) >= page_size || len > 240 || ! len)
     return;
 
-  acc = (char *) (buf2 + (random () & 255));
-  s = (char *) (buf1 + align);
+  acc = (CHAR *) (buf2) + (random () & 255);
+  s = (CHAR *) (buf1) + align;
 
   for (i = 0; i < len; ++i)
     {
-      acc[i] = random () & 255;
+      acc[i] = random () & BIG_CHAR;
       if (!acc[i])
-	acc[i] = random () & 255;
+	acc[i] = random () & BIG_CHAR;
       if (!acc[i])
-	acc[i] = 1 + (random () & 127);
+	acc[i] = 1 + (random () & SMALL_CHAR);
     }
   acc[len] = '\0';
 
   for (i = 0; i < pos; ++i)
     s[i] = acc[random () % len];
-  s[pos] = random () & 255;
-  if (strchr (acc, s[pos]))
+  s[pos] = random () & BIG_CHAR;
+  if (STRCHR (acc, s[pos]))
     s[pos] = '\0';
   else
     {
       for (i = pos + 1; i < pos + 10; ++i)
-	s[i] = random () & 255;
+	s[i] = random () & BIG_CHAR;
       s[i] = '\0';
     }