Changes in / [145dcd5:c90db2d]
- Files:
-
- 5 added
- 3 deleted
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/readyQ/churn.cfa
r145dcd5 rc90db2d 21 21 wait( sem ); 22 22 for() { 23 uint 64_t r = thread_rand();23 uint32_t r = prng(); 24 24 bench_sem * next = __atomic_exchange_n(&spots[r % spot_cnt], &sem, __ATOMIC_SEQ_CST); 25 25 if(next) post( *next ); -
benchmark/readyQ/locality.cfa
r145dcd5 rc90db2d 128 128 __attribute__((noinline)) void work(MyData & data, size_t cnt_, uint64_t & state) { 129 129 for (cnt_) { 130 access(data, __xorshift64(state));130 access(data, xorshift_13_7_17(state)); 131 131 } 132 132 } 133 133 134 134 void main(MyThread & this) { 135 uint64_t state = thread_rand();135 uint64_t state = prng(); 136 136 137 137 // Wait for start … … 144 144 145 145 // Wait on a random spot 146 uint64_t idx = __xorshift64(state) % this.spots.len;146 uint64_t idx = xorshift_13_7_17(state) % this.spots.len; 147 147 bool closed = put(*this.spots.ptr[idx], this, this.data, this.share); 148 148 -
libcfa/prelude/Makefile.am
r145dcd5 rc90db2d 11 11 ## Created On : Sun May 31 08:54:01 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Mon Feb 3 21:27:18 202014 ## Update Count : 2 0813 ## Last Modified On : Thu Jan 13 17:06:27 2022 14 ## Update Count : 215 15 15 ############################################################################### 16 16 … … 37 37 # create extra forward types/declarations to reduce inclusion of library files 38 38 extras.cf : ${srcdir}/extras.regx ${srcdir}/extras.c 39 ${AM_V_GEN}gcc ${AM_CFLAGS} -E ${srcdir}/extras.c | grep -f ${srcdir}/extras.regx > extras.cf 40 ${AM_V_GEN}gcc ${AM_CFLAGS} -E ${srcdir}/extras.c | grep -zo -f ${srcdir}/extras.regx2 | tr '\0' '\n' >> extras.cf 39 @echo '# 2 "${@}" // needed for error messages from this file' > ${@} 40 ${AM_V_GEN}gcc ${AM_CFLAGS} -E ${srcdir}/extras.c | grep -f ${srcdir}/extras.regx >> ${@} 41 ${AM_V_GEN}gcc ${AM_CFLAGS} -E ${srcdir}/extras.c | grep -zo -f ${srcdir}/extras.regx2 | tr '\0' '\n' >> ${@} 41 42 42 43 # create forward declarations for gcc builtins 43 44 gcc-builtins.cf : gcc-builtins.c ${srcdir}/prototypes.sed 44 ${AM_V_GEN}gcc -I${srcdir} -E -P $< | sed -r -f ${srcdir}/prototypes.sed > $@ 45 @echo '# 2 "${@}" // needed for error messages from this file' > ${@} 46 ${AM_V_GEN}gcc -I${srcdir} -E -P $< | sed -r -f ${srcdir}/prototypes.sed >> ${@} 45 47 46 48 gcc-builtins.c : ${srcdir}/builtins.def ${srcdir}/prototypes.awk ${srcdir}/sync-builtins.cf ${srcdir}/prototypes.c 47 ${AM_V_GEN}gcc -I${srcdir} -E ${srcdir}/prototypes.c | awk -f ${srcdir}/prototypes.awk > $ @49 ${AM_V_GEN}gcc -I${srcdir} -E ${srcdir}/prototypes.c | awk -f ${srcdir}/prototypes.awk > ${@} 48 50 49 51 prelude.cfa : prelude-gen.cc 50 52 ${AM_V_GEN}${CXX} ${AM_CXXFLAGS} ${CXXFLAGS} ${AM_CFLAGS} ${<} -o prelude-gen -Wall -Wextra -O2 -g -std=c++14 51 @./prelude-gen > $ @53 @./prelude-gen > ${@} 52 54 @rm ./prelude-gen 53 55 … … 58 60 # create forward declarations for cfa builtins 59 61 builtins.cf : builtins.c @LOCAL_CFACC@ 60 ${AM_V_GEN}gcc ${AM_CFLAGS} -E -P${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po -D__cforall62 ${AM_V_GEN}gcc ${AM_CFLAGS} -E ${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po -D__cforall 61 63 ${AM_V_at}sed -i 's/builtins.o/builtins.cf/g' $(DEPDIR)/builtins.Po 62 64 … … 64 66 65 67 bootloader.c : ${srcdir}/bootloader.cf prelude.cfa extras.cf gcc-builtins.cf builtins.cf @CFACPP@ 66 ${AM_V_GEN}@CFACPP@ --prelude-dir=${builddir} -tpm ${srcdir}/bootloader.cf $ @# use src/cfa-cpp as not in lib until after install68 ${AM_V_GEN}@CFACPP@ --prelude-dir=${builddir} -tpm ${srcdir}/bootloader.cf ${@} # use src/cfa-cpp as not in lib until after install 67 69 68 70 maintainer-clean-local : -
libcfa/src/bits/random.hfa
r145dcd5 rc90db2d 3 3 #include <stdint.h> 4 4 5 // Pipelined to allow out-of-order overlap with reduced dependencies. Critically, return the current value, and compute 6 // and store the next value. 7 5 8 //-------------------------------------------------- 6 9 #if defined(__SIZEOF_INT128__) 7 typedef __uint128_t __lehmer64_state_t;8 static inline uint64_t __lehmer64( __lehmer64_state_t & state ) {10 static inline uint64_t lehmer64( __uint128_t & state ) { 11 __uint128_t ret = state; 9 12 state *= 0xda942042e4dd58b5; 10 return state>> 64;13 return ret >> 64; 11 14 } 12 15 13 16 //-------------------------------------------------- 14 typedef uint64_t __wyhash64_state_t; 15 static inline uint64_t __wyhash64( __wyhash64_state_t & state ) { 17 static inline uint64_t wyhash64( uint64_t & state ) { 16 18 state += 0x60bee2bee120fc15; 17 19 __uint128_t tmp; … … 25 27 26 28 //-------------------------------------------------- 27 typedef uint64_t __xorshift64_state_t; 28 static inline uint64_t __xorshift64( __xorshift64_state_t & state ) { 29 uint64_t x = state; 30 x ^= x << 13; 31 x ^= x >> 7; 32 x ^= x << 17; 33 return state = x; 29 static inline uint64_t xorshift_13_7_17( uint64_t & state ) { 30 uint64_t ret = state; 31 state ^= state << 13; 32 state ^= state >> 7; 33 state ^= state << 17; 34 return ret; 34 35 } 36 37 //-------------------------------------------------- 38 static inline uint32_t xorshift_6_21_7( uint32_t & state ) { 39 uint32_t ret = state; 40 state ^= state << 6; 41 state ^= state >> 21; 42 state ^= state << 7; 43 return ret; 44 } // xorshift_6_21_7 35 45 36 46 //-------------------------------------------------- … … 38 48 uint32_t a, b, c, d; 39 49 uint32_t counter; 40 } __xorwow__state_t;50 } xorwow__state_t; 41 51 42 52 /* The state array must be initialized to not be all zero in the first four words */ 43 static inline uint32_t __xorwow( __xorwow__state_t & state ) {53 static inline uint32_t xorwow( xorwow__state_t & state ) { 44 54 /* Algorithm "xorwow" from p. 5 of Marsaglia, "Xorshift RNGs" */ 55 uint32_t ret = state.a + state.counter; 45 56 uint32_t t = state.d; 46 57 … … 56 67 57 68 state.counter += 362437; 58 return t + state.counter;69 return ret; 59 70 } 71 72 //-------------------------------------------------- 73 static inline uint32_t LCG( uint32_t & state ) { // linear congruential generator 74 uint32_t ret = state; 75 state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime! No not change it! 76 return ret; 77 } // LCG 78 79 //-------------------------------------------------- 80 #define M (1_l64u << 48_l64u) 81 #define A (25214903917_l64u) 82 #define AI (18446708753438544741_l64u) 83 #define C (11_l64u) 84 #define D (16_l64u) 85 86 static inline uint32_t LCGBI_fwd( uint64_t & state ) { 87 state = (A * state + C) & (M - 1); 88 return state >> D; 89 } 90 91 static inline uint32_t LCGBI_bck( uint64_t & state ) { 92 unsigned int r = state >> D; 93 state = AI * (state - C) & (M - 1); 94 return r; 95 } 96 97 #undef M 98 #undef A 99 #undef AI 100 #undef C 101 #undef D -
libcfa/src/concurrency/clib/cfathread.cfa
r145dcd5 rc90db2d 22 22 #include "thread.hfa" 23 23 #include "time.hfa" 24 #include "stdlib.hfa" 24 25 25 26 #include "cfathread.h" … … 195 196 eevent.data.u64 = (uint64_t)active_thread(); 196 197 197 int id = thread_rand() % poller_cnt;198 int id = prng() % poller_cnt; 198 199 if(0 != epoll_ctl(poller_fds[id], EPOLL_CTL_ADD, fd, &eevent)) 199 200 { -
libcfa/src/concurrency/kernel/fwd.hfa
r145dcd5 rc90db2d 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/kernel/startup.cfa
r145dcd5 rc90db2d 102 102 extern void __wake_proc(processor *); 103 103 extern int cfa_main_returned; // from interpose.cfa 104 extern uint32_t __global_random_seed; 104 105 105 106 //----------------------------------------------------------------------------- … … 175 176 this.context = &storage_mainThreadCtx; 176 177 } 177 178 178 179 179 … … 490 490 preferred = ready_queue_new_preferred(); 491 491 last_proc = 0p; 492 random_state = __global_random_seed; 492 493 #if defined( __CFA_WITH_VERIFY__ ) 493 494 canary = 0x0D15EA5E0D15EA5Ep; -
libcfa/src/concurrency/thread.cfa
r145dcd5 rc90db2d 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:35 202213 // Update Count : 2812 // Last Modified On : Thu Jan 13 20:11:55 2022 13 // Update Count : 42 14 14 // 15 15 … … 25 25 #include "invoke.h" 26 26 27 uint64_t thread_rand(); 28 29 extern uint32_t __thread_seed; // global thread seed 27 extern uint32_t __global_random_seed; 30 28 31 29 //----------------------------------------------------------------------------- … … 41 39 self_mon.owner = &this; 42 40 self_mon.recursion = 1; 43 random_state = __thread_seed;44 41 self_mon_p = &self_mon; 45 42 curr_cluster = &cl; … … 48 45 preferred = ready_queue_new_preferred(); 49 46 last_proc = 0p; 47 random_state = __global_random_seed; 50 48 #if defined( __CFA_WITH_VERIFY__ ) 51 49 canary = 0x0D15EA5E0D15EA5Ep; … … 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 176 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; } 177 void set_seed( uint32_t seed ) { 178 active_thread()->random_state = __global_random_seed = seed; 179 GENERATOR( active_thread()->random_state ); 180 } // set_seed 197 181 uint32_t prng( void ) { return GENERATOR( active_thread()->random_state ); } // [0,UINT_MAX] 198 182 -
libcfa/src/parseconfig.cfa
r145dcd5 rc90db2d 1 2 3 #pragma GCC diagnostic push 4 //#pragma GCC diagnostic ignored "-Wunused-parameter" 5 //#pragma GCC diagnostic ignored "-Wunused-function" 6 //#pragma GCC diagnostic ignored "-Wuninitialized" 7 //#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" 8 1 9 #include <fstream.hfa> 2 10 #include <parseargs.hfa> … … 19 27 // TODO: use string interface when it's ready (and implement exception msg protocol) 20 28 [ void ] msg( * Missing_Config_Entries ex ) { 21 serr | nlOff; 22 serr | "The config file is missing " | ex->num_missing; 23 serr | nlOn; 24 if ( ex->num_missing == 1 ) { 25 serr | " entry."; 26 } else { 27 serr | " entries."; 28 } 29 serr | "The config file is missing " | ex->num_missing | "entr" | sepOff | (ex->num_missing == 1 ? "y." : "ies."); 29 30 } // msg 30 31 … … 223 224 return value < zero_val; 224 225 } 226 #pragma GCC diagnostic pop 225 227 226 228 -
libcfa/src/startup.cfa
r145dcd5 rc90db2d 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 18:51:24 2022 13 // Update Count : 51 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, __global_random_state; 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_state = __global_random_seed = rdtscl(); 50 54 __cfaabi_interpose_startup(); 51 55 __cfaabi_device_startup(); -
libcfa/src/stdlib.cfa
r145dcd5 rc90db2d 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 : 5 7212 // 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 … … 225 225 #define GENERATOR LCG 226 226 227 inline uint32_t MarsagliaXor( uint32_t & state ) { 228 state ^= state << 6; 229 state ^= state >> 21; 230 state ^= state << 7; 231 return state; 232 } // MarsagliaXor 233 234 inline uint32_t LCG( uint32_t & state ) { // linear congruential generator 235 return state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime! 236 } // LCG 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; } 227 uint32_t __global_random_seed; // sequential/concurrent 228 uint32_t __global_random_state; // sequential only 229 230 void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; GENERATOR( state ); } // set seed 242 231 uint32_t prng( PRNG & prng ) with( prng ) { callcnt += 1; return GENERATOR( state ); } 243 232 244 uint32_t prng( void ) { return GENERATOR( __thread_seed ); } // [0,UINT_MAX] 233 void set_seed( uint32_t seed ) { __global_random_seed = seed; GENERATOR( __global_random_state ); } 234 uint32_t get_seed() { return __global_random_seed; } 235 uint32_t prng( void ) { return GENERATOR( __global_random_state ); } // [0,UINT_MAX] 245 236 246 237 //--------------------------------------- -
libcfa/src/stdlib.hfa
r145dcd5 rc90db2d 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:18202213 // Update Count : 6 1912 // Last Modified On : Thu Jan 13 21:34:46 2022 13 // Update Count : 636 14 14 // 15 15 … … 208 208 209 209 forall( TT... | { T * alloc_internal$( void *, T *, size_t, size_t, S_fill(T), TT ); } ) { 210 211 210 T * alloc_internal$( void * , T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest) { 212 211 return alloc_internal$( Resize, (T*)0p, Align, Dim, Fill, rest); … … 232 231 return alloc_internal$( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), dim, (S_fill(T)){'0'}, all); 233 232 } 234 235 233 } // distribution TT 236 234 } // distribution T … … 386 384 //--------------------------------------- 387 385 386 // Sequential Pseudo Random-Number Generator : generate repeatable sequence of values that appear random. 387 // 388 // Declaration : 389 // PRNG sprng = { 1009 } - set starting seed versus random seed 390 // 391 // Interface : 392 // set_seed( sprng, 1009 ) - set starting seed for ALL kernel threads versus random seed 393 // get_seed( sprng ) - read seed 394 // prng( sprng ) - generate random value in range [0,UINT_MAX] 395 // prng( sprng, u ) - generate random value in range [0,u) 396 // prng( sprng, l, u ) - generate random value in range [l,u] 397 // calls( sprng ) - number of generated random value so far 398 // 399 // Examples : generate random number between 5-21 400 // prng( sprng ) % 17 + 5; values 0-16 + 5 = 5-21 401 // prng( sprng, 16 + 1 ) + 5; 402 // prng( sprng, 5, 21 ); 403 // calls( sprng ); 404 388 405 struct PRNG { 389 406 uint32_t callcnt; // call count … … 392 409 }; // PRNG 393 410 411 void set_seed( PRNG & prng, uint32_t seed_ ); 394 412 uint32_t prng( PRNG & prng ) __attribute__(( warn_unused_result )); // [0,UINT_MAX] 395 413 static inline { 396 void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; } // set seed397 414 void ?{}( PRNG & prng ) { set_seed( prng, rdtscl() ); } // random seed 398 415 void ?{}( PRNG & prng, uint32_t seed ) { set_seed( prng, seed ); } // fixed seed … … 403 420 } // distribution 404 421 422 // Concurrent Pseudo Random-Number Generator : generate repeatable sequence of values that appear random. 423 // 424 // Interface : 425 // set_seed( 1009 ) - fixed seed for all kernel threads versus random seed 426 // get_seed() - read seed 427 // prng() - generate random value in range [0,UINT_MAX] 428 // prng( u ) - generate random value in range [0,u) 429 // prng( l, u ) - generate random value in range [l,u] 430 // 431 // Examples : generate random number between 5-21 432 // prng() % 17 + 5; values 0-16 + 5 = 5-21 433 // prng( 16 + 1 ) + 5; 434 // prng( 5, 21 ); 435 405 436 void set_seed( uint32_t seed_ ) OPTIONAL_THREAD; 406 437 uint32_t get_seed() __attribute__(( warn_unused_result )); -
src/AST/Decl.cpp
r145dcd5 rc90db2d 26 26 #include "Node.hpp" // for readonly 27 27 #include "Type.hpp" // for readonly 28 #include "Expr.hpp" 28 29 29 30 namespace ast { … … 65 66 for (auto & tp : this->type_params) { 66 67 ftype->forall.emplace_back(new TypeInstType(tp->name, tp)); 68 for (auto & ap: tp->assertions) { 69 ftype->assertions.emplace_back(new VariableExpr(loc, ap)); 70 } 67 71 } 68 72 this->type = ftype; -
tests/io/io-acquire-no-io.cfa
r145dcd5 rc90db2d 10 10 // Created On : Mon Mar 1 18:40:09 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Oct 6 18:04:58 202113 // Update Count : 7 212 // Last Modified On : Fri Jan 14 09:13:54 2022 13 // Update Count : 73 14 14 // 15 15 … … 17 17 #include <thread.hfa> 18 18 #include <mutex_stmt.hfa> 19 20 Duration default_preemption() { return 0; } 19 21 20 22 multiple_acquisition_lock soutLock, sinLock; -
tests/io/io-acquire.cfa
r145dcd5 rc90db2d 10 10 // Created On : Mon Mar 1 18:40:09 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 10 07:57:12202213 // Update Count : 7 312 // Last Modified On : Fri Jan 14 09:13:18 2022 13 // Update Count : 74 14 14 // 15 15 … … 17 17 #include <thread.hfa> 18 18 #include <mutex_stmt.hfa> 19 20 Duration default_preemption() { return 0; } 19 21 20 22 thread T {};
Note: See TracChangeset
for help on using the changeset viewer.