diff options
| author | 2020-07-16 17:41:55 -0300 | |
|---|---|---|
| committer | 2020-07-16 17:41:55 -0300 | |
| commit | 104c523d3d8c8d48431f4b110097771d5fa43bf0 (patch) | |
| tree | f86fb4ef8fd0765822da547057a8b0d78261037f /src | |
| parent | Merge pull request #4333 from lioncash/desig3 (diff) | |
| parent | address_space_info: Use type alias to simplify code (diff) | |
| download | yuzu-104c523d3d8c8d48431f4b110097771d5fa43bf0.tar.gz yuzu-104c523d3d8c8d48431f4b110097771d5fa43bf0.tar.xz yuzu-104c523d3d8c8d48431f4b110097771d5fa43bf0.zip | |
Merge pull request #4327 from lioncash/desig2
address_space_info: Make use of designated initializers
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/memory/address_space_info.cpp | 67 | ||||
| -rw-r--r-- | src/core/hle/kernel/memory/address_space_info.h | 29 |
2 files changed, 38 insertions, 58 deletions
diff --git a/src/core/hle/kernel/memory/address_space_info.cpp b/src/core/hle/kernel/memory/address_space_info.cpp index a523a2502..e4288cab4 100644 --- a/src/core/hle/kernel/memory/address_space_info.cpp +++ b/src/core/hle/kernel/memory/address_space_info.cpp | |||
| @@ -29,40 +29,39 @@ enum : u64 { | |||
| 29 | 29 | ||
| 30 | // clang-format off | 30 | // clang-format off |
| 31 | constexpr std::array<AddressSpaceInfo, 13> AddressSpaceInfos{{ | 31 | constexpr std::array<AddressSpaceInfo, 13> AddressSpaceInfos{{ |
| 32 | { 32 /*bit_width*/, Size_2_MB /*addr*/, Size_1_GB - Size_2_MB /*size*/, AddressSpaceInfo::Type::Is32Bit, }, | 32 | { .bit_width = 32, .address = Size_2_MB , .size = Size_1_GB - Size_2_MB , .type = AddressSpaceInfo::Type::Is32Bit, }, |
| 33 | { 32 /*bit_width*/, Size_1_GB /*addr*/, Size_4_GB - Size_1_GB /*size*/, AddressSpaceInfo::Type::Small64Bit, }, | 33 | { .bit_width = 32, .address = Size_1_GB , .size = Size_4_GB - Size_1_GB , .type = AddressSpaceInfo::Type::Small64Bit, }, |
| 34 | { 32 /*bit_width*/, Invalid /*addr*/, Size_1_GB /*size*/, AddressSpaceInfo::Type::Heap, }, | 34 | { .bit_width = 32, .address = Invalid , .size = Size_1_GB , .type = AddressSpaceInfo::Type::Heap, }, |
| 35 | { 32 /*bit_width*/, Invalid /*addr*/, Size_1_GB /*size*/, AddressSpaceInfo::Type::Alias, }, | 35 | { .bit_width = 32, .address = Invalid , .size = Size_1_GB , .type = AddressSpaceInfo::Type::Alias, }, |
| 36 | { 36 /*bit_width*/, Size_128_MB /*addr*/, Size_2_GB - Size_128_MB /*size*/, AddressSpaceInfo::Type::Is32Bit, }, | 36 | { .bit_width = 36, .address = Size_128_MB, .size = Size_2_GB - Size_128_MB, .type = AddressSpaceInfo::Type::Is32Bit, }, |
| 37 | { 36 /*bit_width*/, Size_2_GB /*addr*/, Size_64_GB - Size_2_GB /*size*/, AddressSpaceInfo::Type::Small64Bit, }, | 37 | { .bit_width = 36, .address = Size_2_GB , .size = Size_64_GB - Size_2_GB , .type = AddressSpaceInfo::Type::Small64Bit, }, |
| 38 | { 36 /*bit_width*/, Invalid /*addr*/, Size_6_GB /*size*/, AddressSpaceInfo::Type::Heap, }, | 38 | { .bit_width = 36, .address = Invalid , .size = Size_6_GB , .type = AddressSpaceInfo::Type::Heap, }, |
| 39 | { 36 /*bit_width*/, Invalid /*addr*/, Size_6_GB /*size*/, AddressSpaceInfo::Type::Alias, }, | 39 | { .bit_width = 36, .address = Invalid , .size = Size_6_GB , .type = AddressSpaceInfo::Type::Alias, }, |
| 40 | { 39 /*bit_width*/, Size_128_MB /*addr*/, Size_512_GB - Size_128_MB /*size*/, AddressSpaceInfo::Type::Large64Bit, }, | 40 | { .bit_width = 39, .address = Size_128_MB, .size = Size_512_GB - Size_128_MB, .type = AddressSpaceInfo::Type::Large64Bit, }, |
| 41 | { 39 /*bit_width*/, Invalid /*addr*/, Size_64_GB /*size*/, AddressSpaceInfo::Type::Is32Bit }, | 41 | { .bit_width = 39, .address = Invalid , .size = Size_64_GB , .type = AddressSpaceInfo::Type::Is32Bit }, |
| 42 | { 39 /*bit_width*/, Invalid /*addr*/, Size_6_GB /*size*/, AddressSpaceInfo::Type::Heap, }, | 42 | { .bit_width = 39, .address = Invalid , .size = Size_6_GB , .type = AddressSpaceInfo::Type::Heap, }, |
| 43 | { 39 /*bit_width*/, Invalid /*addr*/, Size_64_GB /*size*/, AddressSpaceInfo::Type::Alias, }, | 43 | { .bit_width = 39, .address = Invalid , .size = Size_64_GB , .type = AddressSpaceInfo::Type::Alias, }, |
| 44 | { 39 /*bit_width*/, Invalid /*addr*/, Size_2_GB /*size*/, AddressSpaceInfo::Type::Stack, }, | 44 | { .bit_width = 39, .address = Invalid , .size = Size_2_GB , .type = AddressSpaceInfo::Type::Stack, }, |
| 45 | }}; | 45 | }}; |
| 46 | // clang-format on | 46 | // clang-format on |
| 47 | 47 | ||
| 48 | constexpr bool IsAllowedIndexForAddress(std::size_t index) { | 48 | constexpr bool IsAllowedIndexForAddress(std::size_t index) { |
| 49 | return index < std::size(AddressSpaceInfos) && AddressSpaceInfos[index].GetAddress() != Invalid; | 49 | return index < AddressSpaceInfos.size() && AddressSpaceInfos[index].address != Invalid; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | constexpr std::array<std::size_t, static_cast<std::size_t>(AddressSpaceInfo::Type::Count)> | 52 | using IndexArray = std::array<std::size_t, static_cast<std::size_t>(AddressSpaceInfo::Type::Count)>; |
| 53 | AddressSpaceIndices32Bit{ | ||
| 54 | 0, 1, 0, 2, 0, 3, | ||
| 55 | }; | ||
| 56 | 53 | ||
| 57 | constexpr std::array<std::size_t, static_cast<std::size_t>(AddressSpaceInfo::Type::Count)> | 54 | constexpr IndexArray AddressSpaceIndices32Bit{ |
| 58 | AddressSpaceIndices36Bit{ | 55 | 0, 1, 0, 2, 0, 3, |
| 59 | 4, 5, 4, 6, 4, 7, | 56 | }; |
| 60 | }; | 57 | |
| 58 | constexpr IndexArray AddressSpaceIndices36Bit{ | ||
| 59 | 4, 5, 4, 6, 4, 7, | ||
| 60 | }; | ||
| 61 | 61 | ||
| 62 | constexpr std::array<std::size_t, static_cast<std::size_t>(AddressSpaceInfo::Type::Count)> | 62 | constexpr IndexArray AddressSpaceIndices39Bit{ |
| 63 | AddressSpaceIndices39Bit{ | 63 | 9, 8, 8, 10, 12, 11, |
| 64 | 9, 8, 8, 10, 12, 11, | 64 | }; |
| 65 | }; | ||
| 66 | 65 | ||
| 67 | constexpr bool IsAllowed32BitType(AddressSpaceInfo::Type type) { | 66 | constexpr bool IsAllowed32BitType(AddressSpaceInfo::Type type) { |
| 68 | return type < AddressSpaceInfo::Type::Count && type != AddressSpaceInfo::Type::Large64Bit && | 67 | return type < AddressSpaceInfo::Type::Count && type != AddressSpaceInfo::Type::Large64Bit && |
| @@ -80,37 +79,37 @@ constexpr bool IsAllowed39BitType(AddressSpaceInfo::Type type) { | |||
| 80 | 79 | ||
| 81 | } // namespace | 80 | } // namespace |
| 82 | 81 | ||
| 83 | u64 AddressSpaceInfo::GetAddressSpaceStart(std::size_t width, AddressSpaceInfo::Type type) { | 82 | u64 AddressSpaceInfo::GetAddressSpaceStart(std::size_t width, Type type) { |
| 84 | const std::size_t index{static_cast<std::size_t>(type)}; | 83 | const std::size_t index{static_cast<std::size_t>(type)}; |
| 85 | switch (width) { | 84 | switch (width) { |
| 86 | case 32: | 85 | case 32: |
| 87 | ASSERT(IsAllowed32BitType(type)); | 86 | ASSERT(IsAllowed32BitType(type)); |
| 88 | ASSERT(IsAllowedIndexForAddress(AddressSpaceIndices32Bit[index])); | 87 | ASSERT(IsAllowedIndexForAddress(AddressSpaceIndices32Bit[index])); |
| 89 | return AddressSpaceInfos[AddressSpaceIndices32Bit[index]].GetAddress(); | 88 | return AddressSpaceInfos[AddressSpaceIndices32Bit[index]].address; |
| 90 | case 36: | 89 | case 36: |
| 91 | ASSERT(IsAllowed36BitType(type)); | 90 | ASSERT(IsAllowed36BitType(type)); |
| 92 | ASSERT(IsAllowedIndexForAddress(AddressSpaceIndices36Bit[index])); | 91 | ASSERT(IsAllowedIndexForAddress(AddressSpaceIndices36Bit[index])); |
| 93 | return AddressSpaceInfos[AddressSpaceIndices36Bit[index]].GetAddress(); | 92 | return AddressSpaceInfos[AddressSpaceIndices36Bit[index]].address; |
| 94 | case 39: | 93 | case 39: |
| 95 | ASSERT(IsAllowed39BitType(type)); | 94 | ASSERT(IsAllowed39BitType(type)); |
| 96 | ASSERT(IsAllowedIndexForAddress(AddressSpaceIndices39Bit[index])); | 95 | ASSERT(IsAllowedIndexForAddress(AddressSpaceIndices39Bit[index])); |
| 97 | return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].GetAddress(); | 96 | return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].address; |
| 98 | } | 97 | } |
| 99 | UNREACHABLE(); | 98 | UNREACHABLE(); |
| 100 | } | 99 | } |
| 101 | 100 | ||
| 102 | std::size_t AddressSpaceInfo::GetAddressSpaceSize(std::size_t width, AddressSpaceInfo::Type type) { | 101 | std::size_t AddressSpaceInfo::GetAddressSpaceSize(std::size_t width, Type type) { |
| 103 | const std::size_t index{static_cast<std::size_t>(type)}; | 102 | const std::size_t index{static_cast<std::size_t>(type)}; |
| 104 | switch (width) { | 103 | switch (width) { |
| 105 | case 32: | 104 | case 32: |
| 106 | ASSERT(IsAllowed32BitType(type)); | 105 | ASSERT(IsAllowed32BitType(type)); |
| 107 | return AddressSpaceInfos[AddressSpaceIndices32Bit[index]].GetSize(); | 106 | return AddressSpaceInfos[AddressSpaceIndices32Bit[index]].size; |
| 108 | case 36: | 107 | case 36: |
| 109 | ASSERT(IsAllowed36BitType(type)); | 108 | ASSERT(IsAllowed36BitType(type)); |
| 110 | return AddressSpaceInfos[AddressSpaceIndices36Bit[index]].GetSize(); | 109 | return AddressSpaceInfos[AddressSpaceIndices36Bit[index]].size; |
| 111 | case 39: | 110 | case 39: |
| 112 | ASSERT(IsAllowed39BitType(type)); | 111 | ASSERT(IsAllowed39BitType(type)); |
| 113 | return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].GetSize(); | 112 | return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].size; |
| 114 | } | 113 | } |
| 115 | UNREACHABLE(); | 114 | UNREACHABLE(); |
| 116 | } | 115 | } |
diff --git a/src/core/hle/kernel/memory/address_space_info.h b/src/core/hle/kernel/memory/address_space_info.h index c479890be..a4e6e91e5 100644 --- a/src/core/hle/kernel/memory/address_space_info.h +++ b/src/core/hle/kernel/memory/address_space_info.h | |||
| @@ -11,8 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | namespace Kernel::Memory { | 12 | namespace Kernel::Memory { |
| 13 | 13 | ||
| 14 | class AddressSpaceInfo final : NonCopyable { | 14 | struct AddressSpaceInfo final { |
| 15 | public: | ||
| 16 | enum class Type : u32 { | 15 | enum class Type : u32 { |
| 17 | Is32Bit = 0, | 16 | Is32Bit = 0, |
| 18 | Small64Bit = 1, | 17 | Small64Bit = 1, |
| @@ -23,31 +22,13 @@ public: | |||
| 23 | Count, | 22 | Count, |
| 24 | }; | 23 | }; |
| 25 | 24 | ||
| 26 | private: | ||
| 27 | std::size_t bit_width{}; | ||
| 28 | std::size_t addr{}; | ||
| 29 | std::size_t size{}; | ||
| 30 | Type type{}; | ||
| 31 | |||
| 32 | public: | ||
| 33 | static u64 GetAddressSpaceStart(std::size_t width, Type type); | 25 | static u64 GetAddressSpaceStart(std::size_t width, Type type); |
| 34 | static std::size_t GetAddressSpaceSize(std::size_t width, Type type); | 26 | static std::size_t GetAddressSpaceSize(std::size_t width, Type type); |
| 35 | 27 | ||
| 36 | constexpr AddressSpaceInfo(std::size_t bit_width, std::size_t addr, std::size_t size, Type type) | 28 | const std::size_t bit_width{}; |
| 37 | : bit_width{bit_width}, addr{addr}, size{size}, type{type} {} | 29 | const std::size_t address{}; |
| 38 | 30 | const std::size_t size{}; | |
| 39 | constexpr std::size_t GetWidth() const { | 31 | const Type type{}; |
| 40 | return bit_width; | ||
| 41 | } | ||
| 42 | constexpr std::size_t GetAddress() const { | ||
| 43 | return addr; | ||
| 44 | } | ||
| 45 | constexpr std::size_t GetSize() const { | ||
| 46 | return size; | ||
| 47 | } | ||
| 48 | constexpr Type GetType() const { | ||
| 49 | return type; | ||
| 50 | } | ||
| 51 | }; | 32 | }; |
| 52 | 33 | ||
| 53 | } // namespace Kernel::Memory | 34 | } // namespace Kernel::Memory |