Merge pull request #12010 from TellowKrinkle/AlignUpOpt

Common: Better AlignUp implementation
This commit is contained in:
JMC47 2023-06-29 20:30:13 -04:00 committed by GitHub
commit ff324ef660
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,12 +7,6 @@
namespace Common namespace Common
{ {
template <typename T>
constexpr T AlignUp(T value, size_t size)
{
static_assert(std::is_unsigned<T>(), "T must be an unsigned value.");
return static_cast<T>(value + (size - value % size) % size);
}
template <typename T> template <typename T>
constexpr T AlignDown(T value, size_t size) constexpr T AlignDown(T value, size_t size)
@ -21,4 +15,11 @@ constexpr T AlignDown(T value, size_t size)
return static_cast<T>(value - value % size); return static_cast<T>(value - value % size);
} }
template <typename T>
constexpr T AlignUp(T value, size_t size)
{
static_assert(std::is_unsigned<T>(), "T must be an unsigned value.");
return AlignDown<T>(static_cast<T>(value + (size - 1)), size);
}
} // namespace Common } // namespace Common