C++ API Reference

The full API tree is auto-generated from Doxygen XML by Exhale:

Key headers

namespace prng

Typedefs

using Xoshiro = XoshiroSIMD
namespace prng
class XoshiroNative
#include <xoshiro_simd.hpp>

XoshiroNative: uses the best architecture available at compile time. Zero indirection — direct calls to XoshiroState methods.

Public Types

using result_type = std::uint64_t

Public Functions

inline explicit XoshiroNative(const result_type seed) noexcept
inline explicit XoshiroNative(const result_type seed, const result_type thread_id) noexcept
inline explicit XoshiroNative(const result_type seed, const result_type thread_id, const result_type cluster_id) noexcept
inline result_type operator()() noexcept
inline double uniform() noexcept
inline auto getState(const std::size_t index) const noexcept
inline void jump() noexcept
inline void mid_jump() noexcept
inline void long_jump() noexcept
inline void get_flat_state(result_type *out) const noexcept
inline void set_flat_state(const result_type *in) noexcept
inline std::uint8_t cache_index() const noexcept
inline void set_cache_index(std::uint8_t idx) noexcept
inline const std::array<result_type, CACHE_SIZE> &cache() const noexcept
inline std::array<result_type, CACHE_SIZE> &cache() noexcept

Public Static Functions

static inline constexpr auto() min () noexcept
static inline constexpr auto() max () noexcept
static inline constexpr auto stateSize() noexcept
static inline constexpr std::uint8_t simd_width() noexcept

Private Types

using State = internal::XoshiroState<xsimd::best_arch>

Private Members

std::array<result_type, CACHE_SIZE> m_cache = {}
State m_state = {}
std::uint8_t m_index = {0}

Private Static Attributes

static constexpr auto CACHE_SIZE = State::CACHE_SIZE
class XoshiroSIMD
#include <xoshiro_simd.hpp>

XoshiroSIMD: runtime SIMD dispatch via inline union + function pointers. No heap allocation, no virtual dispatch.

Public Types

using result_type = std::uint64_t

Public Functions

explicit XoshiroSIMD(result_type seed, result_type thread_id = 0, result_type cluster_id = 0) noexcept
inline result_type operator()() noexcept
inline double uniform() noexcept
inline void jump() noexcept
inline void mid_jump() noexcept
inline void long_jump() noexcept
inline void get_flat_state(result_type *out) const noexcept
inline void set_flat_state(const result_type *in) noexcept
inline std::uint8_t simd_width() const noexcept
inline std::uint8_t cache_index() const noexcept
inline void set_cache_index(std::uint8_t idx) noexcept
inline const std::array<result_type, std::numeric_limits<std::uint8_t>::max() + 1> &cache() const noexcept
inline std::array<result_type, std::numeric_limits<std::uint8_t>::max() + 1> &cache() noexcept

Public Static Functions

static inline constexpr result_type() min () noexcept
static inline constexpr result_type() max () noexcept

Protected Types

using populate_fn = void (*)(void*, std::array<result_type, CACHE_SIZE>&) noexcept
using jump_fn = void (*)(void*) noexcept
using get_state_fn = void (*)(const void*, result_type*) noexcept
using set_state_fn = void (*)(void*, const result_type*) noexcept
using simd_width_fn = std::uint8_t (*)() noexcept

Protected Attributes

std::array<result_type, CACHE_SIZE> m_cache = {}
StateStorage m_state
populate_fn m_populate_cache = nullptr
jump_fn m_jump = nullptr
jump_fn m_mid_jump = nullptr
jump_fn m_long_jump = nullptr
get_state_fn m_get_state = nullptr
set_state_fn m_set_state = nullptr
simd_width_fn m_simd_width = nullptr
std::uint8_t m_index = {0}

Protected Static Attributes

static constexpr std::uint16_t CACHE_SIZE = std::numeric_limits<std::uint8_t>::max() + 1
struct StateStorage
#include <xoshiro_simd.hpp>

Public Members

unsigned char data[SIZE]

Public Static Attributes

static constexpr std::size_t SIZE = 256
static constexpr std::size_t ALIGN = 64
namespace internal
struct XoshiroSIMDInitFunctor
#include <xoshiro_simd.hpp>

Functor used by xsimd::dispatch to initialize a XoshiroSIMD instance. Placement-news the correct XoshiroState<Arch> into the byte storage and returns function pointers.

Public Functions

template<class Arch>
XoshiroSIMDInitResult operator()(Arch) const noexcept

Public Members

void *state_storage
std::uint64_t seed
std::uint64_t thread_id
std::uint64_t cluster_id
struct XoshiroSIMDInitResult
#include <xoshiro_simd.hpp>

Result from the runtime dispatch initialization.

Public Types

using populate_fn = void (*)(void*, std::array<std::uint64_t, 256>&) noexcept
using jump_fn = void (*)(void*) noexcept
using get_state_fn = void (*)(const void*, std::uint64_t*) noexcept
using set_state_fn = void (*)(void*, const std::uint64_t*) noexcept
using simd_width_fn = std::uint8_t (*)() noexcept

Public Members

populate_fn populate_cache
jump_fn jump
jump_fn mid_jump
jump_fn long_jump
get_state_fn get_state
set_state_fn set_state
simd_width_fn simd_width
template<class Arch>
struct XoshiroState
#include <xoshiro_simd.hpp>

SIMD state for the vectorized Xoshiro256++ generator. Contains the 4 SIMD register state and all PRNG operations.

Template Parameters:

Arch – The xsimd architecture type.

Public Types

using result_type = std::uint64_t
using simd_type = xsimd::batch<result_type, Arch>

Public Functions

inline constexpr void seed(result_type seed_val, result_type thread_id = 0, result_type cluster_id = 0) noexcept

Seed the SIMD state from a scalar seed, with optional thread and cluster offsets.

inline constexpr simd_type next() noexcept
inline constexpr void populate_cache(std::array<result_type, CACHE_SIZE> &cache) noexcept
inline constexpr void jump() noexcept

Jump function. Equivalent to 2^128 calls to next().

inline constexpr void mid_jump() noexcept

Mid-jump function. Equivalent to 2^160 calls to next().

inline constexpr void long_jump() noexcept

Long-jump function. Equivalent to 2^192 calls to next().

inline constexpr std::array<result_type, RNG_WIDTH> getState(const std::size_t index) const noexcept
inline void get_flat_state(result_type *out) const noexcept
inline void set_flat_state(const result_type *in) noexcept

Public Members

std::array<simd_type, RNG_WIDTH> s = {}

Public Static Attributes

static constexpr std::uint8_t RNG_WIDTH = 4
static constexpr std::uint8_t SIMD_WIDTH = simd_type::size
static constexpr std::uint16_t CACHE_SIZE = std::numeric_limits<std::uint8_t>::max() + 1
namespace prng
class SplitMix
#include <splitmix.hpp>

Public Functions

inline explicit constexpr SplitMix(const std::uint64_t state) noexcept
inline constexpr std::uint64_t operator()() noexcept
inline constexpr std::uint64_t getState() const noexcept
inline constexpr void setState(std::uint64_t state) noexcept

Public Static Functions

static inline constexpr std::uint64_t() min () noexcept
static inline constexpr std::uint64_t() max () noexcept

Private Members

std::uint64_t m_state
namespace prng
template<std::uint8_t R = 20>
class ChaCha
#include <chacha.hpp>

Public Types

using result_type = std::uint64_t
using input_word = std::uint64_t
using matrix_word = std::uint32_t
using matrix_type = std::array<matrix_word, MATRIX_WORDCOUNT>
using result_cache_type = std::array<result_type, MATRIX_WORDCOUNT / 2>

Public Functions

inline explicit ChaCha(const std::array<matrix_word, KEY_WORDCOUNT> key, const input_word counter, const input_word nonce) noexcept

Construct a scalar ChaCha generator with given key, counter and nonce.

Parameters:
  • key – A 256-bit key, divided up into eight 32-bit words.

  • counter – Initial value of the counter.

  • nonce – Initial value of the nonce.

