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