- Timestamp:
- Jan 12, 2022, 6:34:58 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 00f5fde
- Parents:
- a10f6b4
- Location:
- libcfa/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel/startup.cfa
ra10f6b4 r1959528 101 101 extern void __wake_proc(processor *); 102 102 extern int cfa_main_returned; // from interpose.cfa 103 extern uint32_t __global_random_seed; 103 104 104 105 //----------------------------------------------------------------------------- … … 489 490 preferred = ready_queue_new_preferred(); 490 491 last_proc = 0p; 492 random_state = __global_random_seed; 491 493 #if defined( __CFA_WITH_VERIFY__ ) 492 494 canary = 0x0D15EA5E0D15EA5Ep; -
libcfa/src/concurrency/thread.cfa
ra10f6b4 r1959528 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 10 17:05:35202213 // Update Count : 2812 // Last Modified On : Wed Jan 12 18:28:18 2022 13 // Update Count : 35 14 14 // 15 15 … … 27 27 uint64_t thread_rand(); 28 28 29 extern uint32_t __ thread_seed; // global thread seed29 extern uint32_t __global_random_seed; 30 30 31 31 //----------------------------------------------------------------------------- … … 41 41 self_mon.owner = &this; 42 42 self_mon.recursion = 1; 43 random_state = __thread_seed;44 43 self_mon_p = &self_mon; 45 44 curr_cluster = &cl; … … 48 47 preferred = ready_queue_new_preferred(); 49 48 last_proc = 0p; 49 random_state = __global_random_seed; 50 50 #if defined( __CFA_WITH_VERIFY__ ) 51 51 canary = 0x0D15EA5E0D15EA5Ep; … … 180 180 return ret; 181 181 } 182 182 183 183 #define GENERATOR LCG 184 184 185 inline uint32_t MarsagliaXor( uint32_t & state ) { 185 static inline uint32_t MarsagliaXor( uint32_t & state ) { 186 uint32_t ret = state; 186 187 state ^= state << 6; 187 188 state ^= state >> 21; 188 189 state ^= state << 7; 189 return state;190 return ret; 190 191 } // MarsagliaXor 191 192 192 inline uint32_t LCG( uint32_t & state ) { // linear congruential generator 193 return state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime! 193 static inline uint32_t LCG( uint32_t & state ) { // linear congruential generator 194 uint32_t ret = state; 195 state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime! No not change it! 196 return ret; 194 197 } // LCG 195 198 196 void set_seed( uint32_t seed ) { active_thread()->random_state = seed; __ thread_seed = seed; }199 void set_seed( uint32_t seed ) { active_thread()->random_state = seed; __global_random_seed = seed; } 197 200 uint32_t prng( void ) { return GENERATOR( active_thread()->random_state ); } // [0,UINT_MAX] 198 201 -
libcfa/src/startup.cfa
ra10f6b4 r1959528 10 10 // Created On : Tue Jul 24 16:21:57 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jan 9 23:18:23 202113 // Update Count : 3412 // Last Modified On : Wed Jan 12 16:25:37 2022 13 // Update Count : 49 14 14 // 15 15 … … 18 18 #include <stdlib.h> // getenv 19 19 #include "startup.hfa" 20 #include "bits/defs.hfa" 21 22 extern uint32_t __global_random_seed; 20 23 21 24 extern "C" { … … 48 51 void __cfaabi_core_startup( void ) __attribute__(( constructor( STARTUP_PRIORITY_CORE ) )); 49 52 void __cfaabi_core_startup( void ) { 53 __global_random_seed = rdtscl(); 50 54 __cfaabi_interpose_startup(); 51 55 __cfaabi_device_startup(); -
libcfa/src/stdlib.cfa
ra10f6b4 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 10 17:07:21202213 // Update Count : 57 212 // Last Modified On : Wed Jan 12 16:25:36 2022 13 // Update Count : 578 14 14 // 15 15 … … 223 223 //--------------------------------------- 224 224 225 // Pipelined to allow OoO overlap with reduced dependencies. Critically, return the current value, and compute and store 226 // the next value. 227 225 228 #define GENERATOR LCG 226 229 227 inline uint32_t MarsagliaXor( uint32_t & state ) { 230 static inline uint32_t MarsagliaXor( uint32_t & state ) { 231 uint32_t ret = state; 228 232 state ^= state << 6; 229 233 state ^= state >> 21; 230 234 state ^= state << 7; 231 return state;235 return ret; 232 236 } // MarsagliaXor 233 237 234 inline uint32_t LCG( uint32_t & state ) { // linear congruential generator 235 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; 236 242 } // LCG 237 243 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; } 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 242 247 uint32_t prng( PRNG & prng ) with( prng ) { callcnt += 1; return GENERATOR( state ); } 243 248 244 uint32_t prng( void ) { return GENERATOR( __thread_seed ); } // [0,UINT_MAX] 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] 245 255 246 256 //--------------------------------------- -
libcfa/src/stdlib.hfa
ra10f6b4 r1959528 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 10 17:03:18 202213 // Update Count : 6 1912 // Last Modified On : Wed Jan 12 09:09:48 2022 13 // Update Count : 620 14 14 // 15 15 … … 386 386 //--------------------------------------- 387 387 388 // Sequential Pseudo Random-Number Generator : generate repeatable sequence of values that appear random. 389 // 390 // Declaration : 391 // PRNG sprng = { 1009 } - set starting seed versus random seed 392 // 393 // Interface : 394 // set_seed( sprng, 1009 ) - set starting seed for ALL kernel threads versus random seed 395 // get_seed( sprng ) - read seed 396 // prng( sprng ) - generate random value in range [0,UINT_MAX] 397 // prng( sprng, u ) - generate random value in range [0,u) 398 // prng( sprng, l, u ) - generate random value in range [l,u] 399 // calls( sprng ) - number of generated random value so far 400 // 401 // Examples : generate random number between 5-21 402 // prng( sprng ) % 17 + 5; values 0-16 + 5 = 5-21 403 // prng( sprng, 16 + 1 ) + 5; 404 // prng( sprng, 5, 21 ); 405 // calls( sprng ); 406 388 407 struct PRNG { 389 408 uint32_t callcnt; // call count … … 392 411 }; // PRNG 393 412 413 void set_seed( PRNG & prng, uint32_t seed_ ); 394 414 uint32_t prng( PRNG & prng ) __attribute__(( warn_unused_result )); // [0,UINT_MAX] 395 415 static inline { 396 void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; } // set seed397 416 void ?{}( PRNG & prng ) { set_seed( prng, rdtscl() ); } // random seed 398 417 void ?{}( PRNG & prng, uint32_t seed ) { set_seed( prng, seed ); } // fixed seed … … 403 422 } // distribution 404 423 424 // Concurrent Pseudo Random-Number Generator : generate repeatable sequence of values that appear random. 425 // 426 // Interface : 427 // set_seed( 1009 ) - fixed seed for all kernel threads versus random seed 428 // get_seed() - read seed 429 // prng() - generate random value in range [0,UINT_MAX] 430 // prng( u ) - generate random value in range [0,u) 431 // prng( l, u ) - generate random value in range [l,u] 432 // 433 // Examples : generate random number between 5-21 434 // prng() % 17 + 5; values 0-16 + 5 = 5-21 435 // prng( 16 + 1 ) + 5; 436 // prng( 5, 21 ); 437 405 438 void set_seed( uint32_t seed_ ) OPTIONAL_THREAD; 406 uint32_t get_seed() __attribute__(( warn_unused_result )) ;439 uint32_t get_seed() __attribute__(( warn_unused_result )) OPTIONAL_THREAD; 407 440 uint32_t prng( void ) __attribute__(( warn_unused_result )) OPTIONAL_THREAD; // [0,UINT_MAX] 408 441 static inline {
Note: See TracChangeset
for help on using the changeset viewer.