Use generic memset/memcpy/memmove in benchtests
diff mbox series

Message ID VI1PR0801MB212717CB768F9CFF49A635B183A50@VI1PR0801MB2127.eurprd08.prod.outlook.com
State New
Headers show
Series
  • Use generic memset/memcpy/memmove in benchtests
Related show

Commit Message

Wilco Dijkstra Aug. 22, 2019, 2:07 p.m. UTC
Use the generic C memset/memcpy/memmove in benchtests since comparing
against a slow byte-oriented implementation makes no sense.

OK for commit?

2019-08-22  Wilco Dijkstra  <wdijkstr@arm.com>

        * benchtests/bench-memcpy.c (simple_memcpy): Remove.
        (generic_memcpy): Include generic C memcpy.
        * benchtests/bench-memmove.c (simple_memmove): Remove.
        (generic_memmove): Include generic C memmove.
        * benchtests/bench-memset.c (simple_memset): Remove.
        (generic_memset): Include generic C memset.
        * benchtests/bench-memset-large.c (simple_memset): Remove.
        (generic_memset): Include generic C memset.
        * benchtests/bench-memset-walk.c (simple_memset): Remove.
        (generic_memset): Include generic C memset.
        * string/memcpy.c (MEMCPY): Add defines to enable redirection.
        * string/memset.c (MEMSET): Likewise.

--

Comments

Adhemerval Zanella Aug. 27, 2019, 2:47 p.m. UTC | #1
On 22/08/2019 11:07, Wilco Dijkstra wrote:
> 
> Use the generic C memset/memcpy/memmove in benchtests since comparing
> against a slow byte-oriented implementation makes no sense.
> 
> OK for commit?
> 
> 2019-08-22  Wilco Dijkstra  <wdijkstr@arm.com>
> 
>         * benchtests/bench-memcpy.c (simple_memcpy): Remove.
>         (generic_memcpy): Include generic C memcpy.
>         * benchtests/bench-memmove.c (simple_memmove): Remove.
>         (generic_memmove): Include generic C memmove.
>         * benchtests/bench-memset.c (simple_memset): Remove.
>         (generic_memset): Include generic C memset.
>         * benchtests/bench-memset-large.c (simple_memset): Remove.
>         (generic_memset): Include generic C memset.
>         * benchtests/bench-memset-walk.c (simple_memset): Remove.
>         (generic_memset): Include generic C memset.
>         * string/memcpy.c (MEMCPY): Add defines to enable redirection.
>         * string/memset.c (MEMSET): Likewise.
> 
> --
> 
> diff --git a/benchtests/bench-memcpy.c b/benchtests/bench-memcpy.c
> index 6c5c549144417b1845c4f9fedffc329d44fdfa6c..21cb000e4ca721fef3d3236169527317ad2833f7 100644
> --- a/benchtests/bench-memcpy.c
> +++ b/benchtests/bench-memcpy.c
> @@ -23,23 +23,16 @@
>  # define TEST_NAME "memcpy"
>  # include "bench-string.h"
>  
> -char *
> -simple_memcpy (char *dst, const char *src, size_t n)
> -{
> -  char *ret = dst;
> -  while (n--)
> -    *dst++ = *src++;
> -  return ret;
> -}
> +void *generic_memcpy (void *, const void *, size_t);
>  
>  IMPL (memcpy, 1)
> -IMPL (simple_memcpy, 0)
> +IMPL (generic_memcpy, 0)
>  
>  #endif
>  
>  # include "json-lib.h"
>  
> -typedef char *(*proto_t) (char *, const char *, size_t);
> +typedef void *(*proto_t) (void *, const void *, size_t);
>  
>  static void
>  do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, const char *src,
> @@ -161,3 +154,9 @@ test_main (void)
>  }
>  
>  #include <support/test-driver.c>
> +
> +#define libc_hidden_builtin_def(X)
> +#undef MEMCPY
> +#define MEMCPY generic_memcpy
> +#include <string/memcpy.c>
> +#include <string/wordcopy.c>

It requires further adjustment, since some architectures overrides memcopy.h
that can't actually build the generic implementations. x86_64 for instance:

In file included from bench-memcpy.c:161:                                                                                                                                                                  ../string/memcpy.c: In function ‘generic_memcpy’:                                                                                                                                                          ../string/memcpy.c:37:14: error: ‘OP_T_THRES’ undeclared (first use in this function); did you mean ‘OPT_DIRECT’?                                                                                             if (len >= OP_T_THRES)                                                                                                                                                                                                ^~~~~~~~~~                                                                                                                                                                                                 OPT_DIRECT                                                                                                                                                                                   ../string/memcpy.c:37:14: note: each undeclared identifier is reported only once for each function it appears in                                                                                           ../string/memcpy.c:40:24: error: ‘OPSIZ’ undeclared (first use in this function)                                                                                                                                  len -= (-dstp) % OPSIZ;                                                                                                                                                                                                     ^~~~~         

