Fix MLD level mask generation to support 64-bit masks. (#6123)
The generation of level masks for compactly storing partition cells supports sizes that can be stored in 64 bits. The current implementation fails if the total bit sum is 64 bits exactly. A bit shift mechanism is used that is undefined when the shift size is equal to the bit size of the underlying type. This generates an incorrect mask value. We fix this by adding a special case for a 64 bit offset. Given this code is called at most |level| times, there will be no effect on performance. We also update the assertions to reflect 64 bit masks are now supported.
This commit is contained in:
@@ -186,11 +186,12 @@ template <storage::Ownership Ownership> class MultiLevelPartitionImpl final
|
||||
auto bits = static_cast<std::uint64_t>(std::ceil(std::log2(num_cells + 1)));
|
||||
offsets[lidx++] = sum_bits;
|
||||
sum_bits += bits;
|
||||
if (sum_bits > 64)
|
||||
if (sum_bits > NUM_PARTITION_BITS)
|
||||
{
|
||||
throw util::exception(
|
||||
"Can't pack the partition information at level " + std::to_string(lidx) +
|
||||
" into a 64bit integer. Would require " + std::to_string(sum_bits) + " bits.");
|
||||
" into a " + std::to_string(NUM_PARTITION_BITS) +
|
||||
"bit integer. Would require " + std::to_string(sum_bits) + " bits.");
|
||||
}
|
||||
}
|
||||
// sentinel
|
||||
@@ -211,11 +212,15 @@ template <storage::Ownership Ownership> class MultiLevelPartitionImpl final
|
||||
[&](const auto offset, const auto next_offset) {
|
||||
// create mask that has `bits` ones at its LSBs.
|
||||
// 000011
|
||||
BOOST_ASSERT(offset < NUM_PARTITION_BITS);
|
||||
BOOST_ASSERT(offset <= NUM_PARTITION_BITS);
|
||||
PartitionID mask = (1ULL << offset) - 1ULL;
|
||||
// 001111
|
||||
BOOST_ASSERT(next_offset < NUM_PARTITION_BITS);
|
||||
PartitionID next_mask = (1ULL << next_offset) - 1ULL;
|
||||
BOOST_ASSERT(next_offset <= NUM_PARTITION_BITS);
|
||||
// Check offset for shift overflow. Offsets are strictly increasing,
|
||||
// so we only need the check on the last mask.
|
||||
PartitionID next_mask = next_offset == NUM_PARTITION_BITS
|
||||
? -1ULL
|
||||
: (1ULL << next_offset) - 1ULL;
|
||||
// 001100
|
||||
masks[lidx++] = next_mask ^ mask;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user