- Main Page
- Data Structures
- Files

- File List
- Globals

# dSFMT.h

Go to the documentation of this file.

    00001
    00031 #ifndef DSFMT_H
    00032 #define DSFMT_H
    00033
    00034 #include <stdio.h>
    00035 #include <assert.h>
    00036 #include "dSFMT-params.h"
    00037
    00038 #if !defined(DSFMT_BIG_ENDIAN)
    00039 #  if defined(__BYTE_ORDER) && defined(__BIG_ENDIAN)
    00040 #    if __BYTE_ORDER == __BIG_ENDIAN
    00041 #      define DSFMT_BIG_ENDIAN 1
    00042 #    endif
    00043 #  elif defined(_BYTE_ORDER) && defined(_BIG_ENDIAN)
    00044 #    if _BYTE_ORDER == _BIG_ENDIAN
    00045 #      define DSFMT_BIG_ENDIAN 1
    00046 #    endif
    00047 #  elif defined(__BYTE_ORDER__) && defined(__BIG_ENDIAN__)
    00048 #    if __BYTE_ORDER__ == __BIG_ENDIAN__
    00049 #      define DSFMT_BIG_ENDIAN 1
    00050 #    endif
    00051 #  elif defined(BYTE_ORDER) && defined(BIG_ENDIAN)
    00052 #    if BYTE_ORDER == BIG_ENDIAN
    00053 #      define DSFMT_BIG_ENDIAN 1
    00054 #    endif
    00055 #  elif defined(__BIG_ENDIAN) || defined(_BIG_ENDIAN) \
    00056     || defined(__BIG_ENDIAN__) || defined(BIG_ENDIAN)
    00057 #      define DSFMT_BIG_ENDIAN 1
    00058 #  endif
    00059 #endif
    00060
    00061 #if defined(DSFMT_BIG_ENDIAN) && defined(__amd64)
    00062 #  undef DSFMT_BIG_ENDIAN
    00063 #endif
    00064
    00065 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
    00066 #  include <inttypes.h>
    00067 #elif defined(_MSC_VER) || defined(__BORLANDC__)
    00068 #  if !defined(DSFMT_UINT32_DEFINED) && !defined(SFMT_UINT32_DEFINED)
    00069 typedef unsigned int uint32_t;
    00070 typedef unsigned long long uint64_t;
    00071 #    define DSFMT_UINT32_DEFINED
    00072 #    if !defined(inline)
    00073 #      define inline __inline
    00074 #    endif
    00075 #  endif
    00076 #else
    00077 #  include <inttypes.h>
    00078 #  if !defined(inline)
    00079 #    if defined(__GNUC__)
    00080 #      define inline __inline__
    00081 #    else
    00082 #      define inline
    00083 #    endif
    00084 #  endif
    00085 #endif
    00086
    00087 #ifndef PRIu64
    00088 #  if defined(_MSC_VER) || defined(__BORLANDC__)
    00089 #    define PRIu64 "I64u"
    00090 #    define PRIx64 "I64x"
    00091 #  else
    00092 #    define PRIu64 "llu"
    00093 #    define PRIx64 "llx"
    00094 #  endif
    00095 #endif
    00096
    00097 #ifndef UINT64_C
    00098 #  define UINT64_C(v) (v ## ULL)
    00099 #endif
    00100
    00101 /*------------------------------------------
    00102   128-bit SIMD like data type for standard C
    00103   ------------------------------------------*/
    00104 #if defined(HAVE_ALTIVEC)
    00105 #  if !defined(__APPLE__)
    00106 #    include <altivec.h>
    00107 #  endif
    00108
    00109 union W128_T {
    00110     vector unsigned int s;
    00111     uint64_t u[2];
    00112     uint32_t u32[4];
    00113     double d[2];
    00114 };
    00115
    00116 #elif defined(HAVE_SSE2)
    00117 #  include <emmintrin.h>
    00118
    00120 union W128_T {
    00121     __m128i si;
    00122     __m128d sd;
    00123     uint64_t u[2];
    00124     uint32_t u32[4];
    00125     double d[2];
    00126 };
    00127 #else  /* standard C */
    00128
    00129 union W128_T {
    00130     uint64_t u[2];
    00131     uint32_t u32[4];
    00132     double d[2];
    00133 };
    00134 #endif
    00135
    00137 typedef union W128_T w128_t;
    00138
    00140 struct DSFMT_T {
    00141     w128_t status[DSFMT_N + 1];
    00142     int idx;
    00143 };
    00144 typedef struct DSFMT_T dsfmt_t;
    00145
    00147 extern int dsfmt_global_is_initialized;
    00149 extern dsfmt_t dsfmt_global_data;
    00151 extern const int dsfmt_global_mexp;
    00152
    00153 void dsfmt_gen_rand_all(dsfmt_t *dsfmt);
    00154 void dsfmt_fill_array_open_close(dsfmt_t *dsfmt, double array[], int size);
    00155 void dsfmt_fill_array_close_open(dsfmt_t *dsfmt, double array[], int size);
    00156 void dsfmt_fill_array_open_open(dsfmt_t *dsfmt, double array[], int size);
    00157 void dsfmt_fill_array_close1_open2(dsfmt_t *dsfmt, double array[], int size);
    00158 void dsfmt_chk_init_gen_rand(dsfmt_t *dsfmt, uint32_t seed, int mexp);
    00159 void dsfmt_chk_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[],
    00160                              int key_length, int mexp);
    00161 const char *dsfmt_get_idstring(void);
    00162 int dsfmt_get_min_array_size(void);
    00163
    00164 #if defined(__GNUC__)
    00165 #  define DSFMT_PRE_INLINE inline static
    00166 #  define DSFMT_PST_INLINE __attribute__((always_inline))
    00167 #elif defined(_MSC_VER) && _MSC_VER >= 1200
    00168 #  define DSFMT_PRE_INLINE __forceinline
    00169 #  define DSFMT_PST_INLINE
    00170 #else
    00171 #  define DSFMT_PRE_INLINE inline static
    00172 #  define DSFMT_PST_INLINE
    00173 #endif
    00174 DSFMT_PRE_INLINE double dsfmt_genrand_close1_open2(dsfmt_t *dsfmt)
    00175     DSFMT_PST_INLINE;
    00176 DSFMT_PRE_INLINE double dsfmt_genrand_close_open(dsfmt_t *dsfmt)
    00177     DSFMT_PST_INLINE;
    00178 DSFMT_PRE_INLINE double dsfmt_genrand_open_close(dsfmt_t *dsfmt)
    00179     DSFMT_PST_INLINE;
    00180 DSFMT_PRE_INLINE double dsfmt_genrand_open_open(dsfmt_t *dsfmt)
    00181     DSFMT_PST_INLINE;
    00182 DSFMT_PRE_INLINE double dsfmt_gv_genrand_close1_open2(void) DSFMT_PST_INLINE;
    00183 DSFMT_PRE_INLINE double dsfmt_gv_genrand_close_open(void) DSFMT_PST_INLINE;
    00184 DSFMT_PRE_INLINE double dsfmt_gv_genrand_open_close(void) DSFMT_PST_INLINE;
    00185 DSFMT_PRE_INLINE double dsfmt_gv_genrand_open_open(void) DSFMT_PST_INLINE;
    00186 DSFMT_PRE_INLINE void dsfmt_gv_fill_array_open_close(double array[], int size)
    00187     DSFMT_PST_INLINE;
    00188 DSFMT_PRE_INLINE void dsfmt_gv_fill_array_close_open(double array[], int size)
    00189     DSFMT_PST_INLINE;
    00190 DSFMT_PRE_INLINE void dsfmt_gv_fill_array_open_open(double array[], int size)
    00191     DSFMT_PST_INLINE;
    00192 DSFMT_PRE_INLINE void dsfmt_gv_fill_array_close1_open2(double array[], int size)
    00193     DSFMT_PST_INLINE;
    00194 DSFMT_PRE_INLINE void dsfmt_gv_init_gen_rand(uint32_t seed) DSFMT_PST_INLINE;
    00195 DSFMT_PRE_INLINE void dsfmt_gv_init_by_array(uint32_t init_key[],
    00196                                              int key_length) DSFMT_PST_INLINE;
    00197 DSFMT_PRE_INLINE void dsfmt_init_gen_rand(dsfmt_t *dsfmt, uint32_t seed)
    00198     DSFMT_PST_INLINE;
    00199 DSFMT_PRE_INLINE void dsfmt_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[],
    00200                                           int key_length) DSFMT_PST_INLINE;
    00201
    00211 inline static double dsfmt_genrand_close1_open2(dsfmt_t *dsfmt) {
    00212     double r;
    00213     double *psfmt64 = &dsfmt->status[0].d[0];
    00214
    00215     if (dsfmt->idx >= DSFMT_N * 2) {
    00216         dsfmt_gen_rand_all(dsfmt);
    00217         dsfmt->idx = 0;
    00218     }
    00219     r = psfmt64[dsfmt->idx++];
    00220     return r;
    00221 }
    00222
    00231 inline static double dsfmt_gv_genrand_close1_open2(void) {
    00232     assert(dsfmt_global_is_initialized);
    00233     return dsfmt_genrand_close1_open2(&dsfmt_global_data);
    00234 }
    00235
    00244 inline static double dsfmt_genrand_close_open(dsfmt_t *dsfmt) {
    00245     return dsfmt_genrand_close1_open2(dsfmt) - 1.0;
    00246 }
    00247
    00255 inline static double dsfmt_gv_genrand_close_open(void) {
    00256     return dsfmt_gv_genrand_close1_open2() - 1.0;
    00257 }
    00258
    00267 inline static double dsfmt_genrand_open_close(dsfmt_t *dsfmt) {
    00268     return 2.0 - dsfmt_genrand_close1_open2(dsfmt);
    00269 }
    00270
    00278 inline static double dsfmt_gv_genrand_open_close(void) {
    00279     return 2.0 - dsfmt_gv_genrand_close1_open2();
    00280 }
    00281
    00290 inline static double dsfmt_genrand_open_open(dsfmt_t *dsfmt) {
    00291     double *dsfmt64 = &dsfmt->status[0].d[0];
    00292     union {
    00293         double d;
    00294         uint64_t u;
    00295     } r;
    00296
    00297     if (dsfmt->idx >= DSFMT_N * 2) {
    00298         dsfmt_gen_rand_all(dsfmt);
    00299         dsfmt->idx = 0;
    00300     }
    00301     r.d = dsfmt64[dsfmt->idx++];
    00302     r.u |= 1;
    00303     return r.d - 1.0;
    00304 }
    00305
    00313 inline static double dsfmt_gv_genrand_open_open(void) {
    00314     return dsfmt_genrand_open_open(&dsfmt_global_data);
    00315 }
    00316
    00328 inline static void dsfmt_gv_fill_array_close1_open2(double array[], int size) {
    00329     assert(dsfmt_global_is_initialized);
    00330     dsfmt_fill_array_close1_open2(&dsfmt_global_data, array, size);
    00331 }
    00332
    00345 inline static void dsfmt_gv_fill_array_open_close(double array[], int size) {
    00346     assert(dsfmt_global_is_initialized);
    00347     dsfmt_fill_array_open_close(&dsfmt_global_data, array, size);
    00348 }
    00349
    00362 inline static void dsfmt_gv_fill_array_close_open(double array[], int size) {
    00363     assert(dsfmt_global_is_initialized);
    00364     dsfmt_fill_array_close_open(&dsfmt_global_data, array, size);
    00365 }
    00366
    00379 inline static void dsfmt_gv_fill_array_open_open(double array[], int size) {
    00380     assert(dsfmt_global_is_initialized);
    00381     dsfmt_fill_array_open_open(&dsfmt_global_data, array, size);
    00382 }
    00383
    00390 inline static void dsfmt_init_gen_rand(dsfmt_t *dsfmt, uint32_t seed) {
    00391     dsfmt_chk_init_gen_rand(dsfmt, seed, DSFMT_MEXP);
    00392 }
    00393
    00400 inline static void dsfmt_gv_init_gen_rand(uint32_t seed) {
    00401     dsfmt_init_gen_rand(&dsfmt_global_data, seed);
    00402     dsfmt_global_is_initialized = 1;
    00403 }
    00404
    00412 inline static void dsfmt_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[],
    00413                                        int key_length) {
    00414     dsfmt_chk_init_by_array(dsfmt, init_key, key_length, DSFMT_MEXP);
    00415 }
    00416
    00425 inline static void dsfmt_gv_init_by_array(uint32_t init_key[], int key_length) {
    00426     dsfmt_init_by_array(&dsfmt_global_data, init_key, key_length);
    00427     dsfmt_global_is_initialized = 1;
    00428 }
    00429
    00430 #if !defined(DSFMT_DO_NOT_USE_OLD_NAMES)
    00431 DSFMT_PRE_INLINE const char *get_idstring(void) DSFMT_PST_INLINE;
    00432 DSFMT_PRE_INLINE int get_min_array_size(void) DSFMT_PST_INLINE;
    00433 DSFMT_PRE_INLINE void init_gen_rand(uint32_t seed) DSFMT_PST_INLINE;
    00434 DSFMT_PRE_INLINE void init_by_array(uint32_t init_key[], int key_length)
    00435     DSFMT_PST_INLINE;
    00436 DSFMT_PRE_INLINE double genrand_close1_open2(void) DSFMT_PST_INLINE;
    00437 DSFMT_PRE_INLINE double genrand_close_open(void) DSFMT_PST_INLINE;
    00438 DSFMT_PRE_INLINE double genrand_open_close(void) DSFMT_PST_INLINE;
    00439 DSFMT_PRE_INLINE double genrand_open_open(void) DSFMT_PST_INLINE;
    00440 DSFMT_PRE_INLINE void fill_array_open_close(double array[], int size)
    00441     DSFMT_PST_INLINE;
    00442 DSFMT_PRE_INLINE void fill_array_close_open(double array[], int size)
    00443     DSFMT_PST_INLINE;
    00444 DSFMT_PRE_INLINE void fill_array_open_open(double array[], int size)
    00445     DSFMT_PST_INLINE;
    00446 DSFMT_PRE_INLINE void fill_array_close1_open2(double array[], int size)
    00447     DSFMT_PST_INLINE;
    00448
    00454 inline static const char *get_idstring(void) {
    00455     return dsfmt_get_idstring();
    00456 }
    00457
    00463 inline static int get_min_array_size(void) {
    00464     return dsfmt_get_min_array_size();
    00465 }
    00466
    00472 inline static void init_gen_rand(uint32_t seed) {
    00473     dsfmt_gv_init_gen_rand(seed);
    00474 }
    00475
    00482 inline static void init_by_array(uint32_t init_key[], int key_length) {
    00483     dsfmt_gv_init_by_array(init_key, key_length);
    00484 }
    00485
    00492 inline static double genrand_close1_open2(void) {
    00493     return dsfmt_gv_genrand_close1_open2();
    00494 }
    00495
    00502 inline static double genrand_close_open(void) {
    00503     return dsfmt_gv_genrand_close_open();
    00504 }
    00505
    00512 inline static double genrand_open_close(void) {
    00513     return dsfmt_gv_genrand_open_close();
    00514 }
    00515
    00522 inline static double genrand_open_open(void) {
    00523     return dsfmt_gv_genrand_open_open();
    00524 }
    00525
    00535 inline static void fill_array_open_close(double array[], int size) {
    00536     dsfmt_gv_fill_array_open_close(array, size);
    00537 }
    00538
    00548 inline static void fill_array_close_open(double array[], int size) {
    00549     dsfmt_gv_fill_array_close_open(array, size);
    00550 }
    00551
    00561 inline static void fill_array_open_open(double array[], int size) {
    00562     dsfmt_gv_fill_array_open_open(array, size);
    00563 }
    00564
    00573 inline static void fill_array_close1_open2(double array[], int size) {
    00574     dsfmt_gv_fill_array_close1_open2(array, size);
    00575 }
    00576 #endif /* DSFMT_DO_NOT_USE_OLD_NAMES */
    00577
    00578 #endif /* DSFMT_H */