inline constexpr result_type (operator())() noexcept

Generates the next 64-bit output.

Returns:

The next 64-bit output.

inline constexpr double uniform() noexcept

Generates a uniform random number in the range [0, 1).

Returns:

A uniform random number.

inline constexpr matrix_type block() noexcept

Generates the next 64-byte ChaCha block.

Returns:

The next 64-byte ChaCha block.

inline constexpr matrix_type getState() const noexcept

Returns the state of the generator; a 4x4 matrix.

Returns:

State of the generator.

Public Static Functions

static inline constexpr auto() min () noexcept
static inline constexpr auto() max () noexcept

Protected Static Attributes

static constexpr auto MATRIX_WORDCOUNT = std::uint8_t{16}
static constexpr auto KEY_WORDCOUNT = std::uint8_t{8}

Private Functions

inline constexpr void inc_counter() noexcept
inline constexpr result_type next_result() noexcept
inline constexpr matrix_type next_block() noexcept

Returns the next output from the generator, then increases state’s counter by 1.

Returns:

The output for the current internal state.

Private Members

matrix_type m_state
result_cache_type m_result_cache = {}
std::uint8_t m_result_index = static_cast<std::uint8_t>(m_result_cache.size())

Private Static Functions

static inline constexpr auto rotl(const matrix_word x, const int k) noexcept
static inline constexpr void quarter_round(matrix_type &m, const unsigned int a, const unsigned int b, const unsigned int c, const unsigned int d) noexcept
static inline constexpr result_cache_type block_to_results(const matrix_type &block) noexcept
static inline constexpr matrix_type results_to_block(const result_cache_type &results) noexcept

Defines

PRNG_CHACHA_EXTERN_TEMPLATE(R, Arch)
namespace prng

Typedefs

using ChaCha8SIMD = ChaChaSIMD<8>
using ChaCha12SIMD = ChaChaSIMD<12>
using ChaCha20SIMD = ChaChaSIMD<20>
using ChaCha8Native = ChaChaNative<8>
using ChaCha12Native = ChaChaNative<12>
using ChaCha20Native = ChaChaNative<20>
template<std::uint8_t R = 20>
class ChaChaNative
#include <chacha_simd.hpp>

ChaChaNative: uses the best architecture available at compile time. Zero indirection — direct calls to ChaChaState methods.

Template Parameters:

R – Number of ChaCha rounds.

Public Types

using result_type = std::uint64_t
using input_word = std::uint64_t
using matrix_word = std::uint32_t
using matrix_type = std::array<matrix_word, MATRIX_WORDCOUNT>
using result_cache_type = std::array<result_type, MATRIX_WORDCOUNT / 2>

Public Functions

inline explicit ChaChaNative(result_type seed, const input_word counter = 0, const input_word nonce = 0)
inline ChaChaNative(const std::array<matrix_word, KEY_WORDCOUNT> key, const input_word counter, const input_word nonce)
inline constexpr result_type operator()() noexcept
inline constexpr double uniform() noexcept
inline constexpr matrix_type block() noexcept
inline constexpr matrix_type getState() const noexcept
inline matrix_type getStateForSerde() const noexcept
inline void setState(const matrix_type &matrix) noexcept
inline const result_cache_type &result_cache() const noexcept
inline void set_result_cache(const result_cache_type &cache) noexcept
inline std::uint8_t result_index() const noexcept
inline void set_result_index(std::uint8_t idx) noexcept
inline size_t getSIMDSize() const noexcept

Public Static Functions

static inline constexpr auto() min () noexcept
static inline constexpr auto() max () noexcept

Public Static Attributes

static constexpr auto MATRIX_WORDCOUNT = std::uint8_t{16}
static constexpr auto KEY_WORDCOUNT = std::uint8_t{8}

Private Types

using State = internal::ChaChaState<xsimd::best_arch, R>

Private Members

