/Users/richardeakin/projects/libsms/trunk/src/SFMT.c File Reference

#include <string.h>
#include <assert.h>
#include "SFMT.h"
#include "SFMT/SFMT-params.h"
Include dependency graph for SFMT.c:

Typedefs

typedef struct W128_T w128_t

Functions

static int idxof (int i)
static void rshift128 (w128_t *out, w128_t const *in, int shift)
static void lshift128 (w128_t *out, w128_t const *in, int shift)
static void gen_rand_all (void)
static void gen_rand_array (w128_t *array, int size)
static uint32_t func1 (uint32_t x)
static uint32_t func2 (uint32_t x)
static void period_certification (void)
static void do_recursion (w128_t *r, w128_t *a, w128_t *b, w128_t *c, w128_t *d)
const char * get_idstring (void)
int get_min_array_size32 (void)
int get_min_array_size64 (void)
uint32_t gen_rand32 (void)
uint64_t gen_rand64 (void)
void fill_array32 (uint32_t *array, int size)
void fill_array64 (uint64_t *array, int size)
void init_gen_rand (uint32_t seed)
void init_by_array (uint32_t *init_key, int key_length)

Variables

static w128_t sfmt [N]
static uint32_t * psfmt32 = &sfmt[0].u[0]
static uint64_t * psfmt64 = (uint64_t *)&sfmt[0].u[0]
static int idx
static int initialized = 0
static uint32_t parity [4] = {PARITY1, PARITY2, PARITY3, PARITY4}

Typedef Documentation

typedef struct W128_T w128_t

128-bit data type


Function Documentation

static void do_recursion ( w128_t r,
w128_t a,
w128_t b,
w128_t c,
w128_t d 
) [inline, static]

This function represents the recursion formula.

Parameters:
r output
a a 128-bit part of the internal state array
b a 128-bit part of the internal state array
c a 128-bit part of the internal state array
d a 128-bit part of the internal state array

References lshift128(), and rshift128().

Referenced by gen_rand_all(), and gen_rand_array().

Here is the call graph for this function:

void fill_array32 ( uint32_t *  array,
int  size 
)

This function generates pseudorandom 32-bit integers in the specified array[] by one call. The number of pseudorandom integers is specified by the argument size, which must be at least 624 and a multiple of four. The generation by this function is much faster than the following gen_rand function.

For initialization, init_gen_rand or init_by_array must be called before the first call of this function. This function can not be used after calling gen_rand function, without initialization.

Parameters:
array an array where pseudorandom 32-bit integers are filled by this function. The pointer to the array must be "aligned" (namely, must be a multiple of 16) in the SIMD version, since it refers to the address of a 128-bit integer. In the standard C version, the pointer is arbitrary.
size the number of 32-bit pseudorandom integers to be generated. size must be a multiple of 4, and greater than or equal to (MEXP / 128 + 1) * 4.
Note:
memalign or posix_memalign is available to get aligned memory. Mac OSX doesn't have these functions, but malloc of OSX returns the pointer to the aligned memory block.

References gen_rand_array(), idx, and initialized.

Here is the call graph for this function:

void fill_array64 ( uint64_t *  array,
int  size 
)

This function generates pseudorandom 64-bit integers in the specified array[] by one call. The number of pseudorandom integers is specified by the argument size, which must be at least 312 and a multiple of two. The generation by this function is much faster than the following gen_rand function.

For initialization, init_gen_rand or init_by_array must be called before the first call of this function. This function can not be used after calling gen_rand function, without initialization.

Parameters:
array an array where pseudorandom 64-bit integers are filled by this function. The pointer to the array must be "aligned" (namely, must be a multiple of 16) in the SIMD version, since it refers to the address of a 128-bit integer. In the standard C version, the pointer is arbitrary.
size the number of 64-bit pseudorandom integers to be generated. size must be a multiple of 2, and greater than or equal to (MEXP / 128 + 1) * 2
Note:
memalign or posix_memalign is available to get aligned memory. Mac OSX doesn't have these functions, but malloc of OSX returns the pointer to the aligned memory block.

References gen_rand_array(), idx, and initialized.

Here is the call graph for this function:

static uint32_t func1 ( uint32_t  x  )  [inline, static]

This function represents a function used in the initialization by init_by_array

Parameters:
x 32-bit integer
Returns:
32-bit integer

Referenced by init_by_array().

static uint32_t func2 ( uint32_t  x  )  [inline, static]

This function represents a function used in the initialization by init_by_array

Parameters:
x 32-bit integer
Returns:
32-bit integer

Referenced by init_by_array().

uint32_t gen_rand32 ( void   ) 

This function generates and returns 32-bit pseudorandom number. init_gen_rand or init_by_array must be called before this function.

Returns:
32-bit pseudorandom number

References gen_rand_all(), idx, initialized, and psfmt32.

