summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Common/Align.h7
-rw-r--r--Source/Core/Common/LazyMemoryRegionBitSet.cpp4
-rw-r--r--Source/Core/Core/IOS/FS/HostBackend/FS.cpp2
-rw-r--r--Source/Core/Core/PowerPC/JitCommon/JitCache.cpp3
-rw-r--r--Source/Core/DiscIO/DirectoryBlob.cpp4
-rw-r--r--Source/Core/DiscIO/WIABlob.cpp16
-rw-r--r--Source/Core/DolphinQt/MenuBar.cpp8
-rw-r--r--Source/Core/VideoBackends/Vulkan/VKShader.cpp4
-rw-r--r--Source/Core/VideoBackends/Vulkan/VKTexture.cpp2
-rw-r--r--Source/Core/VideoCommon/Assets/CustomTextureData.cpp2
10 files changed, 30 insertions, 22 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));
diff --git a/Source/Core/Core/IOS/FS/HostBackend/FS.cpp b/Source/Core/Core/IOS/FS/HostBackend/FS.cpp
index 31597950a6..3026b293f9 100644
--- a/Source/Core/Core/IOS/FS/HostBackend/FS.cpp
+++ b/Source/Core/Core/IOS/FS/HostBackend/FS.cpp
@@ -693,7 +693,7 @@ static u64 ComputeUsedClusters(const File::FSTEntry& parent_entry)
if (entry.isDirectory)
clusters += ComputeUsedClusters(entry);
else
- clusters += Common::AlignUp(entry.size, CLUSTER_SIZE) / CLUSTER_SIZE;
+ clusters += Common::DivideRoundingUp(entry.size, CLUSTER_SIZE);
}
return clusters;
}
diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp
index 4039c09c4c..35a9b966be 100644
--- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp
+++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp
@@ -183,8 +183,7 @@ void JitBaseBlockCache::FinalizeBlock(JitBlock& block, bool block_link,
for (auto [range_start, range_end] : block.physical_addresses)
{
valid_block.SetBits(range_start / VALID_BLOCK_CACHE_LINE_SIZE,
- Common::AlignUp(range_end, VALID_BLOCK_CACHE_LINE_SIZE) /
- VALID_BLOCK_CACHE_LINE_SIZE);
+ Common::DivideRoundingUp(range_end, VALID_BLOCK_CACHE_LINE_SIZE));
for (u32 i = range_start & BLOCK_RANGE_MAP_MASK; i < range_end; i += BLOCK_RANGE_SIZE)
block_range_map[i].insert(&block);
diff --git a/Source/Core/DiscIO/DirectoryBlob.cpp b/Source/Core/DiscIO/DirectoryBlob.cpp
index 47b9d73e41..c9355db113 100644
--- a/Source/Core/DiscIO/DirectoryBlob.cpp
+++ b/Source/Core/DiscIO/DirectoryBlob.cpp
@@ -792,7 +792,9 @@ void DirectoryBlobReader::SetPartitionHeader(DirectoryBlobPartition* partition,
}
constexpr u32 PARTITION_HEADER_SIZE = 0x1c;
- const u64 data_size = Common::AlignUp(partition->GetDataSize(), 0x7c00) / 0x7c00 * 0x8000;
+ const u64 data_size =
+ Common::DivideRoundingUp(partition->GetDataSize(), VolumeWii::BLOCK_DATA_SIZE) *
+ VolumeWii::BLOCK_TOTAL_SIZE;
std::vector<u8> partition_header(PARTITION_HEADER_SIZE);
Write32(static_cast<u32>(tmd_size), 0x0, &partition_header);
Write32(TMD_OFFSET >> 2, 0x4, &partition_header);
diff --git a/Source/Core/DiscIO/WIABlob.cpp b/Source/Core/DiscIO/WIABlob.cpp
index 3f7b274ca8..6259f61c4f 100644
--- a/Source/Core/DiscIO/WIABlob.cpp
+++ b/Source/Core/DiscIO/WIABlob.cpp
@@ -641,8 +641,8 @@ WIARVZFileReader<RVZ>::Chunk::Chunk(File::DirectIOFile* file, u64 offset_in_file
m_rvz_packed_size(rvz_packed_size), m_data_offset(data_offset)
{
constexpr size_t MAX_SIZE_PER_EXCEPTION_LIST =
- Common::AlignUp(VolumeWii::BLOCK_HEADER_SIZE, Common::SHA1::DIGEST_LEN) /
- Common::SHA1::DIGEST_LEN * VolumeWii::BLOCKS_PER_GROUP * sizeof(HashExceptionEntry) +
+ Common::DivideRoundingUp(VolumeWii::BLOCK_HEADER_SIZE, Common::SHA1::DIGEST_LEN) *
+ VolumeWii::BLOCKS_PER_GROUP * sizeof(HashExceptionEntry) +
sizeof(u16);
m_out_bytes_allocated_for_exceptions =
@@ -909,7 +909,7 @@ void WIARVZFileReader<RVZ>::AddRawDataEntry(u64 offset, u64 size, int chunk_size
return;
const u32 group_index = *total_groups;
- const u32 groups = static_cast<u32>(Common::AlignUp(size, chunk_size) / chunk_size);
+ const u32 groups = static_cast<u32>(Common::DivideRoundingUp(size, chunk_size));
*total_groups += groups;
data_entries->emplace_back(raw_data_entries->size());
@@ -924,7 +924,7 @@ typename WIARVZFileReader<RVZ>::PartitionDataEntry WIARVZFileReader<RVZ>::Create
{
const u32 group_index = *total_groups;
const u64 rounded_size = Common::AlignDown(size, VolumeWii::BLOCK_TOTAL_SIZE);
- const u32 groups = static_cast<u32>(Common::AlignUp(rounded_size, chunk_size) / chunk_size);
+ const u32 groups = static_cast<u32>(Common::DivideRoundingUp(rounded_size, chunk_size));
*total_groups += groups;
data_entries->emplace_back(partition_entries.size(), index);
@@ -1334,8 +1334,8 @@ WIARVZFileReader<RVZ>::ProcessAndCompress(CompressThreadState* state, CompressPa
auto aes_context = Common::AES::CreateContextDecrypt(partition_entry.partition_key.data());
- const u64 groups = Common::AlignUp(parameters.data.size(), VolumeWii::GROUP_TOTAL_SIZE) /
- VolumeWii::GROUP_TOTAL_SIZE;
+ const u64 groups =
+ Common::DivideRoundingUp(parameters.data.size(), VolumeWii::GROUP_TOTAL_SIZE);
ASSERT(parameters.data.size() % VolumeWii::BLOCK_TOTAL_SIZE == 0);
const u64 blocks = parameters.data.size() / VolumeWii::BLOCK_TOTAL_SIZE;
@@ -1344,7 +1344,7 @@ WIARVZFileReader<RVZ>::ProcessAndCompress(CompressThreadState* state, CompressPa
exception_lists_per_chunk * VolumeWii::BLOCKS_PER_GROUP :
VolumeWii::BLOCKS_PER_GROUP / chunks_per_wii_group;
- const u64 chunks = Common::AlignUp(blocks, blocks_per_chunk) / blocks_per_chunk;
+ const u64 chunks = Common::DivideRoundingUp(blocks, blocks_per_chunk);
const u64 in_data_per_chunk = blocks_per_chunk * VolumeWii::BLOCK_TOTAL_SIZE;
const u64 out_data_per_chunk = blocks_per_chunk * VolumeWii::BLOCK_DATA_SIZE;
@@ -1932,7 +1932,7 @@ WIARVZFileReader<RVZ>::Convert(BlobReader* infile, const VolumeDisc* infile_volu
data_offset_in_partition += bytes_to_read;
}
- groups_processed += Common::AlignUp(bytes_to_read, chunk_size) / chunk_size;
+ groups_processed += Common::DivideRoundingUp(bytes_to_read, chunk_size);
}
ASSERT(data_size == 0);
diff --git a/Source/Core/DolphinQt/MenuBar.cpp b/Source/Core/DolphinQt/MenuBar.cpp
index 6d75ee4e79..f0ad6d2c78 100644
--- a/Source/Core/DolphinQt/MenuBar.cpp
+++ b/Source/Core/DolphinQt/MenuBar.cpp
@@ -1370,16 +1370,16 @@ void MenuBar::CheckNAND()
const QString user_cluster_message =
tr("The user-accessible part of your NAND contains %1 blocks (%2 KiB) "
"of data, out of an allowed maximum of %3 blocks (%4 KiB).")
- .arg(Common::AlignUp(result.used_clusters_user, IOS::HLE::FS::CLUSTERS_PER_BLOCK) /
- IOS::HLE::FS::CLUSTERS_PER_BLOCK)
+ .arg(Common::DivideRoundingUp(result.used_clusters_user,
+ IOS::HLE::FS::CLUSTERS_PER_BLOCK))
.arg((result.used_clusters_user * IOS::HLE::FS::CLUSTER_SIZE) / 1024)
.arg(IOS::HLE::FS::USER_CLUSTERS / IOS::HLE::FS::CLUSTERS_PER_BLOCK)
.arg((IOS::HLE::FS::USER_CLUSTERS * IOS::HLE::FS::CLUSTER_SIZE) / 1024);
const QString system_cluster_message =
tr("The system-reserved part of your NAND contains %1 blocks (%2 KiB) "
"of data, out of an allowed maximum of %3 blocks (%4 KiB).")
- .arg(Common::AlignUp(result.used_clusters_system, IOS::HLE::FS::CLUSTERS_PER_BLOCK) /
- IOS::HLE::FS::CLUSTERS_PER_BLOCK)
+ .arg(Common::DivideRoundingUp(result.used_clusters_system,
+ IOS::HLE::FS::CLUSTERS_PER_BLOCK))
.arg((result.used_clusters_system * IOS::HLE::FS::CLUSTER_SIZE) / 1024)
.arg(IOS::HLE::FS::SYSTEM_CLUSTERS / IOS::HLE::FS::CLUSTERS_PER_BLOCK)
.arg((IOS::HLE::FS::SYSTEM_CLUSTERS * IOS::HLE::FS::CLUSTER_SIZE) / 1024);
diff --git a/Source/Core/VideoBackends/Vulkan/VKShader.cpp b/Source/Core/VideoBackends/Vulkan/VKShader.cpp
index 9132085748..914fc0c8e4 100644
--- a/Source/Core/VideoBackends/Vulkan/VKShader.cpp
+++ b/Source/Core/VideoBackends/Vulkan/VKShader.cpp
@@ -138,8 +138,8 @@ std::unique_ptr<VKShader> VKShader::CreateFromSource(ShaderStage stage, std::str
std::unique_ptr<VKShader> VKShader::CreateFromBinary(ShaderStage stage, const void* data,
size_t length, std::string_view name)
{
- const size_t size_in_words = Common::AlignUp(length, sizeof(ShaderCompiler::SPIRVCodeType)) /
- sizeof(ShaderCompiler::SPIRVCodeType);
+ const size_t size_in_words =
+ Common::DivideRoundingUp(length, sizeof(ShaderCompiler::SPIRVCodeType));
ShaderCompiler::SPIRVCodeVector spv(size_in_words);
if (length > 0)
std::memcpy(spv.data(), data, length);
diff --git a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp
index ee6a1b77b3..ea7472597b 100644
--- a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp
+++ b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp
@@ -378,7 +378,7 @@ void VKTexture::Load(u32 level, u32 width, u32 height, u32 row_length, const u8*
// that lie outside of the texture's dimensions.
const u32 upload_alignment = static_cast<u32>(g_vulkan_context->GetBufferImageGranularity());
const u32 block_size = GetBlockSizeForFormat(GetFormat());
- const u32 num_rows = Common::AlignUp(height, block_size) / block_size;
+ const u32 num_rows = Common::DivideRoundingUp(height, block_size);
const u32 source_pitch = CalculateStrideForFormat(m_config.format, row_length);
const u32 upload_size = source_pitch * num_rows;
std::unique_ptr<StagingBuffer> temp_buffer;
diff --git a/Source/Core/VideoCommon/Assets/CustomTextureData.cpp b/Source/Core/VideoCommon/Assets/CustomTextureData.cpp
index 1631002e1c..90b103a804 100644
--- a/Source/Core/VideoCommon/Assets/CustomTextureData.cpp
+++ b/Source/Core/VideoCommon/Assets/CustomTextureData.cpp
@@ -166,7 +166,7 @@ struct DDSLoadInfo
static constexpr u32 GetBlockCount(u32 extent, u32 block_size)
{
- return std::max(Common::AlignUp(extent, block_size) / block_size, 1u);
+ return std::max(Common::DivideRoundingUp(extent, block_size), 1u);
}
static u32 CalculateMipCount(u32 width, u32 height)