OpenQMC API
Loading...
Searching...
No Matches
pcg.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright Contributors to the OpenQMC Project.
3
14
15#pragma once
16
17#include "gpu.h"
18
19#include <cassert>
20#include <cstdint>
21
62
63namespace oqmc
64{
65
66namespace pcg
67{
68
79OQMC_HOST_DEVICE constexpr std::uint32_t stateTransition(std::uint32_t state)
80{
81 // LCG
82 return state * 747796405u + 2891336453u;
83}
84
96OQMC_HOST_DEVICE constexpr std::uint32_t output(std::uint32_t state)
97{
98 // RXS
99 state ^= state >> (4 + (state >> 28));
100
101 // M
102 state *= 277803737u;
103
104 // XS
105 state ^= state >> 22;
106
107 return state;
108}
109
117OQMC_HOST_DEVICE constexpr std::uint32_t init()
118{
119 return stateTransition(0);
120}
121
130OQMC_HOST_DEVICE constexpr std::uint32_t init(std::uint32_t seed)
131{
132 return init() + seed;
133}
134
143OQMC_HOST_DEVICE constexpr std::uint32_t hash(std::uint32_t key)
144{
145 key = stateTransition(key);
146 return output(key);
147}
148
162OQMC_HOST_DEVICE constexpr std::uint32_t rng(std::uint32_t& state)
163{
165 return output(state);
166}
167
168} // namespace pcg
169
170} // namespace oqmc
#define OQMC_HOST_DEVICE
Definition gpu.h:13
constexpr std::uint32_t output(std::uint32_t state)
Output permutation function.
Definition pcg.h:96
constexpr std::uint32_t hash(std::uint32_t key)
Compute a hash value based on an input key.
Definition pcg.h:143
constexpr std::uint32_t stateTransition(std::uint32_t state)
State transition function.
Definition pcg.h:79
constexpr std::uint32_t init()
Default initialise the PRNG state.
Definition pcg.h:117
constexpr std::uint32_t rng(std::uint32_t &state)
Compute a random number from the PRNG sequence.
Definition pcg.h:162
EncodeKey decodeBits16(std::uint16_t value)
Decode a value back into a key.
Definition encode.h:81
Definition bntables.h:21