diff --git a/AK/JsonParser.cpp b/AK/JsonParser.cpp index b99bb91bd5c..323a0308f6d 100644 --- a/AK/JsonParser.cpp +++ b/AK/JsonParser.cpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace AK { diff --git a/AK/Memory.h b/AK/Memory.h new file mode 100644 index 00000000000..27b5d2c54b1 --- /dev/null +++ b/AK/Memory.h @@ -0,0 +1,38 @@ +#pragma once + +#include + +#if defined(KERNEL) || defined(BOOTSTRAPPER) +# include +#else +# include +# include +#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"); +} diff --git a/AK/Optional.h b/AK/Optional.h index 7686bfdd5d3..e14f4ecf494 100644 --- a/AK/Optional.h +++ b/AK/Optional.h @@ -29,6 +29,7 @@ #include #include #include +#include namespace AK { @@ -157,7 +158,7 @@ private: ASSERT(m_has_value); return *reinterpret_cast(&m_storage); } - unsigned char m_storage[sizeof(T)] { 0 }; + u8 m_storage[sizeof(T)] { 0 }; bool m_has_value { false }; }; diff --git a/AK/SinglyLinkedList.h b/AK/SinglyLinkedList.h index eec6a1db869..7238b4c76a6 100644 --- a/AK/SinglyLinkedList.h +++ b/AK/SinglyLinkedList.h @@ -28,6 +28,7 @@ #include #include +#include namespace AK { diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h index 7dea07a6e11..c68f3c93e24 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -26,46 +26,9 @@ #pragma once -#if defined(KERNEL) || defined(BOOTSTRAPPER) -# include -#else -# include -# include -#endif - #define UNUSED_PARAM(x) (void)x -#include - -#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; } diff --git a/AK/String.cpp b/AK/String.cpp index 3f8fb8b10af..81e6e517a12 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include diff --git a/AK/String.h b/AK/String.h index 0158adb2231..c01c771219a 100644 --- a/AK/String.h +++ b/AK/String.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<> diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index 28f89098f54..a047ea70fcc 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -24,10 +24,11 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include -#include #include +#include namespace AK { diff --git a/AK/StringImpl.cpp b/AK/StringImpl.cpp index 5f5d2f77527..b47edf0be25 100644 --- a/AK/StringImpl.cpp +++ b/AK/StringImpl.cpp @@ -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 +#include +#include +#include +#include //#define DEBUG_STRINGIMPL diff --git a/AK/StringView.cpp b/AK/StringView.cpp index 30cf328f4fa..ebd179299c6 100644 --- a/AK/StringView.cpp +++ b/AK/StringView.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include diff --git a/AK/StringView.h b/AK/StringView.h index 6d22f2dcde6..41e7e7e652d 100644 --- a/AK/StringView.h +++ b/AK/StringView.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