source: libcfa/src/bits/random.hfa @ 13c5e19

arm-ehjacob/cs343-translationnew-astnew-ast-unique-expr
Last change on this file since 13c5e19 was 13c5e19, checked in by Thierry Delisle <tdelisle@…>, 17 months ago
  • Moved snzi and subqueues outside of ready_queue.cfa.
  • Added random.hfa with multiple prng.
  • Minor optimizations to ready-queue
  • Stats now track number of local pops( bias pops )
  • Fixed stats for io
  • Fixed calculaton of nprocessors
  • Fixed IO to work with new ready-queue
  • Property mode set to 100644
File size: 1.4 KB
Line 
1#pragma once
2
3#include <stdint.h>
4
5//--------------------------------------------------
6typedef __uint128_t __lehmer64_state_t;
7static inline uint64_t __lehmer64( __lehmer64_state_t & state ) {
8        state *= 0xda942042e4dd58b5;
9        return state >> 64;
10}
11
12//--------------------------------------------------
13typedef uint64_t __wyhash64_state_t;
14static inline uint64_t __wyhash64( __wyhash64_state_t & state ) {
15        state += 0x60bee2bee120fc15;
16        __uint128_t tmp;
17        tmp = (__uint128_t) state * 0xa3b195354a39b70d;
18        uint64_t m1 = (tmp >> 64) ^ tmp;
19        tmp = (__uint128_t)m1 * 0x1b03738712fad5c9;
20        uint64_t m2 = (tmp >> 64) ^ tmp;
21        return m2;
22}
23
24//--------------------------------------------------
25typedef uint64_t __xorshift64_state_t;
26static inline uint64_t __xorshift64( __xorshift64_state_t & state ) {
27        uint64_t x = state;
28        x ^= x << 13;
29        x ^= x >> 7;
30        x ^= x << 17;
31        return state = x;
32}
33
34//--------------------------------------------------
35typedef struct {
36  uint32_t a, b, c, d;
37  uint32_t counter;
38} __xorwow__state_t;
39
40/* The state array must be initialized to not be all zero in the first four words */
41static inline uint32_t __xorwow( __xorwow__state_t & state ) {
42        /* Algorithm "xorwow" from p. 5 of Marsaglia, "Xorshift RNGs" */
43        uint32_t t = state.d;
44
45        uint32_t const s = state.a;
46        state.d = state.c;
47        state.c = state.b;
48        state.b = s;
49
50        t ^= t >> 2;
51        t ^= t << 1;
52        t ^= s ^ (s << 4);
53        state.a = t;
54
55        state.counter += 362437;
56        return t + state.counter;
57}
Note: See TracBrowser for help on using the repository browser.