Referenced by genrand_real1(), genrand_real2(), genrand_real3(), and genrand_res53_mix().

Here is the call graph for this function:

uint64_t gen_rand64 ( void   ) 

This function generates and returns 64-bit pseudorandom number. init_gen_rand or init_by_array must be called before this function. The function gen_rand64 should not be called after gen_rand32, unless an initialization is again executed.

Returns:
64-bit pseudorandom number

References gen_rand_all(), idx, initialized, psfmt32, and psfmt64.

Referenced by genrand_res53().

Here is the call graph for this function:

static void gen_rand_all ( void   )  [inline, static]

This function fills the internal state array with pseudorandom integers.

References do_recursion(), and sfmt.

Referenced by gen_rand32(), and gen_rand64().

Here is the call graph for this function:

static void gen_rand_array ( w128_t array,
int  size 
) [inline, static]

This function fills the user-specified array with pseudorandom integers.

Parameters:
array an 128-bit array to be filled by pseudorandom numbers.
size number of 128-bit pseudorandom numbers to be generated.

References do_recursion(), and sfmt.

Referenced by fill_array32(), and fill_array64().

Here is the call graph for this function:

const char* get_idstring ( void   ) 

This function returns the identification string. The string shows the word size, the Mersenne exponent, and all parameters of this generator.

int get_min_array_size32 ( void   ) 

This function returns the minimum size of array used for fill_array32() function.

Returns:
minimum size of array used for fill_array32() function.
int get_min_array_size64 ( void   ) 

This function returns the minimum size of array used for fill_array64() function.

Returns:
minimum size of array used for fill_array64() function.
static int idxof ( int  i  )  [inline, static]

This function simulate a 64-bit index of LITTLE ENDIAN in BIG ENDIAN machine.

Referenced by init_by_array(), init_gen_rand(), and period_certification().

void init_by_array ( uint32_t *  init_key,
int  key_length 
)

This function initializes the internal state array, with an array of 32-bit integers used as the seeds

Parameters:
init_key the array of 32-bit integers, used as a seed.
key_length the length of init_key.

References func1(), func2(), idx, idxof(), initialized, period_certification(), psfmt32, and sfmt.

Here is the call graph for this function:

void init_gen_rand ( uint32_t  seed  ) 

This function initializes the internal state array with a 32-bit integer seed.

Parameters:
seed a 32-bit integer used as the seed.

References idx, idxof(), initialized, period_certification(), and psfmt32.

Referenced by sms_init().

Here is the call graph for this function:

static void lshift128 ( w128_t out,
w128_t const *  in,
int  shift 
) [inline, static]

This function simulates SIMD 128-bit left shift by the standard C. The 128-bit integer given in in is shifted by (shift * 8) bits. This function simulates the LITTLE ENDIAN SIMD.

Parameters:
out the output of this function
in the 128-bit data to be shifted
shift the shift value

Referenced by do_recursion().

static void period_certification ( void   )  [static]

This function certificate the period of 2^{MEXP}

References idxof(), parity, and psfmt32.

Referenced by init_by_array(), and init_gen_rand().

Here is the call graph for this function:

static void rshift128 ( w128_t out,
w128_t const *  in,
int  shift 
) [inline, static]

This function simulates SIMD 128-bit right shift by the standard C. The 128-bit integer given in in is shifted by (shift * 8) bits. This function simulates the LITTLE ENDIAN SIMD.

Parameters:
out the output of this function
in the 128-bit data to be shifted
shift the shift value

Referenced by do_recursion().


Variable Documentation

int idx [static]

index counter to the 32-bit internal state array

Referenced by fill_array32(), fill_array64(), gen_rand32(), gen_rand64(), init_by_array(), and init_gen_rand().

int initialized = 0 [static]

a flag: it is 0 if and only if the internal state is not yet initialized.

Referenced by fill_array32(), fill_array64(), gen_rand32(), gen_rand64(), init_by_array(), and init_gen_rand().

uint32_t parity[4] = {PARITY1, PARITY2, PARITY3, PARITY4} [static]

a parity check vector which certificate the period of 2^{MEXP}

Referenced by period_certification().

uint32_t* psfmt32 = &sfmt[0].u[0] [static]

the 32bit integer pointer to the 128-bit internal state array

Referenced by gen_rand32(), gen_rand64(), init_by_array(), init_gen_rand(), and period_certification().

uint64_t* psfmt64 = (uint64_t *)&sfmt[0].u[0] [static]

the 64bit integer pointer to the 128-bit internal state array

Referenced by gen_rand64().

w128_t sfmt[N] [static]

the 128-bit internal state array

Referenced by gen_rand_all(), gen_rand_array(), and init_by_array().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Thu Oct 29 04:08:07 2009 for libsms by  doxygen 1.6.1