mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +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
Notes:
sideshowbarker
2024-07-19 08:50:24 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/900f51ccd08
11 changed files with 57 additions and 49 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <AK/JsonArray.h>
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/JsonParser.h>
|
||||
#include <AK/Memory.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
|
38
AK/Memory.h
Normal file
38
AK/Memory.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
|
||||
#if defined(KERNEL) || defined(BOOTSTRAPPER)
|
||||
# include <LibBareMetal/StdLib.h>
|
||||
#else
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#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");
|
||||
}
|
|
@ -29,6 +29,7 @@
|
|||
#include <AK/Assertions.h>
|
||||
#include <AK/Platform.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
@ -157,7 +158,7 @@ private:
|
|||
ASSERT(m_has_value);
|
||||
return *reinterpret_cast<const T*>(&m_storage);
|
||||
}
|
||||
unsigned char m_storage[sizeof(T)] { 0 };
|
||||
u8 m_storage[sizeof(T)] { 0 };
|
||||
bool m_has_value { false };
|
||||
};
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
|
|
|
@ -252,7 +252,7 @@ inline bool StringView::operator==(const String& string) const
|
|||
return false;
|
||||
if (m_characters == string.characters())
|
||||
return true;
|
||||
return !memcmp(m_characters, string.characters(), m_length);
|
||||
return !__builtin_memcmp(m_characters, string.characters(), m_length);
|
||||
}
|
||||
|
||||
template<>
|
||||
|
|
|
@ -24,10 +24,11 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/PrintfImplementation.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
|
|
@ -24,10 +24,11 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "StringImpl.h"
|
||||
#include "HashTable.h"
|
||||
#include "StdLibExtras.h"
|
||||
#include "kmalloc.h"
|
||||
#include <AK/HashTable.h>
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/StringImpl.h>
|
||||
#include <AK/kmalloc.h>
|
||||
|
||||
//#define DEBUG_STRINGIMPL
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
}
|
||||
[[gnu::always_inline]] inline StringView(const char* cstring)
|
||||
: m_characters(cstring)
|
||||
, m_length(cstring ? strlen(cstring) : 0)
|
||||
, m_length(cstring ? __builtin_strlen(cstring) : 0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -105,10 +105,10 @@ public:
|
|||
return !cstring;
|
||||
if (!cstring)
|
||||
return false;
|
||||
size_t other_length = strlen(cstring);
|
||||
size_t other_length = __builtin_strlen(cstring);
|
||||
if (m_length != other_length)
|
||||
return false;
|
||||
return !memcmp(m_characters, cstring, m_length);
|
||||
return !__builtin_memcmp(m_characters, cstring, m_length);
|
||||
}
|
||||
bool operator!=(const char* cstring) const
|
||||
{
|
||||
|
@ -125,7 +125,7 @@ public:
|
|||
return false;
|
||||
if (length() != other.length())
|
||||
return false;
|
||||
return !memcmp(m_characters, other.m_characters, m_length);
|
||||
return !__builtin_memcmp(m_characters, other.m_characters, m_length);
|
||||
}
|
||||
|
||||
bool operator!=(const StringView& other) const
|
||||
|
|
Loading…
Reference in a new issue