forked from liuliu/ccv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added dSFMT library as a 3rdparty module (so if gsl doesn't exists, we
will fallback to dSFMT).
- Loading branch information
Showing
11 changed files
with
1,557 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#pragma once | ||
/** | ||
* @file dSFMT-common.h | ||
* | ||
* @brief SIMD oriented Fast Mersenne Twister(SFMT) pseudorandom | ||
* number generator with jump function. This file includes common functions | ||
* used in random number generation and jump. | ||
* | ||
* @author Mutsuo Saito (Hiroshima University) | ||
* @author Makoto Matsumoto (The University of Tokyo) | ||
* | ||
* Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima | ||
* University. | ||
* Copyright (C) 2012 Mutsuo Saito, Makoto Matsumoto, Hiroshima | ||
* University and The University of Tokyo. | ||
* All rights reserved. | ||
* | ||
* The 3-clause BSD License is applied to this software, see | ||
* LICENSE.txt | ||
*/ | ||
#ifndef DSFMT_COMMON_H | ||
#define DSFMT_COMMON_H | ||
|
||
#include "dSFMT.h" | ||
|
||
#if defined(HAVE_SSE2) | ||
# include <emmintrin.h> | ||
union X128I_T { | ||
uint64_t u[2]; | ||
__m128i i128; | ||
}; | ||
union X128D_T { | ||
double d[2]; | ||
__m128d d128; | ||
}; | ||
/** mask data for sse2 */ | ||
static const union X128I_T sse2_param_mask = {{DSFMT_MSK1, DSFMT_MSK2}}; | ||
#endif | ||
|
||
#if defined(HAVE_ALTIVEC) | ||
inline static void do_recursion(w128_t *r, w128_t *a, w128_t * b, | ||
w128_t *lung) { | ||
const vector unsigned char sl1 = ALTI_SL1; | ||
const vector unsigned char sl1_perm = ALTI_SL1_PERM; | ||
const vector unsigned int sl1_msk = ALTI_SL1_MSK; | ||
const vector unsigned char sr1 = ALTI_SR; | ||
const vector unsigned char sr1_perm = ALTI_SR_PERM; | ||
const vector unsigned int sr1_msk = ALTI_SR_MSK; | ||
const vector unsigned char perm = ALTI_PERM; | ||
const vector unsigned int msk1 = ALTI_MSK; | ||
vector unsigned int w, x, y, z; | ||
|
||
z = a->s; | ||
w = lung->s; | ||
x = vec_perm(w, (vector unsigned int)perm, perm); | ||
y = vec_perm(z, sl1_perm, sl1_perm); | ||
y = vec_sll(y, sl1); | ||
y = vec_and(y, sl1_msk); | ||
w = vec_xor(x, b->s); | ||
w = vec_xor(w, y); | ||
x = vec_perm(w, (vector unsigned int)sr1_perm, sr1_perm); | ||
x = vec_srl(x, sr1); | ||
x = vec_and(x, sr1_msk); | ||
y = vec_and(w, msk1); | ||
z = vec_xor(z, y); | ||
r->s = vec_xor(z, x); | ||
lung->s = w; | ||
} | ||
#elif defined(HAVE_SSE2) | ||
/** | ||
* This function represents the recursion formula. | ||
* @param r output 128-bit | ||
* @param a a 128-bit part of the internal state array | ||
* @param b a 128-bit part of the internal state array | ||
* @param d a 128-bit part of the internal state array (I/O) | ||
*/ | ||
inline static void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *u) { | ||
__m128i v, w, x, y, z; | ||
|
||
x = a->si; | ||
z = _mm_slli_epi64(x, DSFMT_SL1); | ||
y = _mm_shuffle_epi32(u->si, SSE2_SHUFF); | ||
z = _mm_xor_si128(z, b->si); | ||
y = _mm_xor_si128(y, z); | ||
|
||
v = _mm_srli_epi64(y, DSFMT_SR); | ||
w = _mm_and_si128(y, sse2_param_mask.i128); | ||
v = _mm_xor_si128(v, x); | ||
v = _mm_xor_si128(v, w); | ||
r->si = v; | ||
u->si = y; | ||
} | ||
#else | ||
/** | ||
* This function represents the recursion formula. | ||
* @param r output 128-bit | ||
* @param a a 128-bit part of the internal state array | ||
* @param b a 128-bit part of the internal state array | ||
* @param lung a 128-bit part of the internal state array (I/O) | ||
*/ | ||
inline static void do_recursion(w128_t *r, w128_t *a, w128_t * b, | ||
w128_t *lung) { | ||
uint64_t t0, t1, L0, L1; | ||
|
||
t0 = a->u[0]; | ||
t1 = a->u[1]; | ||
L0 = lung->u[0]; | ||
L1 = lung->u[1]; | ||
lung->u[0] = (t0 << DSFMT_SL1) ^ (L1 >> 32) ^ (L1 << 32) ^ b->u[0]; | ||
lung->u[1] = (t1 << DSFMT_SL1) ^ (L0 >> 32) ^ (L0 << 32) ^ b->u[1]; | ||
r->u[0] = (lung->u[0] >> DSFMT_SR) ^ (lung->u[0] & DSFMT_MSK1) ^ t0; | ||
r->u[1] = (lung->u[1] >> DSFMT_SR) ^ (lung->u[1] & DSFMT_MSK2) ^ t1; | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef DSFMT_PARAMS_H | ||
#define DSFMT_PARAMS_H | ||
|
||
#include "dSFMT.h" | ||
|
||
/*---------------------- | ||
the parameters of DSFMT | ||
following definitions are in dSFMT-paramsXXXX.h file. | ||
----------------------*/ | ||
/** the pick up position of the array. | ||
#define DSFMT_POS1 122 | ||
*/ | ||
|
||
/** the parameter of shift left as four 32-bit registers. | ||
#define DSFMT_SL1 18 | ||
*/ | ||
|
||
/** the parameter of shift right as four 32-bit registers. | ||
#define DSFMT_SR1 12 | ||
*/ | ||
|
||
/** A bitmask, used in the recursion. These parameters are introduced | ||
* to break symmetry of SIMD. | ||
#define DSFMT_MSK1 (uint64_t)0xdfffffefULL | ||
#define DSFMT_MSK2 (uint64_t)0xddfecb7fULL | ||
*/ | ||
|
||
/** These definitions are part of a 128-bit period certification vector. | ||
#define DSFMT_PCV1 UINT64_C(0x00000001) | ||
#define DSFMT_PCV2 UINT64_C(0x00000000) | ||
*/ | ||
|
||
#define DSFMT_LOW_MASK UINT64_C(0x000FFFFFFFFFFFFF) | ||
#define DSFMT_HIGH_CONST UINT64_C(0x3FF0000000000000) | ||
#define DSFMT_SR 12 | ||
|
||
/* for sse2 */ | ||
#if defined(HAVE_SSE2) | ||
#define SSE2_SHUFF 0x1b | ||
#elif defined(HAVE_ALTIVEC) | ||
#if defined(__APPLE__) /* For OSX */ | ||
#define ALTI_SR (vector unsigned char)(4) | ||
#define ALTI_SR_PERM \ | ||
(vector unsigned char)(15,0,1,2,3,4,5,6,15,8,9,10,11,12,13,14) | ||
#define ALTI_SR_MSK \ | ||
(vector unsigned int)(0x000fffffU,0xffffffffU,0x000fffffU,0xffffffffU) | ||
#define ALTI_PERM \ | ||
(vector unsigned char)(12,13,14,15,8,9,10,11,4,5,6,7,0,1,2,3) | ||
#else | ||
#define ALTI_SR {4} | ||
#define ALTI_SR_PERM {15,0,1,2,3,4,5,6,15,8,9,10,11,12,13,14} | ||
#define ALTI_SR_MSK {0x000fffffU,0xffffffffU,0x000fffffU,0xffffffffU} | ||
#define ALTI_PERM {12,13,14,15,8,9,10,11,4,5,6,7,0,1,2,3} | ||
#endif | ||
#endif | ||
|
||
#include "dSFMT-params19937.h" | ||
|
||
#endif /* DSFMT_PARAMS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef DSFMT_PARAMS19937_H | ||
#define DSFMT_PARAMS19937_H | ||
|
||
/* #define DSFMT_N 191 */ | ||
/* #define DSFMT_MAXDEGREE 19992 */ | ||
#define DSFMT_POS1 117 | ||
#define DSFMT_SL1 19 | ||
#define DSFMT_MSK1 UINT64_C(0x000ffafffffffb3f) | ||
#define DSFMT_MSK2 UINT64_C(0x000ffdfffc90fffd) | ||
#define DSFMT_MSK32_1 0x000ffaffU | ||
#define DSFMT_MSK32_2 0xfffffb3fU | ||
#define DSFMT_MSK32_3 0x000ffdffU | ||
#define DSFMT_MSK32_4 0xfc90fffdU | ||
#define DSFMT_FIX1 UINT64_C(0x90014964b32f4329) | ||
#define DSFMT_FIX2 UINT64_C(0x3b8d12ac548a7c7a) | ||
#define DSFMT_PCV1 UINT64_C(0x3d84e1ac0dc82880) | ||
#define DSFMT_PCV2 UINT64_C(0x0000000000000001) | ||
#define DSFMT_IDSTR "dSFMT2-19937:117-19:ffafffffffb3f-ffdfffc90fffd" | ||
|
||
|
||
/* PARAMETERS FOR ALTIVEC */ | ||
#if defined(__APPLE__) /* For OSX */ | ||
#define ALTI_SL1 (vector unsigned int)(3, 3, 3, 3) | ||
#define ALTI_SL1_PERM \ | ||
(vector unsigned char)(2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1) | ||
#define ALTI_SL1_MSK \ | ||
(vector unsigned int)(0xffffffffU,0xfff80000U,0xffffffffU,0xfff80000U) | ||
#define ALTI_MSK (vector unsigned int)(DSFMT_MSK32_1, \ | ||
DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4) | ||
#else /* For OTHER OSs(Linux?) */ | ||
#define ALTI_SL1 {3, 3, 3, 3} | ||
#define ALTI_SL1_PERM \ | ||
{2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1} | ||
#define ALTI_SL1_MSK \ | ||
{0xffffffffU,0xfff80000U,0xffffffffU,0xfff80000U} | ||
#define ALTI_MSK \ | ||
{DSFMT_MSK32_1, DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4} | ||
#endif | ||
|
||
#endif /* DSFMT_PARAMS19937_H */ |
Oops, something went wrong.