MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / ceil_to_pow_2

Function ceil_to_pow_2

deps/concurrentqueue/concurrentqueue.h:490–504  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

488
489 template<typename T>
490 static inline T ceil_to_pow_2(T x)
491 {
492 static_assert(std::is_integral<T>::value && !std::numeric_limits<T>::is_signed, "ceil_to_pow_2 is intended to be used only with unsigned integer types");
493
494 // Adapted from http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
495 --x;
496 x |= x >> 1;
497 x |= x >> 2;
498 x |= x >> 4;
499 for (std::size_t i = 1; i < sizeof(T); i <<= 1) {
500 x |= x >> (i << 3);
501 }
502 ++x;
503 return x;
504 }
505
506 template<typename T>
507 static inline void swap_relaxed(std::atomic<T>& left, std::atomic<T>& right)

Callers 1

ExplicitProducerMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected