]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.1.0/test_and_benchmark/libbenchmark/inc/libbenchmark/libbenchmark_prng.h
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.1.0 / test_and_benchmark / libbenchmark / inc / libbenchmark / libbenchmark_prng.h
1 /***** defines *****/
2 #define LIBBENCHMARK_PRNG_MAX   ( (lfds710_pal_uint_t) -1 )
3
4 // TRD : 32-bit SplitMix, derived from Sebastiano vigna's site, CC0 license, http://xorshift.di.unimi.it/splitmix64.c, and email with Dr. Vigna
5 #if( LFDS710_PAL_ALIGN_SINGLE_POINTER == 4 ) // TRD : any 32-bit platform
6   // TRD : struct LIBBENCHMARK_prng_state prng_state, lfds710_pal_uint_t seed
7   #define LIBBENCHMARK_PRNG_INIT( prng_state, seed )  (prng_state).entropy = (seed), (prng_state).entropy = ((prng_state).entropy ^ ((prng_state).entropy >> 16)) * 0x85ebca6bUL, (prng_state).entropy = ((prng_state).entropy ^ ((prng_state).entropy >> 13)) * 0xc2b2ae35UL, (prng_state).entropy = ((prng_state).entropy ^ ((prng_state).entropy >> 16))
8
9   // TRD : struct libbenchmark_prng_state prng_state, LIBBENCHMARK_pal_atom_t random_value
10   #define LIBBENCHMARK_PRNG_GENERATE( prng_state, random_value )                \
11   {                                                                             \
12     (random_value) = ( (prng_state).entropy += 0x9E3779B9UL );                  \
13     (random_value) = ((random_value) ^ ((random_value) >> 16)) * 0x85ebca6bUL;  \
14     (random_value) = ((random_value) ^ ((random_value) >> 13)) * 0xc2b2ae35UL;  \
15     (random_value) = (random_value ^ (random_value >> 16));                     \
16   }
17
18   #define LIBBENCHMARK_PRNG_MURMURHASH3_MIXING_FUNCTION( random_value )  \
19   {                                                                      \
20         (random_value) ^= ((random_value) >> 16);                            \
21         (random_value) *= 0x85ebca6b;                                        \
22         (random_value) ^= ((random_value) >> 13);                            \
23         (random_value) *= 0xc2b2ae35;                                        \
24         (random_value) ^= ((random_value) >> 16);                            \
25   }
26 #endif
27
28 // TRD : 64-bit SplitMix, from Sebastiano vigna's site, CC0 license, http://xorshift.di.unimi.it/splitmix64.c
29 #if( LFDS710_PAL_ALIGN_SINGLE_POINTER == 8 ) // TRD : any 64-bit platform
30   // TRD : struct LIBBENCHMARK_prng_state prng_state, LIBBENCHMARK_atom_uint_t seed
31   #define LIBBENCHMARK_PRNG_INIT( prng_state, seed )  (prng_state).entropy = (seed), (prng_state).entropy = ((prng_state).entropy ^ ((prng_state).entropy >> 33)) * 0xff51afd7ed558ccdULL, (prng_state).entropy = ((prng_state).entropy ^ ((prng_state).entropy >> 33)) * 0xc4ceb9fe1a85ec53ULL, (prng_state).entropy = ((prng_state).entropy ^ ((prng_state).entropy >> 33))
32
33   // TRD : struct libbenchmark_prng_state prng_state, lfds710_pal_uint_t random_value
34   #define LIBBENCHMARK_PRNG_GENERATE( prng_state, random_value )                         \
35   {                                                                                      \
36     (random_value) = ( (prng_state).entropy += 0x9E3779B97F4A7C15ULL );                  \
37     (random_value) = ((random_value) ^ ((random_value) >> 30)) * 0xBF58476D1CE4E5B9ULL;  \
38     (random_value) = ((random_value) ^ ((random_value) >> 27)) * 0x94D049BB133111EBULL;  \
39     (random_value) = (random_value ^ (random_value >> 31));                              \
40   }
41
42   #define LIBBENCHMARK_PRNG_MURMURHASH3_MIXING_FUNCTION( random_value )  \
43   {                                                                      \
44         (random_value) ^= (random_value) >> 33;                              \
45         (random_value) *= 0xff51afd7ed558ccdULL;                             \
46         (random_value) ^= (random_value) >> 33;                              \
47         (random_value) *= 0xc4ceb9fe1a85ec53ULL;                             \
48         (random_value) ^= (random_value) >> 33;                              \
49   }
50 #endif
51
52 /***** enums *****/
53
54 /***** structs *****/
55 struct libbenchmark_prng_state
56 {
57   lfds710_pal_uint_t
58     entropy;
59 };
60
61 /***** externs *****/
62
63 /***** public prototypes *****/
64