mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:17:35 +00:00
AK: Move memory stuff (fast memcpy, etc) to a separate header
Move the "fast memcpy" stuff out of StdLibExtras.h and into Memory.h. This will break a ton of things that were relying on StdLibExtras.h to include a bunch of other headers. Fix will follow immediately after. This makes it possible to include StdLibExtras.h from Types.h, which is the main point of this exercise.
This commit is contained in:
parent
fa9fba6901
commit
900f51ccd0
11 changed files with 57 additions and 49 deletions
|
@ -26,46 +26,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#if defined(KERNEL) || defined(BOOTSTRAPPER)
|
||||
# include <LibBareMetal/StdLib.h>
|
||||
#else
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#define UNUSED_PARAM(x) (void)x
|
||||
|
||||
#include <AK/Types.h>
|
||||
|
||||
#if defined(__serenity__) && !defined(KERNEL) && !defined(BOOTSTRAPPER)
|
||||
extern "C" void* mmx_memcpy(void* to, const void* from, size_t);
|
||||
#endif
|
||||
|
||||
[[gnu::always_inline]] inline void fast_u32_copy(u32* dest, const u32* src, size_t count)
|
||||
{
|
||||
#if defined(__serenity__) && !defined(KERNEL) && !defined(BOOTSTRAPPER)
|
||||
if (count >= 256) {
|
||||
mmx_memcpy(dest, src, count * sizeof(count));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
asm volatile(
|
||||
"rep movsl\n"
|
||||
: "=S"(src), "=D"(dest), "=c"(count)
|
||||
: "S"(src), "D"(dest), "c"(count)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
[[gnu::always_inline]] inline void fast_u32_fill(u32* dest, u32 value, size_t count)
|
||||
{
|
||||
asm volatile(
|
||||
"rep stosl\n"
|
||||
: "=D"(dest), "=c"(count)
|
||||
: "D"(dest), "c"(count), "a"(value)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
inline constexpr u32 round_up_to_power_of_two(u32 value, u32 power_of_two)
|
||||
inline constexpr unsigned round_up_to_power_of_two(unsigned value, unsigned power_of_two)
|
||||
{
|
||||
return ((value - 1) & ~(power_of_two - 1)) + power_of_two;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue