32 #ifndef VSMC_RNGC_THREEFRY_H 33 #define VSMC_RNGC_THREEFRY_H 139 if (++ctr->
v[0] != 0)
141 if (++ctr->
v[1] != 0)
147 if (++ctr->
v[0] != 0)
149 if (++ctr->
v[1] != 0)
151 if (++ctr->
v[2] != 0)
153 if (++ctr->
v[3] != 0)
159 if (++ctr->
v[0] != 0)
161 if (++ctr->
v[1] != 0)
167 if (++ctr->
v[0] != 0)
169 if (++ctr->
v[1] != 0)
171 if (++ctr->
v[2] != 0)
173 if (++ctr->
v[3] != 0)
180 par->
v[0] = key->
v[0];
181 par->
v[1] = key->
v[1];
184 par->
v[2] ^= par->
v[0];
185 par->
v[2] ^= par->
v[1];
191 par->
v[0] = key->
v[0];
192 par->
v[1] = key->
v[1];
193 par->
v[2] = key->
v[2];
194 par->
v[3] = key->
v[3];
197 par->
v[4] ^= par->
v[0];
198 par->
v[4] ^= par->
v[1];
199 par->
v[4] ^= par->
v[2];
200 par->
v[4] ^= par->
v[3];
206 par->
v[0] = key->
v[0];
207 par->
v[1] = key->
v[1];
209 par->
v[2] =
UINT64_C(0x1BD11BDAA9FC1A22);
210 par->
v[2] ^= par->
v[0];
211 par->
v[2] ^= par->
v[1];
217 par->
v[0] = key->
v[0];
218 par->
v[1] = key->
v[1];
219 par->
v[2] = key->
v[2];
220 par->
v[3] = key->
v[3];
222 par->
v[4] =
UINT64_C(0x1BD11BDAA9FC1A22);
223 par->
v[4] ^= par->
v[0];
224 par->
v[4] ^= par->
v[1];
225 par->
v[4] ^= par->
v[2];
226 par->
v[4] ^= par->
v[3];
232 state->
v[0] += state->
v[1];
233 state->
v[1] = ((state->
v[1]) << r) | ((state->
v[1]) >> (32 - r));
234 state->
v[1] ^= state->
v[0];
240 state->
v[0] += state->
v[i0];
241 state->
v[i0] = ((state->
v[i0]) << r0) | ((state->
v[i0]) >> (32 - r0));
242 state->
v[i0] ^= state->
v[0];
244 state->
v[2] += state->
v[i2];
245 state->
v[i2] = ((state->
v[i2]) << r2) | ((state->
v[i2]) >> (32 - r2));
246 state->
v[i2] ^= state->
v[2];
252 state->
v[0] += state->
v[1];
253 state->
v[1] = ((state->
v[1]) << r) | ((state->
v[1]) >> (64 - r));
254 state->
v[1] ^= state->
v[0];
260 state->
v[0] += state->
v[i0];
261 state->
v[i0] = ((state->
v[i0]) << r0) | ((state->
v[i0]) >> (64 - r0));
262 state->
v[i0] ^= state->
v[0];
264 state->
v[2] += state->
v[i2];
265 state->
v[i2] = ((state->
v[i2]) << r2) | ((state->
v[i2]) >> (64 - r2));
266 state->
v[i2] ^= state->
v[2];
272 state->
v[0] += par->
v[i0];
273 state->
v[1] += par->
v[i1];
281 state->
v[0] += par->
v[i0];
282 state->
v[1] += par->
v[i1];
283 state->
v[2] += par->
v[i2];
284 state->
v[3] += par->
v[i3];
291 state->
v[0] += par->
v[i0];
292 state->
v[1] += par->
v[i1];
300 state->
v[0] += par->
v[i0];
301 state->
v[1] += par->
v[i1];
302 state->
v[2] += par->
v[i2];
303 state->
v[3] += par->
v[i3];
462 rng->
key.
v[0] = seed;
476 rng->
key.
v[0] = seed;
490 rng->
key.
v[0] = seed;
504 rng->
key.
v[0] = seed;
515 if (rng->
index == 2) {
528 if (rng->
index == 4) {
541 if (rng->
index == 2) {
554 if (rng->
index == 4) {
563 #endif // VSMC_RNGC_THREEFRY_H
static void vsmc_threefry4x32_initpar(const vsmc_threefry4x32_key_t *key, vsmc_threefry4x32_par_t *par)
static void vsmc_threefry4x32_rotate(vsmc_threefry4x32_ctr_t *state, uint32_t r0, uint32_t r2, int i0, int i2)
static void vsmc_threefry2x32_init(vsmc_threefry2x32 *rng, uint32_t seed)
Initialize Threefry2x32 RNG state.
static void vsmc_threefry4x32_inc(vsmc_threefry4x32_ctr_t *ctr)
static void vsmc_threefry2x64_inc(vsmc_threefry2x64_ctr_t *ctr)
vsmc_threefry2x32_key_t key
static void vsmc_threefry4x64_init(vsmc_threefry4x64 *rng, uint64_t seed)
Initialize Threefry4x64 RNG state.
Threefry2x64 counter type.
static void vsmc_threefry2x64_init(vsmc_threefry2x64 *rng, uint64_t seed)
Initialize Threefry2x64 RNG state.
static void vsmc_threefry2x32_gen(const vsmc_threefry2x32_ctr_t *ctr, const vsmc_threefry2x32_key_t *key, vsmc_threefry2x32_ctr_t *state)
Generate Threefry2x32 RNG state.
vsmc_threefry2x64_ctr_t ctr
static void vsmc_threefry4x64_insertkey(vsmc_threefry4x64_ctr_t *state, const vsmc_threefry4x64_par_t *par, uint64_t inc, int i0, int i1, int i2, int i3)
Threefry4x64 counter type.
static void vsmc_threefry2x64_rotate(vsmc_threefry2x64_ctr_t *state, uint64_t r)
static void vsmc_threefry4x64_initpar(const vsmc_threefry4x64_key_t *key, vsmc_threefry4x64_par_t *par)
static void vsmc_threefry2x32_initpar(const vsmc_threefry2x32_key_t *key, vsmc_threefry2x32_par_t *par)
vsmc_threefry4x32_ctr_t state
vsmc_threefry4x32_key_t key
static void vsmc_threefry4x64_gen(const vsmc_threefry4x64_ctr_t *ctr, const vsmc_threefry4x64_key_t *key, vsmc_threefry4x64_ctr_t *state)
Generate Threefry4x64 RNG state.
static void vsmc_threefry4x32_init(vsmc_threefry4x32 *rng, uint32_t seed)
Initialize Threefry4x32 RNG state.
vsmc_threefry4x64_key_t key
static void vsmc_threefry4x32_insertkey(vsmc_threefry4x32_ctr_t *state, const vsmc_threefry4x32_par_t *par, uint32_t inc, int i0, int i1, int i2, int i3)
vsmc_threefry2x32_ctr_t state
Threefry2x32 counter type.
vsmc_threefry4x64_ctr_t state
static uint64_t vsmc_threefry2x64_rand(vsmc_threefry2x64 *rng)
Generate random 64-bits integers from Threefry2x64 RNG.
Threefry2x32 RNG state structure.
Threefry2x64 RNG state structure.
static uint32_t vsmc_threefry2x32_rand(vsmc_threefry2x32 *rng)
Generate random 32-bits integers from Threefry2x32 RNG.
Threefry4x32 counter type.
vsmc_threefry4x32_ctr_t ctr
static void vsmc_threefry2x32_insertkey(vsmc_threefry2x32_ctr_t *state, const vsmc_threefry2x32_par_t *par, uint32_t inc, int i0, int i1)
Threefry4x32 RNG state structure.
Threefry4x64 RNG state structure.
static void vsmc_threefry2x64_gen(const vsmc_threefry2x64_ctr_t *ctr, const vsmc_threefry2x64_key_t *key, vsmc_threefry2x64_ctr_t *state)
Generate Threefry2x64 RNG state.
static void vsmc_threefry2x64_insertkey(vsmc_threefry2x64_ctr_t *state, const vsmc_threefry2x64_par_t *par, uint64_t inc, int i0, int i1)
vsmc_threefry2x64_key_t key
static uint64_t vsmc_threefry4x64_rand(vsmc_threefry4x64 *rng)
Generate random 64-bits integers from Threefry4x64 RNG.
static void vsmc_threefry4x64_rotate(vsmc_threefry4x64_ctr_t *state, uint64_t r0, uint64_t r2, int i0, int i2)
static void vsmc_threefry2x64_initpar(const vsmc_threefry2x64_key_t *key, vsmc_threefry2x64_par_t *par)
vsmc_threefry4x64_ctr_t ctr
static uint32_t vsmc_threefry4x32_rand(vsmc_threefry4x32 *rng)
Generate random 32-bits integers from Threefry4x32 RNG.
static void vsmc_threefry4x32_gen(const vsmc_threefry4x32_ctr_t *ctr, const vsmc_threefry4x32_key_t *key, vsmc_threefry4x32_ctr_t *state)
Generate Threefry4x32 RNG state.
static void vsmc_threefry2x32_rotate(vsmc_threefry2x32_ctr_t *state, uint32_t r)
vsmc_threefry2x64_ctr_t state
static void vsmc_threefry4x64_inc(vsmc_threefry4x64_ctr_t *ctr)
vsmc_threefry2x32_ctr_t ctr
static void vsmc_threefry2x32_inc(vsmc_threefry2x32_ctr_t *ctr)