x86_64 also reimplements all the generic routines that uses wordcopy.h
so it is ok to just remove sysdeps/x86_64/memcopy.h.

s390, i686, and m68k build ok.

> diff --git a/benchtests/bench-memmove.c b/benchtests/bench-memmove.c
> index a4d5ecd6386896017386be94a6f07eb68fc868c5..9804e718b9be3c6174e426602f5f70d216272c47 100644
> --- a/benchtests/bench-memmove.c
> +++ b/benchtests/bench-memmove.c
> @@ -21,30 +21,12 @@
>  #include "bench-string.h"
>  #include "json-lib.h"
>  
> -char *simple_memmove (char *, const char *, size_t);
> +void *generic_memmove (void *, const void *, size_t);
>  
> -typedef char *(*proto_t) (char *, const char *, size_t);
> +typedef void *(*proto_t) (void *, const void *, size_t);
>  
>  IMPL (memmove, 1)
> -IMPL (simple_memmove, 0)
> -
> -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;
> -}
> +IMPL (generic_memmove, 0)
>  
>  static void
>  do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, char *src,
> @@ -165,3 +147,9 @@ test_main (void)
>  }
>  
>  #include <support/test-driver.c>
> +
> +#define libc_hidden_builtin_def(X)
> +#undef MEMMOVE
> +#define MEMMOVE generic_memmove
> +#include <string/memmove.c>
> +#include <string/wordcopy.c>

Same as memcpy.

> diff --git a/benchtests/bench-memset-large.c b/benchtests/bench-memset-large.c
> index d99f0a24aab3730274dcf22c1e37706bfc4d0b0d..97ba30f122bdf51e7b9395b5539684a210ca8d5f 100644
> --- a/benchtests/bench-memset-large.c
> +++ b/benchtests/bench-memset-large.c
> @@ -17,38 +17,20 @@
>     <http://www.gnu.org/licenses/>.  */
>  
>  #define TEST_MAIN
> -#ifndef WIDE
> -# define TEST_NAME "memset"
> -#else
> -# define TEST_NAME "wmemset"
> -#endif /* WIDE */
> +#define TEST_NAME "memset"
>  #define START_SIZE (128 * 1024)
>  #define MIN_PAGE_SIZE (getpagesize () + 64 * 1024 * 1024)
>  #define TIMEOUT (20 * 60)
>  #include "bench-string.h"
>  
> -#ifndef WIDE
> -# define SIMPLE_MEMSET simple_memset
> -#else
> -# define SIMPLE_MEMSET simple_wmemset
> -#endif /* WIDE */
> -
>  #include <assert.h>
>  #include "json-lib.h"
>  
> -IMPL (MEMSET, 1)
> -
> -typedef CHAR *(*proto_t) (CHAR *, int, size_t);
> +void *generic_memset (void *, int, size_t);
> +typedef void *(*proto_t) (void *, int, size_t);
>  
> -CHAR *
> -inhibit_loop_to_libcall
> -SIMPLE_MEMSET (CHAR *s, int c, size_t n)
> -{
> -  CHAR *r = s, *end = s + n;
> -  while (r < end)
> -    *r++ = c;
> -  return s;
> -}
> +IMPL (MEMSET, 1)
> +IMPL (generic_memset, 0)
>  
>  static void
>  do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
> @@ -133,3 +115,11 @@ test_main (void)
>  }
>  
>  #include <support/test-driver.c>
> +
> +#define libc_hidden_builtin_def(X)
> +#define libc_hidden_def(X)
> +#define libc_hidden_weak(X)
> +#define weak_alias(X,Y)
> +#undef MEMSET
> +#define MEMSET generic_memset
> +#include <string/memset.c>

Ok.

