diff options
author | Stefan Liebler <stli@linux.vnet.ibm.com> | 2015-08-26 10:26:20 +0200 |
---|---|---|
committer | Andreas Krebbel <krebbel@linux.vnet.ibm.com> | 2015-08-26 10:26:20 +0200 |
commit | fcf40ebe2682fd65d64f94d69a3df798960cf1b7 (patch) | |
tree | 45b1b3ea6b9a5105a81ca6d7fe351b79a9042eb6 /benchtests | |
parent | 9472f35a0a6dbbda82ce103aaf0f5013f5d46e34 (diff) | |
download | glibc-fcf40ebe2682fd65d64f94d69a3df798960cf1b7.tar.gz |
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 'benchtests')
-rw-r--r-- | benchtests/Makefile | 2 | ||||
-rw-r--r-- | benchtests/bench-strnlen.c | 71 | ||||
-rw-r--r-- | benchtests/bench-wcsnlen.c | 20 |
3 files changed, 67 insertions, 26 deletions
diff --git a/benchtests/Makefile b/benchtests/Makefile index 5d4afabc52..295738eede 100644 --- a/benchtests/Makefile +++ b/benchtests/Makefile @@ -36,7 +36,7 @@ string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \ strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \ strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \ strcoll -wcsmbs-bench := wcslen +wcsmbs-bench := wcslen wcsnlen string-bench-all := $(string-bench) ${wcsmbs-bench} # We have to generate locales diff --git a/benchtests/bench-strnlen.c b/benchtests/bench-strnlen.c index 35266e5bf9..cbdce75b74 100644 --- a/benchtests/bench-strnlen.c +++ b/benchtests/bench-strnlen.c @@ -17,17 +17,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 "bench-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; @@ -36,7 +55,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), i, iters = INNER_LOOP_ITERS; timing_t start, stop, cur; @@ -66,18 +85,20 @@ 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 + 7 * i % max_char; + buf[align + len] = 0; printf ("Length %4zd, alignment %2zd:", len, align); 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)); putchar ('\n'); } @@ -96,34 +117,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); } return ret; diff --git a/benchtests/bench-wcsnlen.c b/benchtests/bench-wcsnlen.c new file mode 100644 index 0000000000..2b5a51cabf --- /dev/null +++ b/benchtests/bench-wcsnlen.c @@ -0,0 +1,20 @@ +/* Measure wcsnlen functions. + Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#define WIDE 1 +#include "bench-strnlen.c" |