Changeset 2210cfc
- Timestamp:
- Jan 10, 2022, 5:43:42 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- c52f033
- Parents:
- 4177592f
- Location:
- libcfa/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/invoke.h
r4177592f r2210cfc 10 10 // Created On : Tue Jan 17 12:27:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jan 6 16:37:40202213 // Update Count : 4 712 // Last Modified On : Sun Jan 9 19:06:45 2022 13 // Update Count : 48 14 14 // 15 15 … … 211 211 struct processor * last_proc; 212 212 213 uint32_t random_state; // fast random numbers 214 213 215 #if defined( __CFA_WITH_VERIFY__ ) 214 216 void * canary; -
libcfa/src/concurrency/thread.cfa
r4177592f r2210cfc 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 4 09:17:49 201913 // Update Count : 912 // Last Modified On : Mon Jan 10 17:05:35 2022 13 // Update Count : 28 14 14 // 15 15 … … 27 27 uint64_t thread_rand(); 28 28 29 extern uint32_t __thread_seed; // global thread seed 30 29 31 //----------------------------------------------------------------------------- 30 32 // Thread ctors and dtors 31 void ?{}( thread$ & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) {33 void ?{}( thread$ & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) { 32 34 context{ 0p, 0p }; 33 35 self_cor{ name, storage, storageSize }; … … 39 41 self_mon.owner = &this; 40 42 self_mon.recursion = 1; 43 random_state = __thread_seed; 41 44 self_mon_p = &self_mon; 42 45 curr_cluster = &cl; … … 178 181 } 179 182 183 #define GENERATOR LCG 184 185 inline uint32_t MarsagliaXor( uint32_t & state ) { 186 state ^= state << 6; 187 state ^= state >> 21; 188 state ^= state << 7; 189 return state; 190 } // MarsagliaXor 191 192 inline uint32_t LCG( uint32_t & state ) { // linear congruential generator 193 return state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime! 194 } // LCG 195 196 void set_seed( uint32_t seed ) { active_thread()->random_state = seed; __thread_seed = seed; } 197 uint32_t prng( void ) { return GENERATOR( active_thread()->random_state ); } // [0,UINT_MAX] 198 180 199 // Local Variables: // 181 200 // mode: c // -
libcfa/src/stdlib.cfa
r4177592f r2210cfc 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 : Mon Jan 10 17:07:21 2022 13 // Update Count : 572 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 seed224 static thread_local uint32_t state; // random state225 226 void set_seed( uint32_t seed_ ) { state = seed = seed_; }227 uint32_t get_seed() { return seed; }228 229 225 #define GENERATOR LCG 230 226 231 227 inline uint32_t MarsagliaXor( uint32_t & state ) { 232 if ( unlikely( seed == 0 ) ) set_seed( rdtscl() );233 else if ( unlikely( state == 0 ) ) state = seed;234 228 state ^= state << 6; 235 229 state ^= state >> 21; … … 239 233 240 234 inline uint32_t LCG( uint32_t & state ) { // linear congruential generator 241 if ( unlikely( seed == 0 ) ) set_seed( rdtscl() );242 else if ( unlikely( state == 0 ) ) state = seed;243 235 return state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime! 244 236 } // LCG 245 237 238 uint32_t __thread_seed = rdtscl(); // global thread seed 239 240 void set_seed( uint32_t seed ) { __thread_seed = seed; } 241 uint32_t get_seed() { return __thread_seed; } 246 242 uint32_t prng( PRNG & prng ) with( prng ) { callcnt += 1; return GENERATOR( state ); } 247 243 248 uint32_t prng( void ) { return GENERATOR( state ); }244 uint32_t prng( void ) { return GENERATOR( __thread_seed ); } // [0,UINT_MAX] 249 245 250 246 //--------------------------------------- -
libcfa/src/stdlib.hfa
r4177592f r2210cfc 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jan 2 22:53:57202213 // Update Count : 59412 // Last Modified On : Mon Jan 10 17:03:18 2022 13 // Update Count : 619 14 14 // 15 15 … … 21 21 #include <stdlib.h> // *alloc, strto*, ato* 22 22 #include <heap.hfa> 23 23 24 24 25 // Reduce includes by explicitly defining these routines. … … 391 392 }; // PRNG 392 393 393 externuint32_t prng( PRNG & prng ) __attribute__(( warn_unused_result )); // [0,UINT_MAX]394 uint32_t prng( PRNG & prng ) __attribute__(( warn_unused_result )); // [0,UINT_MAX] 394 395 static inline { 395 396 void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; } // set seed … … 402 403 } // distribution 403 404 404 extern void set_seed( uint32_t seed ); // set per thread seed 405 extern uint32_t get_seed(); // get seed 406 extern uint32_t prng( void ) __attribute__(( warn_unused_result )); // [0,UINT_MAX]405 void set_seed( uint32_t seed_ ) OPTIONAL_THREAD; 406 uint32_t get_seed() __attribute__(( warn_unused_result )); 407 uint32_t prng( void ) __attribute__(( warn_unused_result )) OPTIONAL_THREAD; // [0,UINT_MAX] 407 408 static inline { 408 uint32_t prng( uint32_t u ) __attribute__(( warn_unused_result )); 409 uint32_t prng( uint32_t u ) { return prng() % u; } // [0,u) 410 uint32_t prng( uint32_t l, uint32_t u ) __attribute__(( warn_unused_result )); 411 uint32_t prng( uint32_t l, uint32_t u ) { return prng( u - l + 1 ) + l; } // [l,u] 409 uint32_t prng( uint32_t u ) __attribute__(( warn_unused_result )) { return prng() % u; } // [0,u) 410 uint32_t prng( uint32_t l, uint32_t u ) __attribute__(( warn_unused_result )) { return prng( u - l + 1 ) + l; } // [l,u] 412 411 } // distribution 413 412
Note: See TracChangeset
for help on using the changeset viewer.