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