5
5
#ifndef BITCOIN_TEST_UTIL_XOROSHIRO128PLUSPLUS_H
6
6
#define BITCOIN_TEST_UTIL_XOROSHIRO128PLUSPLUS_H
7
7
8
+ #include < bit>
8
9
#include < cstdint>
9
10
#include < limits>
10
11
@@ -21,26 +22,19 @@ class XoRoShiRo128PlusPlus
21
22
uint64_t m_s0;
22
23
uint64_t m_s1;
23
24
24
- [[nodiscard]] constexpr static uint64_t rotl (uint64_t x, int n)
25
- {
26
- return (x << n) | (x >> (64 - n));
27
- }
28
-
29
25
[[nodiscard]] constexpr static uint64_t SplitMix64 (uint64_t & seedval) noexcept
30
26
{
31
- uint64_t z = (seedval += UINT64_C ( 0x9e3779b97f4a7c15 ) );
32
- z = (z ^ (z >> 30U )) * UINT64_C ( 0xbf58476d1ce4e5b9 ) ;
33
- z = (z ^ (z >> 27U )) * UINT64_C ( 0x94d049bb133111eb ) ;
34
- return z ^ (z >> 31U );
27
+ uint64_t z = (seedval += 0x9e3779b97f4a7c15 );
28
+ z = (z ^ (z >> 30 )) * 0xbf58476d1ce4e5b9 ;
29
+ z = (z ^ (z >> 27 )) * 0x94d049bb133111eb ;
30
+ return z ^ (z >> 31 );
35
31
}
36
32
37
33
public:
38
34
using result_type = uint64_t ;
39
35
40
36
constexpr explicit XoRoShiRo128PlusPlus (uint64_t seedval) noexcept
41
- : m_s0(SplitMix64(seedval)), m_s1(SplitMix64(seedval))
42
- {
43
- }
37
+ : m_s0(SplitMix64(seedval)), m_s1(SplitMix64(seedval)) {}
44
38
45
39
// no copy - that is dangerous, we don't want accidentally copy the RNG and then have two streams
46
40
// with exactly the same results. If you need a copy, call copy().
@@ -51,15 +45,13 @@ class XoRoShiRo128PlusPlus
51
45
XoRoShiRo128PlusPlus (XoRoShiRo128PlusPlus&&) = default ;
52
46
XoRoShiRo128PlusPlus& operator =(XoRoShiRo128PlusPlus&&) = default ;
53
47
54
- ~XoRoShiRo128PlusPlus () = default ;
55
-
56
48
constexpr result_type operator ()() noexcept
57
49
{
58
50
uint64_t s0 = m_s0, s1 = m_s1;
59
- const uint64_t result = rotl (s0 + s1, 17 ) + s0;
51
+ const uint64_t result = std:: rotl (s0 + s1, 17 ) + s0;
60
52
s1 ^= s0;
61
- m_s0 = rotl (s0, 49 ) ^ s1 ^ (s1 << 21 );
62
- m_s1 = rotl (s1, 28 );
53
+ m_s0 = std:: rotl (s0, 49 ) ^ s1 ^ (s1 << 21 );
54
+ m_s1 = std:: rotl (s1, 28 );
63
55
return result;
64
56
}
65
57
0 commit comments