mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Kernel/LibC: Make memset implementations the same
I dont know why we do a fast path in the Kernel, but not in Userspace Also simplified the byte explosion in memset to "explode_byte" it even seemed so, that we missed the highest byte when memseting something
This commit is contained in:
parent
74de4795dc
commit
e8ef10e2a6
Notes:
sideshowbarker
2024-07-18 20:38:39 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/e8ef10e2a63 Pull-request: https://github.com/SerenityOS/serenity/pull/6179 Reviewed-by: https://github.com/awesomekling
2 changed files with 18 additions and 7 deletions
|
@ -282,9 +282,7 @@ void* memset(void* dest_ptr, int c, size_t n)
|
|||
// FIXME: Support starting at an unaligned address.
|
||||
if (!(dest & 0x3) && n >= 12) {
|
||||
size_t size_ts = n / sizeof(size_t);
|
||||
size_t expanded_c = (u8)c;
|
||||
expanded_c |= expanded_c << 8;
|
||||
expanded_c |= expanded_c << 16;
|
||||
size_t expanded_c = explode_byte((u8)c);
|
||||
asm volatile(
|
||||
"rep stosl\n"
|
||||
: "=D"(dest)
|
||||
|
|
|
@ -142,13 +142,26 @@ void* memcpy(void* dest_ptr, const void* src_ptr, size_t n)
|
|||
|
||||
void* memset(void* dest_ptr, int c, size_t n)
|
||||
{
|
||||
void* original_dest = dest_ptr;
|
||||
size_t dest = (size_t)dest_ptr;
|
||||
// FIXME: Support starting at an unaligned address.
|
||||
if (!(dest & 0x3) && n >= 12) {
|
||||
size_t size_ts = n / sizeof(size_t);
|
||||
size_t expanded_c = explode_byte((u8)c);
|
||||
asm volatile(
|
||||
"rep stosl\n"
|
||||
: "=D"(dest)
|
||||
: "D"(dest), "c"(size_ts), "a"(expanded_c)
|
||||
: "memory");
|
||||
n -= size_ts * sizeof(size_t);
|
||||
if (n == 0)
|
||||
return dest_ptr;
|
||||
}
|
||||
asm volatile(
|
||||
"rep stosb\n"
|
||||
: "=D"(dest_ptr), "=c"(n)
|
||||
: "0"(dest_ptr), "1"(n), "a"(c)
|
||||
: "=D"(dest), "=c"(n)
|
||||
: "0"(dest), "1"(n), "a"(c)
|
||||
: "memory");
|
||||
return original_dest;
|
||||
return dest_ptr;
|
||||
}
|
||||
#else
|
||||
void* memcpy(void* dest_ptr, const void* src_ptr, size_t n)
|
||||
|
|
Loading…
Reference in a new issue