State m_state
result_cache_type m_result_cache = {}
std::uint8_t m_result_index = static_cast<std::uint8_t>(m_result_cache.size())
template<std::uint8_t R = 20>
class ChaChaSIMD
#include <chacha_simd.hpp>

ChaChaSIMD: runtime SIMD dispatch via inline union + function pointers. No heap allocation, no virtual dispatch.

Template Parameters:

R – Number of ChaCha rounds.

Public Types

using result_type = std::uint64_t
using input_word = std::uint64_t
using matrix_word = std::uint32_t
using matrix_type = std::array<matrix_word, MATRIX_WORDCOUNT>
using result_cache_type = std::array<result_type, MATRIX_WORDCOUNT / 2>

Public Functions

inline explicit ChaChaSIMD(result_type seed, const input_word counter = 0, const input_word nonce = 0)
inline explicit ChaChaSIMD(const std::array<matrix_word, KEY_WORDCOUNT> key, const input_word counter, const input_word nonce)
inline constexpr result_type operator()() noexcept
inline constexpr double uniform() noexcept
inline constexpr matrix_type block() noexcept
inline constexpr matrix_type getState() const noexcept
inline matrix_type getStateForSerde() const noexcept
inline void setState(const matrix_type &matrix) noexcept
inline const result_cache_type &result_cache() const noexcept
inline void set_result_cache(const result_cache_type &cache) noexcept
inline std::uint8_t result_index() const noexcept
inline void set_result_index(std::uint8_t idx) noexcept
inline size_t getSIMDSize() const noexcept

Public Static Functions

static inline constexpr auto() min () noexcept
static inline constexpr auto() max () noexcept
static inline constexpr matrix_type results_to_block(const result_cache_type &results) noexcept
static inline constexpr result_cache_type block_to_results(const matrix_type &block) noexcept
static inline constexpr std::array<matrix_word, KEY_WORDCOUNT> seed_to_key(result_type seed) noexcept

Public Static Attributes

static constexpr auto MATRIX_WORDCOUNT = std::uint8_t{16}
static constexpr auto KEY_WORDCOUNT = std::uint8_t{8}

Private Types

using next_block_fn = internal::ChaChaSIMDInitResult::next_block_fn
using get_state_fn = internal::ChaChaSIMDInitResult::get_state_fn
using set_state_fn = internal::ChaChaSIMDInitResult::set_state_fn
using get_cache_index_fn = internal::ChaChaSIMDInitResult::get_cache_index_fn

Private Members

StateStorage m_state
next_block_fn m_next_block = nullptr
get_state_fn m_get_state = nullptr
set_state_fn m_set_state = nullptr
get_cache_index_fn m_get_cache_index = nullptr
std::size_t m_simd_size = 0
result_cache_type m_result_cache = {}
std::uint8_t m_result_index = static_cast<std::uint8_t>(m_result_cache.size())
struct StateStorage

Public Members

unsigned char data[SIZE]

Public Static Attributes

static constexpr std::size_t SIZE = 2176
static constexpr std::size_t ALIGN = 64
namespace internal
template<std::uint8_t R>
struct ChaChaSIMDInitFunctor
#include <chacha_simd.hpp>

Functor used by xsimd::dispatch to initialize a ChaChaSIMD instance.

Public Functions

template<class Arch>
ChaChaSIMDInitResult operator()(Arch) const noexcept

Public Members

void *state_storage
const std::array<std::uint32_t, 8> key
const std::uint64_t counter
const std::uint64_t nonce
struct ChaChaSIMDInitResult
#include <chacha_simd.hpp>

Result from the runtime dispatch initialization for ChaChaSIMD.

Public Types

using matrix_type = std::array<std::uint32_t, 16>
using next_block_fn = matrix_type (*)(void*) noexcept
using get_state_fn = matrix_type (*)(const void*, bool) noexcept
using set_state_fn = void (*)(void*, const matrix_type&) noexcept
using get_cache_index_fn = std::uint8_t (*)(const void*) noexcept

Public Members

next_block_fn next_block
get_state_fn get_state
set_state_fn set_state
get_cache_index_fn get_cache_index
std::size_t simd_size
template<class Arch, std::uint8_t R>
struct ChaChaState
#include <chacha_simd.hpp>