> diff --git a/benchtests/bench-memset-walk.c b/benchtests/bench-memset-walk.c
> index 930aae34d10603c80a7c40d123fb0376cde56436..2d18c186fc18abca732748dd74a038d9ae659976 100644
> --- a/benchtests/bench-memset-walk.c
> +++ b/benchtests/bench-memset-walk.c
> @@ -17,39 +17,20 @@
>     <http://www.gnu.org/licenses/>.  */
>  
>  #define TEST_MAIN
> -#ifndef WIDE
> -# define TEST_NAME "memset"
> -#else
> -# define TEST_NAME "wmemset"
> -#endif /* WIDE */
> +#define TEST_NAME "memset"
>  #define START_SIZE 128
>  #define MIN_PAGE_SIZE (getpagesize () + 32 * 1024 * 1024)
>  #define TIMEOUT (20 * 60)
>  #include "bench-string.h"
>  
> -#ifndef WIDE
> -# define SIMPLE_MEMSET simple_memset
> -#else
> -# define SIMPLE_MEMSET simple_wmemset
> -#endif /* WIDE */
> -
>  #include <assert.h>
>  #include "json-lib.h"
>  
> +void *generic_memset (void *, int, size_t);
> +typedef void *(*proto_t) (void *, int, size_t);
>  
> -typedef CHAR *(*proto_t) (CHAR *, int, size_t);
> -
> -CHAR *
> -inhibit_loop_to_libcall
> -SIMPLE_MEMSET (CHAR *s, int c, size_t n)
> -{
> -  CHAR *r = s, *end = s + n;
> -  while (r < end)
> -    *r++ = c;
> -  return s;
> -}
> -
> -IMPL (SIMPLE_MEMSET, 1)
> +IMPL (MEMSET, 1)
> +IMPL (generic_memset, 0)
>  
>  static void
>  do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, CHAR *s_end,
> @@ -132,3 +113,11 @@ test_main (void)
>  }
>  
>  #include <support/test-driver.c>
> +
> +#define libc_hidden_builtin_def(X)
> +#define libc_hidden_def(X)
> +#define libc_hidden_weak(X)
> +#define weak_alias(X,Y)
> +#undef MEMSET
> +#define MEMSET generic_memset
> +#include <string/memset.c>

Ok.

> diff --git a/benchtests/bench-memset.c b/benchtests/bench-memset.c
> index 0df55d126352d0db20681944e73241fef4483a80..69e8d36e966655c65b5cd70f5a54998feceb1cc6 100644
> --- a/benchtests/bench-memset.c
> +++ b/benchtests/bench-memset.c
> @@ -21,28 +21,23 @@
>  # define TEST_NAME "memset"
>  #else
>  # define TEST_NAME "wmemset"
> +# define generic_memset generic_wmemset
>  #endif /* WIDE */
>  #define MIN_PAGE_SIZE 131072
>  #include "bench-string.h"
>  
>  #include "json-lib.h"
>  
> -CHAR *SIMPLE_MEMSET (CHAR *, int, size_t);
> +#ifdef WIDE
> +CHAR *generic_wmemset (CHAR *, CHAR, size_t);
> +#else
> +void *generic_memset (void *, int, size_t);
> +#endif
>  
> -typedef CHAR *(*proto_t) (CHAR *, int, size_t);
> +typedef void *(*proto_t) (void *, int, size_t);
>  
>  IMPL (MEMSET, 1)
> -IMPL (SIMPLE_MEMSET, 0)
> -
> -CHAR *
> -inhibit_loop_to_libcall
> -SIMPLE_MEMSET (CHAR *s, int c, size_t n)
> -{
> -  CHAR *r = s, *end = s + n;
> -  while (r < end)
> -    *r++ = c;
> -  return s;
> -}
> +IMPL (generic_memset, 0)
>  
>  static void
>  do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
> @@ -146,3 +141,16 @@ test_main (void)
>  }
>  
>  #include <support/test-driver.c>
> +
> +#define libc_hidden_builtin_def(X)
> +#define libc_hidden_def(X)
> +#define libc_hidden_weak(X)
> +#define weak_alias(X,Y)
> +#ifndef WIDE
> +# undef MEMSET
> +# define MEMSET generic_memset
> +# include <string/memset.c>
> +#else
> +# define WMEMSET generic_wmemset
> +# include <wcsmbs/wmemset.c>
> +#endif
> diff --git a/string/memcpy.c b/string/memcpy.c

Ok.

> index a1c4c72d67c5be2b52860cbaae93be3b191d1c1d..2315b6fecb7f35c9539bd24cc8b20f21b5e541b1 100644
> --- a/string/memcpy.c
> +++ b/string/memcpy.c
> @@ -21,10 +21,12 @@
>  #include <string.h>
>  #include <memcopy.h>
>  
> -#undef memcpy
> +#ifndef MEMCPY
> +# define MEMCPY memcpy
> +#endif
>  
>  void *
> -memcpy (void *dstpp, const void *srcpp, size_t len)
> +MEMCPY (void *dstpp, const void *srcpp, size_t len)
>  {
>    unsigned long int dstp = (long int) dstpp;
>    unsigned long int srcp = (long int) srcpp;
> @@ -57,4 +59,4 @@ memcpy (void *dstpp, const void *srcpp, size_t len)
>  
>    return dstpp;
>  }
> -libc_hidden_builtin_def (memcpy)
> +libc_hidden_builtin_def (MEMCPY)

