From 0751db5d1251f9d7a790a2a68b4b6c5257ef5968 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 15 Jan 2020 23:47:14 -0800 Subject: [PATCH] fixes for previous two commits --- Makefile | 24 +++- .../vapours/util/util_intrusive_list.hpp | 8 +- .../util/util_intrusive_red_black_tree.hpp | 3 +- .../vapours/util/util_parent_of_member.hpp | 112 +++++++++--------- .../vapours/util/util_typed_storage.hpp | 14 +-- 5 files changed, 87 insertions(+), 74 deletions(-) diff --git a/Makefile b/Makefile index 9d89d8a6c..37c89a2a0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -TOPTARGETS := all clean dist +TOPTARGETS := all clean dist-no-debug dist AMSBRANCH := $(shell git symbolic-ref --short HEAD) AMSHASH := $(shell git rev-parse --short HEAD) AMSREV := $(AMSBRANCH)-$(AMSHASH) @@ -39,7 +39,7 @@ clean: $(MAKE) -C fusee clean rm -rf out -dist: all +dist-no-debug: all $(eval MAJORVER = $(shell grep 'define ATMOSPHERE_RELEASE_VERSION_MAJOR\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \ | tr -s [:blank:] \ | cut -d' ' -f3)) @@ -91,6 +91,21 @@ dist: all cp troposphere/reboot_to_payload/reboot_to_payload.nro atmosphere-$(AMSVER)/switch/reboot_to_payload.nro cd atmosphere-$(AMSVER); zip -r ../atmosphere-$(AMSVER).zip ./*; cd ../; rm -r atmosphere-$(AMSVER) + mkdir out + mv atmosphere-$(AMSVER).zip out/atmosphere-$(AMSVER).zip + cp fusee/fusee-primary/fusee-primary.bin out/fusee-primary.bin + +dist: dist-no-debug + $(eval MAJORVER = $(shell grep 'define ATMOSPHERE_RELEASE_VERSION_MAJOR\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \ + | tr -s [:blank:] \ + | cut -d' ' -f3)) + $(eval MINORVER = $(shell grep 'define ATMOSPHERE_RELEASE_VERSION_MINOR\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \ + | tr -s [:blank:] \ + | cut -d' ' -f3)) + $(eval MICROVER = $(shell grep 'define ATMOSPHERE_RELEASE_VERSION_MICRO\b' libraries/libvapours/include/vapours/ams/ams_api_version.h \ + | tr -s [:blank:] \ + | cut -d' ' -f3)) + $(eval AMSVER = $(MAJORVER).$(MINORVER).$(MICROVER)-$(AMSREV)) rm -rf atmosphere-$(AMSVER)-debug mkdir atmosphere-$(AMSVER)-debug cp fusee/fusee-primary/fusee-primary.elf atmosphere-$(AMSVER)-debug/fusee-primary.elf @@ -118,10 +133,7 @@ dist: all cp stratosphere/spl/spl.elf atmosphere-$(AMSVER)-debug/spl.elf cd atmosphere-$(AMSVER)-debug; zip -r ../atmosphere-$(AMSVER)-debug.zip ./*; cd ../; rm -r atmosphere-$(AMSVER)-debug - mkdir out - mv atmosphere-$(AMSVER).zip out/atmosphere-$(AMSVER).zip - mv atmosphere-$(AMSVER).zip out/atmosphere-$(AMSVER)-debug.zip - cp fusee/fusee-primary/fusee-primary.bin out/fusee-primary.bin + mv atmosphere-$(AMSVER)-debug.zip out/atmosphere-$(AMSVER)-debug.zip .PHONY: $(TOPTARGETS) $(COMPONENTS) diff --git a/libraries/libvapours/include/vapours/util/util_intrusive_list.hpp b/libraries/libvapours/include/vapours/util/util_intrusive_list.hpp index 4323220fb..42afcbf1c 100644 --- a/libraries/libvapours/include/vapours/util/util_intrusive_list.hpp +++ b/libraries/libvapours/include/vapours/util/util_intrusive_list.hpp @@ -34,12 +34,9 @@ namespace ams::util { IntrusiveListNode *prev; IntrusiveListNode *next; public: - IntrusiveListNode() { - this->prev = this; - this->next = this; - } + constexpr IntrusiveListNode() : prev(this), next(this) { /* ... */ } - bool IsLinked() const { + constexpr bool IsLinked() const { return this->next != this; } private: @@ -102,6 +99,7 @@ namespace ams::util { return this->next; } }; + static_assert(std::is_literal_type::value); namespace impl { 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 19f004b89..9feeb938f 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 @@ -28,8 +28,9 @@ namespace ams::util { template friend class IntrusiveRedBlackTree; public: - IntrusiveRedBlackTreeNode() { /* ... */} + constexpr IntrusiveRedBlackTreeNode() : entry() { /* ... */} }; + static_assert(std::is_literal_type::value); template class IntrusiveRedBlackTree { diff --git a/libraries/libvapours/include/vapours/util/util_parent_of_member.hpp b/libraries/libvapours/include/vapours/util/util_parent_of_member.hpp index 18d7a0cb5..99c9821f8 100644 --- a/libraries/libvapours/include/vapours/util/util_parent_of_member.hpp +++ b/libraries/libvapours/include/vapours/util/util_parent_of_member.hpp @@ -16,6 +16,7 @@ #pragma once #include "../defines.hpp" +#include "util_typed_storage.hpp" namespace ams::util { @@ -54,7 +55,7 @@ namespace ams::util { union Union { char c; UnionHolder first_union; - ParentType parent; + TYPED_STORAGE(ParentType) parent; /* This coerces the active member to be c. */ constexpr Union() : c() { /* ... */ } @@ -75,7 +76,7 @@ namespace ams::util { template static constexpr std::ptrdiff_t OffsetOfImpl(MemberType ParentType::*member, CurUnion &cur_union) { constexpr size_t Offset = CurUnion::GetOffset(); - const auto target = std::addressof(U.parent.*member); + const auto target = std::addressof(GetPointer(U.parent)->*member); const auto start = std::addressof(cur_union.data.members[0]); const auto next = GetNextAddress(start, target); @@ -116,6 +117,7 @@ namespace ams::util { using DeducedParentType = GetParentType; using MemberType = GetMemberType; static_assert(std::is_base_of::value || std::is_same::value); + static_assert(std::is_literal_type::value); return OffsetOfCalculator::OffsetOf(MemberPtr); }(); @@ -125,17 +127,13 @@ namespace ams::util { template> constexpr ALWAYS_INLINE RealParentType &GetParentReference(impl::GetMemberType *member) { constexpr std::ptrdiff_t Offset = impl::OffsetOf; - uint8_t *addr = static_cast(static_cast(member)); - addr -= Offset; - return *static_cast(static_cast(addr)); + return *static_cast(static_cast(static_cast(static_cast(member)) - Offset)); } template> constexpr ALWAYS_INLINE RealParentType const &GetParentReference(impl::GetMemberType const *member) { constexpr std::ptrdiff_t Offset = impl::OffsetOf; - const uint8_t *addr = static_cast(static_cast(member)); - addr -= Offset; - return *static_cast(static_cast(addr)); + return *static_cast(static_cast(static_cast(static_cast(member)) - Offset)); } template> @@ -148,6 +146,35 @@ namespace ams::util { return std::addressof(GetParentReference(member)); } + template> + constexpr ALWAYS_INLINE RealParentType &GetParentReference(impl::GetMemberType &member) { + return GetParentReference(std::addressof(member)); + } + + template> + constexpr ALWAYS_INLINE RealParentType const &GetParentReference(impl::GetMemberType const &member) { + return GetParentReference(std::addressof(member)); + } + + template> + constexpr ALWAYS_INLINE RealParentType *GetParentPointer(impl::GetMemberType &member) { + return std::addressof(GetParentReference(member)); + } + + template> + constexpr ALWAYS_INLINE RealParentType const *GetParentPointer(impl::GetMemberType const &member) { + return std::addressof(GetParentReference(member)); + } + + +/* Defines, for use by other code. */ + +#define OFFSETOF(parent, member) (::ams::util::OffsetOf<&parent::member, parent>) + +#define GET_PARENT_PTR(parent, member, _arg) (::ams::util::GetParentPointer<&parent::member, parent>(_arg)) + +#define GET_PARENT_REF(parent, member, _arg) (::ams::util::GetParentReference<&parent::member, parent>(_arg)) + namespace test { struct Struct1 { @@ -174,9 +201,12 @@ namespace ams::util { constexpr Struct3 TestStruct3 = {}; - static_assert(std::addressof(TestStruct3) == GetParentPointer<&Struct3::a, Struct3>(std::addressof(TestStruct3.a))); - static_assert(std::addressof(TestStruct3) == GetParentPointer<&Struct3::b, Struct3>(std::addressof(TestStruct3.b))); - static_assert(std::addressof(TestStruct3) == GetParentPointer<&Struct3::c, Struct3>(std::addressof(TestStruct3.c))); + static_assert(std::addressof(TestStruct3) == GET_PARENT_PTR(Struct3, a, TestStruct3.a)); + static_assert(std::addressof(TestStruct3) == GET_PARENT_PTR(Struct3, a, std::addressof(TestStruct3.a))); + static_assert(std::addressof(TestStruct3) == GET_PARENT_PTR(Struct3, b, TestStruct3.b)); + static_assert(std::addressof(TestStruct3) == GET_PARENT_PTR(Struct3, b, std::addressof(TestStruct3.b))); + static_assert(std::addressof(TestStruct3) == GET_PARENT_PTR(Struct3, c, TestStruct3.c)); + static_assert(std::addressof(TestStruct3) == GET_PARENT_PTR(Struct3, c, std::addressof(TestStruct3.c))); struct CharArray { char c0; @@ -200,51 +230,23 @@ namespace ams::util { constexpr CharArray TestCharArray = {}; - static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c0>(std::addressof(TestCharArray.c0))); - static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c1>(std::addressof(TestCharArray.c1))); - static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c2>(std::addressof(TestCharArray.c2))); - static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c3>(std::addressof(TestCharArray.c3))); - static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c4>(std::addressof(TestCharArray.c4))); - static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c5>(std::addressof(TestCharArray.c5))); - static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c6>(std::addressof(TestCharArray.c6))); - static_assert(std::addressof(TestCharArray) == GetParentPointer<&CharArray::c7>(std::addressof(TestCharArray.c7))); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c0, TestCharArray.c0)); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c0, std::addressof(TestCharArray.c0))); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c1, TestCharArray.c1)); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c1, std::addressof(TestCharArray.c1))); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c2, TestCharArray.c2)); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c2, std::addressof(TestCharArray.c2))); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c3, TestCharArray.c3)); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c3, std::addressof(TestCharArray.c3))); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c4, TestCharArray.c4)); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c4, std::addressof(TestCharArray.c4))); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c5, TestCharArray.c5)); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c5, std::addressof(TestCharArray.c5))); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c6, TestCharArray.c6)); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c6, std::addressof(TestCharArray.c6))); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c7, TestCharArray.c7)); + static_assert(std::addressof(TestCharArray) == GET_PARENT_PTR(CharArray, c7, std::addressof(TestCharArray.c7))); } } - -/* Defines, for use by other code. */ - -#define OFFSETOF(parent, member) (::ams::util::OffsetOf<&parent::member, parent>) - -#define AMS_GET_PARENT_TYPE_IMPL(parent, argt) typename std::conditional::value, \ - typename std::conditional::type>::value, \ - const parent, \ - parent \ - >::type, \ - typename std::conditional::type>::value, \ - const parent, \ - parent \ - >::type \ - >::type - -#define GET_PARENT_PTR(parent, member, _arg) ([](GetParentPtrArgType &arg) ALWAYS_INLINE_LAMBDA -> AMS_GET_PARENT_TYPE_IMPL(parent, GetParentPtrArgType) * { \ - using ParentPtrType = typename std::conditional::value, const parent, parent>::type *; \ - if constexpr (std::is_pointer::value) { \ - static_assert(std::is_same::type, typename std::remove_cv::type>::type>::value); \ - return ::ams::util::GetParentPointer<&parent::member, parent>(arg); \ - } else { \ - static_assert(std::is_same::type, typename std::remove_cv::type>::type>::value); \ - return ::ams::util::GetParentPointer<&parent::member, parent>(std::addressof(arg)); \ - } \ -}(_arg)) - -#define GET_PARENT_REF(parent, member, _arg) ([](GetParentPtrArgType &arg) ALWAYS_INLINE_LAMBDA -> AMS_GET_PARENT_TYPE_IMPL(parent, GetParentPtrArgType) & { \ - if constexpr (std::is_pointer::value) { \ - static_assert(std::is_same::type, typename std::remove_cv::type>::type>::value); \ - return ::ams::util::GetParentReference<&parent::member, parent>(arg); \ - } else { \ - static_assert(std::is_same::type, typename std::remove_cv::type>::type>::value); \ - return ::ams::util::GetParentReference<&parent::member, parent>(std::addressof(arg)); \ - } \ -}(_arg)) diff --git a/libraries/libvapours/include/vapours/util/util_typed_storage.hpp b/libraries/libvapours/include/vapours/util/util_typed_storage.hpp index 62d65b2de..e1061a9fa 100644 --- a/libraries/libvapours/include/vapours/util/util_typed_storage.hpp +++ b/libraries/libvapours/include/vapours/util/util_typed_storage.hpp @@ -24,25 +24,25 @@ namespace ams::util { typename std::aligned_storage::type _storage; }; - #define TYPED_STORAGE(T) ::ams::util::TypedStorage + #define TYPED_STORAGE(...) ::ams::util::TypedStorage<__VA_ARGS__, sizeof(__VA_ARGS__), alignof(__VA_ARGS__)> template - static constexpr inline __attribute__((always_inline)) T *GetPointer(TYPED_STORAGE(T) &ts) { - return reinterpret_cast(&ts._storage); + static constexpr ALWAYS_INLINE T *GetPointer(TYPED_STORAGE(T) &ts) { + return static_cast(static_cast(std::addressof(ts._storage))); } template - static constexpr inline __attribute__((always_inline)) const T *GetPointer(const TYPED_STORAGE(T) &ts) { - return reinterpret_cast(&ts._storage); + static constexpr ALWAYS_INLINE const T *GetPointer(const TYPED_STORAGE(T) &ts) { + return static_cast(static_cast(std::addressof(ts._storage))); } template - static constexpr inline __attribute__((always_inline)) T &GetReference(TYPED_STORAGE(T) &ts) { + static constexpr ALWAYS_INLINE T &GetReference(TYPED_STORAGE(T) &ts) { return *GetPointer(ts); } template - static constexpr inline __attribute__((always_inline)) const T &GetReference(const TYPED_STORAGE(T) &ts) { + static constexpr ALWAYS_INLINE const T &GetReference(const TYPED_STORAGE(T) &ts) { return *GetPointer(ts); }