The ROme OpTimistic Simulator  3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
xoroshiro.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <stdint.h>
14 
15 #define rotl(x, k) (((x) << (k)) | ((x) >> (64 - (k))))
16 
17 #define random_u64(rng_s) \
18 __extension__ ({ \
19  const uint64_t __res = rotl((rng_s)[1] * 5, 7) * 9; \
20  const uint64_t __t = (rng_s)[1] << 17; \
21  \
22  (rng_s)[2] ^= (rng_s)[0]; \
23  (rng_s)[3] ^= (rng_s)[1]; \
24  (rng_s)[1] ^= (rng_s)[2]; \
25  (rng_s)[0] ^= (rng_s)[3]; \
26  (rng_s)[2] ^= __t; \
27  (rng_s)[3] = rotl((rng_s)[3], 45); \
28  \
29  __res; \
30 })
31 
32 // FIXME: this is a very poor way to seed the generator
33 #define random_init(rng_s, llid, seed) \
34 __extension__ ({ \
35  (rng_s)[0] = (llid + 1) * UINT64_C(16232384076195101791) ^ seed;\
36  (rng_s)[1] = (llid + 1) * UINT64_C(13983006573105492179) ^ seed;\
37  (rng_s)[2] = (llid + 1) * UINT64_C(10204677566545858177) ^ seed;\
38  (rng_s)[3] = (llid + 1) * UINT64_C(14539058011249359317) ^ seed;\
39  unsigned __i = 1024; \
40  while (__i--) \
41  random_u64((rng_s)); \
42 })
43