Ignore:
Timestamp:
Nov 20, 2022, 10:24:14 PM (2 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master
Children:
910e1d0
Parents:
25b0fde
Message:

major update of PRNG

Location:
libcfa/src/concurrency
Files:
4 edited

Legend:

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

    r25b0fde rd2ad151  
    1010// Created On       : Tue Jan 17 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jan  9 19:06:45 2022
    13 // Update Count     : 48
     12// Last Modified On : Fri Nov 18 12:20:26 2022
     13// Update Count     : 49
    1414//
    1515
     
    222222                struct processor * last_proc;
    223223
    224                 uint32_t random_state;                                                  // fast random numbers
     224                __uint128_t random_state;                                               // fast random numbers
    225225
    226226                #if defined( __CFA_WITH_VERIFY__ )
  • libcfa/src/concurrency/kernel/startup.cfa

    r25b0fde rd2ad151  
    3939#include "limits.hfa"
    4040#include "math.hfa"
     41#include "bits/random.hfa"                                                              // prng
    4142
    4243#define CFA_PROCESSOR_USE_MMAP 0
     
    107108extern void __wake_proc(processor *);
    108109extern int cfa_main_returned;                                                   // from interpose.cfa
    109 uint32_t __global_random_prime = 4_294_967_291u, __global_random_mask = false;
     110PRNG_ARG_T __global_random_prime = 4_294_967_291u;
     111bool __global_random_mask = false;
    110112
    111113//-----------------------------------------------------------------------------
  • libcfa/src/concurrency/thread.cfa

    r25b0fde rd2ad151  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Feb 12 15:24:18 2022
    13 // Update Count     : 66
     12// Last Modified On : Sun Nov 20 17:17:50 2022
     13// Update Count     : 80
    1414//
    1515
     
    2626#include "invoke.h"
    2727
    28 extern uint32_t __global_random_seed, __global_random_prime, __global_random_mask;
     28extern PRNG_ARG_T __global_random_seed, __global_random_prime;
     29extern bool __global_random_mask;
    2930
    3031#pragma GCC visibility push(default)
     
    221222
    222223//-----------------------------------------------------------------------------
    223 #define GENERATOR LCG
    224 
    225 void set_seed( uint32_t seed ) {
    226         uint32_t & state = active_thread()->random_state;
     224
     225void set_seed( uint64_t seed ) {
     226        PRNG_ARG_T & state = active_thread()->random_state;
    227227        state = __global_random_seed = seed;
    228         GENERATOR( state );
     228        (void)PRNG_NAME( state );                                                       // prime PRNG
    229229        __global_random_prime = state;
    230230        __global_random_mask = true;
    231231} // set_seed
    232232
    233 uint32_t prng( void ) {                                                                 // [0,UINT_MAX]
    234         uint32_t & state = active_thread()->random_state;
    235         return GENERATOR( state );
     233uint64_t prng( void ) {                                                                 // [0,UINT_MAX]
     234        PRNG_ARG_T & state = active_thread()->random_state;
     235        return PRNG_NAME( state );
    236236} // prng
    237237
  • libcfa/src/concurrency/thread.hfa

    r25b0fde rd2ad151  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb 11 16:34:07 2022
    13 // Update Count     : 20
     12// Last Modified On : Sat Nov 19 16:41:27 2022
     13// Update Count     : 30
    1414//
    1515
     
    2323#include "monitor.hfa"
    2424#include "exception.hfa"
     25#include "bits/random.hfa"
    2526
    2627//-----------------------------------------------------------------------------
     
    142143// prng
    143144static inline {
    144         uint32_t prng( thread$ & th ) __attribute__(( warn_unused_result )) { return LCG( th.random_state ); } // [0,UINT_MAX]
    145         uint32_t prng( thread$ & th, uint32_t u ) __attribute__(( warn_unused_result )) { return prng( th ) % u; } // [0,u)
    146         uint32_t prng( thread$ & th, uint32_t l, uint32_t u ) __attribute__(( warn_unused_result )) { return prng( th, u - l + 1 ) + l; } // [l,u]
     145        uint64_t prng( thread$ & th ) __attribute__(( warn_unused_result )) { return PRNG_NAME( th.random_state ); } // [0,UINT_MAX]
     146        uint64_t prng( thread$ & th, uint64_t u ) __attribute__(( warn_unused_result )) { return prng( th ) % u; } // [0,u)
     147        uint64_t prng( thread$ & th, uint64_t l, uint64_t u ) __attribute__(( warn_unused_result )) { return prng( th, u - l + 1 ) + l; } // [l,u]
    147148        forall( T & | is_thread(T) ) {
    148                 uint32_t prng( T & th ) __attribute__(( warn_unused_result )) { return prng( (thread &)th ); } // [0,UINT_MAX]
    149                 uint32_t prng( T & th, uint32_t u ) __attribute__(( warn_unused_result )) { return prng( th ) % u; } // [0,u)
    150                 uint32_t prng( T & th, uint32_t l, uint32_t u ) __attribute__(( warn_unused_result )) { return prng( th, u - l + 1 ) + l; } // [l,u]
     149                uint64_t prng( T & th ) __attribute__(( warn_unused_result )) { return prng( (thread &)th ); } // [0,UINT_MAX]
     150                uint64_t prng( T & th, uint64_t u ) __attribute__(( warn_unused_result )) { return prng( th ) % u; } // [0,u)
     151                uint64_t prng( T & th, uint64_t l, uint64_t u ) __attribute__(( warn_unused_result )) { return prng( th, u - l + 1 ) + l; } // [l,u]
    151152        } // distribution
    152153} // distribution
Note: See TracChangeset for help on using the changeset viewer.