From 19105542e561e630979fcab29dadc2da10bfda1e Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Mon, 28 Feb 2022 18:56:38 -0800 Subject: [PATCH] [libc] Change memcpy back to rep movsb Influenced by other libc implementations, I had tried to make memcpy smarter for differently-sized ranges, but my benchmarks showed no real change. So change memcpy back to the simple rep movsb implementation. --- src/libraries/libc/string/memcpy.cpp | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/src/libraries/libc/string/memcpy.cpp b/src/libraries/libc/string/memcpy.cpp index 8cc218d..47cb222 100644 --- a/src/libraries/libc/string/memcpy.cpp +++ b/src/libraries/libc/string/memcpy.cpp @@ -10,33 +10,8 @@ #include #include -#include <__j6libc/copy.h> - -using namespace __j6libc; - -inline void memcpy_dispatch(char *s1, const char *s2, size_t n) { - if (n == 0) return; - if (n == 1) return do_copy<1>(s1, s2); - if (n == 2) return do_copy<2>(s1, s2); - if (n == 3) return do_copy<3>(s1, s2); - if (n == 4) return do_copy<4>(s1, s2); - if (n < 8) return do_double_copy<4>(s1, s2, n); - if (n == 8) return do_copy<8>(s1, s2); - if (n < 16) return do_double_copy<8>(s1, s2, n); - if (n < 32) return do_double_copy<16>(s1, s2, n); - if (n < 64) return do_double_copy<32>(s1, s2, n); - - if (n < 128) - return do_double_copy<64>(s1, s2, n); - else - return do_large_copy(s1, s2, n); -} void *memcpy(void * restrict s1, const void * restrict s2, size_t n) { - memcpy_dispatch( - reinterpret_cast(s1), - reinterpret_cast(s2), - n); - + asm volatile ("rep movsb" : "+D"(s1), "+S"(s2), "+c"(n) :: "memory"); return s1; }