summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO
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/DiscIO
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/DiscIO')
-rw-r--r--Source/Core/DiscIO/DirectoryBlob.cpp4
-rw-r--r--Source/Core/DiscIO/WIABlob.cpp16
2 files changed, 11 insertions, 9 deletions
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);