19 #include <glog/logging.h> 22 #include <immintrin.h> 31 namespace compression {
32 namespace instructions {
47 return uint64_t(__builtin_popcountll(value));
51 return __builtin_ctzll(value);
55 return __builtin_clzll(value);
58 return value & (value - 1);
69 if (start + length > 64) {
73 return (value >> start) &
74 ((length == 64) ? (~0ULL) : ((1ULL << length) - 1ULL));
82 return value & ((
uint64_t(1) << index) - 1);
88 return cpuId.popcnt();
93 #if defined(__GNUC__) || defined(__clang__) 96 asm(
"popcntq %1, %0" :
"=r"(result) :
"r"(value));
99 return uint64_t(_mm_popcnt_u64(value));
112 #if defined(__GNUC__) || defined(__clang__) 115 asm(
"blsrq %1, %0" :
"=r"(result) :
"r"(value));
118 return _blsr_u64(value);
124 #if defined(__GNUC__) || defined(__clang__) 130 pattern = pattern | ((length & 0xFF) << 8);
132 asm(
"bextrq %2, %1, %0" :
"=r"(result) :
"r"(value),
"r"(pattern));
135 return _bextr_u64(value, start, length);
140 #if defined(__GNUC__) || defined(__clang__) 144 asm(
"bzhiq %2, %1, %0" :
"=r"(result) :
"r"(value),
"r"(index64));
147 return _bzhi_u64(value, index);
161 VLOG(2) <<
"Will use folly::compression::instructions::Haswell";
164 VLOG(2) <<
"Will use folly::compression::instructions::Nehalem";
167 VLOG(2) <<
"Will use folly::compression::instructions::Default";
189 auto dispatch(F&&
f) -> decltype(
f(std::declval<Default>())) {
#define FOLLY_ALWAYS_INLINE
static FOLLY_ALWAYS_INLINE uint64_t popcount(uint64_t value)
static FOLLY_ALWAYS_INLINE uint64_t blsr(uint64_t value)
—— Concurrent Priority Queue Implementation ——
static FOLLY_ALWAYS_INLINE uint64_t bextr(uint64_t value, uint32_t start, uint32_t length)
static FOLLY_ALWAYS_INLINE int clz(uint64_t value)
static FOLLY_ALWAYS_INLINE int ctz(uint64_t value)
FOLLY_ALWAYS_INLINE void assume_unreachable()
static bool supported(const folly::CpuId &cpuId={})
static FOLLY_ALWAYS_INLINE uint64_t bzhi(uint64_t value, uint32_t index)
static FOLLY_ALWAYS_INLINE uint64_t bzhi(uint64_t value, uint32_t index)
static bool supported(const folly::CpuId &cpuId={})
auto dispatch(Type type, F &&f) -> decltype(f(std::declval< Default >()))
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
static FOLLY_ALWAYS_INLINE uint64_t bextr(uint64_t value, uint32_t start, uint32_t length)
static FOLLY_ALWAYS_INLINE uint64_t blsr(uint64_t value)
static bool supported(const folly::CpuId &={})
static FOLLY_ALWAYS_INLINE uint64_t popcount(uint64_t value)