mdbx-test: обновление ГПСЧ.

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2024-02-27 20:46:27 +03:00
parent 3373631cff
commit 00c4e2636e
2 changed files with 25 additions and 18 deletions

View File

@ -107,18 +107,22 @@ uint64_t prng64_white(uint64_t &state) {
return bleach64(state); return bleach64(state);
} }
uint32_t prng32(uint64_t &state) { uint32_t prng32_fast(uint64_t &state) {
return (uint32_t)(prng64_careless(state) >> 32); return uint32_t(prng64_careless(state) >> 32);
}
uint32_t prng32_white(uint64_t &state) {
return bleach32(uint32_t(prng64_careless(state) >> 32));
} }
void prng_fill(uint64_t &state, void *ptr, size_t bytes) { void prng_fill(uint64_t &state, void *ptr, size_t bytes) {
uint32_t u32 = prng32(state); uint32_t u32 = prng32_fast(state);
while (bytes >= 4) { while (bytes >= 4) {
memcpy(ptr, &u32, 4); memcpy(ptr, &u32, 4);
ptr = (uint32_t *)ptr + 1; ptr = (uint32_t *)ptr + 1;
bytes -= 4; bytes -= 4;
u32 = prng32(state); u32 = prng32_fast(state);
} }
switch (bytes & 3) { switch (bytes & 3) {
@ -140,7 +144,7 @@ void prng_fill(uint64_t &state, void *ptr, size_t bytes) {
void prng_seed(uint64_t seed) { prng_state = bleach64(seed); } void prng_seed(uint64_t seed) { prng_state = bleach64(seed); }
uint32_t prng32(void) { return prng32(prng_state); } uint32_t prng32(void) { return prng32_white(prng_state); }
uint64_t prng64(void) { return prng64_white(prng_state); } uint64_t prng64(void) { return prng64_white(prng_state); }

View File

@ -288,24 +288,26 @@ inline bool is_samedata(const MDBX_val &a, const MDBX_val &b) {
} }
std::string format(const char *fmt, ...); std::string format(const char *fmt, ...);
static inline uint64_t bleach64(uint64_t v) { static inline uint64_t bleach64(uint64_t x) {
// Tommy Ettinger, https://www.blogger.com/profile/04953541827437796598 // NASAM from Tommy Ettinger,
// http://mostlymangling.blogspot.com/2019/01/better-stronger-mixer-and-test-procedure.html // https://www.blogger.com/profile/04953541827437796598
v ^= rot64(v, 25) ^ rot64(v, 50); // http://mostlymangling.blogspot.com/2020/01/nasam-not-another-strange-acronym-mixer.html
v *= UINT64_C(0xA24BAED4963EE407); x ^= rot64(x, 25) ^ rot64(x, 47);
v ^= rot64(v, 24) ^ rot64(v, 49); x *= UINT64_C(0x9E6C63D0676A9A99);
v *= UINT64_C(0x9FB21C651E98DF25); x ^= x >> 23 ^ x >> 51;
return v ^ v >> 28; x *= UINT64_C(0x9E6D62D06F6A9A9B);
x ^= x >> 23 ^ x >> 51;
return x;
} }
static inline uint32_t bleach32(uint32_t x) { static inline uint32_t bleach32(uint32_t x) {
// https://github.com/skeeto/hash-prospector // https://github.com/skeeto/hash-prospector
// exact bias: 0.17353355999581582 // exact bias: 0.10760229515479501
x ^= x >> 16; x ^= x >> 16;
x *= UINT32_C(0x7feb352d); x *= UINT32_C(0x21f0aaad);
x ^= 0x3027C563 ^ (x >> 15); x ^= 0x3027C563 ^ (x >> 15);
x *= UINT32_C(0x846ca68b); x *= UINT32_C(0x0d35a2d97);
x ^= x >> 16; x ^= x >> 15;
return x; return x;
} }
@ -343,7 +345,8 @@ static inline double u64_to_double1(uint64_t v) {
} }
uint64_t prng64_white(uint64_t &state); uint64_t prng64_white(uint64_t &state);
uint32_t prng32(uint64_t &state); uint32_t prng32_white(uint64_t &state);
uint32_t prng32_fast(uint64_t &state);
void prng_fill(uint64_t &state, void *ptr, size_t bytes); void prng_fill(uint64_t &state, void *ptr, size_t bytes);
extern uint64_t prng_state; extern uint64_t prng_state;