mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Make the kernel's memcpy() and memset() go fast with dword copies.
Also I learned that the ABI allows us to assume DF=0 on function entry.
This commit is contained in:
parent
20156f9ec5
commit
24b2cadb82
Notes:
sideshowbarker
2024-07-19 16:03:49 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/24b2cadb82b
1 changed files with 36 additions and 7 deletions
|
@ -5,12 +5,27 @@
|
|||
|
||||
extern "C" {
|
||||
|
||||
void memcpy(void *dest, const void *src, dword n)
|
||||
void memcpy(void *dest_ptr, const void *src_ptr, dword n)
|
||||
{
|
||||
byte* bdest = (byte*)dest;
|
||||
const byte* bsrc = (const byte*)src;
|
||||
for (; n; --n)
|
||||
*(bdest++) = *(bsrc++);
|
||||
dword dest = (dword)dest_ptr;
|
||||
dword src = (dword)src_ptr;
|
||||
if (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;
|
||||
}
|
||||
asm volatile(
|
||||
"rep movsb\n"
|
||||
:: "S"(src), "D"(dest), "c"(n)
|
||||
: "memory"
|
||||
);
|
||||
}
|
||||
|
||||
void strcpy(char* dest, const char *src)
|
||||
|
@ -21,12 +36,26 @@ void strcpy(char* dest, const char *src)
|
|||
void* memset(void* dest_ptr, byte c, dword n)
|
||||
{
|
||||
dword dest = (dword)dest_ptr;
|
||||
if (n >= 12) {
|
||||
size_t dwords = n / sizeof(dword);
|
||||
dword expanded_c = c;
|
||||
expanded_c <<= 8;
|
||||
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(
|
||||
"cld\n"
|
||||
"rep stosb\n"
|
||||
: "=D" (dest), "=c" (n)
|
||||
: "0" (dest), "1" (n), "a" (c)
|
||||
: "cc", "memory"
|
||||
: "memory"
|
||||
);
|
||||
return dest_ptr;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue