The ROme OpTimistic Simulator  3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
test_rng.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <core/intrinsics.h>
14 
15 #include <memory.h>
16 #include <stdint.h>
17 
19 typedef __uint128_t test_rng_state;
20 
22 #define LCG_MULTIPLIER \
23  ((((__uint128_t)0x0fc94e3bf4e9ab32ULL) << 64) + 0x866458cd56f5e605ULL)
24 
30 #define lcg_init(rng_state, initseq) (rng_state) = ((initseq) << 1u) | 1u
31 
37 #define lcg_random_u(rng_state) \
38 __extension__({ \
39  (rng_state) *= LCG_MULTIPLIER; \
40  uint64_t __rng_val = (uint64_t)((rng_state) >> 64); \
41  __rng_val; \
42 })
43 
49 #define lcg_random(rng_state) \
50 __extension__({ \
51  uint64_t __u_val = lcg_random_u(rng_state); \
52  double __ret = 0.0; \
53  if (__builtin_expect(!!__u_val, 1)) { \
54  unsigned __lzs = intrinsics_clz(__u_val) + 1; \
55  __u_val <<= __lzs; \
56  __u_val >>= 12; \
57  \
58  uint64_t __exp = 1023 - __lzs; \
59  __u_val |= __exp << 52; \
60  \
61  memcpy(&__ret, &__u_val, sizeof(double)); \
62  } \
63  __ret; \
64 })
65 
intrinsics.h
Easier access to compiler extensions.
test_rng_state
__uint128_t test_rng_state
The type of this pseudo random number generator state.
Definition: test_rng.h:19