BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlb_bitutil.h
Go to the documentation of this file.
1/// @file bdlb_bitutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlb_bitutil.h -*-C++-*-
8#ifndef INCLUDED_BDLB_BITUTIL
9#define INCLUDED_BDLB_BITUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlb_bitutil bdlb_bitutil
15/// @brief Provide efficient bit-manipulation of `uint32_t`/`uint64_t` values.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlb
19/// @{
20/// @addtogroup bdlb_bitutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlb_bitutil-purpose"> Purpose</a>
25/// * <a href="#bdlb_bitutil-classes"> Classes </a>
26/// * <a href="#bdlb_bitutil-description"> Description </a>
27/// * <a href="#bdlb_bitutil-usage"> Usage </a>
28///
29/// # Purpose {#bdlb_bitutil-purpose}
30/// Provide efficient bit-manipulation of `uint32_t`/`uint64_t` values.
31///
32/// # Classes {#bdlb_bitutil-classes}
33///
34/// - bdlb::BitUtil: namespace for `uint32_t` and `uint64_t` bit-level operations
35///
36/// # Description {#bdlb_bitutil-description}
37/// This component provides a utility `struct`, `bdlb::BitUtil`,
38/// that serves as a namespace for a collection of efficient, bit-level
39/// procedures on 32- and 64-bit unsigned integer types. In particular,
40/// `BitUtil` supplies single bit manipulation, bit counting, and mathematical
41/// functions that can be optimized with bitwise operations.
42///
43/// This component is meant to interoperate cleanly both with fundamental types,
44/// as well as common sized integer type aliases like `bsl::uin64_t` and
45/// `bslsl::Types::UInt64`. An overload set consisting of the fundamental
46/// integer types `unsigned int`, `unsigned long`, and `unsigned long long` is
47/// used to minimize warnings and avoid ambiguity that may arise when dealing
48/// with explicitly sized types that may alias to different fundamental types on
49/// different platforms.
50///
51/// Some of the methods provided in `BitUtil` have other common names. Below is
52/// a list of mappings from the name used in `BitUtil` to these related function
53/// names:
54///
55/// * numLeadingUnsetBits: cntlz, clz, ffs, ffo, nlz, ctlz
56/// * numTrailingUnsetBits: cnttz, ctz, ntz, cttz
57/// * numBitsSet: popcnt, popcount
58///
59/// ## Usage {#bdlb_bitutil-usage}
60///
61///
62/// The following usage examples illustrate how some of the methods provided by
63/// this component are used. Note that, in all of these examples, the low-order
64/// bit is considered bit 0 and resides on the right edge of the bit string.
65///
66/// First, we use `withBitSet` to demonstrate the ordering of bits:
67/// @code
68/// assert(static_cast<uint32_t>(0x00000001)
69/// == bdlb::BitUtil::withBitSet(static_cast<uint32_t>(0), 0));
70/// assert(static_cast<uint32_t>(0x00000008)
71/// == bdlb::BitUtil::withBitSet(static_cast<uint32_t>(0), 3));
72/// assert(static_cast<uint32_t>(0x00800000)
73/// == bdlb::BitUtil::withBitSet(static_cast<uint32_t>(0), 23));
74/// assert(static_cast<uint32_t>(0x66676666)
75/// == bdlb::BitUtil::withBitSet(static_cast<uint32_t>(0x66666666), 16));
76///
77/// /*------------------------------------------------------------------------+
78/// | 'bdlb::BitUtil::withBitSet(0x66666666, 16)' in binary: |
79/// | |
80/// | input in binary: 01100110011001100110011001100110 |
81/// | set bit 16: 1 |
82/// | result: 01100110011001110110011001100110 |
83/// +------------------------------------------------------------------------*/
84/// @endcode
85/// Then, we count the number of set bits in a value with `numBitsSet`:
86/// @code
87/// assert(0 == bdlb::BitUtil::numBitsSet(static_cast<uint32_t>(0x00000000)));
88/// assert(2 == bdlb::BitUtil::numBitsSet(static_cast<uint32_t>(0x00101000)));
89/// assert(8 == bdlb::BitUtil::numBitsSet(static_cast<uint32_t>(0x30071101)));
90///
91/// /*------------------------------------------------------------------------+
92/// | 'bdlb::BitUtil::numBitsSet(0x30071101)' in binary: |
93/// | |
94/// | input in binary: 00110000000001110001000100000001 |
95/// | that has 8 bits set. result: 8 |
96/// +------------------------------------------------------------------------*/
97/// @endcode
98/// Finally, we use `numLeadingUnsetBits` to determine the number of unset bits
99/// with a higher index than the first set bit:
100/// @code
101/// assert(32 ==
102/// bdlb::BitUtil::numLeadingUnsetBits(static_cast<uint32_t>(0x00000000)));
103/// assert(31 ==
104/// bdlb::BitUtil::numLeadingUnsetBits(static_cast<uint32_t>(0x00000001)));
105/// assert(7 ==
106/// bdlb::BitUtil::numLeadingUnsetBits(static_cast<uint32_t>(0x01000000)));
107/// assert(7 ==
108/// bdlb::BitUtil::numLeadingUnsetBits(static_cast<uint32_t>(0x01620030)));
109///
110/// /*------------------------------------------------------------------------+
111/// | 'bdlb::BitUtil::numLeadingUnsetBits(0x01620030)' in binary: |
112/// | |
113/// | input in binary: 00000001011000100000000000110000 |
114/// | highest set bit: 1 |
115/// | number of unset bits leading this set bit == 7 |
116/// +------------------------------------------------------------------------*/
117/// @endcode
118/// @}
119/** @} */
120/** @} */
121
122/** @addtogroup bdl
123 * @{
124 */
125/** @addtogroup bdlb
126 * @{
127 */
128/** @addtogroup bdlb_bitutil
129 * @{
130 */
131
132#include <bdlscm_version.h>
133
134#include <bslmf_conditional.h>
135
136#include <bsls_assert.h>
137#include <bsls_performancehint.h>
138#include <bsls_platform.h>
139#include <bsls_review.h>
140
141#include <bsl_climits.h>
142#include <bsl_cstdint.h>
143
144#if defined(BSLS_PLATFORM_CMP_GNU) || defined(BSLS_PLATFORM_CMP_CLANG)
145/// Use optimal intrinsics that know about CPU instruction sets on compilers
146/// the recognize the Gnu intrinsic spellings.
147# define BDLB_BITUTIL_USE_GNU_INTRINSICS 1
148#endif
149
150#ifdef BSLS_PLATFORM_CMP_MSVC
151#include <intrin.h>
152# define BDLB_BITUTIL_USE_MSVC_INTRINSICS 1
153 // Use the intrinsics that map directly to CPU instructions on MSVC
154
155# if defined(BSLS_PLATFORM_CPU_ARM)
156# define BDLB_BITUTIL_USE_MSVC_COUNT_ONE_BITS 1
157 // Use _CountOneBits instead of __popcnt intrinsics on MSVC
158# endif
159
160#endif
161
162
163namespace bdlb {
164
165 // ==============
166 // struct BitUtil
167 // ==============
168
169/// This utility `struct` provides a namespace for a set of bit-level,
170/// stateless functions that operate on the built-in 32- and 64-bit unsigned
171/// integer types.
172///
173/// See @ref bdlb_bitutil
174struct BitUtil {
175
176 private:
177 // PRIVATE CONSTANTS
178 enum {
179 k_BITS_PER_INT32 = 32, // bits used to represent an 'int32_t'
180 k_BITS_PER_INT64 = 64 // bits used to represent an 'int64_t'
181 };
182
183 public:
184 // PUBLIC TYPE ALIASES (to support old toolchains)
185 typedef bsl::uint32_t uint32_t;
186 typedef bsl::uint64_t uint64_t;
187
188 private:
189 // PRIVATE TYPES
190 typedef bsl::conditional<sizeof(unsigned long) == sizeof(unsigned int),
191 unsigned int,
192 unsigned long long>::type ULongLikeType;
193
194 // PRIVATE CLASS METHODS
195
196 /// Convert the specified `value` from `unsigned long` to another
197 /// unsigned type of the same size - `unsigned int` or
198 /// `unsigned long long`.
199 static ULongLikeType normalize(unsigned long value);
200
201 /// Return the number of 1 bits in the specified `value`.
202 static int privateNumBitsSet(unsigned int value);
203 static int privateNumBitsSet(unsigned long value);
204 static int privateNumBitsSet(unsigned long long value);
205
206 /// Return the number of consecutive 0 bits starting from the
207 /// most-significant bit in the specified `value`.
208 static int privateNumLeadingUnsetBits(unsigned int value);
209 static int privateNumLeadingUnsetBits(unsigned long value);
210 static int privateNumLeadingUnsetBits(unsigned long long value);
211
212 /// Return the number of consecutive 0 bits starting from the
213 /// least-significant bit in the specified `value`.
214 static int privateNumTrailingUnsetBits(unsigned int value);
215 static int privateNumTrailingUnsetBits(unsigned long value);
216 static int privateNumTrailingUnsetBits(unsigned long long value);
217
218 public:
219 // CLASS METHODS
220
221 /// Return `true` if the bit in the specified `value` at the specified
222 /// `index` is set to 1, and `false` otherwise.
223 ///
224 /// \pre The behavior is undefined unless `0 <= index < sizeInBits(value)`.
225 static bool isBitSet(unsigned int value, int index);
226 static bool isBitSet(unsigned long value, int index);
227 static bool isBitSet(unsigned long long value, int index);
228
229 /// Return the base-2 logarithm of the specified `value` rounded up to the nearest integer.
230 ///
231 /// \pre The behavior is undefined unless `0 < value`.
232 static int log2(unsigned int value);
233 static int log2(unsigned long value);
234 static int log2(unsigned long long value);
235
236 /// Return the number of 1 bits in the specified `value`.
237 static int numBitsSet(unsigned int value);
238 static int numBitsSet(unsigned long value);
239 static int numBitsSet(unsigned long long value);
240
241 /// Return the number of consecutive 0 bits starting from the
242 /// most-significant bit in the specified `value`.
243 static int numLeadingUnsetBits(unsigned int value);
244 static int numLeadingUnsetBits(unsigned long value);
245 static int numLeadingUnsetBits(unsigned long long value);
246
247 /// Return the number of consecutive 0 bits starting from the
248 /// least-significant bit in the specified `value`.
249 static int numTrailingUnsetBits(unsigned int value);
250 static int numTrailingUnsetBits(unsigned long value);
251 static int numTrailingUnsetBits(unsigned long long value);
252
253 /// Return the least multiple of the specified `boundary` that is
254 /// greater than or equal to the specified `value`, and 0 if
255 /// `0 == value` or the conversion was not successful.
256 ///
257 /// \pre The behavior is undefined unless `1 == numBitsSet(boundary)`.
258 /// \note Note that the
259 /// conversion will succeed if and only if `0 == value % boundary` or
260 /// `(1 << sizeInBits(value)) > (value / boundary + 1) * boundary`.
261 static unsigned int roundUp(unsigned int value, unsigned int boundary);
262 static unsigned long roundUp(unsigned long value, unsigned long boundary);
263 static unsigned long long roundUp(unsigned long long value,
264 unsigned long long boundary);
265
266 /// Return the least power of 2 that is greater than or equal to the
267 /// specified `value`, and 0 if the conversion was not successful.
268 ///
269 /// \note Note that the conversion will succeed if and only if
270 /// `0 < value <= (1 << (sizeInBits(value) - 1))`
271 static unsigned int roundUpToBinaryPower(unsigned int value);
272 static unsigned long roundUpToBinaryPower(unsigned long value);
273 static unsigned long long roundUpToBinaryPower(unsigned long long value);
274
275 /// Return the number of bits in the specified `value` of the (template
276 /// parameter) type `INTEGER`.
277 template <class INTEGER>
278 static int sizeInBits(INTEGER value = 0);
279
280 /// Return the result of replacing the bit at the specified `index` in
281 /// the specified `value` with 0, transferring all other bits from `value` unchanged.
282 ///
283 /// \pre The behavior is undefined unless
284 /// `0 <= index < sizeInBits(value)`.
285 static unsigned int withBitCleared(unsigned int value, int index);
286 static unsigned long withBitCleared(unsigned long value, int index);
287 static unsigned long long withBitCleared(unsigned long long value,
288 int index);
289
290 /// Return the result of replacing the bit at the specified `index` in
291 /// the specified `value` with 1, transferring all other bits from `value` unchanged.
292 ///
293 /// \pre The behavior is undefined unless
294 /// `0 <= index < sizeInBits(value)`.
295 static unsigned int withBitSet(unsigned int value, int index);
296 static unsigned long withBitSet(unsigned long value, int index);
297 static unsigned long long withBitSet(unsigned long long value, int index);
298};
299
300// ============================================================================
301// INLINE FUNCTION DEFINITIONS
302// ============================================================================
303
304 // --------------
305 // struct BitUtil
306 // --------------
307
308// CLASS METHODS
309inline
310BitUtil::ULongLikeType BitUtil::normalize(unsigned long value)
311{
312 return static_cast<ULongLikeType>(value);
313}
314
315inline
316bool BitUtil::isBitSet(unsigned int value, int index)
317{
318 BSLS_ASSERT_SAFE( 0 <= index);
319 BSLS_ASSERT_SAFE(index < k_BITS_PER_INT32);
320
321 return ((1 << index) & value) != 0;
322}
323
324inline
325bool BitUtil::isBitSet(unsigned long long value, int index)
326{
327 BSLS_ASSERT_SAFE( 0 <= index);
328 BSLS_ASSERT_SAFE(index < k_BITS_PER_INT64);
329
330 return ((1ULL << index) & value) != 0;
331}
332
333inline
334bool BitUtil::isBitSet(unsigned long value, int index)
335{
336 return isBitSet(normalize(value), index);
337}
338
339inline
340int BitUtil::log2(unsigned int value)
341{
342 BSLS_ASSERT(0 < value);
343
344 return k_BITS_PER_INT32 - numLeadingUnsetBits(value - 1);
345}
346
347inline
348int BitUtil::log2(unsigned long long value)
349{
350 BSLS_ASSERT(0ULL < value);
351
352 return k_BITS_PER_INT64 - numLeadingUnsetBits(value - 1);
353}
354
355inline
356int BitUtil::log2(unsigned long value)
357{
358 return log2(normalize(value));
359}
360
361inline
362int BitUtil::numBitsSet(unsigned int value)
363{
364#if defined(BDLB_BITUTIL_USE_GNU_INTRINSICS)
365 return __builtin_popcount(value);
366#elif defined(BDLB_BITUTIL_USE_MSVC_INTRINSICS)
367# if !defined(BDLB_BITUTIL_USE_MSVC_COUNT_ONE_BITS)
368 return __popcnt(value);
369# else
370 return _CountOneBits(value);
371# endif
372#else
373 return privateNumBitsSet(value);
374#endif
375}
376
377inline
378int BitUtil::numBitsSet(unsigned long long value)
379{
380#if defined(BDLB_BITUTIL_USE_GNU_INTRINSICS)
381 return __builtin_popcountll(value);
382#elif defined(BDLB_BITUTIL_USE_MSVC_INTRINSICS)
383 #if !defined(BDLB_BITUTIL_USE_MSVC_COUNT_ONE_BITS)
384 #if defined(BSLS_PLATFORM_CPU_64_BIT)
385 return static_cast<int>(__popcnt64(value));
386 #else
387 // '__popcnt64' available only in 64bit target
388 return __popcnt(static_cast<unsigned int>(value)) +
389 __popcnt(static_cast<unsigned int>(value >>
390 k_BITS_PER_INT32));
391 #endif
392 #else
393 return _CountOneBits64(value);
394 #endif
395#else
396 return privateNumBitsSet(value);
397#endif
398}
399
400inline
401int BitUtil::numBitsSet(unsigned long value)
402{
403 return numBitsSet(normalize(value));
404}
405
406inline
407int BitUtil::numLeadingUnsetBits(unsigned int value)
408{
409#if defined(BDLB_BITUTIL_USE_GNU_INTRINSICS)
410 // '__builtin_clz(0)' is undefined
411 return __builtin_clz(value | 1) + static_cast<int>(!value);
412#elif defined(BDLB_BITUTIL_USE_MSVC_INTRINSICS)
413 // '_BitScanReverse(&index, 0)' sets 'index' to an unspecified value
414 unsigned long index;
415 return _BitScanReverse(&index, value)
416 ? k_BITS_PER_INT32 - 1 - index
417 : k_BITS_PER_INT32;
418#else
419 return privateNumLeadingUnsetBits(value);
420#endif
421}
422
423inline
424int BitUtil::numLeadingUnsetBits(unsigned long long value)
425{
426#if defined(BDLB_BITUTIL_USE_GNU_INTRINSICS)
427 // '__builtin_clzll(0)' is undefined
428 return __builtin_clzll(value | 1) + static_cast<int>(!value);
429#elif defined(BDLB_BITUTIL_USE_MSVC_INTRINSICS)
430 #if defined(BSLS_PLATFORM_CPU_64_BIT)
431 // '_BitScanReverse64(&index, 0)' sets 'index' to an unspecified value
432 unsigned long index;
433 return _BitScanReverse64(&index, value)
434 ? k_BITS_PER_INT64 - 1 - index
435 : k_BITS_PER_INT64;
436 #else
437 // '_BitScanReverse64' available only in 64bit target
438 return value > 0xffffffff
439 ? numLeadingUnsetBits(static_cast<unsigned int>(
440 value >> k_BITS_PER_INT32))
441 : numLeadingUnsetBits(static_cast<unsigned int>(value))
442 + k_BITS_PER_INT32;
443 #endif
444#else
445 return privateNumLeadingUnsetBits(value);
446#endif
447}
448
449inline
450int BitUtil::numLeadingUnsetBits(unsigned long value)
451{
452 return numLeadingUnsetBits(normalize(value));
453}
454
455inline
456int BitUtil::numTrailingUnsetBits(unsigned int value)
457{
458#if defined(BDLB_BITUTIL_USE_GNU_INTRINSICS)
459 enum {
460 k_INT32_MASK = k_BITS_PER_INT32 - 1
461 };
462 const unsigned int a = __builtin_ffs(value) - 1;
463 return (a & k_INT32_MASK) + (a >> k_INT32_MASK);
464
465 // Other possibility:
466 //..
467 // return (__builtin_ffs(value) - 1) ^ ((-!value) & ~k_BITS_PER_INT32);
468 //..
469#elif defined(BDLB_BITUTIL_USE_MSVC_INTRINSICS)
470 // '_BitScanForward(&index, 0)' sets 'index' to an unspecified value
471 unsigned long index;
472 return _BitScanForward(&index, value) ? index : k_BITS_PER_INT32;
473#else
474 return privateNumTrailingUnsetBits(value);
475#endif
476}
477
478inline
479int BitUtil::numTrailingUnsetBits(unsigned long long value)
480{
481#if defined(BDLB_BITUTIL_USE_GNU_INTRINSICS)
482 enum {
483 k_INT64_MASK = k_BITS_PER_INT64 - 1,
484 k_INT32_MASK = k_BITS_PER_INT32 - 1
485 };
486 const unsigned int a = __builtin_ffsll(value) - 1;
487 return (a & k_INT64_MASK) + (a >> k_INT32_MASK);
488
489 // Other possibility:
490 //..
491 // return (__builtin_ffsll(value) - 1) ^ ((-!value) & ~k_BITS_PER_INT64);
492 //..
493#elif defined(BDLB_BITUTIL_USE_MSVC_INTRINSICS)
494 #if defined(BSLS_PLATFORM_CPU_64_BIT)
495 // '_BitScanForward64(&index, 0)' sets 'index' to an unspecified value
496 unsigned long index;
497 return _BitScanForward64(&index, value) ? index : k_BITS_PER_INT64;
498 #else
499 // '_BitScanForward64' available only in 64bit target
500 return 0 != (value & 0xffffffff)
501 ? numTrailingUnsetBits(static_cast<unsigned int>(value))
502 : numTrailingUnsetBits(static_cast<unsigned int>(
503 value >> k_BITS_PER_INT32)) + k_BITS_PER_INT32;
504 #endif
505#else
506 return privateNumTrailingUnsetBits(value);
507#endif
508}
509
510inline
511int BitUtil::numTrailingUnsetBits(unsigned long value)
512{
513 return numTrailingUnsetBits(normalize(value));
514}
515
516inline
517unsigned int BitUtil::roundUp(unsigned int value, unsigned int boundary)
518{
519 BSLS_ASSERT(1 == numBitsSet(boundary));
520
521 return ((value - 1) | (boundary - 1)) + 1;
522}
523
524inline
525unsigned long long BitUtil::roundUp(unsigned long long value,
526 unsigned long long boundary)
527{
528 BSLS_ASSERT(1 == numBitsSet(boundary));
529
530 return ((value - 1) | (boundary - 1)) + 1;
531}
532
533inline
534unsigned long BitUtil::roundUp(unsigned long value, unsigned long boundary)
535{
536 return roundUp(normalize(value), normalize(boundary));
537}
538
539inline
540unsigned int BitUtil::roundUpToBinaryPower(unsigned int value)
541{
542 const int index = numLeadingUnsetBits(value - 1);
544 ? 1U << (k_BITS_PER_INT32 - index)
545 : 0;
546}
547
548inline
549unsigned long long BitUtil::roundUpToBinaryPower(unsigned long long value)
550{
551 const int index = numLeadingUnsetBits(value - 1);
553 ? 1ULL << (k_BITS_PER_INT64 - index)
554 : 0;
555}
556
557inline
558unsigned long BitUtil::roundUpToBinaryPower(unsigned long value)
559{
560 return roundUpToBinaryPower(normalize(value));
561}
562
563template <class TYPE>
564inline
566{
567 return static_cast<int>(CHAR_BIT * sizeof(TYPE));
568}
569
570inline
571unsigned int BitUtil::withBitCleared(unsigned int value, int index)
572{
573 BSLS_ASSERT( 0 <= index);
574 BSLS_ASSERT(index < k_BITS_PER_INT32);
575
576 return value & ~(1 << index);
577}
578
579inline
580unsigned long long BitUtil::withBitCleared(unsigned long long value, int index)
581{
582 BSLS_ASSERT( 0 <= index);
583 BSLS_ASSERT(index < k_BITS_PER_INT64);
584
585 return value & ~(1ULL << index);
586}
587
588inline
589unsigned long BitUtil::withBitCleared(unsigned long value, int index)
590{
591 return withBitCleared(normalize(value), index);
592}
593
594inline
595unsigned int BitUtil::withBitSet(unsigned int value, int index)
596{
597 BSLS_ASSERT( 0 <= index);
598 BSLS_ASSERT(index < k_BITS_PER_INT32);
599
600 return value | (1 << index);
601}
602
603inline
604unsigned long long BitUtil::withBitSet(unsigned long long value, int index)
605{
606 BSLS_ASSERT( 0 <= index);
607 BSLS_ASSERT(index < k_BITS_PER_INT64);
608
609 return value | (1ULL << index);
610}
611
612inline
613unsigned long BitUtil::withBitSet(unsigned long value, int index)
614{
615 return withBitSet(normalize(value), index);
616}
617
618} // close package namespace
619
620
621#endif
622
623// ----------------------------------------------------------------------------
624// Copyright 2014 Bloomberg Finance L.P.
625//
626// Licensed under the Apache License, Version 2.0 (the "License");
627// you may not use this file except in compliance with the License.
628// You may obtain a copy of the License at
629//
630// http://www.apache.org/licenses/LICENSE-2.0
631//
632// Unless required by applicable law or agreed to in writing, software
633// distributed under the License is distributed on an "AS IS" BASIS,
634// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
635// See the License for the specific language governing permissions and
636// limitations under the License.
637// ----------------------------- END-OF-FILE ----------------------------------
638
639/** @} */
640/** @} */
641/** @} */
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_PERFORMANCEHINT_PREDICT_LIKELY(expr)
Definition bsls_performancehint.h:451
Definition bdlb_algorithmworkaroundutil.h:74
Definition bdlb_bitutil.h:174
static int numTrailingUnsetBits(unsigned int value)
Definition bdlb_bitutil.h:456
static unsigned int withBitSet(unsigned int value, int index)
Definition bdlb_bitutil.h:595
static int numLeadingUnsetBits(unsigned int value)
Definition bdlb_bitutil.h:407
static unsigned int withBitCleared(unsigned int value, int index)
Definition bdlb_bitutil.h:571
static int log2(unsigned int value)
Definition bdlb_bitutil.h:340
static int numBitsSet(unsigned int value)
Return the number of 1 bits in the specified value.
Definition bdlb_bitutil.h:362
static unsigned int roundUp(unsigned int value, unsigned int boundary)
Definition bdlb_bitutil.h:517
bsl::uint64_t uint64_t
Definition bdlb_bitutil.h:186
static unsigned int roundUpToBinaryPower(unsigned int value)
Definition bdlb_bitutil.h:540
bsl::uint32_t uint32_t
Definition bdlb_bitutil.h:185
static bool isBitSet(unsigned int value, int index)
Definition bdlb_bitutil.h:316
static int sizeInBits(INTEGER value=0)
Definition bslmf_conditional.h:123
Definition bslmf_integralconstant.h:261