Changes in / [70cd431:74227c6]
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/random.hfa
r70cd431 r74227c6 10 10 // Created On : Fri Jan 14 07:18:11 2022 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 9 17:08:30202213 // Update Count : 1 6912 // Last Modified On : Mon Dec 5 13:13:14 2022 13 // Update Count : 128 14 14 // 15 15 … … 23 23 // Set default PRNG for architecture size. 24 24 #ifdef __x86_64__ // 64-bit architecture 25 // 64-bit generators 26 #define LEHMER64 27 //#define XORSHIFT_12_25_27 28 //#define XOSHIRO256PP 29 //#define KISS_64 30 31 // 32-bit generators 32 #define XORSHIFT_6_21_7 33 //#define XOSHIRO128PP 25 #define LEHMER64 26 #define XORSHIFT_6_21_7 27 //#define XOSHIRO256PP 28 //#define XOSHIRO128PP 34 29 #else // 32-bit architecture 35 // 64-bit generators 36 #define XORSHIFT_13_7_17 37 38 // 32-bit generators 39 #define XORSHIFT_6_21_7 30 #define XORSHIFT_13_7_17 31 #define XORSHIFT_6_21_7 40 32 #endif // __x86_64__ 41 33 … … 43 35 44 36 // SKULLDUGGERY: typedefs name struct and typedef with the same name to deal with CFA typedef numbering problem. 37 38 #ifdef LEHMER64 39 #define PRNG_NAME_64 lehmer64 40 #define PRNG_STATE_64_T __uint128_t 41 #endif // LEHMER64 42 43 #ifdef XORSHIFT_13_7_17 44 #define PRNG_NAME_64 xorshift_13_7_17 45 #define PRNG_STATE_64_T uint64_t 46 #endif // XORSHIFT_13_7_17 47 48 #ifdef XORSHIFT_6_21_7 49 #define PRNG_NAME_32 xorshift_6_21_7 50 #define PRNG_STATE_32_T uint32_t 51 #endif // XORSHIFT_6_21_7 45 52 46 53 #ifdef XOSHIRO256PP … … 55 62 typedef struct PRNG_STATE_32_T { uint32_t s[4]; } PRNG_STATE_32_T; 56 63 #endif // XOSHIRO128PP 57 58 #ifdef LEHMER6459 #define PRNG_NAME_64 lehmer6460 #define PRNG_STATE_64_T __uint128_t61 #endif // LEHMER6462 63 #ifdef WYHASH6464 #define PRNG_NAME_64 wyhash6465 #define PRNG_STATE_64_T uint64_t66 #endif // LEHMER6467 68 #ifdef XORSHIFT_13_7_1769 #define PRNG_NAME_64 xorshift_13_7_1770 #define PRNG_STATE_64_T uint64_t71 #endif // XORSHIFT_13_7_1772 73 #ifdef XORSHIFT_6_21_774 #define PRNG_NAME_32 xorshift_6_21_775 #define PRNG_STATE_32_T uint32_t76 #endif // XORSHIFT_6_21_777 78 #ifdef XORSHIFT_12_25_2779 #define PRNG_NAME_64 xorshift_12_25_2780 #define PRNG_STATE_64_T uint64_t81 #endif // XORSHIFT_12_25_2782 83 #ifdef KISS_6484 #define PRNG_NAME_64 kiss_6485 #define PRNG_STATE_64_T GLUE(PRNG_NAME_64,_t)86 typedef struct PRNG_STATE_64_T { uint64_t z, w, jsr, jcong; } PRNG_STATE_64_T;87 #endif // KISS_^6488 64 89 65 #ifdef XORWOW … … 109 85 110 86 111 // ALL PRNG ALGORITHMS ARE OPTIMIZED SO THAT THE PRNG LOGIC CAN HAPPEN IN PARALLEL WITH THE USE OF THE RESULT.112 // Therefore, the set_seed routine primes the state by calling the PRNG with the state so the seed is not return as the113 // first random value.114 115 87 #ifdef __cforall // don't include in C code (invoke.h) 116 88 … … 148 120 static inline void xoshiro256pp_set_seed( xoshiro256pp_t & state, uint64_t seed ) { 149 121 state = (xoshiro256pp_t){ {seed, seed, seed, seed} }; 150 xoshiro256pp( state );151 122 } // xoshiro256pp_set_seed 152 123 … … 183 154 static inline void xoshiro128pp_set_seed( xoshiro128pp_t & state, uint32_t seed ) { 184 155 state = (xoshiro128pp_t){ {seed, seed, seed, seed} }; 185 xoshiro128pp( state ); // prime186 156 } // xoshiro128pp_set_seed 187 157 … … 198 168 static inline void lehmer64_set_seed( __uint128_t & state, uint64_t seed ) { 199 169 state = seed; 200 lehmer64( state );201 170 } // lehmer64_set_seed 202 171 203 172 //-------------------------------------------------- 204 173 static inline uint64_t wyhash64( uint64_t & state ) { 205 uint64_t ret = state; 206 state += 0x_60be_e2be_e120_fc15; 174 state += 0x60bee2bee120fc15; 207 175 __uint128_t tmp; 208 tmp = (__uint128_t) ret * 0x_a3b1_9535_4a39_b70d;176 tmp = (__uint128_t) state * 0xa3b195354a39b70d; 209 177 uint64_t m1 = (tmp >> 64) ^ tmp; 210 tmp = (__uint128_t)m1 * 0x _1b03_7387_12fa_d5c9;178 tmp = (__uint128_t)m1 * 0x1b03738712fad5c9; 211 179 uint64_t m2 = (tmp >> 64) ^ tmp; 212 180 return m2; 213 } // wyhash64214 215 static inline void wyhash64_set_seed( uint64_t & state, uint64_t seed ) {181 } 182 183 static inline void wyhash64_set_seed( __uint128_t & state, uint64_t seed ) { 216 184 state = seed; 217 wyhash64( state ); // prime 218 } // wyhash64_set_seed 185 } // lehmer64_set_seed 219 186 #endif // __SIZEOF_INT128__ 220 187 … … 228 195 } // xorshift_13_7_17 229 196 230 static inline void xorshift_13_7_17_set_seed( uint64_t & state, uint 64_t seed ) {197 static inline void xorshift_13_7_17_set_seed( uint64_t & state, uint32_t seed ) { 231 198 state = seed; 232 xorshift_13_7_17( state ); // prime233 199 } // xorshift_13_7_17_set_seed 234 200 … … 248 214 static inline void xorshift_6_21_7_set_seed( uint32_t & state, uint32_t seed ) { 249 215 state = seed; 250 xorshift_6_21_7( state ); // prime251 216 } // xorshift_6_21_7_set_seed 252 253 //--------------------------------------------------254 // The state must be seeded with a nonzero value.255 static inline uint64_t xorshift_12_25_27( uint64_t & state ) {256 uint64_t ret = state;257 state ^= state >> 12;258 state ^= state << 25;259 state ^= state >> 27;260 return ret * 0x_2545_F491_4F6C_DD1D;261 } // xorshift_12_25_27262 263 static inline void xorshift_12_25_27_set_seed( uint64_t & state, uint64_t seed ) {264 state = seed;265 xorshift_12_25_27( state ); // prime266 } // xorshift_12_25_27_set_seed267 268 //--------------------------------------------------269 // The state must be seeded with a nonzero value.270 #ifndef KISS_64271 typedef struct kiss_64_t { uint64_t z, w, jsr, jcong; } kiss_64_t;272 #endif // ! KISS_64273 274 static inline uint64_t kiss_64( kiss_64_t & state ) with(state) {275 kiss_64_t ret = state;276 z = 36969 * (z & 65535) + (z >> 16);277 w = 18000 * (w & 65535) + (w >> 16);278 jsr ^= (jsr << 17);279 jsr ^= (jsr << 13);280 jsr ^= (jsr << 5);281 jcong = 69069 * jcong + 1234567;282 return ((ret.z << 16 + ret.w) ^ ret.jcong) + ret.jsr;283 } // kiss_64284 285 static inline void kiss_64_set_seed( kiss_64_t & state, uint64_t seed ) with(state) {286 z = 1; w = 1; jsr = 4; jcong = seed;287 kiss_64( state ); // prime288 } // kiss_64_set_seed289 217 290 218 //-------------------------------------------------- … … 294 222 #endif // ! XORWOW 295 223 296 static inline uint32_t xorwow( xorwow_t & state ) with(state){224 static inline uint32_t xorwow( xorwow_t & state ) { 297 225 // Algorithm "xorwow" from p. 5 of Marsaglia, "Xorshift RNGs". 298 uint32_t ret = a +counter;299 uint32_t t = d;300 301 uint32_t const s = a;302 d =c;303 c =b;304 b = s;226 uint32_t ret = state.a + state.counter; 227 uint32_t t = state.d; 228 229 uint32_t const s = state.a; 230 state.d = state.c; 231 state.c = state.b; 232 state.b = s; 305 233 306 234 t ^= t >> 2; 307 235 t ^= t << 1; 308 236 t ^= s ^ (s << 4); 309 a = t; 310 counter += 362437; 237 state.a = t; 238 239 state.counter += 362437; 311 240 return ret; 312 241 } // xorwow … … 314 243 static inline void xorwow_set_seed( xorwow_t & state, uint32_t seed ) { 315 244 state = (xorwow_t){ seed, seed, seed, seed, 0 }; 316 xorwow( state ); // prime317 245 } // xorwow_set_seed 318 246 -
libcfa/src/concurrency/thread.cfa
r70cd431 r74227c6 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 9 15:13:04202213 // Update Count : 9 812 // Last Modified On : Wed Nov 30 18:14:07 2022 13 // Update Count : 95 14 14 // 15 15 … … 230 230 void set_seed( size_t seed ) { 231 231 PRNG_STATE_T & state = active_thread()->random_state; 232 __global_random_seed = seed; 232 233 PRNG_SET_SEED( state, seed ); 233 __global_random_seed = seed;234 (void)PRNG_NAME( state ); // prime PRNG 234 235 __global_random_prime = seed; 235 236 __global_random_mask = true; -
libcfa/src/stdlib.cfa
r70cd431 r74227c6 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 9 15:11:30202213 // Update Count : 6 3112 // Last Modified On : Mon Dec 5 11:59:03 2022 13 // Update Count : 628 14 14 // 15 15 … … 232 232 __global_random_seed = seed; 233 233 PRNG_SET_SEED( __global_random_state, seed ); 234 PRNG_NAME( __global_random_state ); 234 235 } // set_seed 235 236 -
libcfa/src/stdlib.hfa
r70cd431 r74227c6 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 9 15:11:30202213 // Update Count : 76 312 // Last Modified On : Wed Nov 30 18:18:26 2022 13 // Update Count : 760 14 14 // 15 15 … … 426 426 427 427 static inline { 428 void set_seed( PRNG32 & prng, uint32_t seed_ ) with( prng ) { seed = seed_; PRNG_SET_SEED_32( state, seed ); }429 uint32_t get_seed( PRNG32 & prng ) __attribute__(( warn_unused_result )) with( prng ) { return seed; } 428 void set_seed( PRNG32 & prng, uint32_t seed_ ) with( prng ) { seed = seed_; PRNG_SET_SEED_32( state, seed ); PRNG_NAME_32( state ); } // set seed 429 uint32_t get_seed( PRNG32 & prng ) __attribute__(( warn_unused_result )) with( prng ) { return seed; } // get seed 430 430 uint32_t prng( PRNG32 & prng ) __attribute__(( warn_unused_result )) with( prng ) { callcnt += 1; return PRNG_NAME_32( state ); } // [0,UINT_MAX] 431 431 uint32_t prng( PRNG32 & prng, size_t u ) __attribute__(( warn_unused_result )) { return prng( prng ) % u; } // [0,u) … … 443 443 444 444 static inline { 445 void set_seed( PRNG64 & prng, uint64_t seed_ ) with( prng ) { seed = seed_; PRNG_SET_SEED_64( state, seed ); }446 uint64_t get_seed( PRNG64 & prng ) __attribute__(( warn_unused_result )) with( prng ) { return seed; } 445 void set_seed( PRNG64 & prng, uint64_t seed_ ) with( prng ) { seed = seed_; PRNG_SET_SEED_64( state, seed ); PRNG_NAME_64( state ); } // set seed 446 uint64_t get_seed( PRNG64 & prng ) __attribute__(( warn_unused_result )) with( prng ) { return seed; } // get seed 447 447 uint64_t prng( PRNG64 & prng ) __attribute__(( warn_unused_result )) with( prng ) { callcnt += 1; return PRNG_NAME_64( state ); } // [0,UINT_MAX] 448 448 uint64_t prng( PRNG64 & prng, size_t u ) __attribute__(( warn_unused_result )) { return prng( prng ) % u; } // [0,u) -
tests/.expect/nested_function.x64.txt
r70cd431 r74227c6 1 total 801 total 75
Note: See TracChangeset
for help on using the changeset viewer.