From 086b7a45375269f67056cd71d0503678f74d0da0 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 28 Jun 2021 21:08:26 +0200 Subject: LibC: Implement memcpy and memset for x86_64 --- Userland/Libraries/LibC/string.cpp | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'Userland/Libraries/LibC') diff --git a/Userland/Libraries/LibC/string.cpp b/Userland/Libraries/LibC/string.cpp index a2542507af..d6a96d16fa 100644 --- a/Userland/Libraries/LibC/string.cpp +++ b/Userland/Libraries/LibC/string.cpp @@ -111,7 +111,6 @@ int memcmp(const void* v1, const void* v2, size_t n) return 0; } -#if ARCH(I386) void* memcpy(void* dest_ptr, const void* src_ptr, size_t n) { void* original_dest = dest_ptr; @@ -128,11 +127,19 @@ void* memset(void* dest_ptr, int c, size_t n) if (!(dest & 0x3) && n >= 12) { size_t size_ts = n / sizeof(size_t); size_t expanded_c = explode_byte((u8)c); +#if ARCH(I386) asm volatile( "rep stosl\n" : "=D"(dest) : "D"(dest), "c"(size_ts), "a"(expanded_c) : "memory"); +#else + asm volatile( + "rep stosq\n" + : "=D"(dest) + : "D"(dest), "c"(size_ts), "a"(expanded_c) + : "memory"); +#endif n -= size_ts * sizeof(size_t); if (n == 0) return dest_ptr; @@ -144,24 +151,6 @@ void* memset(void* dest_ptr, int c, size_t n) : "memory"); return dest_ptr; } -#else -void* memcpy(void* dest_ptr, const void* src_ptr, size_t n) -{ - auto* dest = (u8*)dest_ptr; - auto* src = (const u8*)src_ptr; - for (size_t i = 0; i < n; ++i) - dest[i] = src[i]; - return dest_ptr; -} - -void* memset(void* dest_ptr, int c, size_t n) -{ - auto* dest = (u8*)dest_ptr; - for (size_t i = 0; i < n; ++i) - dest[i] = (u8)c; - return dest_ptr; -} -#endif void* memmove(void* dest, const void* src, size_t n) { -- cgit v1.2.3