From 0dea545c950230964036c4e89b327de2c7dcfe81 Mon Sep 17 00:00:00 2001 From: fis Date: Thu, 26 Mar 2020 17:12:50 +0800 Subject: [PATCH] Force compressed buffer to be 4 bytes aligned. --- src/common/compressed_iterator.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/common/compressed_iterator.h b/src/common/compressed_iterator.h index 64702f2a4584..71326e8fe822 100644 --- a/src/common/compressed_iterator.h +++ b/src/common/compressed_iterator.h @@ -75,11 +75,16 @@ class CompressedBufferWriter { * \return The calculated buffer size. */ static size_t CalculateBufferSize(size_t num_elements, size_t num_symbols) { - const int bits_per_byte = 8; + constexpr int kBitsPerByte = 8; size_t compressed_size = static_cast(std::ceil( static_cast(detail::SymbolBits(num_symbols) * num_elements) / - bits_per_byte)); - return compressed_size + detail::kPadding; + kBitsPerByte)); + // Handle atomicOr where input must be unsigned int, hence 4 bytes aligned. + size_t ret = + std::ceil(static_cast(compressed_size + detail::kPadding) / + static_cast(sizeof(unsigned int))) * + sizeof(unsigned int); + return ret; } template