From 00c4e2636ec0febc549a9fea5499655155ced093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Tue, 27 Feb 2024 20:46:27 +0300 Subject: [PATCH] =?UTF-8?q?mdbx-test:=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=93=D0=9F=D0=A1=D0=A7.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/utils.c++ | 14 +++++++++----- test/utils.h++ | 29 ++++++++++++++++------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/test/utils.c++ b/test/utils.c++ index 399ea472..fd32c689 100644 --- a/test/utils.c++ +++ b/test/utils.c++ @@ -107,18 +107,22 @@ uint64_t prng64_white(uint64_t &state) { return bleach64(state); } -uint32_t prng32(uint64_t &state) { - return (uint32_t)(prng64_careless(state) >> 32); +uint32_t prng32_fast(uint64_t &state) { + 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) { - uint32_t u32 = prng32(state); + uint32_t u32 = prng32_fast(state); while (bytes >= 4) { memcpy(ptr, &u32, 4); ptr = (uint32_t *)ptr + 1; bytes -= 4; - u32 = prng32(state); + u32 = prng32_fast(state); } 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); } -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); } diff --git a/test/utils.h++ b/test/utils.h++ index f8083437..055e7912 100644 --- a/test/utils.h++ +++ b/test/utils.h++ @@ -288,24 +288,26 @@ inline bool is_samedata(const MDBX_val &a, const MDBX_val &b) { } std::string format(const char *fmt, ...); -static inline uint64_t bleach64(uint64_t v) { - // Tommy Ettinger, https://www.blogger.com/profile/04953541827437796598 - // http://mostlymangling.blogspot.com/2019/01/better-stronger-mixer-and-test-procedure.html - v ^= rot64(v, 25) ^ rot64(v, 50); - v *= UINT64_C(0xA24BAED4963EE407); - v ^= rot64(v, 24) ^ rot64(v, 49); - v *= UINT64_C(0x9FB21C651E98DF25); - return v ^ v >> 28; +static inline uint64_t bleach64(uint64_t x) { + // NASAM from Tommy Ettinger, + // https://www.blogger.com/profile/04953541827437796598 + // http://mostlymangling.blogspot.com/2020/01/nasam-not-another-strange-acronym-mixer.html + x ^= rot64(x, 25) ^ rot64(x, 47); + x *= UINT64_C(0x9E6C63D0676A9A99); + x ^= x >> 23 ^ x >> 51; + x *= UINT64_C(0x9E6D62D06F6A9A9B); + x ^= x >> 23 ^ x >> 51; + return x; } static inline uint32_t bleach32(uint32_t x) { // https://github.com/skeeto/hash-prospector - // exact bias: 0.17353355999581582 + // exact bias: 0.10760229515479501 x ^= x >> 16; - x *= UINT32_C(0x7feb352d); + x *= UINT32_C(0x21f0aaad); x ^= 0x3027C563 ^ (x >> 15); - x *= UINT32_C(0x846ca68b); - x ^= x >> 16; + x *= UINT32_C(0x0d35a2d97); + x ^= x >> 15; return x; } @@ -343,7 +345,8 @@ static inline double u64_to_double1(uint64_t v) { } 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); extern uint64_t prng_state;