mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-17 17:11:23 +00:00
Simplify utils::align() a bit
std::is_unsigned implies std::is_integral I believe.
This commit is contained in:
parent
73d45f3bf0
commit
9dc238187f
@ -366,24 +366,24 @@ namespace utils
|
||||
}
|
||||
|
||||
// Align to power of 2
|
||||
template <typename T, typename = std::enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value>>
|
||||
constexpr T align(T value, ullong align)
|
||||
template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
|
||||
constexpr T align(T value, std::type_identity_t<T> align)
|
||||
{
|
||||
return static_cast<T>((value + (align - 1)) & (0 - align));
|
||||
return static_cast<T>((value + (align - 1)) & (T{0} - align));
|
||||
}
|
||||
|
||||
// General purpose aligned division, the result is rounded up not truncated
|
||||
template <typename T, typename = std::enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value>>
|
||||
template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
|
||||
constexpr T aligned_div(T value, std::type_identity_t<T> align)
|
||||
{
|
||||
return static_cast<T>(value / align + T{!!(value % align)});
|
||||
}
|
||||
|
||||
// General purpose aligned division, the result is rounded to nearest
|
||||
template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
|
||||
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
|
||||
constexpr T rounded_div(T value, std::type_identity_t<T> align)
|
||||
{
|
||||
if constexpr (std::is_unsigned<T>::value)
|
||||
if constexpr (std::is_unsigned_v<T>)
|
||||
{
|
||||
return static_cast<T>(value / align + T{(value % align) > (align / 2)});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user