This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Deduplicate copy benchtests.


Hi,

Benchtests now are difficult to change given number of places that need
to be changed. This can be simplified by reducing duplicated code.

Here I moved *cpy and memmove functions to common bench-copy.h file that
is easier to update. 

I added address randomization for copy implementations.

OK to commit?

	* benchtests/bench-copy.h: New file.
	* benchtests/bench-memcpy.c: Use implementation in
	benchtests/bench-copy.h
	* benchtests/bench-memmove.c: Likewise.
	* benchtests/bench-mempcpy.c: Likewise.
	* benchtests/bench-stpcpy.c: Likewise.
	* benchtests/bench-strcpy.c: Likewise.
	* benchtests/bench-strncpy.c: Likewise.


---
 benchtests/bench-copy.h    |  111 +++++++++++++++++++++++++++++
 benchtests/bench-memcpy.c  |  139 ++-----------------------------------
 benchtests/bench-memmove.c |  166 ++------------------------------------------
 benchtests/bench-mempcpy.c |   23 ++----
 benchtests/bench-stpcpy.c  |   22 ++----
 benchtests/bench-stpncpy.c |   53 +++-----------
 benchtests/bench-strcpy.c  |  161 ++----------------------------------------
 benchtests/bench-strncpy.c |  158 ++---------------------------------------
 8 files changed, 159 insertions(+), 674 deletions(-)
 create mode 100644 benchtests/bench-copy.h

diff --git a/benchtests/bench-copy.h b/benchtests/bench-copy.h
new file mode 100644
index 0000000..3a04e7a
--- /dev/null
+++ b/benchtests/bench-copy.h
@@ -0,0 +1,111 @@
+/* Measure memcpy, strcpy, stpcpy, ... functions.
+   Copyright (C) 2013 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 MEMCPY_RESULT(dst, len) dst
+#define MIN_PAGE_SIZE (1<<22)
+#define TEST_MAIN
+#include "bench-string.h"
+
+PROTO
+IMPLS
+
+static void
+do_one_test (impl_t *impl, size_t aligned, size_t len)
+{
+  size_t i, iters = INNER_LOOP_ITERS;
+  timing_t start, stop, cur;
+  static unsigned int r_seed = 42;
+
+  char *dsts[INNER_LOOP_ITERS], *srcs[INNER_LOOP_ITERS];
+  for (i = 0; i < iters; ++i)
+    {
+      srcs[i] = ((char *) buf1) + rand_r (&r_seed) % (MIN_PAGE_SIZE / 2);
+      dsts[i] = ((char *) buf2) + rand_r (&r_seed) % (MIN_PAGE_SIZE / 2);
+      if (aligned) /* Align pointers.  */
+        {
+          srcs[i] = srcs[i] - ((uintptr_t) srcs[i]) % 64;
+          dsts[i] = dsts[i] - ((uintptr_t) dsts[i]) % 64;
+        }
+    }
+
+  TIMING_NOW (start);
+  for (i = 0; i < iters; ++i)
+    {
+      srcs[i][len] = 0;
+      CALL2 (impl, dsts[i], srcs[i], len);
+      srcs[i][len] = 1;
+    }
+  TIMING_NOW (stop);
+
+  TIMING_DIFF (cur, start, stop);
+
+  TIMING_PRINT_MEAN ((double) cur, (double) iters);
+}
+
+static void
+do_test (size_t aligned, size_t len)
+{
+  printf ("Length %4zd, aligned %c:", len, aligned ? 'y' : 'n' );
+
+  FOR_EACH_IMPL (impl, 0)
+    do_one_test (impl, aligned, len);
+
+  putchar ('\n');
+}
+
+int
+test_main (void)
+{
+  size_t i;
+
+  test_init ();
+
+  memset (buf1, 1, MIN_PAGE_SIZE);
+
+#ifdef TEST_OVERLAP
+  buf1 = buf2;
+#endif
+
+  printf ("%23s", "");
+  FOR_EACH_IMPL (impl, 0)
+    printf ("\t%10s", impl->name);
+  putchar ('\n');
+
+  for (i = 0; i < 18; ++i)
+    {
+      do_test (0, 1 << i);
+      do_test (1, 1 << i);
+    }
+
+  for (i = 0; i < 32; ++i)
+    {
+      do_test (0, i);
+      do_test (1, i);
+    }
+
+  for (i = 3; i < 32; ++i)
+    {
+      do_test (0, 16 * i);
+      do_test (1, 16 * i);
+    }
+
+
+  return ret;
+}
+
+#include "../test-skeleton.c"
diff --git a/benchtests/bench-memcpy.c b/benchtests/bench-memcpy.c
index 8cd9c23..bebf0ea 100644
--- a/benchtests/bench-memcpy.c
+++ b/benchtests/bench-memcpy.c
@@ -16,142 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef MEMCPY_RESULT
-# define MEMCPY_RESULT(dst, len) dst
-# define MIN_PAGE_SIZE 131072
-# define TEST_MAIN
-# 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)
-{
-  char *ret = dst;
-  while (n--)
-    *dst++ = *src++;
-  return ret;
-}
-
-char *
-builtin_memcpy (char *dst, const char *src, size_t n)
-{
-  return __builtin_memcpy (dst, src, n);
-}
-#endif
-
-typedef char *(*proto_t) (char *, const char *, size_t);
-
-static void
-do_one_test (impl_t *impl, char *dst, const char *src,
-	     size_t len)
-{
-  size_t i, iters = INNER_LOOP_ITERS;
-  timing_t start, stop, cur;
-
-  if (CALL (impl, dst, src, len) != MEMCPY_RESULT (dst, len))
-    {
-      error (0, 0, "Wrong result in function %s %p %p", impl->name,
-	     CALL (impl, dst, src, len), MEMCPY_RESULT (dst, len));
-      ret = 1;
-      return;
-    }
-
-  if (memcmp (dst, src, len) != 0)
-    {
-      error (0, 0, "Wrong result in function %s dst \"%s\" src \"%s\"",
-	     impl->name, dst, src);
-      ret = 1;
-      return;
-    }
-
-  TIMING_NOW (start);
-  for (i = 0; i < iters; ++i)
-    {
-      CALL (impl, dst, src, len);
-    }
-  TIMING_NOW (stop);
-
-  TIMING_DIFF (cur, start, stop);
-
-  TIMING_PRINT_MEAN ((double) cur, (double) iters);
-}
-
-static void
-do_test (size_t align1, size_t align2, size_t len)
-{
-  size_t i, j;
-  char *s1, *s2;
 
-  align1 &= 63;
-  if (align1 + len >= page_size)
-    return;
-
-  align2 &= 63;
-  if (align2 + len >= page_size)
-    return;
-
-  s1 = (char *) (buf1 + align1);
-  s2 = (char *) (buf2 + align2);
-
-  for (i = 0, j = 1; i < len; i++, j += 23)
-    s1[i] = j;
-
-  printf ("Length %4zd, alignment %2zd/%2zd:", len, align1, align2);
-
-  FOR_EACH_IMPL (impl, 0)
-    do_one_test (impl, s2, s1, len);
-
-  putchar ('\n');
-}
-
-int
-test_main (void)
-{
-  size_t i;
-
-  test_init ();
-
-  printf ("%23s", "");
-  FOR_EACH_IMPL (impl, 0)
-    printf ("\t%s", impl->name);
-  putchar ('\n');
-
-  for (i = 0; i < 18; ++i)
-    {
-      do_test (0, 0, 1 << i);
-      do_test (i, 0, 1 << i);
-      do_test (0, i, 1 << i);
-      do_test (i, i, 1 << i);
-    }
-
-  for (i = 0; i < 32; ++i)
-    {
-      do_test (0, 0, i);
-      do_test (i, 0, i);
-      do_test (0, i, i);
-      do_test (i, i, i);
-    }
+# define TEST_NAME "memcpy"
 
-  for (i = 3; i < 32; ++i)
-    {
-      if ((i & (i - 1)) == 0)
-	continue;
-      do_test (0, 0, 16 * i);
-      do_test (i, 0, 16 * i);
-      do_test (0, i, 16 * i);
-      do_test (i, i, 16 * i);
-    }
+#define PROTO typedef char *(*proto_t) (char *, const char *, size_t);
+#define IMPLS IMPL (memcpy, 1)
 
-  do_test (0, 0, getpagesize ());
 
-  return ret;
-}
+#define CALL2(impl, dst, src, len) CALL (impl, dst, src, len)
 
