From 86f6b6b7b2d930e8203114332b04a5c49a780b06 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 10 Aug 2023 21:34:43 -0400 Subject: vfs: expand support for NCA reading --- src/common/alignment.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/common/alignment.h') diff --git a/src/common/alignment.h b/src/common/alignment.h index fa715d497..0057052af 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include #include @@ -10,7 +11,7 @@ namespace Common { template - requires std::is_unsigned_v + requires std::is_integral_v [[nodiscard]] constexpr T AlignUp(T value, size_t size) { auto mod{static_cast(value % size)}; value -= mod; @@ -24,7 +25,7 @@ template } template - requires std::is_unsigned_v + requires std::is_integral_v [[nodiscard]] constexpr T AlignDown(T value, size_t size) { return static_cast(value - value % size); } @@ -55,6 +56,30 @@ template return (x + (y - 1)) / y; } +template + requires std::is_integral_v +[[nodiscard]] constexpr T LeastSignificantOneBit(T x) { + return x & ~(x - 1); +} + +template + requires std::is_integral_v +[[nodiscard]] constexpr T ResetLeastSignificantOneBit(T x) { + return x & (x - 1); +} + +template + requires std::is_integral_v +[[nodiscard]] constexpr bool IsPowerOfTwo(T x) { + return x > 0 && ResetLeastSignificantOneBit(x) == 0; +} + +template + requires std::is_integral_v +[[nodiscard]] constexpr T FloorPowerOfTwo(T x) { + return T{1} << (sizeof(T) * 8 - std::countl_zero(x) - 1); +} + template class AlignmentAllocator { public: -- cgit v1.2.3 From 50eee9b2185c59c32fb82cf464230a058edd10ea Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 12 Aug 2023 15:18:55 -0400 Subject: fssystem: rework for yuzu style --- src/common/alignment.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/common/alignment.h') diff --git a/src/common/alignment.h b/src/common/alignment.h index 0057052af..fc5c26898 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h @@ -12,7 +12,9 @@ namespace Common { template requires std::is_integral_v -[[nodiscard]] constexpr T AlignUp(T value, size_t size) { +[[nodiscard]] constexpr T AlignUp(T value_, size_t size) { + using U = typename std::make_unsigned_t; + auto value{static_cast(value_)}; auto mod{static_cast(value % size)}; value -= mod; return static_cast(mod == T{0} ? value : value + size); @@ -26,7 +28,9 @@ template template requires std::is_integral_v -[[nodiscard]] constexpr T AlignDown(T value, size_t size) { +[[nodiscard]] constexpr T AlignDown(T value_, size_t size) { + using U = typename std::make_unsigned_t; + const auto value{static_cast(value_)}; return static_cast(value - value % size); } -- cgit v1.2.3