SIMD state for the ChaCha generator. Contains the matrix state, SIMD block cache, and all generation logic.

Template Parameters:
  • Arch – The xsimd architecture type.

  • R – Number of ChaCha rounds.

Public Types

using input_word = std::uint64_t
using matrix_word = std::uint32_t
using matrix_type = std::array<matrix_word, MATRIX_WORDCOUNT>
using simd_type = xsimd::batch<matrix_word, Arch>
using working_state_type = std::array<simd_type, MATRIX_WORDCOUNT>
using cache_block_type = std::array<simd_type, BLOCK_SEGMENTCOUNT>
using cache_batch_type = std::array<cache_block_type, SIMD_WIDTH>

Public Functions

inline explicit ChaChaState(const std::array<matrix_word, KEY_WORDCOUNT> key, const input_word counter, const input_word nonce)
inline matrix_type getState(bool prev) const noexcept
inline matrix_type next_block() noexcept

Public Members

matrix_type m_state
std::array<cache_batch_type, CACHE_BATCHCOUNT> m_cache
std::uint8_t m_cache_index = CACHE_BLOCKCOUNT

Public Static Functions

static inline constexpr std::uint8_t cache_batchcount() noexcept

Public Static Attributes

static constexpr auto MATRIX_WORDCOUNT = std::uint8_t{16}
static constexpr auto KEY_WORDCOUNT = std::uint8_t{8}
static constexpr std::uint8_t SIMD_WIDTH = std::uint8_t{simd_type::size}
static constexpr std::uint8_t SIMD_WIDTH_SHIFT = SIMD_WIDTH > 0 ? static_cast<std::uint8_t>(std::countr_zero(static_cast<unsigned int>(SIMD_WIDTH))) : 0
static constexpr std::uint8_t SIMD_WIDTH_MASK = SIMD_WIDTH > 0 ? std::uint8_t(SIMD_WIDTH - 1) : 0
static constexpr std::uint8_t BLOCK_SEGMENTCOUNT = SIMD_WIDTH > 0 ? static_cast<std::uint8_t>(MATRIX_WORDCOUNT / SIMD_WIDTH) : 0
static constexpr auto CACHE_BATCHCOUNT = cache_batchcount()
static constexpr auto CACHE_BLOCKCOUNT = std::uint8_t{CACHE_BATCHCOUNT * SIMD_WIDTH}

Private Functions

inline constexpr void gen_next_blocks_in_cache() noexcept

Private Static Functions

static inline simd_type make_higher_counter_inc(matrix_word overflow_index) noexcept
static inline void init_state_batches(working_state_type &x, const matrix_type &state, simd_type lower_counter_inc, simd_type higher_counter_inc) noexcept
static inline void add_original_state(working_state_type &x, const matrix_type &state, simd_type lower_counter_inc, simd_type higher_counter_inc) noexcept
static inline void transpose_into_cache(cache_batch_type &cache, working_state_type &x) noexcept
static inline constexpr void advance_counter(matrix_type &state) noexcept
template<unsigned A, unsigned B, unsigned C, unsigned D>
static inline void quarter_round(working_state_type &x) noexcept
static inline void gen_block_batch(cache_batch_type &cache, const matrix_type &state) noexcept

Private Static Attributes

static constexpr std::array<matrix_word, SIMD_WIDTH> LANE_OFFSETS = [] {std::array<matrix_word, SIMD_WIDTH> offsets{};poet::static_for<0,SIMD_WIDTH>([&](auto I) {offsets[I] = static_cast<matrix_word>(I.value);});return offsets;}()
namespace prng

Typedefs

using Philox4x32 = Philox<4, 32, 10>
using Philox2x32 = Philox<2, 32, 10>
using Philox4x64 = Philox<4, 64, 10>
using Philox2x64 = Philox<2, 64, 10>
template<std::uint8_t N = 4, std::uint8_t W = 32, std::uint8_t R = 10>
class Philox
#include <philox.hpp>

Public Types

using result_type = std::uint64_t
using word_type = std::conditional_t<W == 32, std::uint32_t, std::uint64_t>
using counter_type = std::array<word_type, N>
using key_type = std::array<word_type, N / 2>
using result_block_type = std::array<result_type, RESULTS_PER_BLOCK>

Public Functions

inline explicit Philox(result_type seed, result_type counter = 0) noexcept
inline explicit Philox(key_type key, counter_type counter) noexcept
inline constexpr result_type operator()() noexcept
inline constexpr double uniform() noexcept
inline counter_type getCounter() const noexcept
inline key_type getKey() const noexcept
inline void setCounter(const counter_type &ctr) noexcept
inline void setKey(const key_type &key) noexcept
inline counter_type getCounterForSerde() const noexcept
inline void setState(const counter_type &ctr, const key_type &key) noexcept
inline const result_block_type &result_cache() const noexcept
inline void set_result_cache(const result_block_type &cache) noexcept
inline std::uint8_t result_index() const noexcept
inline void set_result_index(std::uint8_t idx) noexcept

Public Static Functions

static inline constexpr auto() min () noexcept
static inline constexpr auto() max () noexcept
static inline constexpr key_type seed_to_key(result_type seed) noexcept
static inline constexpr counter_type counter_from_uint64(result_type counter) noexcept

Public Static Attributes

static constexpr auto RESULTS_PER_BLOCK = std::uint8_t{N * W / 64}

Private Types

using C = internal::PhiloxConstants<N, W>

Private Functions

inline constexpr void inc_counter() noexcept
inline constexpr result_block_type next_block() noexcept

Private Members

counter_type m_counter
key_type m_key
result_block_type m_result_cache = {}
std::uint8_t m_result_index = RESULTS_PER_BLOCK

Private Static Functions

static inline constexpr void mulhilo(word_type a, word_type b, word_type &hi, word_type &lo) noexcept
static inline constexpr void single_round(counter_type &ctr, key_type &key) noexcept
static inline constexpr counter_type philox_rounds(counter_type ctr, key_type key) noexcept
static inline constexpr void dec_counter(counter_type &ctr) noexcept
namespace internal
template<>
struct PhiloxConstants<2, 32>
#include <philox.hpp>

Public Static Attributes

static constexpr std::uint32_t M0 = 0xD256D193
static constexpr std::uint32_t W0 = 0x9E3779B9
template<>
struct PhiloxConstants<2, 64>
#include <philox.hpp>

Public Static Attributes

static constexpr std::uint64_t M0 = 0xD2B74407B1CE6E93ULL
static constexpr std::uint64_t W0 = 0x9E3779B97F4A7C15ULL
template<>
struct PhiloxConstants<4, 32>
#include <philox.hpp>

Public Static Attributes

static constexpr std::uint32_t M0 = 0xD2511F53
static constexpr std::uint32_t M1 = 0xCD9E8D57
static constexpr std::uint32_t W0 = 0x9E3779B9
static constexpr std::uint32_t W1 = 0xBB67AE85
template<>
struct PhiloxConstants<4, 64>
#include <philox.hpp>

Public Static Attributes

static constexpr std::uint64_t M0 = 0xD2E7470EE14C6C93ULL
static constexpr std::uint64_t M1 = 0xCA5A826395121157ULL
static constexpr std::uint64_t W0 = 0x9E3779B97F4A7C15ULL
static constexpr std::uint64_t W1 = 0xBB67AE8584CAA73BULL

Defines

PRNG_PHILOX_EXTERN_TEMPLATE(N, W, R, Arch)
PRNG_PHILOX_EXTERN_TEMPLATES_FOR_ARCH(Arch)
namespace prng

Typedefs

