1*7877fdebSMatt Macy /*
2*7877fdebSMatt Macy * Xorshift Pseudo Random Number Generator based on work by David Blackman
3*7877fdebSMatt Macy * and Sebastiano Vigna (vigna@acm.org).
4*7877fdebSMatt Macy *
5*7877fdebSMatt Macy * "Further scramblings of Marsaglia's xorshift generators"
6*7877fdebSMatt Macy * http://vigna.di.unimi.it/ftp/papers/xorshiftplus.pdf
7*7877fdebSMatt Macy * http://prng.di.unimi.it/xoroshiro128plusplus.c
8*7877fdebSMatt Macy *
9*7877fdebSMatt Macy * To the extent possible under law, the author has dedicated all copyright
10*7877fdebSMatt Macy * and related and neighboring rights to this software to the public domain
11*7877fdebSMatt Macy * worldwide. This software is distributed without any warranty.
12*7877fdebSMatt Macy *
13*7877fdebSMatt Macy * See <http://creativecommons.org/publicdomain/zero/1.0/>.
14*7877fdebSMatt Macy *
15*7877fdebSMatt Macy * This is xoroshiro128++ 1.0, one of our all-purpose, rock-solid,
16*7877fdebSMatt Macy * small-state generators. It is extremely (sub-ns) fast and it passes all
17*7877fdebSMatt Macy * tests we are aware of, but its state space is large enough only for
18*7877fdebSMatt Macy * mild parallelism.
19*7877fdebSMatt Macy */
20*7877fdebSMatt Macy
21*7877fdebSMatt Macy #include <sys/vdev_draid.h>
22*7877fdebSMatt Macy
rotl(const uint64_t x,int k)23*7877fdebSMatt Macy static inline uint64_t rotl(const uint64_t x, int k)
24*7877fdebSMatt Macy {
25*7877fdebSMatt Macy return (x << k) | (x >> (64 - k));
26*7877fdebSMatt Macy }
27*7877fdebSMatt Macy
28*7877fdebSMatt Macy uint64_t
vdev_draid_rand(uint64_t * s)29*7877fdebSMatt Macy vdev_draid_rand(uint64_t *s)
30*7877fdebSMatt Macy {
31*7877fdebSMatt Macy const uint64_t s0 = s[0];
32*7877fdebSMatt Macy uint64_t s1 = s[1];
33*7877fdebSMatt Macy const uint64_t result = rotl(s0 + s1, 17) + s0;
34*7877fdebSMatt Macy
35*7877fdebSMatt Macy s1 ^= s0;
36*7877fdebSMatt Macy s[0] = rotl(s0, 49) ^ s1 ^ (s1 << 21); // a, b
37*7877fdebSMatt Macy s[1] = rotl(s1, 28); // c
38*7877fdebSMatt Macy
39*7877fdebSMatt Macy return (result);
40*7877fdebSMatt Macy }
41