+2019-02-12 Wilco Dijkstra <wdijkstr@arm.com>
+
+ * benchtests/bench-strcasecmp.c (stupid_strcasecmp): Remove.
+ * benchtests/bench-strcasestr.c (stupid_strcasestr): Remove.
+ * benchtests/bench-strchr.c (stupid_strchr): Remove.
+ * benchtests/bench-strcmp.c (stupid_strcmp): Remove.
+ * benchtests/bench-strcspn.c (stupid_strcspn): Remove.
+ * benchtests/bench-strlen.c (builtin_strlen): Remove.
+ * benchtests/bench-strncasecmp.c (stupid_strncasecmp): Remove.
+ * benchtests/bench-strncmp.c (stupid_strncmp): Remove.
+ * benchtests/bench-strpbrk.c (stupid_strpbrk): Remove.
+ * benchtests/bench-strspn.c (stupid_strspn): Remove.
+ * benchtests/Makefile: Remove bench-bcopy.c and bench-bzero.c.
+ * benchtests/bench-bcopy.c: Delete file.
+ * benchtests/bench-bzero.c: Likewise.
+ * benchtests/bench-memccpy.c (stupid_memccpy): Remove.
+ (simple_memccpy): Remove.
+ (generic_memccpy): Add function.
+ * benchtests/bench-memcpy.c: (builtin_memcpy): Remove.
+ * benchtests/bench-memmove.c (simple_bcopy): Remove.
+ * benchtests/bench-mempcpy.c (simple_mempcpy): Remove.
+ (generic_mempcpy): Add new function.
+ * benchtests/bench-memset.c (simple_bzero): Remove.
+ (builtin_bzero): Remove.
+ (builtin_memset): Remove.
+ * benchtests/bench-rawmemchr.c (simple_rawmemchr): Remove.
+ (generic_rawmemchr): Add new function.
+
2019-02-12 Florian Weimer <fweimer@redhat.com>
* nss/getent.c (ahosts_keys_int): Include IPv6 scope ID in output.
endif
# String function benchmarks.
-string-benchset := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
+string-benchset := memccpy memchr memcmp memcpy memmem memmove \
mempcpy memset rawmemchr stpcpy stpncpy strcasecmp strcasestr \
strcat strchr strchrnul strcmp strcpy strcspn strlen \
strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
+++ /dev/null
-/* Measure bcopy functions.
- Copyright (C) 2013-2019 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 TEST_BCOPY
-#include "bench-memmove.c"
+++ /dev/null
-/* Measure bzero functions.
- Copyright (C) 2013-2019 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 TEST_BZERO
-#include "bench-memset.c"
#define TEST_NAME "memccpy"
#include "bench-string.h"
-void *simple_memccpy (void *, const void *, int, size_t);
-void *stupid_memccpy (void *, const void *, int, size_t);
-
-IMPL (stupid_memccpy, 0)
-IMPL (simple_memccpy, 0)
-IMPL (memccpy, 1)
-
-void *
-simple_memccpy (void *dst, const void *src, int c, size_t n)
-{
- const char *s = src;
- char *d = dst;
-
- while (n-- > 0)
- if ((*d++ = *s++) == (char) c)
- return d;
-
- return NULL;
-}
-
void *
-stupid_memccpy (void *dst, const void *src, int c, size_t n)
+generic_memccpy (void *dst, const void *src, int c, size_t n)
{
void *p = memchr (src, c, n);
return NULL;
}
+IMPL (memccpy, 1)
+IMPL (generic_memccpy, 0)
+
typedef void *(*proto_t) (void *, const void *, int c, size_t);
static void
# define TEST_NAME "memcpy"
# include "bench-string.h"
-char *simple_memcpy (char *, const char *, size_t);
-char *builtin_memcpy (char *, const char *, size_t);
-
-IMPL (simple_memcpy, 0)
-IMPL (builtin_memcpy, 0)
-IMPL (memcpy, 1)
-
char *
simple_memcpy (char *dst, const char *src, size_t n)
{
return ret;
}
-char *
-builtin_memcpy (char *dst, const char *src, size_t n)
-{
- return __builtin_memcpy (dst, src, n);
-}
+IMPL (memcpy, 1)
+IMPL (simple_memcpy, 0)
+
#endif
# include "json-lib.h"
<http://www.gnu.org/licenses/>. */
#define TEST_MAIN
-#ifdef TEST_BCOPY
-# define TEST_NAME "bcopy"
-#else
-# define TEST_NAME "memmove"
-#endif
+#define TEST_NAME "memmove"
#include "bench-string.h"
#include "json-lib.h"
char *simple_memmove (char *, const char *, size_t);
-#ifdef TEST_BCOPY
-typedef void (*proto_t) (const char *, char *, size_t);
-void simple_bcopy (const char *, char *, size_t);
-
-IMPL (simple_bcopy, 0)
-IMPL (bcopy, 1)
-
-void
-simple_bcopy (const char *src, char *dst, size_t n)
-{
- simple_memmove (dst, src, n);
-}
-#else
typedef char *(*proto_t) (char *, const char *, size_t);
-IMPL (simple_memmove, 0)
IMPL (memmove, 1)
-#endif
+IMPL (simple_memmove, 0)
char *
inhibit_loop_to_libcall
TIMING_NOW (start);
for (i = 0; i < iters; ++i)
{
-#ifdef TEST_BCOPY
- CALL (impl, src, dst, len);
-#else
CALL (impl, dst, src, len);
-#endif
}
TIMING_NOW (stop);
#define TEST_NAME "mempcpy"
#include "bench-string.h"
-char *simple_mempcpy (char *, const char *, size_t);
-
-IMPL (simple_mempcpy, 0)
-IMPL (mempcpy, 1)
-
char *
-simple_mempcpy (char *dst, const char *src, size_t n)
+generic_mempcpy (char *dst, const char *src, size_t n)
{
- while (n--)
- *dst++ = *src++;
- return dst;
+ return memcpy (dst, src, n) + n;
}
+IMPL (mempcpy, 1)
+IMPL (generic_mempcpy, 0)
+
#include "bench-memcpy.c"
<http://www.gnu.org/licenses/>. */
#define TEST_MAIN
-#ifdef TEST_BZERO
-# define TEST_NAME "bzero"
-#else
-# ifndef WIDE
-# define TEST_NAME "memset"
-# else
-# define TEST_NAME "wmemset"
-# endif /* WIDE */
-#endif /* !TEST_BZERO */
-#define MIN_PAGE_SIZE 131072
-#include "bench-string.h"
-
#ifndef WIDE
-# define SIMPLE_MEMSET simple_memset
+# define TEST_NAME "memset"
#else
-# define SIMPLE_MEMSET simple_wmemset
+# define TEST_NAME "wmemset"
#endif /* WIDE */
+#define MIN_PAGE_SIZE 131072
+#include "bench-string.h"
#include "json-lib.h"
CHAR *SIMPLE_MEMSET (CHAR *, int, size_t);
-#ifdef TEST_BZERO
-typedef void (*proto_t) (char *, size_t);
-void simple_bzero (char *, size_t);
-void builtin_bzero (char *, size_t);
-
-IMPL (simple_bzero, 0)
-IMPL (builtin_bzero, 0)
-IMPL (bzero, 1)
-
-void
-simple_bzero (char *s, size_t n)
-{
- SIMPLE_MEMSET (s, 0, n);
-}
-
-void
-builtin_bzero (char *s, size_t n)
-{
- __builtin_bzero (s, n);
-}
-#else
typedef CHAR *(*proto_t) (CHAR *, int, size_t);
-IMPL (SIMPLE_MEMSET, 0)
-# ifndef WIDE
-char *builtin_memset (char *, int, size_t);
-IMPL (builtin_memset, 0)
-# endif /* !WIDE */
IMPL (MEMSET, 1)
-
-# ifndef WIDE
-char *
-builtin_memset (char *s, int c, size_t n)
-{
- return __builtin_memset (s, c, n);
-}
-# endif /* !WIDE */
-#endif /* !TEST_BZERO */
+IMPL (SIMPLE_MEMSET, 0)
CHAR *
inhibit_loop_to_libcall
TIMING_NOW (start);
for (i = 0; i < iters; ++i)
{
-#ifdef TEST_BZERO
- CALL (impl, s, n);
-#else
CALL (impl, s, c, n);
-#endif /* !TEST_BZERO */
}
TIMING_NOW (stop);
json_array_begin (&json_ctx, "results");
-#ifndef TEST_BZERO
for (c = -65; c <= 130; c += 65)
-#endif
{
for (i = 0; i < 18; ++i)
do_test (&json_ctx, 0, c, 1 << i);
<http://www.gnu.org/licenses/>. */
#include <assert.h>
+#include <stdint.h>
#define TEST_MAIN
#define TEST_NAME "rawmemchr"
#include "bench-string.h"
typedef char *(*proto_t) (const char *, int);
-char *simple_rawmemchr (const char *, int);
-
-IMPL (simple_rawmemchr, 0)
-IMPL (rawmemchr, 1)
char *
-simple_rawmemchr (const char *s, int c)
+generic_rawmemchr (const char *s, int c)
{
- while (1)
- if (*s++ == (char) c)
- return (char *) s - 1;
- return NULL;
+ if (c != 0)
+ return memchr (s, c, PTRDIFF_MAX);
+ return (char *)s + strlen (s);
}
+IMPL (rawmemchr, 1)
+IMPL (generic_rawmemchr, 0)
+
static void
do_one_test (impl_t *impl, const char *s, int c, char *exp_res)
{
typedef int (*proto_t) (const char *, const char *);
static int simple_strcasecmp (const char *, const char *);
-static int stupid_strcasecmp (const char *, const char *);
-IMPL (stupid_strcasecmp, 0)
IMPL (simple_strcasecmp, 0)
IMPL (strcasecmp, 1)
return ret;
}
-static int
-stupid_strcasecmp (const char *s1, const char *s2)
-{
- size_t ns1 = strlen (s1) + 1, ns2 = strlen (s2) + 1;
- size_t n = ns1 < ns2 ? ns1 : ns2;
- int ret = 0;
-
- while (n--)
- {
- if ((ret = ((unsigned char) tolower (*s1)
- - (unsigned char) tolower (*s2))) != 0)
- break;
- ++s1;
- ++s2;
- }
- return ret;
-}
-
static void
do_one_test (impl_t *impl, const char *s1, const char *s2, int exp_result)
{
#define __strnlen strnlen
#include "../string/strcasestr.c"
-
-static char *
-stupid_strcasestr (const char *s1, const char *s2)
-{
- ssize_t s1len = strlen (s1);
- ssize_t s2len = strlen (s2);
-
- if (s2len > s1len)
- return NULL;
-
- for (ssize_t i = 0; i <= s1len - s2len; ++i)
- {
- size_t j;
- for (j = 0; j < s2len; ++j)
- if (tolower (s1[i + j]) != tolower (s2[j]))
- break;
- if (j == s2len)
- return (char *) s1 + i;
- }
-
- return NULL;
-}
-
-
typedef char *(*proto_t) (const char *, const char *);
-IMPL (stupid_strcasestr, 0)
IMPL (simple_strcasestr, 0)
IMPL (strcasestr, 1)
# ifdef USE_FOR_STRCHRNUL
# undef STRCHR
# define STRCHR strchrnul
-# define stupid_STRCHR stupid_STRCHRNUL
# define simple_STRCHR simple_STRCHRNUL
# endif /* !USE_FOR_STRCHRNUL */
# define MIDDLE_CHAR 127
# ifdef USE_FOR_STRCHRNUL
# undef STRCHR
# define STRCHR wcschrnul
-# define stupid_STRCHR stupid_WCSCHRNUL
# define simple_STRCHR simple_WCSCHRNUL
# endif /* !USE_FOR_STRCHRNUL */
# define MIDDLE_CHAR 1121
return (CHAR *) s;
}
-CHAR *
-stupid_STRCHR (const CHAR *s, int c)
-{
- size_t n = STRLEN (s) + 1;
-
- while (n--)
- if (*s++ == (CHAR) c)
- return (CHAR *) s - 1;
- return NULLRET ((CHAR *) s - 1);
-}
-
-IMPL (stupid_STRCHR, 0)
IMPL (simple_STRCHR, 0)
IMPL (STRCHR, 1)
#ifdef WIDE
# define L(str) L##str
# define SIMPLE_STRCMP simple_wcscmp
-# define STUPID_STRCMP stupid_wcscmp
# define CHARBYTESLOG 2
# define MIDCHAR 0x7fffffff
# define LARGECHAR 0xfffffffe
return c1 < c2 ? -1 : 1;
}
-int
-stupid_wcscmp (const wchar_t *s1, const wchar_t *s2)
-{
- size_t ns1 = wcslen (s1) + 1;
- size_t ns2 = wcslen (s2) + 1;
- size_t n = ns1 < ns2 ? ns1 : ns2;
- int ret = 0;
-
- wchar_t c1, c2;
-
- while (n--) {
- c1 = *s1++;
- c2 = *s2++;
- if ((ret = c1 < c2 ? -1 : c1 == c2 ? 0 : 1) != 0)
- break;
- }
- return ret;
-}
-
#else
# include <limits.h>
# define L(str) str
# define SIMPLE_STRCMP simple_strcmp
-# define STUPID_STRCMP stupid_strcmp
# define CHARBYTESLOG 0
# define MIDCHAR 0x7f
# define LARGECHAR 0xfe
return ret;
}
-int
-stupid_strcmp (const char *s1, const char *s2)
-{
- size_t ns1 = strlen (s1) + 1;
- size_t ns2 = strlen (s2) + 1;
- size_t n = ns1 < ns2 ? ns1 : ns2;
- int ret = 0;
-
- while (n--)
- if ((ret = *(unsigned char *) s1++ - *(unsigned char *) s2++) != 0)
- break;
- return ret;
-}
#endif
# include "json-lib.h"
typedef int (*proto_t) (const CHAR *, const CHAR *);
-IMPL (STUPID_STRCMP, 1)
IMPL (SIMPLE_STRCMP, 1)
IMPL (STRCMP, 1)
#ifndef WIDE
# define SIMPLE_STRCSPN simple_strcspn
-# define STUPID_STRCSPN stupid_strcspn
#else
# define SIMPLE_STRCSPN simple_wcscspn
-# define STUPID_STRCSPN stupid_wcscspn
#endif /* WIDE */
typedef size_t (*proto_t) (const CHAR *, const CHAR *);
size_t SIMPLE_STRCSPN (const CHAR *, const CHAR *);
-size_t STUPID_STRCSPN (const CHAR *, const CHAR *);
-IMPL (STUPID_STRCSPN, 0)
IMPL (SIMPLE_STRCSPN, 0)
IMPL (STRCSPN, 1)
return s - str - 1;
}
-size_t
-STUPID_STRCSPN (const CHAR *s, const CHAR *rej)
-{
- size_t ns = STRLEN (s), nrej = STRLEN (rej);
- size_t i, j;
-
- for (i = 0; i < ns; ++i)
- for (j = 0; j < nrej; ++j)
- if (s[i] == rej[j])
- return i;
- return i;
-}
-
#include "bench-strpbrk.c"
IMPL (memchr_strlen, 0)
IMPL (generic_strlen, 0)
-#ifndef WIDE
-size_t
-builtin_strlen (const CHAR *p)
-{
- return __builtin_strlen (p);
-}
-IMPL (builtin_strlen, 0)
-#endif
-
size_t
memchr_strlen (const CHAR *p)
{
typedef int (*proto_t) (const char *, const char *, size_t);
static int simple_strncasecmp (const char *, const char *, size_t);
-static int stupid_strncasecmp (const char *, const char *, size_t);
-IMPL (stupid_strncasecmp, 0)
IMPL (simple_strncasecmp, 0)
IMPL (strncasecmp, 1)
return ret;
}
-static int
-stupid_strncasecmp (const char *s1, const char *s2, size_t max)
-{
- size_t ns1 = strlen (s1) + 1;
- size_t ns2 = strlen (s2) + 1;
- size_t n = ns1 < ns2 ? ns1 : ns2;
- if (n > max)
- n = max;
- int ret = 0;
-
- while (n--)
- {
- if ((ret = ((unsigned char) tolower (*s1)
- - (unsigned char) tolower (*s2))) != 0)
- break;
- ++s1;
- ++s2;
- }
- return ret;
-}
-
static void
do_one_test (impl_t *impl, const char *s1, const char *s2, size_t n,
int exp_result)
#ifdef WIDE
# define L(str) L##str
# define SIMPLE_STRNCMP simple_wcsncmp
-# define STUPID_STRNCMP stupid_wcsncmp
/* Wcsncmp uses signed semantics for comparison, not unsigned.
Avoid using substraction since possible overflow. */
return 0;
}
-int
-stupid_wcsncmp (const CHAR *s1, const CHAR *s2, size_t n)
-{
- wchar_t c1, c2;
- size_t ns1 = wcsnlen (s1, n) + 1, ns2 = wcsnlen (s2, n) + 1;
-
- n = ns1 < n ? ns1 : n;
- n = ns2 < n ? ns2 : n;
-
- while (n--)
- {
- c1 = *s1++;
- c2 = *s2++;
- if (c1 != c2)
- return c1 > c2 ? 1 : -1;
- }
- return 0;
-}
-
#else
# define L(str) str
# define SIMPLE_STRNCMP simple_strncmp
-# define STUPID_STRNCMP stupid_strncmp
/* Strncmp uses unsigned semantics for comparison. */
int
return ret;
}
-int
-stupid_strncmp (const char *s1, const char *s2, size_t n)
-{
- size_t ns1 = strnlen (s1, n) + 1, ns2 = strnlen (s2, n) + 1;
- int ret = 0;
-
- n = ns1 < n ? ns1 : n;
- n = ns2 < n ? ns2 : n;
- while (n-- && (ret = *(unsigned char *) s1++ - *(unsigned char *) s2++) == 0);
- return ret;
-}
-
#endif /* !WIDE */
typedef int (*proto_t) (const CHAR *, const CHAR *, size_t);
-IMPL (STUPID_STRNCMP, 0)
IMPL (SIMPLE_STRNCMP, 0)
IMPL (STRNCMP, 1)
# ifndef WIDE
# define SIMPLE_STRPBRK simple_strpbrk
-# define STUPID_STRPBRK stupid_strpbrk
# else
# define SIMPLE_STRPBRK simple_wcspbrk
-# define STUPID_STRPBRK stupid_wcspbrk
# endif /* WIDE */
typedef CHAR *(*proto_t) (const CHAR *, const CHAR *);
CHAR *SIMPLE_STRPBRK (const CHAR *, const CHAR *);
-CHAR *STUPID_STRPBRK (const CHAR *, const CHAR *);
-IMPL (STUPID_STRPBRK, 0)
IMPL (SIMPLE_STRPBRK, 0)
IMPL (STRPBRK, 1)
return NULL;
}
-CHAR *
-STUPID_STRPBRK (const CHAR *s, const CHAR *rej)
-{
- size_t ns = STRLEN (s), nrej = STRLEN (rej);
- size_t i, j;
-
- for (i = 0; i < ns; ++i)
- for (j = 0; j < nrej; ++j)
- if (s[i] == rej[j])
- return (CHAR *) s + i;
- return NULL;
-}
#endif /* !STRPBRK_RESULT */
static void
#ifndef WIDE
# define SIMPLE_STRSPN simple_strspn
-# define STUPID_STRSPN stupid_strspn
# define SMALL_CHAR 127
#else
# define SIMPLE_STRSPN simple_wcsspn
-# define STUPID_STRSPN stupid_wcsspn
# 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)
return s - str - 1;
}
-size_t
-STUPID_STRSPN (const CHAR *s, const CHAR *acc)
-{
- size_t ns = STRLEN (s), nacc = STRLEN (acc);
- size_t i, j;
-
- for (i = 0; i < ns; ++i)
- {
- for (j = 0; j < nacc; ++j)
- if (s[i] == acc[j])
- break;
- if (j == nacc)
- return i;
- }
- return i;
-}
-
static void
do_one_test (impl_t *impl, const CHAR *s, const CHAR *acc, size_t exp_res)
{