Ok.

> diff --git a/string/memset.c b/string/memset.c
> index 4ac8cb6426777ac8d46928846e5ca63eef677aae..950445c51cd9f5d04b3b65ce1251015a08b09336 100644
> --- a/string/memset.c
> +++ b/string/memset.c
> @@ -18,11 +18,13 @@
>  #include <string.h>
>  #include <memcopy.h>
>  
> -#undef memset
> +#ifndef MEMSET
> +# define MEMSET memset
> +#endif
>  
>  void *
>  inhibit_loop_to_libcall
> -memset (void *dstpp, int c, size_t len)
> +MEMSET (void *dstpp, int c, size_t len)
>  {
>    long int dstp = (long int) dstpp;
>  
> @@ -85,4 +87,4 @@ memset (void *dstpp, int c, size_t len)
>  
>    return dstpp;
>  }
> -libc_hidden_builtin_def (memset)
> +libc_hidden_builtin_def (MEMSET)
> 

Ok.
Wilco Dijkstra Aug. 29, 2019, 4:13 p.m. UTC | #2
Hi Adhemerval,

> > +#include <string/wordcopy.c>
 
> It requires further adjustment, since some architectures overrides memcopy.h
> that can't actually build the generic implementations. x86_64 for instance:
   
> x86_64 also reimplements all the generic routines that uses wordcopy.h
> so it is ok to just remove sysdeps/x86_64/memcopy.h.

Thanks for spotting that! It's easy to remove it indeed, x64 build, test & bench
all work without that file. So here is the updated version:


Use the generic C memset/memcpy/memmove in benchtests since comparing
against a slow byte-oriented implementation makes no sense.

OK for commit?

2019-08-29  Wilco Dijkstra  <wdijkstr@arm.com>

        * benchtests/bench-memcpy.c (simple_memcpy): Remove.
        (generic_memcpy): Include generic C memcpy.
        * benchtests/bench-memmove.c (simple_memmove): Remove.
        (generic_memmove): Include generic C memmove.
        * benchtests/bench-memset.c (simple_memset): Remove.
        (generic_memset): Include generic C memset.
        * benchtests/bench-memset-large.c (simple_memset): Remove.
        (generic_memset): Include generic C memset.
        * benchtests/bench-memset-walk.c (simple_memset): Remove.
        (generic_memset): Include generic C memset.
        * string/memcpy.c (MEMCPY): Add defines to enable redirection.
        * string/memset.c (MEMSET): Likewise.
        * sysdeps/x86_64/memcopy.h: Remove empty file.
---

diff --git a/benchtests/bench-memcpy.c b/benchtests/bench-memcpy.c
index 6c5c549144417b1845c4f9fedffc329d44fdfa6c..21cb000e4ca721fef3d3236169527317ad2833f7 100644
--- a/benchtests/bench-memcpy.c
+++ b/benchtests/bench-memcpy.c
@@ -23,23 +23,16 @@
 # define TEST_NAME "memcpy"
 # include "bench-string.h"
 
-char *
-simple_memcpy (char *dst, const char *src, size_t n)
-{
-  char *ret = dst;
-  while (n--)
-    *dst++ = *src++;
-  return ret;
-}
+void *generic_memcpy (void *, const void *, size_t);
 
 IMPL (memcpy, 1)
-IMPL (simple_memcpy, 0)
+IMPL (generic_memcpy, 0)
 
 #endif
 
 # include "json-lib.h"
 
-typedef char *(*proto_t) (char *, const char *, size_t);
+typedef void *(*proto_t) (void *, const void *, size_t);
 
 static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, const char *src,
@@ -161,3 +154,9 @@ test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#define libc_hidden_builtin_def(X)
+#undef MEMCPY
+#define MEMCPY generic_memcpy
+#include <string/memcpy.c>
+#include <string/wordcopy.c>
diff --git a/benchtests/bench-memmove.c b/benchtests/bench-memmove.c
index a4d5ecd6386896017386be94a6f07eb68fc868c5..9804e718b9be3c6174e426602f5f70d216272c47 100644
--- a/benchtests/bench-memmove.c
+++ b/benchtests/bench-memmove.c
@@ -21,30 +21,12 @@
 #include "bench-string.h"
 #include "json-lib.h"
 
-char *simple_memmove (char *, const char *, size_t);
+void *generic_memmove (void *, const void *, size_t);
 
-typedef char *(*proto_t) (char *, const char *, size_t);
+typedef void *(*proto_t) (void *, const void *, size_t);
 
 IMPL (memmove, 1)
-IMPL (simple_memmove, 0)
-
-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;
-}
+IMPL (generic_memmove, 0)
 
 static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, char *src,
