Changeset 35487 in project


Ignore:
Timestamp:
04/29/18 22:41:01 (4 months ago)
Author:
kon
Message:

WELL512 wip

Location:
release/4/srfi-27/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/4/srfi-27/trunk/WELL512a.c

    r34855 r35487  
    1919#define MAT4NEG(t,b,v) (v ^ ((v<<(-(t))) & b))
    2020
    21 #define V0            STATE[state_i                   ]
    22 #define VM1           STATE[(state_i+M1) & 0x0000000fU]
    23 #define VM2           STATE[(state_i+M2) & 0x0000000fU]
    24 #define VM3           STATE[(state_i+M3) & 0x0000000fU]
    25 #define VRm1          STATE[(state_i+15) & 0x0000000fU]
    26 #define VRm2          STATE[(state_i+14) & 0x0000000fU]
    27 #define newV0         STATE[(state_i+15) & 0x0000000fU]
    28 #define newV1         STATE[state_i                 ]
    29 #define newVRm1       STATE[(state_i+14) & 0x0000000fU]
     21typedef struct {
     22  unsigned int i;
     23  uint32_t state[R];
     24} WELL512State;
     25
     26#define V0            well->state[well->i                   ]
     27#define VM1           well->state[(well->i+M1) & 0x0000000fU]
     28#define VM2           well->state[(well->i+M2) & 0x0000000fU]
     29#define VM3           well->state[(well->i+M3) & 0x0000000fU]
     30#define VRm1          well->state[(well->i+15) & 0x0000000fU]
     31#define VRm2          well->state[(well->i+14) & 0x0000000fU]
     32#define newV0         well->state[(well->i+15) & 0x0000000fU]
     33#define newV1         well->state[well->i                   ]
     34#define newVRm1       well->state[(well->i+14) & 0x0000000fU]
    3035
    3136#define FACT 2.32830643653869628906e-10
    3237
    33 static unsigned int state_i = 0;
    34 static unsigned int STATE[R];
    35 static unsigned int z0, z1, z2;
    36 
    37 void InitWELLRNG512a (unsigned int *init){
     38void
     39InitWELLRNG512a( WELL512State *well )
     40{
    3841   int j;
    39    state_i = 0;
     42   well->i = 0;
    4043   for (j = 0; j < R; j++)
    41      STATE[j] = init[j];
     44     well->state[j] = rand()^(rand()<<16)^(rand()<<31);
    4245}
    4346
    44 double WELLRNG512a (void){
    45   z0    = VRm1;
    46   z1    = MAT0NEG (-16,V0)    ^ MAT0NEG (-15, VM1);
    47   z2    = MAT0POS (11, VM2)  ;
    48   newV1 = z1                  ^ z2;
    49   newV0 = MAT0NEG (-2,z0)     ^ MAT0NEG(-18,z1)    ^ MAT3NEG(-28,z2) ^ MAT4NEG(-5,0xda442d24U,newV1) ;
    50   state_i = (state_i + 15) & 0x0000000fU;
    51   return ((double) STATE[state_i]) * FACT;
     47double
     48WELLRNG512a( WELL512State *well )
     49{
     50  uint32_t z0 = VRm1;
     51  uint32_t z1 = MAT0NEG (-16,V0)    ^ MAT0NEG (-15, VM1);
     52  uint32_t z2 = MAT0POS (11, VM2)  ;
     53  newV1 = z1                  ^ z2;
     54  newV0 = MAT0NEG (-2,z0)     ^ MAT0NEG(-18,z1) ^ MAT3NEG(-28,z2) ^ MAT4NEG(-5,0xda442d24U,newV1) ;
     55  well->i = (well->i + 15) & 0x0000000fU;
     56  return ((double) well->state[well->i]) * FACT;
    5257}
  • release/4/srfi-27/trunk/srfi-27.setup

    r35479 r35487  
    5858
    5959;; Random Source Modules
     60
     61#; ;WIP
     62(setup-shared-extension-module 'well512 (extension-version "3.3.2")
     63  #:inline? #t #:types? #t #:compile-options UTILITY-OPTIONS)
    6064
    6165(setup-shared-extension-module 'random-source (extension-version "3.3.2")
  • release/4/srfi-27/trunk/well512.scm

    r35486 r35487  
    2828#include "WELL512a.c"
    2929
    30 // uint init[ 16 ]
     30static uint32_t init[ R ];
     31
    3132static void
    32 init_state() {
    33   InitWELLRNG512a( unsigned int *init );
     33init_state(uint32_t *vec, uint_64 seed) {
     34  InitWELLRNG512a( init );
    3435}
    3536
     
    3738uniformf64( uint32_t *state )
    3839{
    39   return WELLRNG512a();
     40  C_return( WELLRNG512a() );
    4041}
    4142
     
    4344randomu32( uint32_t *state, uint32_t m )
    4445{
    45   return WELLRNG512a (void) ;
     46  C_return( (uint32_t) WELLRNG512a() );
    4647}
    4748
     
    6263
    6364<#
     65
     66(define STATE-LENGTH (foreign-value "R" integer32))
    6467
    6568(define init_state (foreign-lambda void "init_state" nonnull-u32vector unsigned-integer64))
     
    8083    (define-constant maximum-unsigned-integer32 1073741823) ) )  ;32bit most-positive-fixnum
    8184
     85;;
     86
    8287(define-constant fpMAX maximum-unsigned-integer32-flonum)  ;2^32 - 1
    8388(define-constant LOG2-PERIOD 250)
     
    8590(define eMAX (inexact->exact fpMAX)) ;Create a "bignum" if necessary
    8691
    87 (define-constant INITIAL-SEED maximum-unsigned-integer32-flonum)
    88 
    89 (define-constant STATE-LENGTH 10)
     92(define-constant INITIAL-SEED maximum-unsigned-integer32)
    9093
    9194(define INTERNAL-ID 'well512)
Note: See TracChangeset for help on using the changeset viewer.