diff --git a/rpcs3/util/asm.hpp b/rpcs3/util/asm.hpp index c4b8f1f4b9..d4e15468e2 100644 --- a/rpcs3/util/asm.hpp +++ b/rpcs3/util/asm.hpp @@ -374,21 +374,21 @@ namespace utils // General purpose aligned division, the result is rounded up not truncated template ::value && std::is_unsigned::value>> - constexpr T aligned_div(T value, ullong align) + constexpr T aligned_div(T value, std::type_identity_t align) { - return static_cast((value + align - 1) / align); + return static_cast(value / align + T{!!(value % align)}); } // General purpose aligned division, the result is rounded to nearest template ::value>> - constexpr T rounded_div(T value, std::conditional_t::value, llong, ullong> align) + constexpr T rounded_div(T value, std::type_identity_t align) { if constexpr (std::is_unsigned::value) { - return static_cast((value + (align / 2)) / align); + return static_cast(value / align + T{(value % align) > (align / 2)}); } - return static_cast((value + (value < 0 ? 0 - align : align) / 2) / align); + return static_cast(value / align + (value > 0 ? T{(value % align) > (align / 2)} : 0 - T{(value % align) < (align / 2)})); } } // namespace utils