@@ -165,3 +147,9 @@ test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#define libc_hidden_builtin_def(X)
+#undef MEMMOVE
+#define MEMMOVE generic_memmove
+#include <string/memmove.c>
+#include <string/wordcopy.c>
diff --git a/benchtests/bench-memset-large.c b/benchtests/bench-memset-large.c
index d99f0a24aab3730274dcf22c1e37706bfc4d0b0d..97ba30f122bdf51e7b9395b5539684a210ca8d5f 100644
--- a/benchtests/bench-memset-large.c
+++ b/benchtests/bench-memset-large.c
@@ -17,38 +17,20 @@
    <http://www.gnu.org/licenses/>.  */
 
 #define TEST_MAIN
-#ifndef WIDE
-# define TEST_NAME "memset"
-#else
-# define TEST_NAME "wmemset"
-#endif /* WIDE */
+#define TEST_NAME "memset"
 #define START_SIZE (128 * 1024)
 #define MIN_PAGE_SIZE (getpagesize () + 64 * 1024 * 1024)
 #define TIMEOUT (20 * 60)
 #include "bench-string.h"
 
-#ifndef WIDE
-# define SIMPLE_MEMSET simple_memset
-#else
-# define SIMPLE_MEMSET simple_wmemset
-#endif /* WIDE */
-
 #include <assert.h>
 #include "json-lib.h"
 
-IMPL (MEMSET, 1)
-
-typedef CHAR *(*proto_t) (CHAR *, int, size_t);
+void *generic_memset (void *, int, size_t);
+typedef void *(*proto_t) (void *, int, size_t);
 
-CHAR *
-inhibit_loop_to_libcall
-SIMPLE_MEMSET (CHAR *s, int c, size_t n)
-{
-  CHAR *r = s, *end = s + n;
-  while (r < end)
-    *r++ = c;
-  return s;
-}
+IMPL (MEMSET, 1)
+IMPL (generic_memset, 0)
 
 static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
@@ -133,3 +115,11 @@ test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#define libc_hidden_builtin_def(X)
+#define libc_hidden_def(X)
+#define libc_hidden_weak(X)
+#define weak_alias(X,Y)
+#undef MEMSET
+#define MEMSET generic_memset
+#include <string/memset.c>
diff --git a/benchtests/bench-memset-walk.c b/benchtests/bench-memset-walk.c
index 930aae34d10603c80a7c40d123fb0376cde56436..2d18c186fc18abca732748dd74a038d9ae659976 100644
--- a/benchtests/bench-memset-walk.c
+++ b/benchtests/bench-memset-walk.c
@@ -17,39 +17,20 @@
    <http://www.gnu.org/licenses/>.  */
 
 #define TEST_MAIN
-#ifndef WIDE
-# define TEST_NAME "memset"
-#else
-# define TEST_NAME "wmemset"
-#endif /* WIDE */
+#define TEST_NAME "memset"
 #define START_SIZE 128
 #define MIN_PAGE_SIZE (getpagesize () + 32 * 1024 * 1024)
 #define TIMEOUT (20 * 60)
 #include "bench-string.h"
 
-#ifndef WIDE
-# define SIMPLE_MEMSET simple_memset
-#else
-# define SIMPLE_MEMSET simple_wmemset
-#endif /* WIDE */
-
 #include <assert.h>
 #include "json-lib.h"
 
+void *generic_memset (void *, int, size_t);
+typedef void *(*proto_t) (void *, int, size_t);
 
-typedef CHAR *(*proto_t) (CHAR *, int, size_t);
-
-CHAR *
-inhibit_loop_to_libcall
-SIMPLE_MEMSET (CHAR *s, int c, size_t n)
-{
-  CHAR *r = s, *end = s + n;
-  while (r < end)
-    *r++ = c;
-  return s;
-}
-
-IMPL (SIMPLE_MEMSET, 1)
+IMPL (MEMSET, 1)
+IMPL (generic_memset, 0)
 
 static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, CHAR *s_end,
@@ -132,3 +113,11 @@ test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#define libc_hidden_builtin_def(X)
+#define libc_hidden_def(X)
+#define libc_hidden_weak(X)
+#define weak_alias(X,Y)
+#undef MEMSET
+#define MEMSET generic_memset
+#include <string/memset.c>
diff --git a/benchtests/bench-memset.c b/benchtests/bench-memset.c
index 0df55d126352d0db20681944e73241fef4483a80..69e8d36e966655c65b5cd70f5a54998feceb1cc6 100644
--- a/benchtests/bench-memset.c
+++ b/benchtests/bench-memset.c
@@ -21,28 +21,23 @@
 # define TEST_NAME "memset"
 #else
 # define TEST_NAME "wmemset"