using Philox4x32SIMD = PhiloxSIMD<4, 32, 10>
using Philox2x32SIMD = PhiloxSIMD<2, 32, 10>
using Philox4x64SIMD = PhiloxSIMD<4, 64, 10>
using Philox2x64SIMD = PhiloxSIMD<2, 64, 10>
using Philox4x32Native = PhiloxNative<4, 32, 10>
using Philox2x32Native = PhiloxNative<2, 32, 10>
using Philox4x64Native = PhiloxNative<4, 64, 10>
using Philox2x64Native = PhiloxNative<2, 64, 10>
template<std::uint8_t N = 4, std::uint8_t W = 32, std::uint8_t R = 10>
class PhiloxNative
#include <philox_simd.hpp>

Public Types

using result_type = std::uint64_t
using word_type = std::conditional_t<W == 32, std::uint32_t, std::uint64_t>
using counter_type = std::array<word_type, N>
using key_type = std::array<word_type, N / 2>

Public Functions

inline explicit PhiloxNative(result_type seed, result_type counter = 0) noexcept
inline PhiloxNative(key_type key, counter_type counter) noexcept
inline result_type operator()() noexcept
inline double uniform() noexcept
inline counter_type getCounter() const noexcept
inline key_type getKey() const noexcept
inline counter_type getCounterForSerde() const noexcept
inline void setState(const counter_type &ctr, const key_type &key) noexcept
inline std::uint8_t cache_index() const noexcept
inline void set_cache_index(std::uint8_t idx) noexcept
inline const std::array<result_type, CACHE_SIZE> &cache() const noexcept
inline std::array<result_type, CACHE_SIZE> &cache() noexcept
inline std::size_t getSIMDSize() const noexcept

Public Static Functions

static inline constexpr auto() min () noexcept
static inline constexpr auto() max () noexcept

Public Static Attributes

static constexpr std::uint16_t CACHE_SIZE = 256

Private Types

using State = internal::PhiloxState<xsimd::best_arch, N, W, R>

Private Members

std::array<result_type, CACHE_SIZE> m_cache = {}
State m_state
std::uint8_t m_index = 0
template<std::uint8_t N = 4, std::uint8_t W = 32, std::uint8_t R = 10>
class PhiloxSIMD
#include <philox_simd.hpp>

Public Types

using result_type = std::uint64_t
using word_type = std::conditional_t<W == 32, std::uint32_t, std::uint64_t>
using counter_type = std::array<word_type, N>
using key_type = std::array<word_type, N / 2>

Public Functions

inline explicit PhiloxSIMD(result_type seed, result_type counter = 0) noexcept
inline explicit PhiloxSIMD(key_type key, counter_type counter) noexcept
inline result_type operator()() noexcept
inline double uniform() noexcept
inline counter_type getCounter() const noexcept
inline key_type getKey() const noexcept
inline counter_type getCounterForSerde() const noexcept
inline void setState(const counter_type &ctr, const key_type &key) noexcept
inline std::uint8_t cache_index() const noexcept
inline void set_cache_index(std::uint8_t idx) noexcept
inline const std::array<result_type, CACHE_SIZE> &cache() const noexcept
inline std::array<result_type, CACHE_SIZE> &cache() noexcept
inline std::size_t getSIMDSize() const noexcept

Public Static Functions

static inline constexpr auto() min () noexcept
static inline constexpr auto() max () noexcept
static inline constexpr key_type seed_to_key(result_type seed) noexcept
static inline constexpr counter_type counter_from_uint64(result_type counter) noexcept

Public Static Attributes

static constexpr std::uint16_t CACHE_SIZE = 256

Private Types

using InitResult = internal::PhiloxSIMDInitResult<N, W>
using populate_fn = typename InitResult::populate_fn
using get_counter_fn = typename InitResult::get_counter_fn
using get_raw_counter_fn = typename InitResult::get_raw_counter_fn
using get_key_fn = typename InitResult::get_key_fn
using set_state_fn = typename InitResult::set_state_fn

Private Members

std::array<result_type, CACHE_SIZE> m_cache = {}
StateStorage m_state
populate_fn m_populate_cache = nullptr
get_counter_fn m_get_counter = nullptr
get_raw_counter_fn m_get_raw_counter = nullptr
get_key_fn m_get_key = nullptr
set_state_fn m_set_state = nullptr
std::size_t m_simd_size = 0
std::uint8_t m_index = 0
struct StateStorage

