- Timestamp:
- Jan 13, 2022, 9:42:08 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 75965a6
- Parents:
- 919a6b2
- Location:
- libcfa/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel/fwd.hfa
r919a6b2 r5d1ebb9 79 79 return 80 80 #if defined(__SIZEOF_INT128__) 81 __lehmer64( kernelTLS().rand_seed );81 lehmer64( kernelTLS().rand_seed ); 82 82 #else 83 __xorshift64( kernelTLS().rand_seed );83 xorshift_13_7_17( kernelTLS().rand_seed ); 84 84 #endif 85 85 } 86 86 87 #define M (1_l64u << 48_l64u)88 #define A (25214903917_l64u)89 #define AI (18446708753438544741_l64u)90 #define C (11_l64u)91 #define D (16_l64u)92 93 87 static inline unsigned __tls_rand_fwd() { 94 kernelTLS().ready_rng.fwd_seed = (A * kernelTLS().ready_rng.fwd_seed + C) & (M - 1); 95 return kernelTLS().ready_rng.fwd_seed >> D; 88 return LCGBI_fwd( kernelTLS().ready_rng.fwd_seed ); 96 89 } 97 90 98 91 static inline unsigned __tls_rand_bck() { 99 unsigned int r = kernelTLS().ready_rng.bck_seed >> D; 100 kernelTLS().ready_rng.bck_seed = AI * (kernelTLS().ready_rng.bck_seed - C) & (M - 1); 101 return r; 102 } 103 104 #undef M 105 #undef A 106 #undef AI 107 #undef C 108 #undef D 92 return LCGBI_bck( kernelTLS().ready_rng.bck_seed ); 93 } 109 94 110 95 static inline void __tls_rand_advance_bck(void) { … … 140 125 } 141 126 } 142 143 extern uint64_t thread_rand();144 127 145 128 // Semaphore which only supports a single thread -
libcfa/src/concurrency/thread.cfa
r919a6b2 r5d1ebb9 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jan 12 18:46:48202213 // Update Count : 3612 // Last Modified On : Thu Jan 13 20:11:55 2022 13 // Update Count : 42 14 14 // 15 15 … … 24 24 #define __CFA_INVOKE_PRIVATE__ 25 25 #include "invoke.h" 26 27 uint64_t thread_rand();28 26 29 27 extern uint32_t __global_random_seed; … … 174 172 } 175 173 176 uint64_t thread_rand() { 177 disable_interrupts(); 178 uint64_t ret = __tls_rand(); 179 enable_interrupts(); 180 return ret; 181 } 182 174 //----------------------------------------------------------------------------- 183 175 #define GENERATOR LCG 184 185 static inline uint32_t MarsagliaXor( uint32_t & state ) {186 uint32_t ret = state;187 state ^= state << 6;188 state ^= state >> 21;189 state ^= state << 7;190 return ret;191 } // MarsagliaXor192 193 static inline uint32_t LCG( uint32_t & state ) { // linear congruential generator194 uint32_t ret = state;195 state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime! No not change it!196 return ret;197 } // LCG198 176 199 177 void set_seed( uint32_t seed ) { -
libcfa/src/stdlib.cfa
r919a6b2 r5d1ebb9 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jan 12 18:52:41202213 // Update Count : 5 8212 // Last Modified On : Thu Jan 13 21:38:30 2022 13 // Update Count : 593 14 14 // 15 15 16 16 #include "stdlib.hfa" 17 //#include "concurrency/kernel/fwd.hfa"17 #include "bits/random.hfa" 18 18 #include "concurrency/invoke.h" // random_state 19 19 … … 223 223 //--------------------------------------- 224 224 225 // Pipelined to allow OoO overlap with reduced dependencies. Critically, return the current value, and compute and store226 // the next value.227 228 225 #define GENERATOR LCG 229 226 230 static inline uint32_t MarsagliaXor( uint32_t & state ) {231 uint32_t ret = state;232 state ^= state << 6;233 state ^= state >> 21;234 state ^= state << 7;235 return ret;236 } // MarsagliaXor237 238 static inline uint32_t LCG( uint32_t & state ) { // linear congruential generator239 uint32_t ret = state;240 state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime! No not change it!241 return ret;242 } // LCG243 244 227 uint32_t __global_random_seed; // sequential/concurrent 245 uint32_t __global_random_state; 228 uint32_t __global_random_state; // sequential only 246 229 247 230 void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; GENERATOR( state ); } // set seed
Note: See TracChangeset
for help on using the changeset viewer.