Returns ceil(log2(x)).
| 140 | |
| 141 | // Returns ceil(log2(x)). |
| 142 | static inline int Log2(uint64_t x) { |
| 143 | // DCHECK_GT(x, 0); |
| 144 | |
| 145 | // TODO: We can remove this condition once CRAN upgrades its macOS |
| 146 | // SDK from 11.3. |
| 147 | // __apple_build_version__ should be defined only on Apple clang |
| 148 | #if defined(__apple_build_version__) && !defined(__cpp_lib_bitops) |
| 149 | return std::log2p1(x - 1); |
| 150 | #else |
| 151 | return std::bit_width(x - 1); |
| 152 | #endif |
| 153 | } |
| 154 | |
| 155 | // |
| 156 | // Utilities for reading and writing individual bits by their index |