Lines Matching +full:half +full:- +full:bit

9  *   https://github.com/imneme/pcg-c
11 * -----------------------------------------------------------------------------
15 * Copyright (c) 2014-2017 Melissa O'Neill and PCG Project contributors
16 * Copyright (c) 2018-2024 Gavin D. Howard and contributors.
64 * Adds two 64-bit values and preserves the overflow.
81 * Adds two 128-bit values and discards the overflow.
99 * Multiplies two 64-bit values and preserves the overflow.
129 * Multiplies two 128-bit values and discards the overflow.
161 r->inc |= (BcRandState) 1UL;
163 r->inc.lo |= (uint_fast64_t) 1UL;
176 r->inc &= ~((BcRandState) 1UL);
178 r->inc.lo &= ~(1UL);
251 * Reads random data from rand(), byte-by-byte because rand() is only guaranteed
253 * preferred as it is possible to access cryptographically-secure PRNG's on most
266 // Fill up the unsigned long byte-by-byte.
277 * bit.
279 * @return The increment of the PRNG, including the last odd bit.
287 inc = r->inc | 1;
289 inc.lo = r->inc.lo | 1;
290 inc.hi = r->inc.hi;
304 r->inc <<= 1UL;
306 r->inc.hi <<= 1UL;
307 r->inc.hi |= (r->inc.lo & (1UL << (BC_LONG_BIT - 1))) >> (BC_LONG_BIT - 1);
308 r->inc.lo <<= 1UL;
315 * @param val1 The lower half of the state.
316 * @param val2 The upper half of the state.
324 state->lo = val1;
325 state->hi = val2;
332 * @param state1 The lower half of the state.
333 * @param state2 The upper half of the state.
334 * @param inc1 The lower half of the increment.
335 * @param inc2 The upper half of the increment.
341 bc_rand_seedState(&r->state, state1, state2);
342 bc_rand_seedState(&r->inc, inc1, inc2);
373 BcRandState temp = bc_rand_mul2(r->state, bc_rand_multiplier);
374 r->state = bc_rand_add2(temp, bc_rand_inc(r));
385 return BC_RAND_ROT(BC_RAND_FOLD(r->state), BC_RAND_ROTAMT(r->state));
400 if (r->v.len <= idx) return;
403 rng2 = bc_vec_item_rev(&r->v, idx);
411 for (i = 1; i < r->v.len; ++i)
413 bc_rand_copy(bc_vec_item_rev(&r->v, i), rng);
470 if (r->v.len <= 1) return;
479 for (i = 1; go && i < r->v.len; ++i)
481 BcRNGData* rng2 = bc_vec_item_rev(&r->v, i);
499 BcRNGData* rng = bc_vec_top(&r->v);
524 threshold = (0 - bound) % bound;
539 BcRNGData* rng = bc_vec_top(&r->v);
542 bc_rand_seedState(&rng->inc, inc1, inc2);
551 memcpy(&rng->state, &rng->inc, sizeof(BcRandState));
554 else bc_rand_seedState(&rng->state, state1, state2);
561 * Returns the increment in the PRNG *without* the odd bit and also with being
562 * shifted one bit down.
564 * @return The increment without the odd bit and with being shifted one bit
573 res = r->inc >> 1;
575 res = r->inc;
577 res.lo |= (res.hi & 1) << (BC_LONG_BIT - 1);
588 BcRNGData* rng = bc_vec_top(&r->v);
596 *s1 = BC_RAND_TRUNC(rng->state);
597 *s2 = BC_RAND_CHOP(rng->state);
607 BcRNGData* rng = bc_vec_pushEmpty(&r->v);
615 if (r->v.len > 1) bc_rand_copy(rng, bc_vec_item_rev(&r->v, 1));
621 bc_vec_npop(&r->v, reset ? r->v.len - 1 : 1);
628 bc_vec_init(&r->v, sizeof(BcRNGData), BC_DTOR_NONE);
637 bc_vec_free(&r->v);