Sux
Namespaces | Macros | Functions | Variables
common.hpp File Reference
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstring>
#include <inttypes.h>
#include <memory>
#include <x86intrin.h>

Go to the source code of this file.

Namespaces

 sux
 

Macros

#define __STRINGIFY(s)   #s
 
#define STRINGIFY(s)   __STRINGIFY(s)
 
#define likely(x)   __builtin_expect(!!(x), 1)
 
#define unlikely(x)   __builtin_expect(!!(x), 0)
 
#define ONES_STEP_4   (UINT64_C(0x1111111111111111))
 
#define ONES_STEP_8   (UINT64_C(0x0101010101010101))
 
#define ONES_STEP_9   (UINT64_C(1) << 0 | UINT64_C(1) << 9 | UINT64_C(1) << 18 | UINT64_C(1) << 27 | UINT64_C(1) << 36 | UINT64_C(1) << 45 | UINT64_C(1) << 54)
 
#define ONES_STEP_16   (UINT64_C(1) << 0 | UINT64_C(1) << 16 | UINT64_C(1) << 32 | UINT64_C(1) << 48)
 
#define ONES_STEP_32   (UINT64_C(0x0000000100000001))
 
#define MSBS_STEP_4   (UINT64_C(0x8) * ONES_STEP_4)
 
#define MSBS_STEP_8   (UINT64_C(0x80) * ONES_STEP_8)
 
#define MSBS_STEP_9   (UINT64_C(0x100) * ONES_STEP_9)
 
#define MSBS_STEP_16   (UINT64_C(0x8000) * ONES_STEP_16)
 
#define MSBS_STEP_32   (UINT64_C(0x8000000080000000))
 
#define ULEQ_STEP_9(x, y)   (((((((y) | MSBS_STEP_9) - ((x) & ~MSBS_STEP_9)) | (x ^ y)) ^ (x & ~y)) & MSBS_STEP_9) >> 8)
 
#define ULEQ_STEP_16(x, y)   (((((((y) | MSBS_STEP_16) - ((x) & ~MSBS_STEP_16)) | (x ^ y)) ^ (x & ~y)) & MSBS_STEP_16) >> 15)
 

Typedefs

using sux::auint64_t = std::uint64_t __attribute__((__may_alias__))
 
using sux::auint32_t = std::uint32_t __attribute__((__may_alias__))
 
using sux::auint16_t = std::uint16_t __attribute__((__may_alias__))
 
using sux::auint8_t = std::uint8_t __attribute__((__may_alias__))
 

Functions

constexpr size_t sux::ceil_log2_plus1 (size_t n)
 
int sux::ceil_log2 (const uint64_t x)
 
constexpr uint64_t sux::round_pow2 (uint64_t v)
 
int sux::rho (uint64_t word)
 
int sux::lambda (uint64_t word)
 
int sux::lambda_safe (uint64_t word)
 
uint64_t sux::clear_rho (uint64_t word)
 
uint64_t sux::mask_rho (uint64_t word)
 
uint64_t sux::mask_lambda (uint64_t word)
 
uint64_t sux::compact_bitmask (size_t count, size_t pos)
 
uint64_t sux::bitextract (const uint64_t *word, int from, int length)
 
uint64_t sux::byteread (const void *const word, int length)
 
void sux::bytewrite (void *const word, int length, uint64_t val)
 
void sux::bytewrite_inc (void *const word, uint64_t inc)
 
uint64_t sux::bitread (const void *const word, int from, int length)
 
void sux::bitwrite (void *word, int from, int length, uint64_t val)
 
void sux::bitwrite_inc (void *const word, int from, int length, uint64_t inc)
 
int sux::nu (uint64_t word)
 
uint64_t sux::mround (uint64_t number, uint64_t multiple)
 
size_t sux::updroot (size_t j, size_t n)
 
uint64_t sux::select64 (uint64_t x, uint64_t k)
 
bool sux::is_big_endian (void)
 
bool sux::is_little_endian (void)
 
template<class T >
std::enable_if< std::is_integral< T >::value, T >::type sux::swap_endian (T value)
 
template<class T >
sux::hton (T value)
 
template<class T >
sux::ntoh (T value)
 
template<class T >
sux::ltoh (T value)
 
template<class T >
sux::htol (T value)
 

Variables

constexpr uint8_t sux::kSelectInByte [2048]
 

Macro Definition Documentation

◆ __STRINGIFY

#define __STRINGIFY (   s)    #s

◆ likely

#define likely (   x)    __builtin_expect(!!(x), 1)

◆ MSBS_STEP_16

#define MSBS_STEP_16   (UINT64_C(0x8000) * ONES_STEP_16)

◆ MSBS_STEP_32

#define MSBS_STEP_32   (UINT64_C(0x8000000080000000))

◆ MSBS_STEP_4

#define MSBS_STEP_4   (UINT64_C(0x8) * ONES_STEP_4)

◆ MSBS_STEP_8

#define MSBS_STEP_8   (UINT64_C(0x80) * ONES_STEP_8)

◆ MSBS_STEP_9

#define MSBS_STEP_9   (UINT64_C(0x100) * ONES_STEP_9)

◆ ONES_STEP_16

#define ONES_STEP_16   (UINT64_C(1) << 0 | UINT64_C(1) << 16 | UINT64_C(1) << 32 | UINT64_C(1) << 48)

◆ ONES_STEP_32

#define ONES_STEP_32   (UINT64_C(0x0000000100000001))

◆ ONES_STEP_4

#define ONES_STEP_4   (UINT64_C(0x1111111111111111))

◆ ONES_STEP_8

#define ONES_STEP_8   (UINT64_C(0x0101010101010101))

◆ ONES_STEP_9

#define ONES_STEP_9   (UINT64_C(1) << 0 | UINT64_C(1) << 9 | UINT64_C(1) << 18 | UINT64_C(1) << 27 | UINT64_C(1) << 36 | UINT64_C(1) << 45 | UINT64_C(1) << 54)

◆ STRINGIFY

#define STRINGIFY (   s)    __STRINGIFY(s)

◆ ULEQ_STEP_16

#define ULEQ_STEP_16 (   x,
 
)    (((((((y) | MSBS_STEP_16) - ((x) & ~MSBS_STEP_16)) | (x ^ y)) ^ (x & ~y)) & MSBS_STEP_16) >> 15)

◆ ULEQ_STEP_9

#define ULEQ_STEP_9 (   x,
 
)    (((((((y) | MSBS_STEP_9) - ((x) & ~MSBS_STEP_9)) | (x ^ y)) ^ (x & ~y)) & MSBS_STEP_9) >> 8)

◆ unlikely

#define unlikely (   x)    __builtin_expect(!!(x), 0)