From b965e3f335e4449a6180fa76e4c85909696c594c Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 2 Jan 2020 17:43:17 -0800 Subject: [PATCH] libvapours: add (kibi/mebi/gibi)byte literals --- .../nintendo/switch/kern_k_system_control.cpp | 11 ++--- libraries/libvapours/include/vapours.hpp | 1 + .../libvapours/include/vapours/literals.hpp | 33 +++++++++++++++ .../pm/source/impl/pm_resource_manager.cpp | 42 +++++++++---------- 4 files changed, 57 insertions(+), 30 deletions(-) create mode 100644 libraries/libvapours/include/vapours/literals.hpp diff --git a/libraries/libmesosphere/source/board/nintendo/switch/kern_k_system_control.cpp b/libraries/libmesosphere/source/board/nintendo/switch/kern_k_system_control.cpp index 87b1ecd41..5e999a079 100644 --- a/libraries/libmesosphere/source/board/nintendo/switch/kern_k_system_control.cpp +++ b/libraries/libmesosphere/source/board/nintendo/switch/kern_k_system_control.cpp @@ -20,11 +20,6 @@ namespace ams::kern { namespace { - /* Convenience definitions. */ - constexpr size_t FourGigabytes = 0x100000000ul; - constexpr size_t SixGigabytes = 0x180000000ul; - constexpr size_t EightGigabytes = 0x200000000ul; - ALWAYS_INLINE size_t GetRealMemorySizeForInit() { /* TODO: Move this into a header for the MC in general. */ constexpr u32 MemoryControllerConfigurationRegister = 0x70019050; @@ -49,11 +44,11 @@ namespace ams::kern { switch (GetKernelConfigurationForInit().Get()) { case smc::MemorySize_4GB: default: /* All invalid modes should go to 4GB. */ - return FourGigabytes; + return 4_GB; case smc::MemorySize_6GB: - return SixGigabytes; + return 6_GB; case smc::MemorySize_8GB: - return EightGigabytes; + return 8_GB; } } diff --git a/libraries/libvapours/include/vapours.hpp b/libraries/libvapours/include/vapours.hpp index 73bb5b274..f27e558a5 100644 --- a/libraries/libvapours/include/vapours.hpp +++ b/libraries/libvapours/include/vapours.hpp @@ -17,6 +17,7 @@ #pragma once #include "vapours/includes.hpp" #include "vapours/defines.hpp" +#include "vapours/literals.hpp" #include "vapours/util.hpp" #include "vapours/results.hpp" diff --git a/libraries/libvapours/include/vapours/literals.hpp b/libraries/libvapours/include/vapours/literals.hpp new file mode 100644 index 000000000..6e919461c --- /dev/null +++ b/libraries/libvapours/include/vapours/literals.hpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018-2019 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include "../defines.hpp" + +namespace ams { inline namespace literals { + + constexpr ALWAYS_INLINE size_t operator ""_KB(unsigned long long n) { + return static_cast(n) * size_t(1024); + } + + constexpr ALWAYS_INLINE size_t operator ""_MB(unsigned long long n) { + return operator ""_KB(n) * size_t(1024); + } + + constexpr ALWAYS_INLINE size_t operator ""_GB(unsigned long long n) { + return operator ""_MB(n) * size_t(1024); + } + +} } diff --git a/stratosphere/pm/source/impl/pm_resource_manager.cpp b/stratosphere/pm/source/impl/pm_resource_manager.cpp index f07d09dec..688ebfc9d 100644 --- a/stratosphere/pm/source/impl/pm_resource_manager.cpp +++ b/stratosphere/pm/source/impl/pm_resource_manager.cpp @@ -28,19 +28,17 @@ namespace ams::pm::resource { }; constexpr size_t LimitableResource_Count = util::size(LimitableResources); - constexpr size_t Megabyte = 0x100000; - /* Definitions for limit differences over time. */ constexpr size_t ExtraSystemThreadCount400 = 100; - constexpr size_t ExtraSystemMemorySize400 = 10 * Megabyte; - constexpr size_t ExtraSystemMemorySize500 = 12 * Megabyte; + constexpr size_t ExtraSystemMemorySize400 = 10_MB; + constexpr size_t ExtraSystemMemorySize500 = 12_MB; constexpr size_t ExtraSystemEventCount600 = 100; constexpr size_t ExtraSystemSessionCount600 = 100; - constexpr size_t ReservedMemorySize600 = 5 * Megabyte; + constexpr size_t ReservedMemorySize600 = 5_MB; /* Atmosphere always allocates extra memory for system usage. */ - constexpr size_t ExtraSystemMemorySizeAtmosphere = 24 * Megabyte; - constexpr size_t ExtraSystemMemorySizeAtmosphere500 = 33 * Megabyte; /* Applet pool is 0x20100000 */ + constexpr size_t ExtraSystemMemorySizeAtmosphere = 24_MB; + constexpr size_t ExtraSystemMemorySizeAtmosphere500 = 33_MB; /* Applet pool is 0x20100000 */ /* Globals. */ os::Mutex g_resource_limit_lock; @@ -75,29 +73,29 @@ namespace ams::pm::resource { u64 g_memory_resource_limits[spl::MemoryArrangement_Count][ResourceLimitGroup_Count] = { [spl::MemoryArrangement_Standard] = { - [ResourceLimitGroup_System] = 269 * Megabyte, - [ResourceLimitGroup_Application] = 3285 * Megabyte, - [ResourceLimitGroup_Applet] = 535 * Megabyte, + [ResourceLimitGroup_System] = 269_MB, + [ResourceLimitGroup_Application] = 3285_MB, + [ResourceLimitGroup_Applet] = 535_MB, }, [spl::MemoryArrangement_StandardForAppletDev] = { - [ResourceLimitGroup_System] = 481 * Megabyte, - [ResourceLimitGroup_Application] = 2048 * Megabyte, - [ResourceLimitGroup_Applet] = 1560 * Megabyte, + [ResourceLimitGroup_System] = 481_MB, + [ResourceLimitGroup_Application] = 2048_MB, + [ResourceLimitGroup_Applet] = 1560_MB, }, [spl::MemoryArrangement_StandardForSystemDev] = { - [ResourceLimitGroup_System] = 328 * Megabyte, - [ResourceLimitGroup_Application] = 3285 * Megabyte, - [ResourceLimitGroup_Applet] = 476 * Megabyte, + [ResourceLimitGroup_System] = 328_MB, + [ResourceLimitGroup_Application] = 3285_MB, + [ResourceLimitGroup_Applet] = 476_MB, }, [spl::MemoryArrangement_Expanded] = { - [ResourceLimitGroup_System] = 653 * Megabyte, - [ResourceLimitGroup_Application] = 4916 * Megabyte, - [ResourceLimitGroup_Applet] = 568 * Megabyte, + [ResourceLimitGroup_System] = 653_MB, + [ResourceLimitGroup_Application] = 4916_MB, + [ResourceLimitGroup_Applet] = 568_MB, }, [spl::MemoryArrangement_ExpandedForAppletDev] = { - [ResourceLimitGroup_System] = 653 * Megabyte, - [ResourceLimitGroup_Application] = 3285 * Megabyte, - [ResourceLimitGroup_Applet] = 2199 * Megabyte, + [ResourceLimitGroup_System] = 653_MB, + [ResourceLimitGroup_Application] = 3285_MB, + [ResourceLimitGroup_Applet] = 2199_MB, }, };