39 #include <emmintrin.h>
56 #define SFMT_N 348 // Size of state vector
57 #define SFMT_M 330 // Position of intermediate feedback
58 #define SFMT_SL1 5 // Left shift of W[N-1], 32-bit words
59 #define SFMT_SL2 3 // Left shift of W[0], *8, 128-bit words
60 #define SFMT_SR1 9 // Right shift of W[M], 32-bit words
61 #define SFMT_SR2 3 // Right shift of W[N-2], *8, 128-bit words
62 #define SFMT_MASK 0xeffffffb,0xdfbebfff,0xbfbf7bef,0x9ffd7bff // AND mask
63 #define SFMT_PARITY 1,0,0xa3ac4000,0xecc1327a // Period certification vector
66 #define SFMT_N 156 // Size of state vector
67 #define SFMT_M 122 // Position of intermediate feedback
68 #define SFMT_SL1 18 // Left shift of W[N-1], 32-bit words
69 #define SFMT_SL2 1 // Left shift of W[0], *8, 128-bit words
70 #define SFMT_SR1 11 // Right shift of W[M], 32-bit words
71 #define SFMT_SR2 1 // Right shift of W[N-2], *8, 128-bit words
72 #define SFMT_MASK 0xdfffffef,0xddfecb7f,0xbffaffff,0xbffffff6 // AND mask
73 #define SFMT_PARITY 1,0,0,0x13c9e684 // Period certification vector
76 #define SFMT_N 88 // Size of state vector
77 #define SFMT_M 68 // Position of intermediate feedback
78 #define SFMT_SL1 14 // Left shift of W[N-1], 32-bit words
79 #define SFMT_SL2 3 // Left shift of W[0], *8, 128-bit words
80 #define SFMT_SR1 7 // Right shift of W[M], 32-bit words
81 #define SFMT_SR2 3 // Right shift of W[N-2], *8, 128-bit words
82 #define SFMT_MASK 0xeffff7fb,0xffffffef,0xdfdfbfff,0x7fffdbfd // AND mask
83 #define SFMT_PARITY 1,0,0xe8148000,0xd0c7afa3 // Period certification vector
86 #define SFMT_N 34 // Size of state vector
87 #define SFMT_M 17 // Position of intermediate feedback
88 #define SFMT_SL1 20 // Left shift of W[N-1], 32-bit words
89 #define SFMT_SL2 1 // Left shift of W[0], *8, 128-bit words
90 #define SFMT_SR1 7 // Right shift of W[M], 32-bit words
91 #define SFMT_SR2 1 // Right shift of W[N-2], *8, 128-bit words
92 #define SFMT_MASK 0x9f7bffff, 0x9fffff5f, 0x3efffffb, 0xfffff7bb // AND mask
93 #define SFMT_PARITY 0xa8000001, 0xaf5390a3, 0xb740b3f8, 0x6c11486d // Period certification vector
96 #define SFMT_N 18 // Size of state vector
97 #define SFMT_M 12 // Position of intermediate feedback
98 #define SFMT_SL1 19 // Left shift of W[N-1], 32-bit words
99 #define SFMT_SL2 1 // Left shift of W[0], *8, 128-bit words
100 #define SFMT_SR1 5 // Right shift of W[M], 32-bit words
101 #define SFMT_SR2 1 // Right shift of W[N-2], *8, 128-bit words
102 #define SFMT_MASK 0xbff7ffbf, 0xfdfffffe, 0xf7ffef7f, 0xf2f7cbbf // AND mask
103 #define SFMT_PARITY 0x00000001, 0x00000000, 0x00000000, 0x41dfa600 // Period certification vector
106 #define SFMT_N 10 // Size of state vector
107 #define SFMT_M 7 // Position of intermediate feedback
108 #define SFMT_SL1 14 // Left shift of W[N-1], 32-bit words
109 #define SFMT_SL2 3 // Left shift of W[0], *8, 128-bit words
110 #define SFMT_SR1 5 // Right shift of W[M], 32-bit words
111 #define SFMT_SR2 1 // Right shift of W[N-2], *8, 128-bit words
112 #define SFMT_MASK 0xf7fefffd, 0x7fefcfff, 0xaff3ef3f, 0xb5ffff7f // AND mask
113 #define SFMT_PARITY 0x00000001, 0x00000000, 0x00000000, 0x20000000 // Period certification vector
116 #define SFMT_N 5 // Size of state vector
117 #define SFMT_M 2 // Position of intermediate feedback
118 #define SFMT_SL1 15 // Left shift of W[N-1], 32-bit words
119 #define SFMT_SL2 3 // Left shift of W[0], *8, 128-bit words
120 #define SFMT_SR1 13 // Right shift of W[M], 32-bit words
121 #define SFMT_SR2 3 // Right shift of W[N-2], *8, 128-bit words
122 #define SFMT_MASK 0xfdff37ff, 0xef7f3f7d, 0xff777b7d, 0x7ff7fb2f // AND mask
123 #define SFMT_PARITY 0x00000001, 0x00000000, 0x00000000, 0x5986f054 // Period certification vector
139 __m128i
const &c, __m128i
const &d, __m128i
const &mask) {
140 __m128i a1, b1, c1, d1, z1, z2;
145 b1 = _mm_and_si128(b1, mask);
146 z1 = _mm_xor_si128(a, a1);
147 z2 = _mm_xor_si128(b1, d1);
148 z1 = _mm_xor_si128(z1, c1);
149 z2 = _mm_xor_si128(z1, z2);
178 const uint32_t factor = 1812433253U;
180 for (i = 1; i < statesize; i++) {
181 y = factor * (y ^ (y >> 30)) + i;
194 if (max == min)
return min;
else return 0x80000000;
201 interval = (
uint32_t)(max - min + 1);
213 if (max == min)
return min;
else return 0;
220 interval = (
uint32_t)(max - min + 1);
237 return (
int64_t)(r >> 12) * (1./(67108864.0*67108864.0));
252 void*
operator new(
size_t size, std::nothrow_t
const&)
254 return _mm_malloc(size, 16);
257 void operator delete(
void* ptr, std::nothrow_t
const&)
262 void*
operator new(
size_t size)
264 return _mm_malloc(size, 16);
267 void operator delete(
void* ptr)
272 void*
operator new[](
size_t size, std::nothrow_t
const&)
274 return _mm_malloc(size, 16);
277 void operator delete[](
void* ptr, std::nothrow_t
const&)
282 void*
operator new[](
size_t size)
284 return _mm_malloc(size, 16);
287 void operator delete[](
void* ptr)
300 mask = _mm_loadu_si128((__m128i*)maskinit);
308 for (i = 0; i < 4; i++)
311 for (i = 16; i > 0; i >>= 1) temp ^= temp >> i;
315 for (i = 0; i < 4; i++) {
317 for (j = 1; j; j <<= 1) {
318 if (parityvec[i] & j) {
#define SFMT_SR1
Definition: SFMT.h:80
#define SFMT_N
Definition: SFMT.h:76
uint32_t LastInterval
Definition: SFMT.h:359
void RandomInit(int seed)
Definition: SFMT.h:168
double Random()
Definition: SFMT.h:227
uint32_t RLimit
Definition: SFMT.h:360
#define SFMT_SR2
Definition: SFMT.h:81
__m128i mask
Definition: SFMT.h:356
signed __int64 int64_t
Definition: stdint.h:89
#define SFMT_SL1
Definition: SFMT.h:78
T max(const T &x, const T &y)
Definition: g3dmath.h:320
unsigned int uint32_t
Definition: stdint.h:80
T min(const T &x, const T &y)
Definition: g3dmath.h:305
void Generate()
Definition: SFMT.h:333
#define SFMT_M
Definition: SFMT.h:77
unsigned __int64 uint64_t
Definition: stdint.h:90
#define SFMT_PARITY
Definition: SFMT.h:83
int32_t IRandom(int32_t min, int32_t max)
Definition: SFMT.h:189
void Init2()
Definition: SFMT.h:293
__m128i state[SFMT_N]
Definition: SFMT.h:357
uint32_t ix
Definition: SFMT.h:358
G3D::int16 y
Definition: Vector2int16.h:38
SFMTRand()
Definition: SFMT.h:162
#define SFMT_SL2
Definition: SFMT.h:79
uint32_t BRandom()
Definition: SFMT.h:240
#define SFMT_MASK
Definition: SFMT.h:82
static __m128i sfmt_recursion(__m128i const &a, __m128i const &b, __m128i const &c, __m128i const &d, __m128i const &mask)
Definition: SFMT.h:138
signed int int32_t
Definition: stdint.h:77
uint32_t URandom(uint32_t min, uint32_t max)
Definition: SFMT.h:208