Changeset 9b33337 for libcfa/src


Ignore:
Timestamp:
Jan 10, 2022, 7:11:34 PM (2 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
07a1e7a
Parents:
5b7a3662 (diff), a10f6b4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
libcfa/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/invoke.h

    r5b7a3662 r9b33337  
    1010// Created On       : Tue Jan 17 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jan  6 16:37:40 2022
    13 // Update Count     : 47
     12// Last Modified On : Sun Jan  9 19:06:45 2022
     13// Update Count     : 48
    1414//
    1515
     
    211211                struct processor * last_proc;
    212212
     213                uint32_t random_state;                                                  // fast random numbers
     214
    213215                #if defined( __CFA_WITH_VERIFY__ )
    214216                        void * canary;
  • libcfa/src/concurrency/kernel/fwd.hfa

    r5b7a3662 r9b33337  
    7777
    7878                static inline uint64_t __tls_rand() {
     79                        return
    7980                        #if defined(__SIZEOF_INT128__)
    80                                 return __lehmer64( kernelTLS().rand_seed );
     81                                __lehmer64( kernelTLS().rand_seed );
    8182                        #else
    82                                 return __xorshift64( kernelTLS().rand_seed );
     83                                __xorshift64( kernelTLS().rand_seed );
    8384                        #endif
    8485                }
     
    9192
    9293                static inline unsigned __tls_rand_fwd() {
    93 
    9494                        kernelTLS().ready_rng.fwd_seed = (A * kernelTLS().ready_rng.fwd_seed + C) & (M - 1);
    9595                        return kernelTLS().ready_rng.fwd_seed >> D;
     
    112112                }
    113113        }
    114 
    115 
    116114
    117115        extern void disable_interrupts();
  • libcfa/src/concurrency/thread.cfa

    r5b7a3662 r9b33337  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec  4 09:17:49 2019
    13 // Update Count     : 9
     12// Last Modified On : Mon Jan 10 17:05:35 2022
     13// Update Count     : 28
    1414//
    1515
     
    2727uint64_t thread_rand();
    2828
     29extern uint32_t __thread_seed;                                                  // global thread seed
     30
    2931//-----------------------------------------------------------------------------
    3032// Thread ctors and dtors
    31 void ?{}(thread$ & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) {
     33void ?{}( thread$ & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) {
    3234        context{ 0p, 0p };
    3335        self_cor{ name, storage, storageSize };
     
    3941        self_mon.owner = &this;
    4042        self_mon.recursion = 1;
     43        random_state = __thread_seed;
    4144        self_mon_p = &self_mon;
    4245        curr_cluster = &cl;
     
    178181}
    179182
     183#define GENERATOR LCG
     184
     185inline uint32_t MarsagliaXor( uint32_t & state ) {
     186        state ^= state << 6;
     187        state ^= state >> 21;
     188        state ^= state << 7;
     189        return state;
     190} // MarsagliaXor
     191
     192inline uint32_t LCG( uint32_t & state ) {                               // linear congruential generator
     193        return state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime!
     194} // LCG
     195
     196void set_seed( uint32_t seed ) { active_thread()->random_state = seed; __thread_seed = seed; }
     197uint32_t prng( void ) { return GENERATOR( active_thread()->random_state ); } // [0,UINT_MAX]
     198
    180199// Local Variables: //
    181200// mode: c //
  • libcfa/src/fstream.cfa

    r5b7a3662 r9b33337  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Oct 10 11:23:05 2021
    13 // Update Count     : 512
     12// Last Modified On : Mon Jan 10 08:45:05 2022
     13// Update Count     : 513
    1414//
    1515
     
    5252inline void setPrt$( ofstream & os, bool state ) { os.prt$ = state; }
    5353
    54 inline void lock( ofstream & os ) with( os ) {  lock( os.lock$ ); }
     54inline void lock( ofstream & os ) with( os ) { lock( os.lock$ ); }
    5555inline void unlock( ofstream & os ) { unlock( os.lock$ ); }
    5656
  • libcfa/src/stdlib.cfa

    r5b7a3662 r9b33337  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan  3 09:36:27 2022
    13 // Update Count     : 519
     12// Last Modified On : Mon Jan 10 17:07:21 2022
     13// Update Count     : 572
    1414//
    1515
    1616#include "stdlib.hfa"
     17//#include "concurrency/kernel/fwd.hfa"
     18#include "concurrency/invoke.h"                                                 // random_state
    1719
    1820//---------------------------------------
     
    221223//---------------------------------------
    222224
    223 static uint32_t seed = 0;                                                               // current seed
    224 static thread_local uint32_t state;                                             // random state
    225 
    226 void set_seed( uint32_t seed_ ) { state = seed = seed_; }
    227 uint32_t get_seed() { return seed; }
    228 
    229225#define GENERATOR LCG
    230226
    231227inline uint32_t MarsagliaXor( uint32_t & state ) {
    232         if ( unlikely( seed == 0 ) ) set_seed( rdtscl() );
    233         else if ( unlikely( state == 0 ) ) state = seed;
    234228        state ^= state << 6;
    235229        state ^= state >> 21;
     
    239233
    240234inline 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;
    243235        return state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime!
    244236} // LCG
    245237
     238uint32_t __thread_seed = rdtscl();                                              // global thread seed
     239
     240void set_seed( uint32_t seed ) { __thread_seed = seed; }
     241uint32_t get_seed() { return  __thread_seed; }
    246242uint32_t prng( PRNG & prng ) with( prng ) { callcnt += 1; return GENERATOR( state ); }
    247243
    248 uint32_t prng( void ) { return GENERATOR( state ); }
     244uint32_t prng( void ) { return GENERATOR( __thread_seed ); } // [0,UINT_MAX]
    249245
    250246//---------------------------------------
  • libcfa/src/stdlib.hfa

    r5b7a3662 r9b33337  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jan  2 22:53:57 2022
    13 // Update Count     : 594
     12// Last Modified On : Mon Jan 10 17:03:18 2022
     13// Update Count     : 619
    1414//
    1515
     
    2121#include <stdlib.h>                                                                             // *alloc, strto*, ato*
    2222#include <heap.hfa>
     23
    2324
    2425// Reduce includes by explicitly defining these routines.
     
    391392}; // PRNG
    392393
    393 extern uint32_t prng( PRNG & prng ) __attribute__(( warn_unused_result )); // [0,UINT_MAX]
     394uint32_t prng( PRNG & prng ) __attribute__(( warn_unused_result )); // [0,UINT_MAX]
    394395static inline {
    395396        void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; } // set seed
     
    402403} // distribution
    403404
    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]
     405void set_seed( uint32_t seed_ ) OPTIONAL_THREAD;
     406uint32_t get_seed() __attribute__(( warn_unused_result ));
     407uint32_t prng( void ) __attribute__(( warn_unused_result )) OPTIONAL_THREAD; // [0,UINT_MAX]
    407408static 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]
    412411} // distribution
    413412
Note: See TracChangeset for help on using the changeset viewer.