+# define generic_memset generic_wmemset
 #endif /* WIDE */
 #define MIN_PAGE_SIZE 131072
 #include "bench-string.h"
 
 #include "json-lib.h"
 
-CHAR *SIMPLE_MEMSET (CHAR *, int, size_t);
+#ifdef WIDE
+CHAR *generic_wmemset (CHAR *, CHAR, size_t);
+#else
+void *generic_memset (void *, int, size_t);
+#endif
 
-typedef CHAR *(*proto_t) (CHAR *, int, size_t);
+typedef void *(*proto_t) (void *, int, size_t);
 
 IMPL (MEMSET, 1)
-IMPL (SIMPLE_MEMSET, 0)
-
-CHAR *
-inhibit_loop_to_libcall
-SIMPLE_MEMSET (CHAR *s, int c, size_t n)
-{
-  CHAR *r = s, *end = s + n;
-  while (r < end)
-    *r++ = c;
-  return s;
-}
+IMPL (generic_memset, 0)
 
 static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
@@ -146,3 +141,16 @@ test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#define libc_hidden_builtin_def(X)
+#define libc_hidden_def(X)
+#define libc_hidden_weak(X)
+#define weak_alias(X,Y)
+#ifndef WIDE
+# undef MEMSET
+# define MEMSET generic_memset
+# include <string/memset.c>
+#else
+# define WMEMSET generic_wmemset
+# include <wcsmbs/wmemset.c>
+#endif
diff --git a/string/memcpy.c b/string/memcpy.c
index a1c4c72d67c5be2b52860cbaae93be3b191d1c1d..2315b6fecb7f35c9539bd24cc8b20f21b5e541b1 100644
--- a/string/memcpy.c
+++ b/string/memcpy.c
@@ -21,10 +21,12 @@
 #include <string.h>
 #include <memcopy.h>
 
-#undef memcpy
+#ifndef MEMCPY
+# define MEMCPY memcpy
+#endif
 
 void *
-memcpy (void *dstpp, const void *srcpp, size_t len)
+MEMCPY (void *dstpp, const void *srcpp, size_t len)
 {
   unsigned long int dstp = (long int) dstpp;
   unsigned long int srcp = (long int) srcpp;
@@ -57,4 +59,4 @@ memcpy (void *dstpp, const void *srcpp, size_t len)
 
   return dstpp;
 }
-libc_hidden_builtin_def (memcpy)
+libc_hidden_builtin_def (MEMCPY)
diff --git a/string/memset.c b/string/memset.c
index 4ac8cb6426777ac8d46928846e5ca63eef677aae..950445c51cd9f5d04b3b65ce1251015a08b09336 100644
--- a/string/memset.c
+++ b/string/memset.c
@@ -18,11 +18,13 @@
 #include <string.h>
 #include <memcopy.h>
 
-#undef memset
+#ifndef MEMSET
+# define MEMSET memset
+#endif
 
 void *
 inhibit_loop_to_libcall
-memset (void *dstpp, int c, size_t len)
+MEMSET (void *dstpp, int c, size_t len)
 {
   long int dstp = (long int) dstpp;
 
@@ -85,4 +87,4 @@ memset (void *dstpp, int c, size_t len)
 
   return dstpp;
 }
-libc_hidden_builtin_def (memset)
+libc_hidden_builtin_def (MEMSET)
diff --git a/sysdeps/x86_64/memcopy.h b/sysdeps/x86_64/memcopy.h
deleted file mode 100644
index 590b6cb16b8f4067ab9cacb66f9e926e8b6c055e..0000000000000000000000000000000000000000
--- a/sysdeps/x86_64/memcopy.h
+++ /dev/null
@@ -1 +0,0 @@
-/* X86-64 doesn't use memory copy functions.  */

Patch
diff mbox series

diff --git a/benchtests/bench-memcpy.c b/benchtests/bench-memcpy.c
index 6c5c549144417b1845c4f9fedffc329d44fdfa6c..21cb000e4ca721fef3d3236169527317ad2833f7 100644
--- a/benchtests/bench-memcpy.c
+++ b/benchtests/bench-memcpy.c
@@ -23,23 +23,16 @@ 
 # define TEST_NAME "memcpy"
 # include "bench-string.h"
 
-char *
-simple_memcpy (char *dst, const char *src, size_t n)
-{
-  char *ret = dst;
-  while (n--)
-    *dst++ = *src++;
-  return ret;
-}
+void *generic_memcpy (void *, const void *, size_t);
 
 IMPL (memcpy, 1)
-IMPL (simple_memcpy, 0)
+IMPL (generic_memcpy, 0)
 
 #endif
 
 # include "json-lib.h"
 
-typedef char *(*proto_t) (char *, const char *, size_t);
+typedef void *(*proto_t) (void *, const void *, size_t);
 
 static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, const char *src,
@@ -161,3 +154,9 @@  test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#define libc_hidden_builtin_def(X)
+#undef MEMCPY
+#define MEMCPY generic_memcpy
+#include <string/memcpy.c>
+#include <string/wordcopy.c>
diff --git a/benchtests/bench-memmove.c b/benchtests/bench-memmove.c
index a4d5ecd6386896017386be94a6f07eb68fc868c5..9804e718b9be3c6174e426602f5f70d216272c47 100644
--- a/benchtests/bench-memmove.c
+++ b/benchtests/bench-memmove.c
@@ -21,30 +21,12 @@ 
 #include "bench-string.h"
 #include "json-lib.h"
 
-char *simple_memmove (char *, const char *, size_t);
+void *generic_memmove (void *, const void *, size_t);
 
-typedef char *(*proto_t) (char *, const char *, size_t);
+typedef void *(*proto_t) (void *, const void *, size_t);
 
 IMPL (memmove, 1)
-IMPL (simple_memmove, 0)
-
-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;
-}
+IMPL (generic_memmove, 0)
 
 static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, char *src,
@@ -165,3 +147,9 @@  test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#define libc_hidden_builtin_def(X)
+#undef MEMMOVE
+#define MEMMOVE generic_memmove
+#include <string/memmove.c>
+#include <string/wordcopy.c>
diff --git a/benchtests/bench-memset-large.c b/benchtests/bench-memset-large.c
index d99f0a24aab3730274dcf22c1e37706bfc4d0b0d..97ba30f122bdf51e7b9395b5539684a210ca8d5f 100644
--- a/benchtests/bench-memset-large.c
+++ b/benchtests/bench-memset-large.c
@@ -17,38 +17,20 @@ 
    <http://www.gnu.org/licenses/>.  */
 
 #define TEST_MAIN
-#ifndef WIDE
-# define TEST_NAME "memset"
-#else
-# define TEST_NAME "wmemset"
-#endif /* WIDE */
+#define TEST_NAME "memset"
 #define START_SIZE (128 * 1024)
 #define MIN_PAGE_SIZE (getpagesize () + 64 * 1024 * 1024)
 #define TIMEOUT (20 * 60)
 #include "bench-string.h"
 
-#ifndef WIDE
-# define SIMPLE_MEMSET simple_memset
-#else
-# define SIMPLE_MEMSET simple_wmemset
-#endif /* WIDE */
-
 #include <assert.h>
 #include "json-lib.h"
 
-IMPL (MEMSET, 1)
-
-typedef CHAR *(*proto_t) (CHAR *, int, size_t);
+void *generic_memset (void *, int, size_t);
+typedef void *(*proto_t) (void *, int, size_t);
 
-CHAR *
-inhibit_loop_to_libcall
-SIMPLE_MEMSET (CHAR *s, int c, size_t n)
-{
-  CHAR *r = s, *end = s + n;
-  while (r < end)
-    *r++ = c;
-  return s;
-}
+IMPL (MEMSET, 1)
+IMPL (generic_memset, 0)
 
 static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
@@ -133,3 +115,11 @@  test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#define libc_hidden_builtin_def(X)
+#define libc_hidden_def(X)
+#define libc_hidden_weak(X)
+#define weak_alias(X,Y)
+#undef MEMSET
+#define MEMSET generic_memset
+#include <string/memset.c>
diff --git a/benchtests/bench-memset-walk.c b/benchtests/bench-memset-walk.c
index 930aae34d10603c80a7c40d123fb0376cde56436..2d18c186fc18abca732748dd74a038d9ae659976 100644
--- a/benchtests/bench-memset-walk.c
+++ b/benchtests/bench-memset-walk.c
@@ -17,39 +17,20 @@ 
    <http://www.gnu.org/licenses/>.  */
 
 #define TEST_MAIN
-#ifndef WIDE
-# define TEST_NAME "memset"
-#else
-# define TEST_NAME "wmemset"
-#endif /* WIDE */
+#define TEST_NAME "memset"
 #define START_SIZE 128
 #define MIN_PAGE_SIZE (getpagesize () + 32 * 1024 * 1024)
 #define TIMEOUT (20 * 60)
 #include "bench-string.h"
 
-#ifndef WIDE
-# define SIMPLE_MEMSET simple_memset
-#else
-# define SIMPLE_MEMSET simple_wmemset
-#endif /* WIDE */
-
 #include <assert.h>
 #include "json-lib.h"
 