Public Members

unsigned char data[SIZE]

Public Static Attributes

static constexpr std::size_t SIZE = 256
static constexpr std::size_t ALIGN = 64
namespace internal
template<std::uint8_t N, std::uint8_t W, std::uint8_t R>
struct PhiloxSIMDInitFunctor
#include <philox_simd.hpp>

Public Types

using word_type = std::conditional_t<W == 32, std::uint32_t, std::uint64_t>
using counter_type = std::array<word_type, N>
using key_type = std::array<word_type, N / 2>

Public Functions

template<class Arch>
PhiloxSIMDInitResult<N, W> operator()(Arch) const noexcept

Public Members

void *state_storage
const key_type key
const counter_type counter
template<std::uint8_t N, std::uint8_t W>
struct PhiloxSIMDInitResult
#include <philox_simd.hpp>

Public Types

using word_type = std::conditional_t<W == 32, std::uint32_t, std::uint64_t>
using counter_type = std::array<word_type, N>
using key_type = std::array<word_type, N / 2>
using result_type = std::uint64_t
using populate_fn = void (*)(void*, std::array<result_type, CACHE_SIZE>&) noexcept
using get_counter_fn = counter_type (*)(const void*, bool, std::uint16_t) noexcept
using get_raw_counter_fn = counter_type (*)(const void*) noexcept
using get_key_fn = key_type (*)(const void*) noexcept
using set_state_fn = void (*)(void*, const counter_type&, const key_type&) noexcept

Public Members

populate_fn populate_cache
get_counter_fn get_counter
get_raw_counter_fn get_raw_counter
get_key_fn get_key
set_state_fn set_state
std::size_t simd_size

Public Static Attributes

static constexpr std::uint16_t CACHE_SIZE = 256
template<class Arch, std::uint8_t N, std::uint8_t W, std::uint8_t R>
struct PhiloxState
#include <philox_simd.hpp>

Public Types

using word_type = std::conditional_t<W == 32, std::uint32_t, std::uint64_t>
using counter_type = std::array<word_type, N>
using key_type = std::array<word_type, N / 2>
using result_type = std::uint64_t
using simd_type = xsimd::batch<word_type, Arch>

Public Functions

inline explicit PhiloxState(const key_type &key, const counter_type &counter) noexcept
inline void populate_cache(std::array<result_type, CACHE_SIZE> &cache) noexcept
inline counter_type getCounter(bool prev, std::uint16_t cache_index) const noexcept
inline counter_type getRawCounter() const noexcept
inline key_type getKey() const noexcept
inline void setState(const counter_type &ctr, const key_type &key) noexcept

Public Members

counter_type m_counter
key_type m_key

Public Static Attributes

static constexpr auto RESULTS_PER_BLOCK = std::uint8_t{N * W / 64}
static constexpr std::uint8_t SIMD_WIDTH = std::uint8_t{simd_type::size}
static constexpr std::uint16_t CACHE_SIZE = 256
static constexpr std::uint16_t BLOCKS_PER_CACHE = CACHE_SIZE / RESULTS_PER_BLOCK
static constexpr std::uint16_t BATCHES_PER_CACHE = SIMD_WIDTH == 0 ? 1 : BLOCKS_PER_CACHE / SIMD_WIDTH

Private Types

using C = PhiloxConstants<N, W>

Private Static Functions

static inline void advance_counter(counter_type &ctr, word_type amount) noexcept
static inline void mulhilo_simd(simd_type a, word_type B, simd_type &hi, simd_type &lo) noexcept
static inline void simd_single_round(std::array<simd_type, N> &ctr, key_type &key) noexcept
static inline void init_counter_batch(std::array<simd_type, N> &ctr_simd, const counter_type &counter) noexcept
static inline void store_blocks_to_cache(result_type *cache, const std::array<simd_type, N> &ctr_simd) noexcept
static inline void gen_block_batch(result_type *cache, const counter_type &counter, const key_type &key) noexcept