21 #ifndef ROCRAND_LFSR113_H_
22 #define ROCRAND_LFSR113_H_
25 #define FQUALIFIERS __forceinline__ __device__
28 #include "rocrand/rocrand_common.h"
36 #define ROCRAND_LFSR113_DEFAULT_SEED_X 2
39 #define ROCRAND_LFSR113_DEFAULT_SEED_Y 8
42 #define ROCRAND_LFSR113_DEFAULT_SEED_Z 16
45 #define ROCRAND_LFSR113_DEFAULT_SEED_W 128
48 namespace rocrand_device
69 const unsigned int subsequence = 0)
71 this->seed(seed, subsequence);
79 void seed(uint4 seed_value,
const unsigned long long subsequence)
81 m_state.subsequence = seed_value;
83 reset_start_subsequence();
84 discard_subsequence(subsequence);
97 void discard_subsequence(
unsigned int subsequence)
99 for(
unsigned int i = 0; i < subsequence; i++)
101 reset_next_subsequence();
106 unsigned int operator()()
116 b = (((m_state.z.x << 6) ^ m_state.z.x) >> 13);
117 m_state.z.x = (((m_state.z.x & 4294967294U) << 18) ^ b);
119 b = (((m_state.z.y << 2) ^ m_state.z.y) >> 27);
120 m_state.z.y = (((m_state.z.y & 4294967288U) << 2) ^ b);
122 b = (((m_state.z.z << 13) ^ m_state.z.z) >> 21);
123 m_state.z.z = (((m_state.z.z & 4294967280U) << 7) ^ b);
125 b = (((m_state.z.w << 3) ^ m_state.z.w) >> 12);
126 m_state.z.w = (((m_state.z.w & 4294967168U) << 13) ^ b);
128 return (m_state.z.x ^ m_state.z.y ^ m_state.z.z ^ m_state.z.w);
134 void reset_start_subsequence()
136 m_state.z.x = m_state.subsequence.x;
137 m_state.z.y = m_state.subsequence.y;
138 m_state.z.z = m_state.subsequence.z;
139 m_state.z.w = m_state.subsequence.w;
144 void reset_next_subsequence()
156 z = m_state.subsequence.x & 0xFFFFFFFE;
159 z = (z) ^ (z << 3) ^ (z << 4) ^ (z << 6) ^ (z << 7) ^ (z << 8) ^ (z << 10) ^ (z << 11)
160 ^ (z << 13) ^ (z << 14) ^ (z << 16) ^ (z << 17) ^ (z << 18) ^ (z << 22) ^ (z << 24)
161 ^ (z << 25) ^ (z << 26) ^ (z << 28) ^ (z << 30);
163 z ^= ((b >> 1) & 0x7FFFFFFF) ^ ((b >> 3) & 0x1FFFFFFF) ^ ((b >> 5) & 0x07FFFFFF)
164 ^ ((b >> 6) & 0x03FFFFFF) ^ ((b >> 7) & 0x01FFFFFF) ^ ((b >> 9) & 0x007FFFFF)
165 ^ ((b >> 13) & 0x0007FFFF) ^ ((b >> 14) & 0x0003FFFF) ^ ((b >> 15) & 0x0001FFFF)
166 ^ ((b >> 17) & 0x00007FFF) ^ ((b >> 18) & 0x00003FFF) ^ ((b >> 20) & 0x00000FFF)
167 ^ ((b >> 21) & 0x000007FF) ^ ((b >> 23) & 0x000001FF) ^ ((b >> 24) & 0x000000FF)
168 ^ ((b >> 25) & 0x0000007F) ^ ((b >> 26) & 0x0000003F) ^ ((b >> 27) & 0x0000001F)
169 ^ ((b >> 30) & 0x00000003);
170 m_state.subsequence.x = z;
172 z = m_state.subsequence.y & 0xFFFFFFF8;
179 b ^= (z << 22) ^ (z << 25) ^ (z << 27);
180 if((z & 0x80000000) != 0)
182 if((z & 0x40000000) != 0)
184 z = b ^ ((z >> 7) & 0x01FFFFFF) ^ ((z >> 20) & 0x00000FFF) ^ ((z >> 21) & 0x000007FF);
185 m_state.subsequence.y = z;
187 z = m_state.subsequence.z & 0xFFFFFFF0;
189 z = ((b >> 3) & 0x1FFFFFFF) ^ ((b >> 17) & 0x00007FFF) ^ (z << 10) ^ (z << 11) ^ (z << 25);
190 m_state.subsequence.z = z;
192 z = m_state.subsequence.w & 0xFFFFFF80;
194 z = (z << 14) ^ (z << 16) ^ (z << 20) ^ ((b >> 5) & 0x07FFFFFF) ^ ((b >> 9) & 0x007FFFFF)
195 ^ ((b >> 11) & 0x001FFFFF);
196 m_state.subsequence.w = z;
198 reset_start_subsequence();
209 lfsr113_state m_state;
221 typedef rocrand_device::lfsr113_engine rocrand_state_lfsr113;
235 void rocrand_init(
const uint4 seed,
const unsigned int subsequence, rocrand_state_lfsr113* state)
237 *state = rocrand_state_lfsr113(seed, subsequence);
253 unsigned int rocrand(rocrand_state_lfsr113* state)
255 return state->next();
#define ROCRAND_LFSR113_DEFAULT_SEED_Y
Default Y seed for LFSR113 PRNG.
Definition: rocrand_lfsr113.h:39
FQUALIFIERS unsigned int rocrand(rocrand_state_lfsr113 *state)
Returns uniformly distributed random unsigned int value from [0; 2^32 - 1] range.
Definition: rocrand_lfsr113.h:253
#define ROCRAND_LFSR113_DEFAULT_SEED_W
Default W seed for LFSR113 PRNG.
Definition: rocrand_lfsr113.h:45
FQUALIFIERS void rocrand_init(const uint4 seed, const unsigned int subsequence, rocrand_state_lfsr113 *state)
Initializes LFSR113 state.
Definition: rocrand_lfsr113.h:235
#define ROCRAND_LFSR113_DEFAULT_SEED_Z
Default Z seed for LFSR113 PRNG.
Definition: rocrand_lfsr113.h:42
#define ROCRAND_LFSR113_DEFAULT_SEED_X
Default X seed for LFSR113 PRNG.
Definition: rocrand_lfsr113.h:36
#define FQUALIFIERS
Shorthand for commonly used function qualifiers.
Definition: rocrand_uniform.h:31