Changes in / [145dcd5:c90db2d]


Ignore:
Files:
5 added
3 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • benchmark/readyQ/churn.cfa

    r145dcd5 rc90db2d  
    2121        wait( sem );
    2222        for() {
    23                 uint64_t r = thread_rand();
     23                uint32_t r = prng();
    2424                bench_sem * next = __atomic_exchange_n(&spots[r % spot_cnt], &sem, __ATOMIC_SEQ_CST);
    2525                if(next) post( *next );
  • benchmark/readyQ/locality.cfa

    r145dcd5 rc90db2d  
    128128__attribute__((noinline)) void work(MyData & data, size_t cnt_, uint64_t & state) {
    129129        for (cnt_) {
    130                 access(data, __xorshift64(state));
     130                access(data, xorshift_13_7_17(state));
    131131        }
    132132}
    133133
    134134void main(MyThread & this) {
    135         uint64_t state = thread_rand();
     135        uint64_t state = prng();
    136136
    137137        // Wait for start
     
    144144
    145145                // 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;
    147147                bool closed = put(*this.spots.ptr[idx], this, this.data, this.share);
    148148
  • libcfa/prelude/Makefile.am

    r145dcd5 rc90db2d  
    1111## Created On       : Sun May 31 08:54:01 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Mon Feb  3 21:27:18 2020
    14 ## Update Count     : 208
     13## Last Modified On : Thu Jan 13 17:06:27 2022
     14## Update Count     : 215
    1515###############################################################################
    1616
     
    3737# create extra forward types/declarations to reduce inclusion of library files
    3838extras.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' >> ${@}
    4142
    4243# create forward declarations for gcc builtins
    4344gcc-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 >> ${@}
    4547
    4648gcc-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 > ${@}
    4850
    4951prelude.cfa : prelude-gen.cc
    5052        ${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 > ${@}
    5254        @rm ./prelude-gen
    5355
     
    5860# create forward declarations for cfa builtins
    5961builtins.cf : builtins.c @LOCAL_CFACC@
    60         ${AM_V_GEN}gcc ${AM_CFLAGS} -E -P ${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po -D__cforall
     62        ${AM_V_GEN}gcc ${AM_CFLAGS} -E ${<} -o ${@} -MD -MP -MF $(DEPDIR)/builtins.Po -D__cforall
    6163        ${AM_V_at}sed -i 's/builtins.o/builtins.cf/g' $(DEPDIR)/builtins.Po
    6264
     
    6466
    6567bootloader.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 install
     68        ${AM_V_GEN}@CFACPP@ --prelude-dir=${builddir} -tpm ${srcdir}/bootloader.cf ${@}  # use src/cfa-cpp as not in lib until after install
    6769
    6870maintainer-clean-local :
  • libcfa/src/bits/random.hfa

    r145dcd5 rc90db2d  
    33#include <stdint.h>
    44
     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
    58//--------------------------------------------------
    69#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;
    912                state *= 0xda942042e4dd58b5;
    10                 return state >> 64;
     13                return ret >> 64;
    1114        }
    1215
    1316//--------------------------------------------------
    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 ) {
    1618                state += 0x60bee2bee120fc15;
    1719                __uint128_t tmp;
     
    2527
    2628//--------------------------------------------------
    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;
     29static 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;
    3435}
     36
     37//--------------------------------------------------
     38static 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
    3545
    3646//--------------------------------------------------
     
    3848  uint32_t a, b, c, d;
    3949  uint32_t counter;
    40 } __xorwow__state_t;
     50} xorwow__state_t;
    4151
    4252/* 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 ) {
     53static inline uint32_t xorwow( xorwow__state_t & state ) {
    4454        /* Algorithm "xorwow" from p. 5 of Marsaglia, "Xorshift RNGs" */
     55        uint32_t ret = state.a + state.counter;
    4556        uint32_t t = state.d;
    4657
     
    5667
    5768        state.counter += 362437;
    58         return t + state.counter;
     69        return ret;
    5970}
     71
     72//--------------------------------------------------
     73static 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
     86static inline uint32_t LCGBI_fwd( uint64_t & state ) {
     87        state = (A * state + C) & (M - 1);
     88        return state >> D;
     89}
     90
     91static 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  
    2222#include "thread.hfa"
    2323#include "time.hfa"
     24#include "stdlib.hfa"
    2425
    2526#include "cfathread.h"
     
    195196                                eevent.data.u64 = (uint64_t)active_thread();
    196197
    197                                 int id = thread_rand() % poller_cnt;
     198                                int id = prng() % poller_cnt;
    198199                                if(0 != epoll_ctl(poller_fds[id], EPOLL_CTL_ADD, fd, &eevent))
    199200                                {
  • libcfa/src/concurrency/kernel/fwd.hfa

    r145dcd5 rc90db2d  
    7979                        return
    8080                        #if defined(__SIZEOF_INT128__)
    81                                 __lehmer64( kernelTLS().rand_seed );
     81                                lehmer64( kernelTLS().rand_seed );
    8282                        #else
    83                                 __xorshift64( kernelTLS().rand_seed );
     83                                xorshift_13_7_17( kernelTLS().rand_seed );
    8484                        #endif
    8585                }
    8686
    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 
    9387                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 );
    9689                }
    9790
    9891                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                }
    10994
    11095                static inline void __tls_rand_advance_bck(void) {
     
    140125                        }
    141126                }
    142 
    143                 extern uint64_t thread_rand();
    144127
    145128                // Semaphore which only supports a single thread
  • libcfa/src/concurrency/kernel/startup.cfa

    r145dcd5 rc90db2d  
    102102extern void __wake_proc(processor *);
    103103extern int cfa_main_returned;                                                   // from interpose.cfa
     104extern uint32_t __global_random_seed;
    104105
    105106//-----------------------------------------------------------------------------
     
    175176        this.context = &storage_mainThreadCtx;
    176177}
    177 
    178178
    179179
     
    490490        preferred = ready_queue_new_preferred();
    491491        last_proc = 0p;
     492        random_state = __global_random_seed;
    492493        #if defined( __CFA_WITH_VERIFY__ )
    493494                canary = 0x0D15EA5E0D15EA5Ep;
  • libcfa/src/concurrency/thread.cfa

    r145dcd5 rc90db2d  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 10 17:05:35 2022
    13 // Update Count     : 28
     12// Last Modified On : Thu Jan 13 20:11:55 2022
     13// Update Count     : 42
    1414//
    1515
     
    2525#include "invoke.h"
    2626
    27 uint64_t thread_rand();
    28 
    29 extern uint32_t __thread_seed;                                                  // global thread seed
     27extern uint32_t __global_random_seed;
    3028
    3129//-----------------------------------------------------------------------------
     
    4139        self_mon.owner = &this;
    4240        self_mon.recursion = 1;
    43         random_state = __thread_seed;
    4441        self_mon_p = &self_mon;
    4542        curr_cluster = &cl;
     
    4845        preferred = ready_queue_new_preferred();
    4946        last_proc = 0p;
     47        random_state = __global_random_seed;
    5048        #if defined( __CFA_WITH_VERIFY__ )
    5149                canary = 0x0D15EA5E0D15EA5Ep;
     
    174172}
    175173
    176 uint64_t thread_rand() {
    177         disable_interrupts();
    178         uint64_t ret = __tls_rand();
    179         enable_interrupts();
    180         return ret;
    181 }
    182 
     174//-----------------------------------------------------------------------------
    183175#define GENERATOR LCG
    184176
    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; }
     177void set_seed( uint32_t seed ) {
     178        active_thread()->random_state = __global_random_seed = seed;
     179        GENERATOR( active_thread()->random_state );
     180} // set_seed
    197181uint32_t prng( void ) { return GENERATOR( active_thread()->random_state ); } // [0,UINT_MAX]
    198182
  • 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
    19#include <fstream.hfa>
    210#include <parseargs.hfa>
     
    1927// TODO: use string interface when it's ready (and implement exception msg protocol)
    2028[ 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.");
    2930} // msg
    3031
     
    223224        return value < zero_val;
    224225}
     226#pragma GCC diagnostic pop
    225227
    226228
  • libcfa/src/startup.cfa

    r145dcd5 rc90db2d  
    1010// Created On       : Tue Jul 24 16:21:57 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jan  9 23:18:23 2021
    13 // Update Count     : 34
     12// Last Modified On : Wed Jan 12 18:51:24 2022
     13// Update Count     : 51
    1414//
    1515
     
    1818#include <stdlib.h>                                                                             // getenv
    1919#include "startup.hfa"
     20#include "bits/defs.hfa"
     21
     22extern uint32_t __global_random_seed, __global_random_state;
    2023
    2124extern "C" {
     
    4851        void __cfaabi_core_startup( void ) __attribute__(( constructor( STARTUP_PRIORITY_CORE ) ));
    4952        void __cfaabi_core_startup( void ) {
     53                __global_random_state = __global_random_seed = rdtscl();
    5054                __cfaabi_interpose_startup();
    5155                __cfaabi_device_startup();
  • libcfa/src/stdlib.cfa

    r145dcd5 rc90db2d  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 10 17:07:21 2022
    13 // Update Count     : 572
     12// Last Modified On : Thu Jan 13 21:38:30 2022
     13// Update Count     : 593
    1414//
    1515
    1616#include "stdlib.hfa"
    17 //#include "concurrency/kernel/fwd.hfa"
     17#include "bits/random.hfa"
    1818#include "concurrency/invoke.h"                                                 // random_state
    1919
     
    225225#define GENERATOR LCG
    226226
    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; }
     227uint32_t __global_random_seed;                                                  // sequential/concurrent
     228uint32_t __global_random_state;                                         // sequential only
     229
     230void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; GENERATOR( state ); } // set seed
    242231uint32_t prng( PRNG & prng ) with( prng ) { callcnt += 1; return GENERATOR( state ); }
    243232
    244 uint32_t prng( void ) { return GENERATOR( __thread_seed ); } // [0,UINT_MAX]
     233void set_seed( uint32_t seed ) { __global_random_seed = seed; GENERATOR( __global_random_state ); }
     234uint32_t get_seed() { return __global_random_seed; }
     235uint32_t prng( void ) { return GENERATOR( __global_random_state ); } // [0,UINT_MAX]
    245236
    246237//---------------------------------------
  • libcfa/src/stdlib.hfa

    r145dcd5 rc90db2d  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 10 17:03:18 2022
    13 // Update Count     : 619
     12// Last Modified On : Thu Jan 13 21:34:46 2022
     13// Update Count     : 636
    1414//
    1515
     
    208208
    209209        forall( TT... | { T * alloc_internal$( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {
    210 
    211210                T * alloc_internal$( void *       , T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest) {
    212211                return alloc_internal$( Resize, (T*)0p, Align, Dim, Fill, rest);
     
    232231                return alloc_internal$( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), dim, (S_fill(T)){'0'}, all);
    233232            }
    234 
    235233        } // distribution TT
    236234} // distribution T
     
    386384//---------------------------------------
    387385
     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
    388405struct PRNG {
    389406        uint32_t callcnt;                                                                       // call count
     
    392409}; // PRNG
    393410
     411void set_seed( PRNG & prng, uint32_t seed_ );
    394412uint32_t prng( PRNG & prng ) __attribute__(( warn_unused_result )); // [0,UINT_MAX]
    395413static inline {
    396         void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; } // set seed
    397414        void ?{}( PRNG & prng ) { set_seed( prng, rdtscl() ); } // random seed
    398415        void ?{}( PRNG & prng, uint32_t seed ) { set_seed( prng, seed ); } // fixed seed
     
    403420} // distribution
    404421
     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
    405436void set_seed( uint32_t seed_ ) OPTIONAL_THREAD;
    406437uint32_t get_seed() __attribute__(( warn_unused_result ));
  • src/AST/Decl.cpp

    r145dcd5 rc90db2d  
    2626#include "Node.hpp"            // for readonly
    2727#include "Type.hpp"            // for readonly
     28#include "Expr.hpp"
    2829
    2930namespace ast {
     
    6566        for (auto & tp : this->type_params) {
    6667                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                }
    6771        }
    6872        this->type = ftype;
  • tests/io/io-acquire-no-io.cfa

    r145dcd5 rc90db2d  
    1010// Created On       : Mon Mar  1 18:40:09 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Oct  6 18:04:58 2021
    13 // Update Count     : 72
     12// Last Modified On : Fri Jan 14 09:13:54 2022
     13// Update Count     : 73
    1414//
    1515
     
    1717#include <thread.hfa>
    1818#include <mutex_stmt.hfa>
     19
     20Duration default_preemption() { return 0; }
    1921
    2022multiple_acquisition_lock soutLock, sinLock;
  • tests/io/io-acquire.cfa

    r145dcd5 rc90db2d  
    1010// Created On       : Mon Mar  1 18:40:09 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 10 07:57:12 2022
    13 // Update Count     : 73
     12// Last Modified On : Fri Jan 14 09:13:18 2022
     13// Update Count     : 74
    1414//
    1515
     
    1717#include <thread.hfa>
    1818#include <mutex_stmt.hfa>
     19
     20Duration default_preemption() { return 0; }
    1921
    2022thread T {};
Note: See TracChangeset for help on using the changeset viewer.