+void *generic_memset (void *, int, size_t);
+typedef void *(*proto_t) (void *, int, size_t);
 
-typedef CHAR *(*proto_t) (CHAR *, int, size_t);
-
-CHAR *
-inhibit_loop_to_libcall
-SIMPLE_MEMSET (CHAR *s, int c, size_t n)
-{
-  CHAR *r = s, *end = s + n;
-  while (r < end)
-    *r++ = c;
-  return s;
-}
-
-IMPL (SIMPLE_MEMSET, 1)
+IMPL (MEMSET, 1)
+IMPL (generic_memset, 0)
 
 static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, CHAR *s_end,
@@ -132,3 +113,11 @@  test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#define libc_hidden_builtin_def(X)
+#define libc_hidden_def(X)
+#define libc_hidden_weak(X)
+#define weak_alias(X,Y)
+#undef MEMSET
+#define MEMSET generic_memset
+#include <string/memset.c>
diff --git a/benchtests/bench-memset.c b/benchtests/bench-memset.c
index 0df55d126352d0db20681944e73241fef4483a80..69e8d36e966655c65b5cd70f5a54998feceb1cc6 100644
--- a/benchtests/bench-memset.c
+++ b/benchtests/bench-memset.c
@@ -21,28 +21,23 @@ 
 # define TEST_NAME "memset"
 #else
 # define TEST_NAME "wmemset"
+# define generic_memset generic_wmemset
 #endif /* WIDE */
 #define MIN_PAGE_SIZE 131072
 #include "bench-string.h"
 
 #include "json-lib.h"
 
-CHAR *SIMPLE_MEMSET (CHAR *, int, size_t);
+#ifdef WIDE
+CHAR *generic_wmemset (CHAR *, CHAR, size_t);
+#else
+void *generic_memset (void *, int, size_t);
+#endif
 
-typedef CHAR *(*proto_t) (CHAR *, int, size_t);
+typedef void *(*proto_t) (void *, int, size_t);
 
 IMPL (MEMSET, 1)
-IMPL (SIMPLE_MEMSET, 0)
-
-CHAR *
-inhibit_loop_to_libcall
-SIMPLE_MEMSET (CHAR *s, int c, size_t n)
-{
-  CHAR *r = s, *end = s + n;
-  while (r < end)
-    *r++ = c;
-  return s;
-}
+IMPL (generic_memset, 0)
 
 static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
@@ -146,3 +141,16 @@  test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#define libc_hidden_builtin_def(X)
+#define libc_hidden_def(X)
+#define libc_hidden_weak(X)
+#define weak_alias(X,Y)
+#ifndef WIDE
+# undef MEMSET
+# define MEMSET generic_memset
+# include <string/memset.c>
+#else
+# define WMEMSET generic_wmemset
+# include <wcsmbs/wmemset.c>
+#endif
diff --git a/string/memcpy.c b/string/memcpy.c
index a1c4c72d67c5be2b52860cbaae93be3b191d1c1d..2315b6fecb7f35c9539bd24cc8b20f21b5e541b1 100644
--- a/string/memcpy.c
+++ b/string/memcpy.c
@@ -21,10 +21,12 @@ 
 #include <string.h>
 #include <memcopy.h>
 
-#undef memcpy
+#ifndef MEMCPY
+# define MEMCPY memcpy
+#endif
 
 void *
-memcpy (void *dstpp, const void *srcpp, size_t len)
+MEMCPY (void *dstpp, const void *srcpp, size_t len)
 {
   unsigned long int dstp = (long int) dstpp;
   unsigned long int srcp = (long int) srcpp;
@@ -57,4 +59,4 @@  memcpy (void *dstpp, const void *srcpp, size_t len)
 
   return dstpp;
 }
-libc_hidden_builtin_def (memcpy)
+libc_hidden_builtin_def (MEMCPY)
diff --git a/string/memset.c b/string/memset.c
index 4ac8cb6426777ac8d46928846e5ca63eef677aae..950445c51cd9f5d04b3b65ce1251015a08b09336 100644
--- a/string/memset.c
+++ b/string/memset.c
@@ -18,11 +18,13 @@ 
 #include <string.h>
 #include <memcopy.h>
 
-#undef memset
+#ifndef MEMSET
+# define MEMSET memset
+#endif
 
 void *
 inhibit_loop_to_libcall
-memset (void *dstpp, int c, size_t len)
+MEMSET (void *dstpp, int c, size_t len)
 {
   long int dstp = (long int) dstpp;
 
@@ -85,4 +87,4 @@  memset (void *dstpp, int c, size_t len)
 
   return dstpp;
 }
-libc_hidden_builtin_def (memset)
+libc_hidden_builtin_def (MEMSET)