mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-08-02 14:19:02 +00:00
Merge pull request #12010 from TellowKrinkle/AlignUpOpt
Common: Better AlignUp implementation
This commit is contained in:
commit
ff324ef660
1 changed files with 7 additions and 6 deletions
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue