Changes in libcfa/src/stdlib.cfa [15b05c8:1959528]
- File:
-
- 1 edited
-
libcfa/src/stdlib.cfa (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.cfa
r15b05c8 r1959528 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 3 09:36:27202213 // Update Count : 5 1912 // Last Modified On : Wed Jan 12 16:25:36 2022 13 // Update Count : 578 14 14 // 15 15 16 16 #include "stdlib.hfa" 17 //#include "concurrency/kernel/fwd.hfa" 18 #include "concurrency/invoke.h" // random_state 17 19 18 20 //--------------------------------------- … … 221 223 //--------------------------------------- 222 224 223 static uint32_t seed = 0; // current seed 224 static thread_local uint32_t state; // random state 225 226 void set_seed( uint32_t seed_ ) { state = seed = seed_; } 227 uint32_t get_seed() { return seed; } 225 // Pipelined to allow OoO overlap with reduced dependencies. Critically, return the current value, and compute and store 226 // the next value. 228 227 229 228 #define GENERATOR LCG 230 229 231 inline uint32_t MarsagliaXor( uint32_t & state ) { 232 if ( unlikely( seed == 0 ) ) set_seed( rdtscl() ); 233 else if ( unlikely( state == 0 ) ) state = seed; 230 static inline uint32_t MarsagliaXor( uint32_t & state ) { 231 uint32_t ret = state; 234 232 state ^= state << 6; 235 233 state ^= state >> 21; 236 234 state ^= state << 7; 237 return state;235 return ret; 238 236 } // MarsagliaXor 239 237 240 inline uint32_t LCG( uint32_t & state ) {// linear congruential generator241 if ( unlikely( seed == 0 ) ) set_seed( rdtscl() );242 else if ( unlikely( state == 0 ) ) state = seed;243 return state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime!238 static inline uint32_t LCG( uint32_t & state ) { // linear congruential generator 239 uint32_t ret = state; 240 state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime! No not change it! 241 return ret; 244 242 } // LCG 245 243 244 uint32_t __global_random_seed; 245 246 void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; GENERATOR( state ); } // set seed 246 247 uint32_t prng( PRNG & prng ) with( prng ) { callcnt += 1; return GENERATOR( state ); } 247 248 248 uint32_t prng( void ) { return GENERATOR( state ); } 249 void set_seed( uint32_t seed ) { 250 active_thread()->random_state = __global_random_seed = seed; 251 GENERATOR( active_thread()->random_state ); 252 } // set_seed 253 uint32_t get_seed() { return __global_random_seed; } 254 uint32_t prng( void ) { return GENERATOR( active_thread()->random_state ); } // [0,UINT_MAX] 249 255 250 256 //---------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.