| 43 | // - a trailing area of size `trailing_bits` after the aligned words |
| 44 | template <uint64_t ALIGN_IN_BYTES> |
| 45 | inline BitmapWordAlignParams BitmapWordAlign(const uint8_t* data, int64_t bit_offset, |
| 46 | int64_t length) { |
| 47 | // TODO: We can remove this condition once CRAN upgrades its macOS |
| 48 | // SDK from 11.3. |
| 49 | // __apple_build_version__ should be defined only on Apple clang |
| 50 | #if defined(__apple_build_version__) && !defined(__cpp_lib_bitops) |
| 51 | static_assert((ALIGN_IN_BYTES != 0) && ((ALIGN_IN_BYTES & (ALIGN_IN_BYTES - 1)) == 0), |
| 52 | "ALIGN_IN_BYTES should be a positive power of two"); |
| 53 | #else |
| 54 | static_assert(std::has_single_bit(ALIGN_IN_BYTES), |
| 55 | "ALIGN_IN_BYTES should be a positive power of two"); |
| 56 | #endif |
| 57 | constexpr uint64_t ALIGN_IN_BITS = ALIGN_IN_BYTES * 8; |
| 58 | |
| 59 | BitmapWordAlignParams p; |
| 60 | |
| 61 | // Compute a "bit address" that we can align up to ALIGN_IN_BITS. |
| 62 | // We don't care about losing the upper bits since we are only interested in the |
| 63 | // difference between both addresses. |
| 64 | const uint64_t bit_addr = |
| 65 | reinterpret_cast<size_t>(data) * 8 + static_cast<uint64_t>(bit_offset); |
| 66 | const uint64_t aligned_bit_addr = bit_util::RoundUpToPowerOf2(bit_addr, ALIGN_IN_BITS); |
| 67 | |
| 68 | p.leading_bits = std::min<int64_t>(length, aligned_bit_addr - bit_addr); |
| 69 | p.aligned_words = (length - p.leading_bits) / ALIGN_IN_BITS; |
| 70 | p.aligned_bits = p.aligned_words * ALIGN_IN_BITS; |
| 71 | p.trailing_bits = length - p.leading_bits - p.aligned_bits; |
| 72 | p.trailing_bit_offset = bit_offset + p.leading_bits + p.aligned_bits; |
| 73 | |
| 74 | p.aligned_start = data + (bit_offset + p.leading_bits) / 8; |
| 75 | return p; |
| 76 | } |
| 77 | } // namespace internal |
| 78 | |
| 79 | namespace util { |
nothing calls this directly
no test coverage detected