mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-22 22:05:38 +00:00
Common/Align: Make constexpr
This commit is contained in:
parent
36bede11ae
commit
3ecae0f409
|
@ -2,37 +2,37 @@
|
|||
|
||||
namespace Common {
|
||||
template<typename T>
|
||||
bool IsAligned(T value, unsigned int alignment)
|
||||
constexpr bool IsAligned(T value, unsigned int alignment)
|
||||
{
|
||||
return (value % static_cast<T>(alignment)) == 0;
|
||||
}
|
||||
template<typename T>
|
||||
T AlignUp(T value, unsigned int alignment)
|
||||
constexpr T AlignUp(T value, unsigned int alignment)
|
||||
{
|
||||
return (value + static_cast<T>(alignment - 1)) / static_cast<T>(alignment) * static_cast<T>(alignment);
|
||||
}
|
||||
template<typename T>
|
||||
T AlignDown(T value, unsigned int alignment)
|
||||
constexpr T AlignDown(T value, unsigned int alignment)
|
||||
{
|
||||
return value / static_cast<T>(alignment) * static_cast<T>(alignment);
|
||||
}
|
||||
template<typename T>
|
||||
bool IsAlignedPow2(T value, unsigned int alignment)
|
||||
constexpr bool IsAlignedPow2(T value, unsigned int alignment)
|
||||
{
|
||||
return (value & static_cast<T>(alignment - 1)) == 0;
|
||||
}
|
||||
template<typename T>
|
||||
T AlignUpPow2(T value, unsigned int alignment)
|
||||
constexpr T AlignUpPow2(T value, unsigned int alignment)
|
||||
{
|
||||
return (value + static_cast<T>(alignment - 1)) & static_cast<T>(~static_cast<T>(alignment - 1));
|
||||
}
|
||||
template<typename T>
|
||||
T AlignDownPow2(T value, unsigned int alignment)
|
||||
constexpr T AlignDownPow2(T value, unsigned int alignment)
|
||||
{
|
||||
return value & static_cast<T>(~static_cast<T>(alignment - 1));
|
||||
}
|
||||
template<typename T>
|
||||
bool IsPow2(T value)
|
||||
constexpr bool IsPow2(T value)
|
||||
{
|
||||
return (value & (value - 1)) == 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue