diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-06-28 21:08:26 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-28 22:29:28 +0200 |
commit | 086b7a45375269f67056cd71d0503678f74d0da0 (patch) | |
tree | 2ee82e8afde428fa95829cde6e2f663529ac51bf /Userland/Libraries/LibC | |
parent | 2a78bf85968ebff58b4d23be43fecdbe6178adb2 (diff) | |
download | serenity-086b7a45375269f67056cd71d0503678f74d0da0.zip |
LibC: Implement memcpy and memset for x86_64
Diffstat (limited to 'Userland/Libraries/LibC')
-rw-r--r-- | Userland/Libraries/LibC/string.cpp | 27 |
1 files changed, 8 insertions, 19 deletions
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) { |