-#include "../test-skeleton.c"
+#include "bench-copy.h"
diff --git a/benchtests/bench-memmove.c b/benchtests/bench-memmove.c
index 332d6af..7daad68 100644
--- a/benchtests/bench-memmove.c
+++ b/benchtests/bench-memmove.c
@@ -1,4 +1,4 @@
-/* Measure memmove functions.
+/* Measure memmove functions.
    Copyright (C) 2013 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,167 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define TEST_MAIN
-#ifdef TEST_BCOPY
-# define TEST_NAME "bcopy"
-#else
-# define TEST_NAME "memmove"
-#endif
-#include "bench-string.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
-
-char *
-inhibit_loop_to_libcall
-simple_memmove (char *dst, const char *src, size_t n)
-{
-  char *ret = dst;
-  if (src < dst)
-    {
-      dst += n;
-      src += n;
-      while (n--)
-	*--dst = *--src;
-    }
-  else
-    while (n--)
-      *dst++ = *src++;
-  return ret;
-}
-
-static void
-do_one_test (impl_t *impl, char *dst, char *src, const char *orig_src,
-	     size_t len)
-{
-  size_t i, iters = INNER_LOOP_ITERS;
-  timing_t start, stop, cur;
-
-  memcpy (src, orig_src, len);
-#ifdef TEST_BCOPY
-  CALL (impl, src, dst, len);
-#else
-  char *res;
-
-  res = CALL (impl, dst, src, len);
-  if (res != dst)
-    {
-      error (0, 0, "Wrong result in function %s %p %p", impl->name,
-	     res, dst);
-      ret = 1;
-      return;
-    }
-#endif
-
-  if (memcmp (dst, orig_src, len) != 0)
-    {
-      error (0, 0, "Wrong result in function %s dst \"%s\" src \"%s\"",
-	     impl->name, dst, src);
-      ret = 1;
-      return;
-    }
-
-  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);
-
-  TIMING_DIFF (cur, start, stop);
 
-  TIMING_PRINT_MEAN ((double) cur, (double) iters);
-}
-
-static void
-do_test (size_t align1, size_t align2, size_t len)
-{
-  size_t i, j;
-  char *s1, *s2;
-
-  align1 &= 63;
-  if (align1 + len >= page_size)
-    return;
-
-  align2 &= 63;
-  if (align2 + len >= page_size)
-    return;
-
-  s1 = (char *) (buf1 + align1);
-  s2 = (char *) (buf2 + align2);
-
-  for (i = 0, j = 1; i < len; i++, j += 23)
-    s1[i] = j;
-
-  printf ("Length %4zd, alignment %2zd/%2zd:", len, align1, align2);
-
-  FOR_EACH_IMPL (impl, 0)
-    do_one_test (impl, s2, (char *) (buf2 + align1), s1, len);
-
-  putchar ('\n');
-}
-
-int
-test_main (void)
-{
-  size_t i;
-
-  test_init ();
-
-  printf ("%23s", "");
-  FOR_EACH_IMPL (impl, 0)
-    printf ("\t%s", impl->name);
-  putchar ('\n');
-
-  for (i = 0; i < 14; ++i)
-    {
-      do_test (0, 32, 1 << i);
-      do_test (32, 0, 1 << i);
-      do_test (0, i, 1 << i);
-      do_test (i, 0, 1 << i);
-    }
+# define TEST_NAME "memmove"
 
-  for (i = 0; i < 32; ++i)
-    {
-      do_test (0, 32, i);
-      do_test (32, 0, i);
-      do_test (0, i, i);
-      do_test (i, 0, i);
-    }
+#define PROTO typedef char *(*proto_t) (char *, const char *, size_t);
+#define IMPLS IMPL (memmove, 1)
 
-  for (i = 3; i < 32; ++i)
-    {
-      if ((i & (i - 1)) == 0)
-	continue;
-      do_test (0, 32, 16 * i);
-      do_test (32, 0, 16 * i);
-      do_test (0, i, 16 * i);
-      do_test (i, 0, 16 * i);
-    }
 
-  return ret;
-}
+#define CALL2(impl, dst, src, len) CALL (impl, dst, src, len)
 
-#include "../test-skeleton.c"
+#include "bench-copy.h"
diff --git a/benchtests/bench-mempcpy.c b/benchtests/bench-mempcpy.c
index 0e0e3b9..c8df984 100644
--- a/benchtests/bench-mempcpy.c
+++ b/benchtests/bench-mempcpy.c
@@ -1,4 +1,4 @@
-/* Measure mempcpy functions.
+/* Measure mempcpy functions.
    Copyright (C) 2013 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,22 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define MEMCPY_RESULT(dst, len) (dst) + (len)
-#define TEST_MAIN
-#define TEST_NAME "mempcpy"
-#include "bench-string.h"
 
-char *simple_mempcpy (char *, const char *, size_t);
+# define TEST_NAME "mempcpy"
 
-IMPL (simple_mempcpy, 0)
-IMPL (mempcpy, 1)
+#define PROTO typedef char *(*proto_t) (char *, const char *, size_t);
+#define IMPLS IMPL (mempcpy, 1)
 
-char *
-simple_mempcpy (char *dst, const char *src, size_t n)
-{
-  while (n--)
-    *dst++ = *src++;
-  return dst;
-}
 
-#include "bench-memcpy.c"
+#define CALL2(impl, dst, src, len) CALL (impl, dst, src, len)
+
+#include "bench-copy.h"
diff --git a/benchtests/bench-stpcpy.c b/benchtests/bench-stpcpy.c
index 0645298..a7e463b 100644
--- a/benchtests/bench-stpcpy.c
+++ b/benchtests/bench-stpcpy.c
@@ -1,4 +1,4 @@
-/* Measure stpcpy functions.
+/* Measure stpcpy functions.
    Copyright (C) 2013 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,21 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define STRCPY_RESULT(dst, len) ((dst) + (len))
-#define TEST_MAIN
-#define TEST_NAME "stpcpy"
-#include "bench-string.h"
 
-char *simple_stpcpy (char *, const char *);
+# define TEST_NAME "stpcpy"
 
-IMPL (simple_stpcpy, 0)
-IMPL (stpcpy, 1)
+#define PROTO typedef char *(*proto_t) (char *, const char *);
+#define IMPLS IMPL (stpcpy, 1)
 
-char *
-simple_stpcpy (char *dst, const char *src)
-{
-  while ((*dst++ = *src++) != '\0');
-  return dst - 1;
-}
 
-#include "bench-strcpy.c"
+#define CALL2(impl, dst, src, len) CALL (impl, dst, src)
+
+#include "bench-copy.h"
diff --git a/benchtests/bench-stpncpy.c b/benchtests/bench-stpncpy.c
index 65ed800..7c914e1 100644
--- a/benchtests/bench-stpncpy.c
+++ b/benchtests/bench-stpncpy.c
@@ -1,4 +1,4 @@
-/* Measure stpncpy functions.
+/* Measure stpncpy functions.
    Copyright (C) 2013 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,44 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define STRNCPY_RESULT(dst, len, n) ((dst) + ((len) > (n) ? (n) : (len)))
-#define TEST_MAIN
-#define TEST_NAME "stpncpy"
-#include "bench-string.h"
-
-char *simple_stpncpy (char *, const char *, size_t);
-char *stupid_stpncpy (char *, const char *, size_t);
-
-IMPL (stupid_stpncpy, 0)
-IMPL (simple_stpncpy, 0)
-IMPL (stpncpy, 1)
-
-char *
-simple_stpncpy (char *dst, const char *src, size_t n)
-{
-  while (n--)
-    if ((*dst++ = *src++) == '\0')
-      {
-	size_t i;
-
-	for (i = 0; i < n; ++i)
-	  dst[i] = '\0';
-	return dst - 1;
-      }
-  return dst;
-}
-
-char *
-stupid_stpncpy (char *dst, const char *src, size_t n)
-{
-  size_t nc = strnlen (src, n);
-  size_t i;
-
-  for (i = 0; i < nc; ++i)
-    dst[i] = src[i];
-  for (; i < n; ++i)
-    dst[i] = '\0';
-  return dst + nc;
-}
-
-#include "bench-strncpy.c"
+
+# define TEST_NAME "stpncpy"
+
+#define PROTO typedef char *(*proto_t) (char *, const char *, size_t);
+#define IMPLS IMPL (stpncpy, 1)
+
+
+#define CALL2(impl, dst, src, len) CALL (impl, dst, src, len)
+
+#include "bench-copy.h"
diff --git a/benchtests/bench-strcpy.c b/benchtests/bench-strcpy.c
index 88db83b..e8b048b 100644
--- a/benchtests/bench-strcpy.c
+++ b/benchtests/bench-strcpy.c
@@ -1,4 +1,4 @@
-/* Measure strcpy functions.
+/* Measure strcpy functions.
    Copyright (C) 2013 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,162 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifdef WIDE
-# include <wchar.h>
-# define CHAR wchar_t
-# define UCHAR wchar_t
-# define sfmt "ls"
-# define BIG_CHAR WCHAR_MAX
-# define SMALL_CHAR 1273
-# define STRCMP wcscmp
-# define MEMCMP wmemcmp
-# define MEMSET wmemset
-#else
-# define CHAR char
-# define UCHAR unsigned char
-# define sfmt "s"
-# define BIG_CHAR CHAR_MAX
-# define SMALL_CHAR 127
-# define STRCMP strcmp
-# define MEMCMP memcmp
-# define MEMSET memset
-#endif
 
-#ifndef STRCPY_RESULT
-# define STRCPY_RESULT(dst, len) dst
-# define TEST_MAIN
-# ifndef WIDE
-#  define TEST_NAME "strcpy"
-# else
-#  define TEST_NAME "wcscpy"
-# endif
-# include "bench-string.h"
-# ifndef WIDE
-#  define SIMPLE_STRCPY simple_strcpy
-#  define STRCPY strcpy
-# else
-#  define SIMPLE_STRCPY simple_wcscpy
-#  define STRCPY wcscpy
-# endif
+# define TEST_NAME "strcpy"
 
-CHAR *SIMPLE_STRCPY (CHAR *, const CHAR *);
+#define PROTO typedef char *(*proto_t) (char *, const char *);
+#define IMPLS IMPL (strcpy, 1)
 
-IMPL (SIMPLE_STRCPY, 0)
-IMPL (STRCPY, 1)
 
-CHAR *
-SIMPLE_STRCPY (CHAR *dst, const CHAR *src)
-{
-  CHAR *ret = dst;
-  while ((*dst++ = *src++) != '\0');
-  return ret;
-}
-#endif
+#define CALL2(impl, dst, src, len) CALL (impl, dst, src)
 
-typedef CHAR *(*proto_t) (CHAR *, const CHAR *);
-
-static void
-do_one_test (impl_t *impl, CHAR *dst, const CHAR *src,
-	     size_t len __attribute__((unused)))
-{
-  size_t i, iters = INNER_LOOP_ITERS;
-  timing_t start, stop, cur;
-
-  if (CALL (impl, dst, src) != STRCPY_RESULT (dst, len))
-    {
-      error (0, 0, "Wrong result in function %s %p %p", impl->name,
-	     CALL (impl, dst, src), STRCPY_RESULT (dst, len));
-      ret = 1;
-      return;
-    }
-
-  if (STRCMP (dst, src) != 0)
-    {
-      error (0, 0,
-	     "Wrong result in function %s dst \"%" sfmt "\" src \"%" sfmt "\"",
-	     impl->name, dst, src);
-      ret = 1;
-      return;
-    }
-
-  TIMING_NOW (start);
-  for (i = 0; i < iters; ++i)
-    {
-	  CALL (impl, dst, src);
-    }
-  TIMING_NOW (stop);
-
-  TIMING_DIFF (cur, start, stop);
-
-  TIMING_PRINT_MEAN ((double) cur, (double) iters);
-}
-
-static void
-do_test (size_t align1, size_t align2, size_t len, int max_char)
-{
-  size_t i;
-  CHAR *s1, *s2;
-/* For wcscpy: align1 and align2 here mean alignment not in bytes,
-   but in wchar_ts, in bytes it will equal to align * (sizeof (wchar_t))
-   len for wcschr here isn't in bytes but it's number of wchar_t symbols.  */
-  align1 &= 7;
-  if ((align1 + len) * sizeof(CHAR) >= page_size)
-    return;
-
-  align2 &= 7;
-  if ((align2 + len) * sizeof(CHAR) >= page_size)
-    return;
-
-  s1 = (CHAR *) (buf1) + align1;
-  s2 = (CHAR *) (buf2) + align2;
-
-  for (i = 0; i < len; i++)
-    s1[i] = 32 + 23 * i % (max_char - 32);
-  s1[len] = 0;
-
-  printf ("Length %4zd, alignments in bytes %2zd/%2zd:", len, align1 * sizeof(CHAR), align2 * sizeof(CHAR));
-
-  FOR_EACH_IMPL (impl, 0)
-    do_one_test (impl, s2, s1, len);
-
-  putchar ('\n');
-}
-
-int
-test_main (void)
-{
-  size_t i;
-
-  test_init ();
-
-  printf ("%23s", "");
-  FOR_EACH_IMPL (impl, 0)
-    printf ("\t%s", impl->name);
-  putchar ('\n');
-
-  for (i = 0; i < 16; ++i)
-    {
-      do_test (0, 0, i, SMALL_CHAR);
-      do_test (0, 0, i, BIG_CHAR);
-      do_test (0, i, i, SMALL_CHAR);
-      do_test (i, 0, i, BIG_CHAR);
-    }
-
-  for (i = 1; i < 8; ++i)
-    {
-      do_test (0, 0, 8 << i, SMALL_CHAR);
-      do_test (8 - i, 2 * i, 8 << i, SMALL_CHAR);
-    }
-
-  for (i = 1; i < 8; ++i)
-    {
-      do_test (i, 2 * i, 8 << i, SMALL_CHAR);
-      do_test (2 * i, i, 8 << i, BIG_CHAR);
-      do_test (i, i, 8 << i, SMALL_CHAR);
-      do_test (i, i, 8 << i, BIG_CHAR);
-    }
-
-  return ret;
-}
-
-#include "../test-skeleton.c"
+#include "bench-copy.h"
diff --git a/benchtests/bench-strncpy.c b/benchtests/bench-strncpy.c
index 645925b..0dec429 100644
--- a/benchtests/bench-strncpy.c
+++ b/benchtests/bench-strncpy.c
@@ -1,4 +1,4 @@
-/* Measure strncpy functions.
+/* Measure strncpy functions.
    Copyright (C) 2013 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,159 +16,13 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifndef STRNCPY_RESULT
-# define STRNCPY_RESULT(dst, len, n) dst
-# define TEST_MAIN
-# define TEST_NAME "strncpy"
-# include "bench-string.h"
-
-char *simple_strncpy (char *, const char *, size_t);
-char *stupid_strncpy (char *, const char *, size_t);
-
-IMPL (stupid_strncpy, 0)
-IMPL (simple_strncpy, 0)
-IMPL (strncpy, 1)
-
-char *
-simple_strncpy (char *dst, const char *src, size_t n)
-{
-  char *ret = dst;
-  while (n--)
-    if ((*dst++ = *src++) == '\0')
-      {
-	while (n--)
-	  *dst++ = '\0';
-	return ret;
-      }
-  return ret;
-}
-
-char *
-stupid_strncpy (char *dst, const char *src, size_t n)
-{
-  size_t nc = strnlen (src, n);
-  size_t i;
-
-  for (i = 0; i < nc; ++i)
-    dst[i] = src[i];
-  for (; i < n; ++i)
-    dst[i] = '\0';
-  return dst;
-}
-#endif
-
-typedef char *(*proto_t) (char *, const char *, size_t);
-
-static void
-do_one_test (impl_t *impl, char *dst, const char *src, size_t len, size_t n)
-{
-  size_t i, iters = INNER_LOOP_ITERS;
-  timing_t start, stop, cur;
-
-  if (CALL (impl, dst, src, n) != STRNCPY_RESULT (dst, len, n))
-    {
-      error (0, 0, "Wrong result in function %s %p %p", impl->name,
-	     CALL (impl, dst, src, n), dst);
-      ret = 1;
-      return;
-    }
-
-  if (memcmp (dst, src, len > n ? n : len) != 0)
-    {
-      error (0, 0, "Wrong result in function %s", impl->name);
-      ret = 1;
-      return;
-    }
-
-  if (n > len)
-    {
-      size_t i;
-
-      for (i = len; i < n; ++i)
-	if (dst [i] != '\0')
-	  {
-	    error (0, 0, "Wrong result in function %s", impl->name);
-	    ret = 1;
-	    return;
-	  }
-    }
-
-  TIMING_NOW (start);
-  for (i = 0; i < iters; ++i)
-    {
-      CALL (impl, dst, src, n);
-    }
-  TIMING_NOW (stop);
 
-  TIMING_DIFF (cur, start, stop);
-
-  TIMING_PRINT_MEAN ((double) cur, (double) iters);
-}
-
-static void
-do_test (size_t align1, size_t align2, size_t len, size_t n, int max_char)
-{
-  size_t i;
-  char *s1, *s2;
-
-  align1 &= 7;
-  if (align1 + len >= page_size)
-    return;
-
-  align2 &= 7;
-  if (align2 + len >= page_size)
-    return;
-
-  s1 = (char *) (buf1 + align1);
-  s2 = (char *) (buf2 + align2);
-
-  for (i = 0; i < len; ++i)
-    s1[i] = 32 + 23 * i % (max_char - 32);
-  s1[len] = 0;
-  for (i = len + 1; i + align1 < page_size && i < len + 64; ++i)
-    s1[i] = 32 + 32 * i % (max_char - 32);
-
-  printf ("Length %4zd, n %4zd, alignment %2zd/%2zd:", len, n, align1, align2);
-
-  FOR_EACH_IMPL (impl, 0)
-    do_one_test (impl, s2, s1, len, n);
-
-  putchar ('\n');
-}
-
-int
-test_main (void)
-{
-  size_t i;
-
-  test_init ();
-
-  printf ("%28s", "");
-  FOR_EACH_IMPL (impl, 0)
-    printf ("\t%s", impl->name);
-  putchar ('\n');
+# define TEST_NAME "strncpy"
 
-  for (i = 1; i < 8; ++i)
-    {
-      do_test (i, i, 16, 16, 127);
-      do_test (i, i, 16, 16, 255);
-      do_test (i, 2 * i, 16, 16, 127);
-      do_test (2 * i, i, 16, 16, 255);
-      do_test (8 - i, 2 * i, 1 << i, 2 << i, 127);
-      do_test (2 * i, 8 - i, 2 << i, 1 << i, 127);
-      do_test (8 - i, 2 * i, 1 << i, 2 << i, 255);
-      do_test (2 * i, 8 - i, 2 << i, 1 << i, 255);
-    }
+#define PROTO typedef char *(*proto_t) (char *, const char *, size_t);
+#define IMPLS IMPL (strncpy, 1)
 
-  for (i = 1; i < 8; ++i)
-    {
-      do_test (0, 0, 4 << i, 8 << i, 127);
-      do_test (0, 0, 16 << i, 8 << i, 127);
-      do_test (8 - i, 2 * i, 4 << i, 8 << i, 127);
-      do_test (8 - i, 2 * i, 16 << i, 8 << i, 127);
-    }
 
-  return ret;
-}
+#define CALL2(impl, dst, src, len) CALL (impl, dst, src, len)
 
-#include "../test-skeleton.c"
+#include "bench-copy.h"
-- 
1.7.10.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]