Changeset 35488 in project


Ignore:
Timestamp:
04/29/18 23:33:19 (4 weeks ago)
Author:
kon
Message:

WELL512 wip

Location:
release/4/srfi-27/trunk
Files:
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/srfi-27/trunk/well512.scm

    r35487 r35488  
    2626
    2727#>
    28 #include "WELL512a.c"
    29 
    30 static uint32_t init[ R ];
     28/* ***************************************************************************** */
     29/* Copyright:      Francois Panneton and Pierre L'Ecuyer, University of Montreal */
     30/*                 Makoto Matsumoto, Hiroshima University                        */
     31/* Notice:         This code can be used freely for personal, academic,          */
     32/*                 or non-commercial purposes. For commercial purposes,          */
     33/*                 please contact P. L'Ecuyer at: lecuyer@iro.UMontreal.ca       */
     34/* ***************************************************************************** */
     35
     36#define R 16
     37
     38typedef struct {
     39  unsigned int i;
     40  uint32_t state[R];
     41} WELL512State;
     42
     43void
     44InitWELLRNG512a( WELL512State *well )
     45{
     46   well->i = 0;
     47   for (int j = 0; j < R; j++)
     48     well->state[j] = rand()^(rand()<<16)^(rand()<<31);
     49}
     50
     51double
     52WELLRNG512a( WELL512State *well )
     53{
     54# define W 32
     55# define P 0
     56# define M1 13
     57# define M2 9
     58# define M3 5
     59
     60# define OFF( o ) ((well->i + (o)) & 0x0000000fU)
     61
     62# define V0       well->state[OFF( 0 )]
     63# define VM1      well->state[OFF( M1 )]
     64# define VM2      well->state[OFF( M2 )]
     65# define VM3      well->state[OFF( M3 )]
     66# define VRm1     well->state[OFF( 15 )]
     67# define VRm2     well->state[OFF( 14 )]
     68# define newV0    well->state[OFF( 15 )]
     69# define newV1    well->state[OFF( 0 )]
     70# define newVRm1  well->state[OFF( 14 )]
     71
     72# define MAT0POS( t, v )     (v^(v>>t))
     73# define MAT0NEG( t, v )     (v^(v<<(-(t))))
     74# define MAT3NEG( t, v )     (v<<(-(t)))
     75# define MAT4NEG( t, b, v )  (v^((v<<(-(t))) & b))
     76
     77# define FACT 2.32830643653869628906e-10
     78
     79  uint32_t z0 = VRm1;
     80  uint32_t z1 = MAT0NEG( -16, V0 ) ^ MAT0NEG( -15, VM1 );
     81  uint32_t z2 = MAT0POS( 11, VM2 );
     82
     83  newV1 = z1 ^ z2;
     84  newV0 = MAT0NEG( -2, z0 ) ^ MAT0NEG( -18, z1 ) ^ MAT3NEG( -28, z2 ) ^ MAT4NEG(-5, 0xda442d24U, newV1 );
     85
     86  well->i = OFF( 15 );
     87  C_return( ((double) well->state[OFF( 0 )]) * FACT );
     88
     89# undef FACT
     90
     91# undef V0
     92# undef VM1
     93# undef VM2
     94# undef VM3
     95# undef VRm1
     96# undef VRm2
     97# undef newV0
     98# undef newV1
     99# undef newVRm1
     100
     101# undef MAT0POS
     102# undef MAT0NEG
     103# undef MAT3NEG
     104# undef MAT4NEG
     105
     106# undef OFF
     107
     108# undef W
     109# undef P
     110# undef M1
     111# undef M2
     112# undef M3
     113}
     114
     115//#undef R
    31116
    32117static void
Note: See TracChangeset for help on using the changeset viewer.