From 1e643f7ab0a76aad55a4f05ecc4e237039d9d8cd Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 8 Jan 2021 02:35:29 -0800 Subject: [PATCH] kern: further codegen tweaks --- .../mesosphere/kern_k_server_session.hpp | 2 +- .../svc/kern_svc_k_user_pointer.hpp | 40 +++++++++---------- .../nintendo/nx/kern_k_device_page_table.cpp | 12 +++--- .../source/kern_k_server_session.cpp | 4 +- .../vapours/svc/ipc/svc_message_buffer.hpp | 4 +- .../vapours/util/util_intrusive_list.hpp | 2 +- .../util/util_intrusive_red_black_tree.hpp | 6 +-- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_server_session.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_server_session.hpp index 307828d71..9216a5ba1 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_server_session.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_server_session.hpp @@ -53,7 +53,7 @@ namespace ams::kern { void Dump(); private: - bool IsSignaledImpl() const; + ALWAYS_INLINE bool IsSignaledImpl() const; void CleanupRequests(); }; diff --git a/libraries/libmesosphere/include/mesosphere/svc/kern_svc_k_user_pointer.hpp b/libraries/libmesosphere/include/mesosphere/svc/kern_svc_k_user_pointer.hpp index 195c13dba..b4b13d519 100644 --- a/libraries/libmesosphere/include/mesosphere/svc/kern_svc_k_user_pointer.hpp +++ b/libraries/libmesosphere/include/mesosphere/svc/kern_svc_k_user_pointer.hpp @@ -54,12 +54,12 @@ namespace ams::kern::svc { public: using T = typename std::remove_const::type>::type; public: - static Result CopyFromUserspace(void *dst, const void *src, size_t size) { + static ALWAYS_INLINE Result CopyFromUserspace(void *dst, const void *src, size_t size) { R_UNLESS(UserspaceAccess::CopyMemoryFromUser(dst, src, size), svc::ResultInvalidPointer()); return ResultSuccess(); } - static Result CopyToUserspace(void *dst, const void *src, size_t size) { + static ALWAYS_INLINE Result CopyToUserspace(void *dst, const void *src, size_t size) { R_UNLESS(UserspaceAccess::CopyMemoryToUser(dst, src, size), svc::ResultInvalidPointer()); return ResultSuccess(); } @@ -70,12 +70,12 @@ namespace ams::kern::svc { public: using T = typename std::remove_const::type>::type; public: - static Result CopyFromUserspace(void *dst, const void *src, size_t size) { + static ALWAYS_INLINE Result CopyFromUserspace(void *dst, const void *src, size_t size) { R_UNLESS(UserspaceAccess::CopyMemoryFromUserAligned32Bit(dst, src, size), svc::ResultInvalidPointer()); return ResultSuccess(); } - static Result CopyToUserspace(void *dst, const void *src, size_t size) { + static ALWAYS_INLINE Result CopyToUserspace(void *dst, const void *src, size_t size) { R_UNLESS(UserspaceAccess::CopyMemoryToUserAligned32Bit(dst, src, size), svc::ResultInvalidPointer()); return ResultSuccess(); } @@ -86,12 +86,12 @@ namespace ams::kern::svc { public: using T = typename std::remove_const::type>::type; public: - static Result CopyFromUserspace(void *dst, const void *src, size_t size) { + static ALWAYS_INLINE Result CopyFromUserspace(void *dst, const void *src, size_t size) { R_UNLESS(UserspaceAccess::CopyMemoryFromUserAligned64Bit(dst, src, size), svc::ResultInvalidPointer()); return ResultSuccess(); } - static Result CopyToUserspace(void *dst, const void *src, size_t size) { + static ALWAYS_INLINE Result CopyToUserspace(void *dst, const void *src, size_t size) { R_UNLESS(UserspaceAccess::CopyMemoryToUserAligned64Bit(dst, src, size), svc::ResultInvalidPointer()); return ResultSuccess(); } @@ -110,26 +110,26 @@ namespace ams::kern::svc { private: CT *m_ptr; private: - Result CopyToImpl(void *p, size_t size) const { + ALWAYS_INLINE Result CopyToImpl(void *p, size_t size) const { return Traits::CopyFromUserspace(p, m_ptr, size); } - Result CopyFromImpl(const void *p, size_t size) const { + ALWAYS_INLINE Result CopyFromImpl(const void *p, size_t size) const { return Traits::CopyToUserspace(m_ptr, p, size); } protected: - Result CopyTo(T *p) const { return this->CopyToImpl(p, sizeof(*p)); } - Result CopyFrom(const T *p) const { return this->CopyFromImpl(p, sizeof(*p)); } + ALWAYS_INLINE Result CopyTo(T *p) const { return this->CopyToImpl(p, sizeof(*p)); } + ALWAYS_INLINE Result CopyFrom(const T *p) const { return this->CopyFromImpl(p, sizeof(*p)); } - Result CopyArrayElementTo(T *p, size_t index) const { return Traits::CopyFromUserspace(p, m_ptr + index, sizeof(*p)); } - Result CopyArrayElementFrom(const T *p, size_t index) const { return Traits::CopyToUserspace(m_ptr + index, p, sizeof(*p)); } + ALWAYS_INLINE Result CopyArrayElementTo(T *p, size_t index) const { return Traits::CopyFromUserspace(p, m_ptr + index, sizeof(*p)); } + ALWAYS_INLINE Result CopyArrayElementFrom(const T *p, size_t index) const { return Traits::CopyToUserspace(m_ptr + index, p, sizeof(*p)); } - Result CopyArrayTo(T *arr, size_t count) const { return this->CopyToImpl(arr, sizeof(*arr) * count); } - Result CopyArrayFrom(const T *arr, size_t count) const { return this->CopyFromImpl(arr, sizeof(*arr) * count); } + ALWAYS_INLINE Result CopyArrayTo(T *arr, size_t count) const { return this->CopyToImpl(arr, sizeof(*arr) * count); } + ALWAYS_INLINE Result CopyArrayFrom(const T *arr, size_t count) const { return this->CopyFromImpl(arr, sizeof(*arr) * count); } - constexpr bool IsNull() const { return m_ptr == nullptr; } + constexpr ALWAYS_INLINE bool IsNull() const { return m_ptr == nullptr; } - constexpr CT *GetUnsafePointer() const { return m_ptr; } + constexpr ALWAYS_INLINE CT *GetUnsafePointer() const { return m_ptr; } }; template<> @@ -142,19 +142,19 @@ namespace ams::kern::svc { private: const char *ptr; protected: - Result CopyStringTo(char *dst, size_t size) const { + ALWAYS_INLINE Result CopyStringTo(char *dst, size_t size) const { static_assert(sizeof(char) == 1); R_UNLESS(UserspaceAccess::CopyStringFromUser(dst, this->ptr, size) > 0, svc::ResultInvalidPointer()); return ResultSuccess(); } - Result CopyArrayElementTo(char *dst, size_t index) const { + ALWAYS_INLINE Result CopyArrayElementTo(char *dst, size_t index) const { return Traits::CopyFromUserspace(dst, this->ptr + index, sizeof(*dst)); } - constexpr bool IsNull() const { return this->ptr == nullptr; } + constexpr ALWAYS_INLINE bool IsNull() const { return this->ptr == nullptr; } - constexpr const char *GetUnsafePointer() const { return this->ptr; } + constexpr ALWAYS_INLINE const char *GetUnsafePointer() const { return this->ptr; } }; } diff --git a/libraries/libmesosphere/source/board/nintendo/nx/kern_k_device_page_table.cpp b/libraries/libmesosphere/source/board/nintendo/nx/kern_k_device_page_table.cpp index 97b95ce8e..76410a1fc 100644 --- a/libraries/libmesosphere/source/board/nintendo/nx/kern_k_device_page_table.cpp +++ b/libraries/libmesosphere/source/board/nintendo/nx/kern_k_device_page_table.cpp @@ -583,15 +583,15 @@ namespace ams::kern::board::nintendo::nx { constinit KMemoryControllerInterruptTask g_mc_interrupt_task; /* Memory controller utilities. */ - void SmmuSynchronizationBarrier() { + ALWAYS_INLINE void SmmuSynchronizationBarrier() { ReadMcRegister(MC_SMMU_CONFIG); } - void InvalidatePtc() { + ALWAYS_INLINE void InvalidatePtc() { WriteMcRegister(MC_SMMU_PTC_FLUSH_0, 0); } - void InvalidatePtc(KPhysicalAddress address) { + ALWAYS_INLINE void InvalidatePtc(KPhysicalAddress address) { WriteMcRegister(MC_SMMU_PTC_FLUSH_1, (static_cast(GetInteger(address)) >> 32)); WriteMcRegister(MC_SMMU_PTC_FLUSH_0, (GetInteger(address) & 0xFFFFFFF0u) | 1u); } @@ -606,15 +606,15 @@ namespace ams::kern::board::nintendo::nx { return ((match_asid ? 1u : 0u) << 31) | ((asid & 0x7F) << 24) | (((address & 0xFFC00000u) >> DevicePageBits)) | (match); } - void InvalidateTlb() { + ALWAYS_INLINE void InvalidateTlb() { return WriteMcRegister(MC_SMMU_TLB_FLUSH, EncodeTlbFlushValue(false, 0, 0, TlbFlushVaMatch_All)); } - void InvalidateTlb(u8 asid) { + ALWAYS_INLINE void InvalidateTlb(u8 asid) { return WriteMcRegister(MC_SMMU_TLB_FLUSH, EncodeTlbFlushValue(true, asid, 0, TlbFlushVaMatch_All)); } - void InvalidateTlbSection(u8 asid, KDeviceVirtualAddress address) { + ALWAYS_INLINE void InvalidateTlbSection(u8 asid, KDeviceVirtualAddress address) { return WriteMcRegister(MC_SMMU_TLB_FLUSH, EncodeTlbFlushValue(true, asid, address, TlbFlushVaMatch_Section)); } diff --git a/libraries/libmesosphere/source/kern_k_server_session.cpp b/libraries/libmesosphere/source/kern_k_server_session.cpp index a5e1d0f1f..d2d67cbab 100644 --- a/libraries/libmesosphere/source/kern_k_server_session.cpp +++ b/libraries/libmesosphere/source/kern_k_server_session.cpp @@ -37,7 +37,7 @@ namespace ams::kern { uintptr_t m_msg_buffer_end; uintptr_t m_msg_buffer_space_end; public: - static constexpr int GetEntryCount(const ipc::MessageBuffer::MessageHeader &header) { + static constexpr ALWAYS_INLINE int GetEntryCount(const ipc::MessageBuffer::MessageHeader &header) { const auto count = header.GetReceiveListCount(); switch (count) { case ipc::MessageBuffer::MessageHeader::ReceiveListCountType_None: @@ -82,7 +82,7 @@ namespace ams::kern { } } - constexpr bool IsIndex() const { + constexpr ALWAYS_INLINE bool IsIndex() const { return m_recv_list_count > ipc::MessageBuffer::MessageHeader::ReceiveListCountType_CountOffset; } diff --git a/libraries/libvapours/include/vapours/svc/ipc/svc_message_buffer.hpp b/libraries/libvapours/include/vapours/svc/ipc/svc_message_buffer.hpp index aae8f8d1c..6a1df8e7e 100644 --- a/libraries/libvapours/include/vapours/svc/ipc/svc_message_buffer.hpp +++ b/libraries/libvapours/include/vapours/svc/ipc/svc_message_buffer.hpp @@ -375,8 +375,8 @@ namespace ams::svc::ipc { u32 *buffer; size_t size; public: - constexpr MessageBuffer(u32 *b, size_t sz) : buffer(b), size(sz) { /* ... */ } - constexpr explicit MessageBuffer(u32 *b) : buffer(b), size(sizeof(::ams::svc::ThreadLocalRegion::message_buffer)) { /* ... */ } + constexpr ALWAYS_INLINE MessageBuffer(u32 *b, size_t sz) : buffer(b), size(sz) { /* ... */ } + constexpr explicit ALWAYS_INLINE MessageBuffer(u32 *b) : buffer(b), size(sizeof(::ams::svc::ThreadLocalRegion::message_buffer)) { /* ... */ } constexpr ALWAYS_INLINE size_t GetBufferSize() const { return this->size; diff --git a/libraries/libvapours/include/vapours/util/util_intrusive_list.hpp b/libraries/libvapours/include/vapours/util/util_intrusive_list.hpp index 70b8d68dd..737c9586b 100644 --- a/libraries/libvapours/include/vapours/util/util_intrusive_list.hpp +++ b/libraries/libvapours/include/vapours/util/util_intrusive_list.hpp @@ -39,7 +39,7 @@ namespace ams::util { IntrusiveListNode *prev; IntrusiveListNode *next; public: - constexpr IntrusiveListNode() : prev(this), next(this) { /* ... */ } + constexpr ALWAYS_INLINE IntrusiveListNode() : prev(this), next(this) { /* ... */ } constexpr ALWAYS_INLINE bool IsLinked() const { return this->next != this; diff --git a/libraries/libvapours/include/vapours/util/util_intrusive_red_black_tree.hpp b/libraries/libvapours/include/vapours/util/util_intrusive_red_black_tree.hpp index 8ff2cd575..192c8bd79 100644 --- a/libraries/libvapours/include/vapours/util/util_intrusive_red_black_tree.hpp +++ b/libraries/libvapours/include/vapours/util/util_intrusive_red_black_tree.hpp @@ -41,7 +41,7 @@ namespace ams::util { template friend class IntrusiveRedBlackTree; public: - constexpr IntrusiveRedBlackTreeNode() : entry() { /* ... */} + constexpr ALWAYS_INLINE IntrusiveRedBlackTreeNode() : entry() { /* ... */} }; static_assert(std::is_literal_type::value); @@ -355,11 +355,11 @@ namespace ams::util { /* Generate static implementations for comparison operations for IntrusiveRedBlackTreeRoot. */ RB_GENERATE_WITH_COMPARE_STATIC(IntrusiveRedBlackTreeRootWithCompare, IntrusiveRedBlackTreeNode, entry, CompareImpl, LightCompareImpl); private: - static int CompareImpl(const IntrusiveRedBlackTreeNode *lhs, const IntrusiveRedBlackTreeNode *rhs) { + static ALWAYS_INLINE int CompareImpl(const IntrusiveRedBlackTreeNode *lhs, const IntrusiveRedBlackTreeNode *rhs) { return Comparator::Compare(*Traits::GetParent(lhs), *Traits::GetParent(rhs)); } - static int LightCompareImpl(const void *elm, const IntrusiveRedBlackTreeNode *rhs) { + static ALWAYS_INLINE int LightCompareImpl(const void *elm, const IntrusiveRedBlackTreeNode *rhs) { return Comparator::Compare(*static_cast(elm), *Traits::GetParent(rhs)); }