summaryrefslogtreecommitdiff
path: root/Source/Core/Common
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2026-08-22 11:22:33 +0200
committerJosJuice <josjuice@gmail.com>2026-08-22 11:52:22 +0200
commitf93a8a995b6e16625c60303ccabb0ea71e7dbeb2 (patch)
treec6303977d6dcd7538ac0eca1561cdb6b1b476b19 /Source/Core/Common
parent82f7ec53902d805a6f5091f913035f29499c873a (diff)
Common: Add DivideRoundingUp function
Many callers of AlignUp are dividing immediately after aligning. Let's add a helper function for this so callers don't have to specify the alignment size twice.
Diffstat (limited to 'Source/Core/Common')
-rw-r--r--Source/Core/Common/Align.h7
-rw-r--r--Source/Core/Common/LazyMemoryRegionBitSet.cpp4
2 files changed, 9 insertions, 2 deletions
diff --git a/Source/Core/Common/Align.h b/Source/Core/Common/Align.h
index 994e505617..c5a4de4ccd 100644
--- a/Source/Core/Common/Align.h
+++ b/Source/Core/Common/Align.h
@@ -22,4 +22,11 @@ constexpr T AlignUp(T value, size_t size)
return AlignDown<T>(static_cast<T>(value + (size - 1)), size);
}
+template <typename T>
+constexpr T DivideRoundingUp(T numerator, size_t denominator)
+{
+ static_assert(std::is_unsigned<T>(), "T must be an unsigned value.");
+ return static_cast<T>((numerator + (denominator - 1)) / denominator);
+}
+
} // namespace Common
diff --git a/Source/Core/Common/LazyMemoryRegionBitSet.cpp b/Source/Core/Common/LazyMemoryRegionBitSet.cpp
index af9d79c8df..89f707daa0 100644
--- a/Source/Core/Common/LazyMemoryRegionBitSet.cpp
+++ b/Source/Core/Common/LazyMemoryRegionBitSet.cpp
@@ -58,7 +58,7 @@ void LazyMemoryRegionBitSet::SetBits(size_t bits_start, size_t bits_end)
if (bits_start % 32 != 0)
m_pointer[bits_start / 32] |= extra_first_word;
- const size_t start_index = Common::AlignUp(bits_start, 32) / 32;
+ const size_t start_index = Common::DivideRoundingUp(bits_start, 32);
const size_t end_index = bits_end / 32;
std::memset(m_pointer + start_index, 0xFF, (end_index - start_index) * 4);
@@ -85,7 +85,7 @@ void LazyMemoryRegionBitSet::ClearBits(size_t bits_start, size_t bits_end)
if (bits_start % 32 != 0)
m_pointer[bits_start / 32] &= extra_first_word;
- const size_t start_index = Common::AlignUp(bits_start, 32) / 32;
+ const size_t start_index = Common::DivideRoundingUp(bits_start, 32);
const size_t end_index = bits_end / 32;
std::memset(m_pointer + start_index, 0x00, (end_index - start_index) * sizeof(u32));