• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_LIBARTBASE_BASE_BIT_UTILS_H_
18 #define ART_LIBARTBASE_BASE_BIT_UTILS_H_
19 
20 #include <limits>
21 #include <type_traits>
22 
23 #include <android-base/logging.h>
24 
25 #include "globals.h"
26 #include "stl_util_identity.h"
27 
28 namespace art {
29 
30 // Like sizeof, but count how many bits a type takes. Pass type explicitly.
31 template <typename T>
BitSizeOf()32 constexpr size_t BitSizeOf() {
33   static_assert(std::is_integral_v<T>, "T must be integral");
34   using unsigned_type = std::make_unsigned_t<T>;
35   static_assert(sizeof(T) == sizeof(unsigned_type), "Unexpected type size mismatch!");
36   static_assert(std::numeric_limits<unsigned_type>::radix == 2, "Unexpected radix!");
37   return std::numeric_limits<unsigned_type>::digits;
38 }
39 
40 // Like sizeof, but count how many bits a type takes. Infers type from parameter.
41 template <typename T>
BitSizeOf(T)42 constexpr size_t BitSizeOf(T /*x*/) {
43   return BitSizeOf<T>();
44 }
45 
46 template<typename T>
CLZ(T x)47 constexpr int CLZ(T x) {
48   static_assert(std::is_integral_v<T>, "T must be integral");
49   static_assert(std::is_unsigned_v<T>, "T must be unsigned");
50   static_assert(std::numeric_limits<T>::radix == 2, "Unexpected radix!");
51   static_assert(sizeof(T) == sizeof(uint64_t) || sizeof(T) <= sizeof(uint32_t),
52                 "Unsupported sizeof(T)");
53   DCHECK_NE(x, 0u);
54   constexpr bool is_64_bit = (sizeof(T) == sizeof(uint64_t));
55   constexpr size_t adjustment =
56       is_64_bit ? 0u : std::numeric_limits<uint32_t>::digits - std::numeric_limits<T>::digits;
57   return is_64_bit ? __builtin_clzll(x) : __builtin_clz(x) - adjustment;
58 }
59 
60 // Similar to CLZ except that on zero input it returns bitwidth and supports signed integers.
61 template<typename T>
JAVASTYLE_CLZ(T x)62 constexpr int JAVASTYLE_CLZ(T x) {
63   static_assert(std::is_integral_v<T>, "T must be integral");
64   using unsigned_type = std::make_unsigned_t<T>;
65   return (x == 0) ? BitSizeOf<T>() : CLZ(static_cast<unsigned_type>(x));
66 }
67 
68 template<typename T>
CTZ(T x)69 constexpr int CTZ(T x) {
70   static_assert(std::is_integral_v<T>, "T must be integral");
71   // It is not unreasonable to ask for trailing zeros in a negative number. As such, do not check
72   // that T is an unsigned type.
73   static_assert(sizeof(T) == sizeof(uint64_t) || sizeof(T) <= sizeof(uint32_t),
74                 "Unsupported sizeof(T)");
75   DCHECK_NE(x, static_cast<T>(0));
76   return (sizeof(T) == sizeof(uint64_t)) ? __builtin_ctzll(x) : __builtin_ctz(x);
77 }
78 
79 // Similar to CTZ except that on zero input it returns bitwidth and supports signed integers.
80 template<typename T>
JAVASTYLE_CTZ(T x)81 constexpr int JAVASTYLE_CTZ(T x) {
82   static_assert(std::is_integral_v<T>, "T must be integral");
83   using unsigned_type = std::make_unsigned_t<T>;
84   return (x == 0) ? BitSizeOf<T>() : CTZ(static_cast<unsigned_type>(x));
85 }
86 
87 // Return the number of 1-bits in `x`.
88 template<typename T>
POPCOUNT(T x)89 constexpr int POPCOUNT(T x) {
90   return (sizeof(T) == sizeof(uint32_t)) ? __builtin_popcount(x) : __builtin_popcountll(x);
91 }
92 
93 // Swap bytes.
94 template<typename T>
BSWAP(T x)95 constexpr T BSWAP(T x) {
96   if (sizeof(T) == sizeof(uint16_t)) {
97     return __builtin_bswap16(x);
98   } else if (sizeof(T) == sizeof(uint32_t)) {
99     return __builtin_bswap32(x);
100   } else {
101     return __builtin_bswap64(x);
102   }
103 }
104 
105 // Find the bit position of the most significant bit (0-based), or -1 if there were no bits set.
106 template <typename T>
MostSignificantBit(T value)107 constexpr ssize_t MostSignificantBit(T value) {
108   static_assert(std::is_integral_v<T>, "T must be integral");
109   static_assert(std::is_unsigned_v<T>, "T must be unsigned");
110   static_assert(std::numeric_limits<T>::radix == 2, "Unexpected radix!");
111   return (value == 0) ? -1 : std::numeric_limits<T>::digits - 1 - CLZ(value);
112 }
113 
114 // Find the bit position of the least significant bit (0-based), or -1 if there were no bits set.
115 template <typename T>
LeastSignificantBit(T value)116 constexpr ssize_t LeastSignificantBit(T value) {
117   static_assert(std::is_integral_v<T>, "T must be integral");
118   static_assert(std::is_unsigned_v<T>, "T must be unsigned");
119   return (value == 0) ? -1 : CTZ(value);
120 }
121 
122 // How many bits (minimally) does it take to store the constant 'value'? i.e. 1 for 1, 3 for 5, etc.
123 template <typename T>
MinimumBitsToStore(T value)124 constexpr size_t MinimumBitsToStore(T value) {
125   return static_cast<size_t>(MostSignificantBit(value) + 1);
126 }
127 
128 template <typename T>
RoundUpToPowerOfTwo(T x)129 constexpr T RoundUpToPowerOfTwo(T x) {
130   static_assert(std::is_integral_v<T>, "T must be integral");
131   static_assert(std::is_unsigned_v<T>, "T must be unsigned");
132   // NOTE: Undefined if x > (1 << (std::numeric_limits<T>::digits - 1)).
133   return (x < 2u) ? x : static_cast<T>(1u) << (std::numeric_limits<T>::digits - CLZ(x - 1u));
134 }
135 
136 // Return highest possible N - a power of two - such that val >= N.
137 template <typename T>
TruncToPowerOfTwo(T val)138 constexpr T TruncToPowerOfTwo(T val) {
139   static_assert(std::is_integral_v<T>, "T must be integral");
140   static_assert(std::is_unsigned_v<T>, "T must be unsigned");
141   return (val != 0) ? static_cast<T>(1u) << (BitSizeOf<T>() - CLZ(val) - 1u) : 0;
142 }
143 
144 template<typename T>
IsPowerOfTwo(T x)145 constexpr bool IsPowerOfTwo(T x) {
146   static_assert(std::is_integral_v<T>, "T must be integral");
147   // TODO: assert unsigned. There is currently many uses with signed values.
148   return (x & (x - 1)) == 0;
149 }
150 
151 template<typename T>
WhichPowerOf2(T x)152 constexpr int WhichPowerOf2(T x) {
153   static_assert(std::is_integral_v<T>, "T must be integral");
154   // TODO: assert unsigned. There is currently many uses with signed values.
155   DCHECK((x != 0) && IsPowerOfTwo(x));
156   return CTZ(x);
157 }
158 
159 // For rounding integers.
160 // Note: Omit the `n` from T type deduction, deduce only from the `x` argument.
161 template<typename T>
162 constexpr T RoundDown(T x, typename Identity<T>::type n) WARN_UNUSED;
163 
164 template<typename T>
RoundDown(T x,typename Identity<T>::type n)165 constexpr T RoundDown(T x, typename Identity<T>::type n) {
166   DCHECK(IsPowerOfTwo(n));
167   return (x & -n);
168 }
169 
170 template<typename T>
171 constexpr T RoundUp(T x, std::remove_reference_t<T> n) WARN_UNUSED;
172 
173 template<typename T>
RoundUp(T x,std::remove_reference_t<T> n)174 constexpr T RoundUp(T x, std::remove_reference_t<T> n) {
175   return RoundDown(x + n - 1, n);
176 }
177 
178 template<bool kRoundUp, typename T>
CondRoundUp(T x,std::remove_reference_t<T> n)179 constexpr T CondRoundUp(T x, std::remove_reference_t<T> n) {
180   if (kRoundUp) {
181     return RoundUp(x, n);
182   } else {
183     return x;
184   }
185 }
186 
187 // For aligning pointers.
188 template<typename T>
189 inline T* AlignDown(T* x, uintptr_t n) WARN_UNUSED;
190 
191 template<typename T>
AlignDown(T * x,uintptr_t n)192 inline T* AlignDown(T* x, uintptr_t n) {
193   return reinterpret_cast<T*>(RoundDown(reinterpret_cast<uintptr_t>(x), n));
194 }
195 
196 template<typename T>
197 inline T* AlignUp(T* x, uintptr_t n) WARN_UNUSED;
198 
199 template<typename T>
AlignUp(T * x,uintptr_t n)200 inline T* AlignUp(T* x, uintptr_t n) {
201   return reinterpret_cast<T*>(RoundUp(reinterpret_cast<uintptr_t>(x), n));
202 }
203 
204 template<int n, typename T>
IsAligned(T x)205 constexpr bool IsAligned(T x) {
206   static_assert((n & (n - 1)) == 0, "n is not a power of two");
207   return (x & (n - 1)) == 0;
208 }
209 
210 template<int n, typename T>
IsAligned(T * x)211 inline bool IsAligned(T* x) {
212   return IsAligned<n>(reinterpret_cast<const uintptr_t>(x));
213 }
214 
215 template<typename T>
IsAlignedParam(T x,int n)216 inline bool IsAlignedParam(T x, int n) {
217   return (x & (n - 1)) == 0;
218 }
219 
220 template<typename T>
IsAlignedParam(T * x,int n)221 inline bool IsAlignedParam(T* x, int n) {
222   return IsAlignedParam(reinterpret_cast<const uintptr_t>(x), n);
223 }
224 
225 #define CHECK_ALIGNED(value, alignment) \
226   CHECK(::art::IsAligned<alignment>(value)) << reinterpret_cast<const void*>(value)
227 
228 #define DCHECK_ALIGNED(value, alignment) \
229   DCHECK(::art::IsAligned<alignment>(value)) << reinterpret_cast<const void*>(value)
230 
231 #define CHECK_ALIGNED_PARAM(value, alignment) \
232   CHECK(::art::IsAlignedParam(value, alignment)) << reinterpret_cast<const void*>(value)
233 
234 #define DCHECK_ALIGNED_PARAM(value, alignment) \
235   DCHECK(::art::IsAlignedParam(value, alignment)) << reinterpret_cast<const void*>(value)
236 
Low16Bits(uint32_t value)237 inline uint16_t Low16Bits(uint32_t value) {
238   return static_cast<uint16_t>(value);
239 }
240 
High16Bits(uint32_t value)241 inline uint16_t High16Bits(uint32_t value) {
242   return static_cast<uint16_t>(value >> 16);
243 }
244 
Low32Bits(uint64_t value)245 inline uint32_t Low32Bits(uint64_t value) {
246   return static_cast<uint32_t>(value);
247 }
248 
High32Bits(uint64_t value)249 inline uint32_t High32Bits(uint64_t value) {
250   return static_cast<uint32_t>(value >> 32);
251 }
252 
253 // Check whether an N-bit two's-complement representation can hold value.
254 template <typename T>
IsInt(size_t N,T value)255 inline bool IsInt(size_t N, T value) {
256   if (N == BitSizeOf<T>()) {
257     return true;
258   } else {
259     CHECK_LT(0u, N);
260     CHECK_LT(N, BitSizeOf<T>());
261     T limit = static_cast<T>(1) << (N - 1u);
262     return (-limit <= value) && (value < limit);
263   }
264 }
265 
266 template <typename T>
GetIntLimit(size_t bits)267 constexpr T GetIntLimit(size_t bits) {
268   DCHECK_NE(bits, 0u);
269   DCHECK_LT(bits, BitSizeOf<T>());
270   return static_cast<T>(1) << (bits - 1);
271 }
272 
273 template <size_t kBits, typename T>
IsInt(T value)274 constexpr bool IsInt(T value) {
275   static_assert(kBits > 0, "kBits cannot be zero.");
276   static_assert(kBits <= BitSizeOf<T>(), "kBits must be <= max.");
277   static_assert(std::is_signed_v<T>, "Needs a signed type.");
278   // Corner case for "use all bits." Can't use the limits, as they would overflow, but it is
279   // trivially true.
280   return (kBits == BitSizeOf<T>()) ?
281       true :
282       (-GetIntLimit<T>(kBits) <= value) && (value < GetIntLimit<T>(kBits));
283 }
284 
285 template <size_t kBits, typename T>
IsUint(T value)286 constexpr bool IsUint(T value) {
287   static_assert(kBits > 0, "kBits cannot be zero.");
288   static_assert(kBits <= BitSizeOf<T>(), "kBits must be <= max.");
289   static_assert(std::is_integral_v<T>, "Needs an integral type.");
290   // Corner case for "use all bits." Can't use the limits, as they would overflow, but it is
291   // trivially true.
292   // NOTE: To avoid triggering assertion in GetIntLimit(kBits+1) if kBits+1==BitSizeOf<T>(),
293   // use GetIntLimit(kBits)*2u. The unsigned arithmetic works well for us if it overflows.
294   using unsigned_type = std::make_unsigned_t<T>;
295   return (0 <= value) &&
296       (kBits == BitSizeOf<T>() ||
297           (static_cast<unsigned_type>(value) <= GetIntLimit<unsigned_type>(kBits) * 2u - 1u));
298 }
299 
300 template <size_t kBits, typename T>
IsAbsoluteUint(T value)301 constexpr bool IsAbsoluteUint(T value) {
302   static_assert(kBits <= BitSizeOf<T>(), "kBits must be <= max.");
303   static_assert(std::is_integral_v<T>, "Needs an integral type.");
304   using unsigned_type = std::make_unsigned_t<T>;
305   return (kBits == BitSizeOf<T>())
306       ? true
307       : IsUint<kBits>(value < 0
308                       ? static_cast<unsigned_type>(-1 - value) + 1u  // Avoid overflow.
309                       : static_cast<unsigned_type>(value));
310 }
311 
312 // Generate maximum/minimum values for signed/unsigned n-bit integers
313 template <typename T>
MaxInt(size_t bits)314 constexpr T MaxInt(size_t bits) {
315   DCHECK(std::is_unsigned_v<T> || bits > 0u) << "bits cannot be zero for signed.";
316   DCHECK_LE(bits, BitSizeOf<T>());
317   using unsigned_type = std::make_unsigned_t<T>;
318   return bits == BitSizeOf<T>()
319       ? std::numeric_limits<T>::max()
320       : std::is_signed_v<T>
321           ? ((bits == 1u) ? 0 : static_cast<T>(MaxInt<unsigned_type>(bits - 1)))
322           : static_cast<T>(UINT64_C(1) << bits) - static_cast<T>(1);
323 }
324 
325 template <typename T>
MinInt(size_t bits)326 constexpr T MinInt(size_t bits) {
327   DCHECK(std::is_unsigned_v<T> || bits > 0) << "bits cannot be zero for signed.";
328   DCHECK_LE(bits, BitSizeOf<T>());
329   return bits == BitSizeOf<T>()
330       ? std::numeric_limits<T>::min()
331       : std::is_signed_v<T>
332           ? ((bits == 1u) ? -1 : static_cast<T>(-1) - MaxInt<T>(bits))
333           : static_cast<T>(0);
334 }
335 
336 // Returns value with bit set in lowest one-bit position or 0 if 0.  (java.lang.X.lowestOneBit).
337 template <typename kind>
LowestOneBitValue(kind opnd)338 inline static kind LowestOneBitValue(kind opnd) {
339   // Hacker's Delight, Section 2-1
340   return opnd & -opnd;
341 }
342 
343 // Returns value with bit set in hightest one-bit position or 0 if 0.  (java.lang.X.highestOneBit).
344 template <typename T>
HighestOneBitValue(T opnd)345 inline static T HighestOneBitValue(T opnd) {
346   using unsigned_type = std::make_unsigned_t<T>;
347   T res;
348   if (opnd == 0) {
349     res = 0;
350   } else {
351     int bit_position = BitSizeOf<T>() - (CLZ(static_cast<unsigned_type>(opnd)) + 1);
352     res = static_cast<T>(UINT64_C(1) << bit_position);
353   }
354   return res;
355 }
356 
357 // Rotate bits.
358 template <typename T, bool left>
Rot(T opnd,int distance)359 inline static T Rot(T opnd, int distance) {
360   int mask = BitSizeOf<T>() - 1;
361   int unsigned_right_shift = left ? (-distance & mask) : (distance & mask);
362   int signed_left_shift = left ? (distance & mask) : (-distance & mask);
363   using unsigned_type = std::make_unsigned_t<T>;
364   return (static_cast<unsigned_type>(opnd) >> unsigned_right_shift) | (opnd << signed_left_shift);
365 }
366 
367 // TUNING: use rbit for arm/arm64
ReverseBits32(uint32_t opnd)368 inline static uint32_t ReverseBits32(uint32_t opnd) {
369   // Hacker's Delight 7-1
370   opnd = ((opnd >>  1) & 0x55555555) | ((opnd & 0x55555555) <<  1);
371   opnd = ((opnd >>  2) & 0x33333333) | ((opnd & 0x33333333) <<  2);
372   opnd = ((opnd >>  4) & 0x0F0F0F0F) | ((opnd & 0x0F0F0F0F) <<  4);
373   opnd = ((opnd >>  8) & 0x00FF00FF) | ((opnd & 0x00FF00FF) <<  8);
374   opnd = ((opnd >> 16)) | ((opnd) << 16);
375   return opnd;
376 }
377 
378 // TUNING: use rbit for arm/arm64
ReverseBits64(uint64_t opnd)379 inline static uint64_t ReverseBits64(uint64_t opnd) {
380   // Hacker's Delight 7-1
381   opnd = (opnd & 0x5555555555555555L) << 1 | ((opnd >> 1) & 0x5555555555555555L);
382   opnd = (opnd & 0x3333333333333333L) << 2 | ((opnd >> 2) & 0x3333333333333333L);
383   opnd = (opnd & 0x0f0f0f0f0f0f0f0fL) << 4 | ((opnd >> 4) & 0x0f0f0f0f0f0f0f0fL);
384   opnd = (opnd & 0x00ff00ff00ff00ffL) << 8 | ((opnd >> 8) & 0x00ff00ff00ff00ffL);
385   opnd = (opnd << 48) | ((opnd & 0xffff0000L) << 16) | ((opnd >> 16) & 0xffff0000L) | (opnd >> 48);
386   return opnd;
387 }
388 
389 // Create a mask for the least significant "bits"
390 // The returned value is always unsigned to prevent undefined behavior for bitwise ops.
391 //
392 // Given 'bits',
393 // Returns:
394 //                   <--- bits --->
395 // +-----------------+------------+
396 // | 0 ............0 |   1.....1  |
397 // +-----------------+------------+
398 // msb                           lsb
399 template <typename T = size_t>
MaskLeastSignificant(size_t bits)400 inline static constexpr std::make_unsigned_t<T> MaskLeastSignificant(size_t bits) {
401   DCHECK_GE(BitSizeOf<T>(), bits) << "Bits out of range for type T";
402   using unsigned_T = std::make_unsigned_t<T>;
403   if (bits >= BitSizeOf<T>()) {
404     return std::numeric_limits<unsigned_T>::max();
405   } else {
406     auto kOne = static_cast<unsigned_T>(1);  // Do not truncate for T>size_t.
407     return static_cast<unsigned_T>((kOne << bits) - kOne);
408   }
409 }
410 
411 // Clears the bitfield starting at the least significant bit "lsb" with a bitwidth of 'width'.
412 // (Equivalent of ARM BFC instruction).
413 //
414 // Given:
415 //           <-- width  -->
416 // +--------+------------+--------+
417 // | ABC... |  bitfield  | XYZ... +
418 // +--------+------------+--------+
419 //                       lsb      0
420 // Returns:
421 //           <-- width  -->
422 // +--------+------------+--------+
423 // | ABC... | 0........0 | XYZ... +
424 // +--------+------------+--------+
425 //                       lsb      0
426 template <typename T>
BitFieldClear(T value,size_t lsb,size_t width)427 inline static constexpr T BitFieldClear(T value, size_t lsb, size_t width) {
428   DCHECK_GE(BitSizeOf(value), lsb + width) << "Bit field out of range for value";
429   const auto val = static_cast<std::make_unsigned_t<T>>(value);
430   const auto mask = MaskLeastSignificant<T>(width);
431 
432   return static_cast<T>(val & ~(mask << lsb));
433 }
434 
435 // Inserts the contents of 'data' into bitfield of 'value'  starting
436 // at the least significant bit "lsb" with a bitwidth of 'width'.
437 // Note: data must be within range of [MinInt(width), MaxInt(width)].
438 // (Equivalent of ARM BFI instruction).
439 //
440 // Given (data):
441 //           <-- width  -->
442 // +--------+------------+--------+
443 // | ABC... |  bitfield  | XYZ... +
444 // +--------+------------+--------+
445 //                       lsb      0
446 // Returns:
447 //           <-- width  -->
448 // +--------+------------+--------+
449 // | ABC... | 0...data   | XYZ... +
450 // +--------+------------+--------+
451 //                       lsb      0
452 
453 template <typename T, typename T2>
BitFieldInsert(T value,T2 data,size_t lsb,size_t width)454 inline static constexpr T BitFieldInsert(T value, T2 data, size_t lsb, size_t width) {
455   DCHECK_GE(BitSizeOf(value), lsb + width) << "Bit field out of range for value";
456   if (width != 0u) {
457     DCHECK_GE(MaxInt<T2>(width), data) << "Data out of range [too large] for bitwidth";
458     DCHECK_LE(MinInt<T2>(width), data) << "Data out of range [too small] for bitwidth";
459   } else {
460     DCHECK_EQ(static_cast<T2>(0), data) << "Data out of range [nonzero] for bitwidth 0";
461   }
462   const auto data_mask = MaskLeastSignificant<T2>(width);
463   const auto value_cleared = BitFieldClear(value, lsb, width);
464 
465   return static_cast<T>(value_cleared | ((data & data_mask) << lsb));
466 }
467 
468 // Extracts the bitfield starting at the least significant bit "lsb" with a bitwidth of 'width'.
469 // Signed types are sign-extended during extraction. (Equivalent of ARM UBFX/SBFX instruction).
470 //
471 // Given:
472 //           <-- width   -->
473 // +--------+-------------+-------+
474 // |        |   bitfield  |       +
475 // +--------+-------------+-------+
476 //                       lsb      0
477 // (Unsigned) Returns:
478 //                  <-- width   -->
479 // +----------------+-------------+
480 // | 0...        0  |   bitfield  |
481 // +----------------+-------------+
482 //                                0
483 // (Signed) Returns:
484 //                  <-- width   -->
485 // +----------------+-------------+
486 // | S...        S  |   bitfield  |
487 // +----------------+-------------+
488 //                                0
489 // where S is the highest bit in 'bitfield'.
490 template <typename T>
BitFieldExtract(T value,size_t lsb,size_t width)491 inline static constexpr T BitFieldExtract(T value, size_t lsb, size_t width) {
492   DCHECK_GE(BitSizeOf(value), lsb + width) << "Bit field out of range for value";
493   const auto val = static_cast<std::make_unsigned_t<T>>(value);
494 
495   const T bitfield_unsigned =
496       static_cast<T>((val >> lsb) & MaskLeastSignificant<T>(width));
497   if (std::is_signed_v<T>) {
498     // Perform sign extension
499     if (width == 0) {  // Avoid underflow.
500       return static_cast<T>(0);
501     } else if (bitfield_unsigned & (1 << (width - 1))) {  // Detect if sign bit was set.
502       // MSB        <width> LSB
503       // 0b11111...100...000000
504       const auto ones_negmask = ~MaskLeastSignificant<T>(width);
505       return static_cast<T>(bitfield_unsigned | ones_negmask);
506     }
507   }
508   // Skip sign extension.
509   return bitfield_unsigned;
510 }
511 
BitsToBytesRoundUp(size_t num_bits)512 inline static constexpr size_t BitsToBytesRoundUp(size_t num_bits) {
513   return RoundUp(num_bits, kBitsPerByte) / kBitsPerByte;
514 }
515 
516 }  // namespace art
517 
518 #endif  // ART_LIBARTBASE_BASE_BIT_UTILS_H_
519