diff --git a/Kernel/StdLib.cpp b/Kernel/StdLib.cpp index 023f8e6ce5..baadb8127b 100644 --- a/Kernel/StdLib.cpp +++ b/Kernel/StdLib.cpp @@ -41,8 +41,8 @@ void* memset(void* dest_ptr, byte c, dword n) if (!(dest & 0x3) && n >= 12) { size_t dwords = n / sizeof(dword); dword expanded_c = c; - expanded_c <<= 8; - expanded_c <<= 16; + expanded_c |= expanded_c << 8; + expanded_c |= expanded_c << 16; asm volatile( "rep stosl\n" : "=D"(dest) diff --git a/LibC/string.cpp b/LibC/string.cpp index f63b535d69..175e0501e2 100644 --- a/LibC/string.cpp +++ b/LibC/string.cpp @@ -3,6 +3,7 @@ #include #include #include +#include extern "C" { @@ -16,14 +17,6 @@ void bcopy(const void* src, void* dest, size_t n) memmove(dest, src, n); } -void* memset(void* dest, int c, size_t n) -{ - uint8_t* bdest = (uint8_t*)dest; - for (; n; --n) - *(bdest++) = c; - return dest; -} - size_t strspn(const char* s, const char* accept) { const char* p = s; @@ -90,15 +83,60 @@ int memcmp(const void* v1, const void* v2, size_t n) return 0; } -void* memcpy(void* dest, const void* src, size_t n) +void* memcpy(void *dest_ptr, const void *src_ptr, dword n) { - auto* bdest = (unsigned char*)dest; - auto* bsrc = (const unsigned char*)src; - for (; n; --n) - *(bdest++) = *(bsrc++); - return dest; + dword dest = (dword)dest_ptr; + dword src = (dword)src_ptr; + // FIXME: Support starting at an unaligned address. + if (!(dest & 0x3) && !(src & 0x3) && n >= 12) { + size_t dwords = n / sizeof(dword); + asm volatile( + "rep movsl\n" + : "=S"(src), "=D"(dest) + : "S"(src), "D"(dest), "c"(dwords) + : "memory" + ); + n -= dwords * sizeof(dword); + if (n == 0) + return dest_ptr; + } + asm volatile( + "rep movsb\n" + :: "S"(src), "D"(dest), "c"(n) + : "memory" + ); + return dest_ptr; } +void* memset(void* dest_ptr, int c, dword n) +{ + dword dest = (dword)dest_ptr; + // FIXME: Support starting at an unaligned address. + if (!(dest & 0x3) && n >= 12) { + size_t dwords = n / sizeof(dword); + dword expanded_c = (byte)c; + expanded_c |= expanded_c << 8; + expanded_c |= expanded_c << 16; + asm volatile( + "rep stosl\n" + : "=D"(dest) + : "D"(dest), "c"(dwords), "a"(expanded_c) + : "memory" + ); + n -= dwords * sizeof(dword); + if (n == 0) + return dest_ptr; + } + asm volatile( + "rep stosb\n" + : "=D" (dest), "=c" (n) + : "0" (dest), "1" (n), "a" (c) + : "memory" + ); + return dest_ptr; +} + + void* memmove(void* dest, const void* src, size_t n) { if (dest < src) diff --git a/Widgets/Painter.cpp b/Widgets/Painter.cpp index 967fe19f5f..c2e1ad1386 100644 --- a/Widgets/Painter.cpp +++ b/Widgets/Painter.cpp @@ -97,7 +97,7 @@ void Painter::draw_glyph(const Point& point, char ch, Color color) { auto* bitmap = font().glyphBitmap(ch); if (!bitmap) { - dbgprintf("Font doesn't have 0x%02x ('%c')\n", (byte)ch, ch); + dbgprintf("Font doesn't have 0x%b ('%c')\n", (byte)ch, ch); ASSERT_NOT_REACHED(); } int x = point.x();