12namespace alpaka::rand::engine::internal
25 template<
typename TParams>
26 class PhiloxSingle :
public PhiloxBaseCommon<TParams, PhiloxSingle<TParams>>
29 using Base = PhiloxBaseCommon<TParams, PhiloxSingle<TParams>>;
32 using Counter =
typename Base::Counter;
34 using Key =
typename Base::Key;
35 using State = PhiloxState<Counter, Key, PhiloxSingle<TParams>>;
44 constexpr void advanceState()
46 this->advanceCounter(this->state.counter);
47 this->state.result = this->nRounds(this->state.counter, this->state.key);
48 this->state.position = 0;
59 constexpr auto nextNumber()
62 auto result = this->state.result[0];
63 ++this->state.position;
64 if(this->state.position == TParams::counterSize)
75 this->state.result[0] = this->state.result[1];
76 this->state.result[1] = this->state.result[2];
77 this->state.result[2] = this->state.result[3];
84 constexpr void skip(uint64_t offset)
86 static_assert(TParams::counterSize == 4,
"Only counterSize is supported.");
87 this->state.position =
static_cast<decltype(this-
>state.position)>(this->state.position + (offset & 3));
88 offset += this->state.position < 4 ? 0 : 4;
89 this->state.position -= this->state.position < 4 ? 0 : 4u;
90 for(
auto numShifts = this->state.position; numShifts > 0; --numShifts)
94 this->state.result[0] = this->state.result[1];
95 this->state.result[1] = this->state.result[2];
96 this->state.result[2] = this->state.result[3];
98 this->skip4(offset / 4);
108 constexpr PhiloxSingle(uint64_t seed = 0, uint64_t subsequence = 0, uint64_t offset = 0)
109 : Base(State{{0, 0, 0, 0}, {low32Bits(seed), high32Bits(seed)}, {0, 0, 0, 0}, 0u})
111 this->skipSubsequence(subsequence);
120 constexpr auto operator()()