diff options
author | Andreas Kling <kling@serenityos.org> | 2020-03-08 12:34:33 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-08 13:06:51 +0100 |
commit | 900f51ccd0832caf8405620e74e14a17deea75c4 (patch) | |
tree | fd2a4a4023293728c8d56c226885d5448e093740 /AK | |
parent | fa9fba69018dd7055794b9dfab81c7b89e98b279 (diff) | |
download | serenity-900f51ccd0832caf8405620e74e14a17deea75c4.zip |
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.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/JsonParser.cpp | 1 | ||||
-rw-r--r-- | AK/Memory.h | 38 | ||||
-rw-r--r-- | AK/Optional.h | 3 | ||||
-rw-r--r-- | AK/SinglyLinkedList.h | 1 | ||||
-rw-r--r-- | AK/StdLibExtras.h | 39 | ||||
-rw-r--r-- | AK/String.cpp | 1 | ||||
-rw-r--r-- | AK/String.h | 2 | ||||
-rw-r--r-- | AK/StringBuilder.cpp | 3 | ||||
-rw-r--r-- | AK/StringImpl.cpp | 9 | ||||
-rw-r--r-- | AK/StringView.cpp | 1 | ||||
-rw-r--r-- | AK/StringView.h | 8 |
11 files changed, 57 insertions, 49 deletions
diff --git a/AK/JsonParser.cpp b/AK/JsonParser.cpp index b99bb91bd5..323a0308f6 100644 --- a/AK/JsonParser.cpp +++ b/AK/JsonParser.cpp @@ -27,6 +27,7 @@ #include <AK/JsonArray.h> #include <AK/JsonObject.h> #include <AK/JsonParser.h> +#include <AK/Memory.h> namespace AK { diff --git a/AK/Memory.h b/AK/Memory.h new file mode 100644 index 0000000000..27b5d2c54b --- /dev/null +++ b/AK/Memory.h @@ -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"); +} diff --git a/AK/Optional.h b/AK/Optional.h index 7686bfdd5d..e14f4ecf49 100644 --- a/AK/Optional.h +++ b/AK/Optional.h @@ -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 }; }; diff --git a/AK/SinglyLinkedList.h b/AK/SinglyLinkedList.h index eec6a1db86..7238b4c76a 100644 --- a/AK/SinglyLinkedList.h +++ b/AK/SinglyLinkedList.h @@ -28,6 +28,7 @@ #include <AK/Assertions.h> #include <AK/StdLibExtras.h> +#include <AK/Types.h> namespace AK { diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h index 7dea07a6e1..c68f3c93e2 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -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; } diff --git a/AK/String.cpp b/AK/String.cpp index 3f8fb8b10a..81e6e517a1 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 <AK/Memory.h> #include <AK/StdLibExtras.h> #include <AK/String.h> #include <AK/StringBuilder.h> diff --git a/AK/String.h b/AK/String.h index 0158adb223..c01c771219 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 28f89098f5..a047ea70fc 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 <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 { diff --git a/AK/StringImpl.cpp b/AK/StringImpl.cpp index 5f5d2f7752..b47edf0be2 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 <AK/HashTable.h> +#include <AK/Memory.h> +#include <AK/StdLibExtras.h> +#include <AK/StringImpl.h> +#include <AK/kmalloc.h> //#define DEBUG_STRINGIMPL diff --git a/AK/StringView.cpp b/AK/StringView.cpp index 30cf328f4f..ebd179299c 100644 --- a/AK/StringView.cpp +++ b/AK/StringView.cpp @@ -25,6 +25,7 @@ */ #include <AK/ByteBuffer.h> +#include <AK/Memory.h> #include <AK/String.h> #include <AK/StringView.h> #include <AK/Vector.h> diff --git a/AK/StringView.h b/AK/StringView.h index 6d22f2dcde..41e7e7e652 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 |