54 #include <type_traits> 65 template <
typename Dst,
typename Src>
70 template <
typename Dst,
typename Src>
85 using S2 =
long long int;
87 static_assert(
sizeof(
T) <=
sizeof(S2),
"over-sized type");
92 return static_cast<unsigned int>(
93 sizeof(
T) <=
sizeof(S0) ? __builtin_ffs(bits_to_signed<S0>(v)) :
94 sizeof(
T) <=
sizeof(S1) ? __builtin_ffsl(bits_to_signed<S1>(v)) :
95 sizeof(
T) <=
sizeof(S2) ? __builtin_ffsll(bits_to_signed<S2>(v)) :
104 template <
typename T>
106 using U0 =
unsigned int;
107 using U1 =
unsigned long int;
108 using U2 =
unsigned long long int;
110 static_assert(
sizeof(
T) <=
sizeof(U2),
"over-sized type");
118 return v ? 1u +
static_cast<unsigned int>((8u *
size{} - 1u) ^ (
119 sizeof(
T) <=
sizeof(U0) ? __builtin_clz(bits_to_unsigned<U0>(v)) :
120 sizeof(
T) <=
sizeof(U1) ? __builtin_clzl(bits_to_unsigned<U1>(v)) :
121 sizeof(
T) <=
sizeof(U2) ? __builtin_clzll(bits_to_unsigned<U2>(v)) :
129 template <
typename T>
131 using U0 =
unsigned int;
132 using U1 =
unsigned long int;
133 using U2 =
unsigned long long int;
135 static_assert(
sizeof(
T) <=
sizeof(U2),
"over-sized type");
140 return static_cast<unsigned int>(
141 sizeof(
T) <=
sizeof(U0) ? __builtin_popcount(bits_to_unsigned<U0>(v)) :
142 sizeof(
T) <=
sizeof(U1) ? __builtin_popcountl(bits_to_unsigned<U1>(v)) :
143 sizeof(
T) <=
sizeof(U2) ? __builtin_popcountll(bits_to_unsigned<U2>(v)) :
165 return (v != 0) && !(v & (v - 1));
173 template <
size_t Size>
176 #define FB_GEN(sz, fn) \ 177 static inline uint##sz##_t byteswap_gen(uint##sz##_t v) { \ 181 struct uint_types_by_size<sz / 8> { \ 182 using type = uint##sz##_t; \ 187 FB_GEN(64, _byteswap_uint64)
188 FB_GEN(32, _byteswap_ulong)
189 FB_GEN(16, _byteswap_ushort)
192 FB_GEN(32, __builtin_bswap32)
193 FB_GEN(16, __builtin_bswap16)
203 "template type parameter must be non-bool integral or floating point");
207 constexpr
auto s =
sizeof(
T);
210 std::memcpy(&b, &x, s);
212 std::memcpy(&x, &b, s);
231 #define FB_GEN1(fn, t, sz) \ 232 static t fn##sz(t x) { \ 236 #define FB_GEN2(t, sz) \ 237 FB_GEN1(swap, t, sz) \ 238 FB_GEN1(big, t, sz) \ 239 FB_GEN1(little, t, sz) 242 FB_GEN2(uint##sz##_t, sz) \ 243 FB_GEN2(int##sz##_t, sz) 267 #if !defined(__ANDROID__) 279 template <
class T,
class Enable =
void>
299 static_assert(
sizeof(
Unaligned<T>) ==
sizeof(
T),
"Invalid unaligned size");
300 static_assert(
alignof(
Unaligned<T>) == 1,
"Invalid alignment");
305 memcpy(&value, p,
sizeof(
T));
325 auto cp =
static_cast<const char*
>(p);
329 memcpy(&value, cp, l);
336 value =
static_cast<T>(loadUnaligned<uint32_t>(cp + avail)) << (avail * 8);
340 value |=
static_cast<T>(loadUnaligned<uint16_t>(cp + avail)) << (avail * 8);
343 value |= loadUnaligned<uint8_t>(cp);
353 static_assert(
sizeof(
Unaligned<T>) ==
sizeof(
T),
"Invalid unaligned size");
354 static_assert(
alignof(
Unaligned<T>) == 1,
"Invalid alignment");
364 memcpy(p, &value,
sizeof(
T));
368 template <
typename T>
371 m = ((m & 0xAAAAAAAAAAAAAAAA) >> 1) | ((m & 0x5555555555555555) << 1);
372 m = ((m & 0xCCCCCCCCCCCCCCCC) >> 2) | ((m & 0x3333333333333333) << 2);
373 m = ((m & 0xF0F0F0F0F0F0F0F0) >> 4) | ((m & 0x0F0F0F0F0F0F0F0F) << 4);
constexpr unsigned int popcount(T const v)
constexpr bool kHasUnalignedAccess
FOLLY_PACK_PUSH struct folly::Unaligned< T, typename std::enable_if< std::is_pod< T >::value >::type > FOLLY_PACK_ATTR
static uint8_t byteswap_gen(uint8_t v)
constexpr T nextPowTwo(T const v)
BitIterator< BaseIter > findFirstSet(BitIterator< BaseIter >, BitIterator< BaseIter >)
std::integral_constant< std::size_t, I > index_constant
constexpr auto kIsLittleEndian
—— Concurrent Priority Queue Implementation ——
constexpr std::make_unsigned_t< Dst > bits_to_unsigned(Src const s)
constexpr bool isPowTwo(T const v)
constexpr auto to_unsigned(T const &t) -> typename std::make_unsigned< T >::type
constexpr auto size(C const &c) -> decltype(c.size())
constexpr T prevPowTwo(T const v)
T partialLoadUnaligned(const void *p, size_t l)
constexpr std::make_signed_t< Dst > bits_to_signed(Src const s)
static map< string, int > m
constexpr unsigned int findLastSet(T const v)
void storeUnaligned(void *p, T value)
static const char *const value
constexpr auto to_signed(T const &t) -> typename std::make_signed< T >::type
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
FOLLY_PACK_POP T loadUnaligned(const void *p)
FOLLY_ALWAYS_INLINE void assume(bool cond)
constexpr auto kIsBigEndian