• R/O
  • HTTP
  • SSH
  • HTTPS

cpp: Commit

psychlops cpp


Commit MetaInfo

Revision00d1c2a000216184893b59166c09927d2fd4deba (tree)
Time2015-04-04 09:31:44
AuthorHOSOKAWA Kenchi <hskwk@inte...>
CommiterHOSOKAWA Kenchi

Log Message

VC12

Change Summary

Incremental Difference

--- /dev/null
+++ b/psychlops/core/math/dSFMT2.0/dSFMT-common.h
@@ -0,0 +1,115 @@
1+#pragma once
2+/**
3+ * @file dSFMT-common.h
4+ *
5+ * @brief SIMD oriented Fast Mersenne Twister(SFMT) pseudorandom
6+ * number generator with jump function. This file includes common functions
7+ * used in random number generation and jump.
8+ *
9+ * @author Mutsuo Saito (Hiroshima University)
10+ * @author Makoto Matsumoto (The University of Tokyo)
11+ *
12+ * Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
13+ * University.
14+ * Copyright (C) 2012 Mutsuo Saito, Makoto Matsumoto, Hiroshima
15+ * University and The University of Tokyo.
16+ * All rights reserved.
17+ *
18+ * The 3-clause BSD License is applied to this software, see
19+ * LICENSE.txt
20+ */
21+#ifndef DSFMT_COMMON_H
22+#define DSFMT_COMMON_H
23+
24+#include "dSFMT.h"
25+
26+#if defined(HAVE_SSE2)
27+# include <emmintrin.h>
28+union X128I_T {
29+ uint64_t u[2];
30+ __m128i i128;
31+};
32+union X128D_T {
33+ double d[2];
34+ __m128d d128;
35+};
36+/** mask data for sse2 */
37+static const union X128I_T sse2_param_mask = {{DSFMT_MSK1, DSFMT_MSK2}};
38+#endif
39+
40+#if defined(HAVE_ALTIVEC)
41+inline static void do_recursion(w128_t *r, w128_t *a, w128_t * b,
42+ w128_t *lung) {
43+ const vector unsigned char sl1 = ALTI_SL1;
44+ const vector unsigned char sl1_perm = ALTI_SL1_PERM;
45+ const vector unsigned int sl1_msk = ALTI_SL1_MSK;
46+ const vector unsigned char sr1 = ALTI_SR;
47+ const vector unsigned char sr1_perm = ALTI_SR_PERM;
48+ const vector unsigned int sr1_msk = ALTI_SR_MSK;
49+ const vector unsigned char perm = ALTI_PERM;
50+ const vector unsigned int msk1 = ALTI_MSK;
51+ vector unsigned int w, x, y, z;
52+
53+ z = a->s;
54+ w = lung->s;
55+ x = vec_perm(w, (vector unsigned int)perm, perm);
56+ y = vec_perm(z, (vector unsigned int)sl1_perm, sl1_perm);
57+ y = vec_sll(y, sl1);
58+ y = vec_and(y, sl1_msk);
59+ w = vec_xor(x, b->s);
60+ w = vec_xor(w, y);
61+ x = vec_perm(w, (vector unsigned int)sr1_perm, sr1_perm);
62+ x = vec_srl(x, sr1);
63+ x = vec_and(x, sr1_msk);
64+ y = vec_and(w, msk1);
65+ z = vec_xor(z, y);
66+ r->s = vec_xor(z, x);
67+ lung->s = w;
68+}
69+#elif defined(HAVE_SSE2)
70+/**
71+ * This function represents the recursion formula.
72+ * @param r output 128-bit
73+ * @param a a 128-bit part of the internal state array
74+ * @param b a 128-bit part of the internal state array
75+ * @param d a 128-bit part of the internal state array (I/O)
76+ */
77+inline static void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *u) {
78+ __m128i v, w, x, y, z;
79+
80+ x = a->si;
81+ z = _mm_slli_epi64(x, DSFMT_SL1);
82+ y = _mm_shuffle_epi32(u->si, SSE2_SHUFF);
83+ z = _mm_xor_si128(z, b->si);
84+ y = _mm_xor_si128(y, z);
85+
86+ v = _mm_srli_epi64(y, DSFMT_SR);
87+ w = _mm_and_si128(y, sse2_param_mask.i128);
88+ v = _mm_xor_si128(v, x);
89+ v = _mm_xor_si128(v, w);
90+ r->si = v;
91+ u->si = y;
92+}
93+#else
94+/**
95+ * This function represents the recursion formula.
96+ * @param r output 128-bit
97+ * @param a a 128-bit part of the internal state array
98+ * @param b a 128-bit part of the internal state array
99+ * @param lung a 128-bit part of the internal state array (I/O)
100+ */
101+inline static void do_recursion(w128_t *r, w128_t *a, w128_t * b,
102+ w128_t *lung) {
103+ uint64_t t0, t1, L0, L1;
104+
105+ t0 = a->u[0];
106+ t1 = a->u[1];
107+ L0 = lung->u[0];
108+ L1 = lung->u[1];
109+ lung->u[0] = (t0 << DSFMT_SL1) ^ (L1 >> 32) ^ (L1 << 32) ^ b->u[0];
110+ lung->u[1] = (t1 << DSFMT_SL1) ^ (L0 >> 32) ^ (L0 << 32) ^ b->u[1];
111+ r->u[0] = (lung->u[0] >> DSFMT_SR) ^ (lung->u[0] & DSFMT_MSK1) ^ t0;
112+ r->u[1] = (lung->u[1] >> DSFMT_SR) ^ (lung->u[1] & DSFMT_MSK2) ^ t1;
113+}
114+#endif
115+#endif
--- a/psychlops/core/math/dSFMT2.0/dSFMT-params.h
+++ b/psychlops/core/math/dSFMT2.0/dSFMT-params.h
@@ -39,7 +39,7 @@
3939 #define SSE2_SHUFF 0x1b
4040 #elif defined(HAVE_ALTIVEC)
4141 #if defined(__APPLE__) /* For OSX */
42- #define ALTI_SR (vector unsigned char)(4)
42+ #define ALTI_SR (vector unsigned char)(4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4)
4343 #define ALTI_SR_PERM \
4444 (vector unsigned char)(15,0,1,2,3,4,5,6,15,8,9,10,11,12,13,14)
4545 #define ALTI_SR_MSK \
@@ -47,7 +47,7 @@
4747 #define ALTI_PERM \
4848 (vector unsigned char)(12,13,14,15,8,9,10,11,4,5,6,7,0,1,2,3)
4949 #else
50- #define ALTI_SR {4}
50+ #define ALTI_SR {4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4}
5151 #define ALTI_SR_PERM {15,0,1,2,3,4,5,6,15,8,9,10,11,12,13,14}
5252 #define ALTI_SR_MSK {0x000fffffU,0xffffffffU,0x000fffffU,0xffffffffU}
5353 #define ALTI_PERM {12,13,14,15,8,9,10,11,4,5,6,7,0,1,2,3}
@@ -66,6 +66,14 @@
6666 #include "dSFMT-params11213.h"
6767 #elif DSFMT_MEXP == 19937
6868 #include "dSFMT-params19937.h"
69+#elif DSFMT_MEXP == 44497
70+ #include "dSFMT-params44497.h"
71+#elif DSFMT_MEXP == 86243
72+ #include "dSFMT-params86243.h"
73+#elif DSFMT_MEXP == 132049
74+ #include "dSFMT-params132049.h"
75+#elif DSFMT_MEXP == 216091
76+ #include "dSFMT-params216091.h"
6977 #else
7078 #ifdef __GNUC__
7179 #error "DSFMT_MEXP is not valid."
--- a/psychlops/core/math/dSFMT2.0/dSFMT-params19937.h
+++ b/psychlops/core/math/dSFMT2.0/dSFMT-params19937.h
@@ -20,7 +20,7 @@
2020
2121 /* PARAMETERS FOR ALTIVEC */
2222 #if defined(__APPLE__) /* For OSX */
23- #define ALTI_SL1 (vector unsigned int)(3, 3, 3, 3)
23+ #define ALTI_SL1 (vector unsigned char)(3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3)
2424 #define ALTI_SL1_PERM \
2525 (vector unsigned char)(2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1)
2626 #define ALTI_SL1_MSK \
@@ -28,7 +28,7 @@
2828 #define ALTI_MSK (vector unsigned int)(DSFMT_MSK32_1, \
2929 DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4)
3030 #else /* For OTHER OSs(Linux?) */
31- #define ALTI_SL1 {3, 3, 3, 3}
31+ #define ALTI_SL1 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}
3232 #define ALTI_SL1_PERM \
3333 {2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1}
3434 #define ALTI_SL1_MSK \
--- a/psychlops/core/math/dSFMT2.0/dSFMT.c
+++ b/psychlops/core/math/dSFMT2.0/dSFMT.c
@@ -15,6 +15,11 @@
1515 #include <string.h>
1616 #include <stdlib.h>
1717 #include "dSFMT-params.h"
18+#include "dSFMT-common.h"
19+
20+#if defined(__cplusplus)
21+extern "C" {
22+#endif
1823
1924 /** dsfmt internal state vector */
2025 dsfmt_t dsfmt_global_data;
@@ -26,30 +31,25 @@ static const int dsfmt_mexp = DSFMT_MEXP;
2631 ----------------*/
2732 inline static uint32_t ini_func1(uint32_t x);
2833 inline static uint32_t ini_func2(uint32_t x);
29-inline static void gen_rand_array_c1o2(dsfmt_t *dsfmt, w128_t array[],
34+inline static void gen_rand_array_c1o2(dsfmt_t *dsfmt, w128_t *array,
3035 int size);
31-inline static void gen_rand_array_c0o1(dsfmt_t *dsfmt, w128_t array[],
36+inline static void gen_rand_array_c0o1(dsfmt_t *dsfmt, w128_t *array,
3237 int size);
33-inline static void gen_rand_array_o0c1(dsfmt_t *dsfmt, w128_t array[],
38+inline static void gen_rand_array_o0c1(dsfmt_t *dsfmt, w128_t *array,
3439 int size);
35-inline static void gen_rand_array_o0o1(dsfmt_t *dsfmt, w128_t array[],
40+inline static void gen_rand_array_o0o1(dsfmt_t *dsfmt, w128_t *array,
3641 int size);
3742 inline static int idxof(int i);
3843 static void initial_mask(dsfmt_t *dsfmt);
3944 static void period_certification(dsfmt_t *dsfmt);
4045
4146 #if defined(HAVE_SSE2)
42-# include <emmintrin.h>
43-/** mask data for sse2 */
44-static __m128i sse2_param_mask;
4547 /** 1 in 64bit for sse2 */
46-static __m128i sse2_int_one;
48+static const union X128I_T sse2_int_one = {{1, 1}};
4749 /** 2.0 double for sse2 */
48-static __m128d sse2_double_two;
50+static const union X128D_T sse2_double_two = {{2.0, 2.0}};
4951 /** -1.0 double for sse2 */
50-static __m128d sse2_double_m_one;
51-
52-static void setup_const(void);
52+static const union X128D_T sse2_double_m_one = {{-1.0, -1.0}};
5353 #endif
5454
5555 /**
@@ -66,105 +66,6 @@ inline static int idxof(int i) {
6666 }
6767 #endif
6868
69-/**
70- * This function represents the recursion formula.
71- * @param r output
72- * @param a a 128-bit part of the internal state array
73- * @param b a 128-bit part of the internal state array
74- * @param lung a 128-bit part of the internal state array
75- */
76-#if defined(HAVE_ALTIVEC)
77-inline static void do_recursion(w128_t *r, w128_t *a, w128_t * b,
78- w128_t *lung) {
79- const vector unsigned char sl1 = ALTI_SL1;
80- const vector unsigned char sl1_perm = ALTI_SL1_PERM;
81- const vector unsigned int sl1_msk = ALTI_SL1_MSK;
82- const vector unsigned char sr1 = ALTI_SR;
83- const vector unsigned char sr1_perm = ALTI_SR_PERM;
84- const vector unsigned int sr1_msk = ALTI_SR_MSK;
85- const vector unsigned char perm = ALTI_PERM;
86- const vector unsigned int msk1 = ALTI_MSK;
87- vector unsigned int w, x, y, z;
88-
89- z = a->s;
90- w = lung->s;
91- x = vec_perm(w, (vector unsigned int)perm, perm);
92- y = vec_perm(z, sl1_perm, sl1_perm);
93- y = vec_sll(y, sl1);
94- y = vec_and(y, sl1_msk);
95- w = vec_xor(x, b->s);
96- w = vec_xor(w, y);
97- x = vec_perm(w, (vector unsigned int)sr1_perm, sr1_perm);
98- x = vec_srl(x, sr1);
99- x = vec_and(x, sr1_msk);
100- y = vec_and(w, msk1);
101- z = vec_xor(z, y);
102- r->s = vec_xor(z, x);
103- lung->s = w;
104-}
105-#elif defined(HAVE_SSE2)
106-/**
107- * This function setup some constant variables for SSE2.
108- */
109-static void setup_const(void) {
110- static int first = 1;
111- if (!first) {
112- return;
113- }
114- sse2_param_mask = _mm_set_epi32(DSFMT_MSK32_3, DSFMT_MSK32_4,
115- DSFMT_MSK32_1, DSFMT_MSK32_2);
116- sse2_int_one = _mm_set_epi32(0, 1, 0, 1);
117- sse2_double_two = _mm_set_pd(2.0, 2.0);
118- sse2_double_m_one = _mm_set_pd(-1.0, -1.0);
119- first = 0;
120-}
121-
122-/**
123- * This function represents the recursion formula.
124- * @param r output 128-bit
125- * @param a a 128-bit part of the internal state array
126- * @param b a 128-bit part of the internal state array
127- * @param d a 128-bit part of the internal state array (I/O)
128- */
129-inline static void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *u) {
130- __m128i v, w, x, y, z;
131-
132- x = a->si;
133- z = _mm_slli_epi64(x, DSFMT_SL1);
134- y = _mm_shuffle_epi32(u->si, SSE2_SHUFF);
135- z = _mm_xor_si128(z, b->si);
136- y = _mm_xor_si128(y, z);
137-
138- v = _mm_srli_epi64(y, DSFMT_SR);
139- w = _mm_and_si128(y, sse2_param_mask);
140- v = _mm_xor_si128(v, x);
141- v = _mm_xor_si128(v, w);
142- r->si = v;
143- u->si = y;
144-}
145-#else /* standard C */
146-/**
147- * This function represents the recursion formula.
148- * @param r output 128-bit
149- * @param a a 128-bit part of the internal state array
150- * @param b a 128-bit part of the internal state array
151- * @param lung a 128-bit part of the internal state array (I/O)
152- */
153-inline static void do_recursion(w128_t *r, w128_t *a, w128_t * b,
154- w128_t *lung) {
155- uint64_t t0, t1, L0, L1;
156-
157- t0 = a->u[0];
158- t1 = a->u[1];
159- L0 = lung->u[0];
160- L1 = lung->u[1];
161- lung->u[0] = (t0 << DSFMT_SL1) ^ (L1 >> 32) ^ (L1 << 32) ^ b->u[0];
162- lung->u[1] = (t1 << DSFMT_SL1) ^ (L0 >> 32) ^ (L0 << 32) ^ b->u[1];
163- r->u[0] = (lung->u[0] >> DSFMT_SR) ^ (lung->u[0] & DSFMT_MSK1) ^ t0;
164- r->u[1] = (lung->u[1] >> DSFMT_SR) ^ (lung->u[1] & DSFMT_MSK2) ^ t1;
165-}
166-#endif
167-
16869 #if defined(HAVE_SSE2)
16970 /**
17071 * This function converts the double precision floating point numbers which
@@ -173,7 +74,7 @@ inline static void do_recursion(w128_t *r, w128_t *a, w128_t * b,
17374 * @param w 128bit stracture of double precision floating point numbers (I/O)
17475 */
17576 inline static void convert_c0o1(w128_t *w) {
176- w->sd = _mm_add_pd(w->sd, sse2_double_m_one);
77+ w->sd = _mm_add_pd(w->sd, sse2_double_m_one.d128);
17778 }
17879
17980 /**
@@ -183,7 +84,7 @@ inline static void convert_c0o1(w128_t *w) {
18384 * @param w 128bit stracture of double precision floating point numbers (I/O)
18485 */
18586 inline static void convert_o0c1(w128_t *w) {
186- w->sd = _mm_sub_pd(sse2_double_two, w->sd);
87+ w->sd = _mm_sub_pd(sse2_double_two.d128, w->sd);
18788 }
18889
18990 /**
@@ -193,8 +94,8 @@ inline static void convert_o0c1(w128_t *w) {
19394 * @param w 128bit stracture of double precision floating point numbers (I/O)
19495 */
19596 inline static void convert_o0o1(w128_t *w) {
196- w->si = _mm_or_si128(w->si, sse2_int_one);
197- w->sd = _mm_add_pd(w->sd, sse2_double_m_one);
97+ w->si = _mm_or_si128(w->si, sse2_int_one.i128);
98+ w->sd = _mm_add_pd(w->sd, sse2_double_m_one.d128);
19899 }
199100 #else /* standard C and altivec */
200101 /**
@@ -240,7 +141,7 @@ inline static void convert_o0o1(w128_t *w) {
240141 * @param array an 128-bit array to be filled by pseudorandom numbers.
241142 * @param size number of 128-bit pseudorandom numbers to be generated.
242143 */
243-inline static void gen_rand_array_c1o2(dsfmt_t *dsfmt, w128_t array[],
144+inline static void gen_rand_array_c1o2(dsfmt_t *dsfmt, w128_t *array,
244145 int size) {
245146 int i, j;
246147 w128_t lung;
@@ -278,7 +179,7 @@ inline static void gen_rand_array_c1o2(dsfmt_t *dsfmt, w128_t array[],
278179 * @param array an 128-bit array to be filled by pseudorandom numbers.
279180 * @param size number of 128-bit pseudorandom numbers to be generated.
280181 */
281-inline static void gen_rand_array_c0o1(dsfmt_t *dsfmt, w128_t array[],
182+inline static void gen_rand_array_c0o1(dsfmt_t *dsfmt, w128_t *array,
282183 int size) {
283184 int i, j;
284185 w128_t lung;
@@ -321,7 +222,7 @@ inline static void gen_rand_array_c0o1(dsfmt_t *dsfmt, w128_t array[],
321222 * @param array an 128-bit array to be filled by pseudorandom numbers.
322223 * @param size number of 128-bit pseudorandom numbers to be generated.
323224 */
324-inline static void gen_rand_array_o0o1(dsfmt_t *dsfmt, w128_t array[],
225+inline static void gen_rand_array_o0o1(dsfmt_t *dsfmt, w128_t *array,
325226 int size) {
326227 int i, j;
327228 w128_t lung;
@@ -364,7 +265,7 @@ inline static void gen_rand_array_o0o1(dsfmt_t *dsfmt, w128_t array[],
364265 * @param array an 128-bit array to be filled by pseudorandom numbers.
365266 * @param size number of 128-bit pseudorandom numbers to be generated.
366267 */
367-inline static void gen_rand_array_o0c1(dsfmt_t *dsfmt, w128_t array[],
268+inline static void gen_rand_array_o0c1(dsfmt_t *dsfmt, w128_t *array,
368269 int size) {
369270 int i, j;
370271 w128_t lung;
@@ -440,10 +341,14 @@ static void initial_mask(dsfmt_t *dsfmt) {
440341 * @param dsfmt dsfmt state vector.
441342 */
442343 static void period_certification(dsfmt_t *dsfmt) {
443- int i, j;
444344 uint64_t pcv[2] = {DSFMT_PCV1, DSFMT_PCV2};
445345 uint64_t tmp[2];
446346 uint64_t inner;
347+ int i;
348+#if (DSFMT_PCV2 & 1) != 1
349+ int j;
350+ uint64_t work;
351+#endif
447352
448353 tmp[0] = (dsfmt->status[DSFMT_N].u[0] ^ DSFMT_FIX1);
449354 tmp[1] = (dsfmt->status[DSFMT_N].u[1] ^ DSFMT_FIX2);
@@ -462,7 +367,6 @@ static void period_certification(dsfmt_t *dsfmt) {
462367 #if (DSFMT_PCV2 & 1) == 1
463368 dsfmt->status[DSFMT_N].u[1] ^= 1;
464369 #else
465- uint64_t work;
466370 for (i = 1; i >= 0; i--) {
467371 work = 1;
468372 for (j = 0; j < 64; j++) {
@@ -637,9 +541,6 @@ void dsfmt_chk_init_gen_rand(dsfmt_t *dsfmt, uint32_t seed, int mexp) {
637541 initial_mask(dsfmt);
638542 period_certification(dsfmt);
639543 dsfmt->idx = DSFMT_N64;
640-#if defined(HAVE_SSE2)
641- setup_const();
642-#endif
643544 }
644545
645546 /**
@@ -688,7 +589,6 @@ void dsfmt_chk_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[],
688589 r += key_length;
689590 psfmt32[idxof((mid + lag) % size)] += r;
690591 psfmt32[idxof(0)] = r;
691- i = 1;
692592 count--;
693593 for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
694594 r = ini_func1(psfmt32[idxof(i)]
@@ -723,10 +623,11 @@ void dsfmt_chk_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[],
723623 initial_mask(dsfmt);
724624 period_certification(dsfmt);
725625 dsfmt->idx = DSFMT_N64;
726-#if defined(HAVE_SSE2)
727- setup_const();
728-#endif
729626 }
730627 #if defined(__INTEL_COMPILER)
731628 # pragma warning(default:981)
732629 #endif
630+
631+#if defined(__cplusplus)
632+}
633+#endif
--- a/psychlops/core/math/dSFMT2.0/dSFMT.h
+++ b/psychlops/core/math/dSFMT2.0/dSFMT.h
@@ -1,5 +1,6 @@
1+#pragma once
12 /**
2- * @file dSFMT_bcc.h
3+ * @file dSFMT.h
34 *
45 * @brief double precision SIMD oriented Fast Mersenne Twister(dSFMT)
56 * pseudorandom number generator based on IEEE 754 format.
@@ -9,6 +10,9 @@
910 *
1011 * Copyright (C) 2007, 2008 Mutsuo Saito, Makoto Matsumoto and
1112 * Hiroshima University. All rights reserved.
13+ * Copyright (C) 2012 Mutsuo Saito, Makoto Matsumoto,
14+ * Hiroshima University and The University of Tokyo.
15+ * All rights reserved.
1216 *
1317 * The new BSD License is applied to this software.
1418 * see LICENSE.txt
@@ -30,6 +34,9 @@
3034
3135 #ifndef DSFMT_H
3236 #define DSFMT_H
37+#if defined(__cplusplus)
38+extern "C" {
39+#endif
3340
3441 #include <stdio.h>
3542 #include <assert.h>
@@ -43,7 +50,7 @@
4350 /*-----------------
4451 BASIC DEFINITIONS
4552 -----------------*/
46-/** Mersenne Exponent. The period of the sequence
53+/* Mersenne Exponent. The period of the sequence
4754 * is a multiple of 2^DSFMT_MEXP-1.
4855 * #define DSFMT_MEXP 19937 */
4956 /** DSFMT generator has an internal state array of 128-bit integers,
@@ -85,27 +92,21 @@
8592
8693 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
8794 # include <inttypes.h>
88-#elif defined(_MSC_VER)
89-# if !defined(DSFMT_UINT32_DEFINED) && !defined(SFMT_UINT32_DEFINED)
90-typedef unsigned int uint32_t;
91-typedef unsigned long long uint64_t;
92-# define DSFMT_UINT32_DEFINED
93-# if !defined(inline)
94-# define inline __inline
95-# endif
96-# endif
97-#elif defined(__BORLANDC__)
95+#elif defined(_MSC_VER) || defined(__BORLANDC__)
9896 # if !defined(DSFMT_UINT32_DEFINED) && !defined(SFMT_UINT32_DEFINED)
9997 typedef unsigned int uint32_t;
10098 typedef unsigned __int64 uint64_t;
99+# ifndef UINT64_C
100+# define UINT64_C(v) (v ## ui64)
101+# endif
101102 # define DSFMT_UINT32_DEFINED
102-# if !defined(inline)
103+# if !defined(inline) && !defined(__cplusplus)
103104 # define inline __inline
104105 # endif
105106 # endif
106107 #else
107108 # include <inttypes.h>
108-# if !defined(inline)
109+# if !defined(inline) && !defined(__cplusplus)
109110 # if defined(__GNUC__)
110111 # define inline __inline__
111112 # else
@@ -125,14 +126,9 @@ typedef unsigned __int64 uint64_t;
125126 #endif
126127
127128 #ifndef UINT64_C
128-# if defined(__BORLANDC__)
129-# define UINT64_C(v) (v ## UI64)
130-# else
131-# define UINT64_C(v) (v ## ULL)
132-# endif
129+# define UINT64_C(v) (v ## ULL)
133130 #endif
134131
135-
136132 /*------------------------------------------
137133 128-bit SIMD like data type for standard C
138134 ------------------------------------------*/
@@ -183,10 +179,6 @@ extern dsfmt_t dsfmt_global_data;
183179 /** dsfmt mexp for check */
184180 extern const int dsfmt_global_mexp;
185181
186-#ifdef _cplusplus
187-extern "C" {
188-#endif
189-
190182 void dsfmt_gen_rand_all(dsfmt_t *dsfmt);
191183 void dsfmt_fill_array_open_close(dsfmt_t *dsfmt, double array[], int size);
192184 void dsfmt_fill_array_close_open(dsfmt_t *dsfmt, double array[], int size);
@@ -194,7 +186,7 @@ void dsfmt_fill_array_open_open(dsfmt_t *dsfmt, double array[], int size);
194186 void dsfmt_fill_array_close1_open2(dsfmt_t *dsfmt, double array[], int size);
195187 void dsfmt_chk_init_gen_rand(dsfmt_t *dsfmt, uint32_t seed, int mexp);
196188 void dsfmt_chk_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[],
197- int key_length, int mexp);
189+ int key_length, int mexp);
198190 const char *dsfmt_get_idstring(void);
199191 int dsfmt_get_min_array_size(void);
200192
@@ -202,12 +194,13 @@ int dsfmt_get_min_array_size(void);
202194 # define DSFMT_PRE_INLINE inline static
203195 # define DSFMT_PST_INLINE __attribute__((always_inline))
204196 #elif defined(_MSC_VER) && _MSC_VER >= 1200
205-# define DSFMT_PRE_INLINE __forceinline
197+# define DSFMT_PRE_INLINE __forceinline static
206198 # define DSFMT_PST_INLINE
207199 #else
208200 # define DSFMT_PRE_INLINE inline static
209201 # define DSFMT_PST_INLINE
210202 #endif
203+DSFMT_PRE_INLINE uint32_t dsfmt_genrand_uint32(dsfmt_t *dsfmt) DSFMT_PST_INLINE;
211204 DSFMT_PRE_INLINE double dsfmt_genrand_close1_open2(dsfmt_t *dsfmt)
212205 DSFMT_PST_INLINE;
213206 DSFMT_PRE_INLINE double dsfmt_genrand_close_open(dsfmt_t *dsfmt)
@@ -216,6 +209,7 @@ DSFMT_PRE_INLINE double dsfmt_genrand_open_close(dsfmt_t *dsfmt)
216209 DSFMT_PST_INLINE;
217210 DSFMT_PRE_INLINE double dsfmt_genrand_open_open(dsfmt_t *dsfmt)
218211 DSFMT_PST_INLINE;
212+DSFMT_PRE_INLINE uint32_t dsfmt_gv_genrand_uint32(void) DSFMT_PST_INLINE;
219213 DSFMT_PRE_INLINE double dsfmt_gv_genrand_close1_open2(void) DSFMT_PST_INLINE;
220214 DSFMT_PRE_INLINE double dsfmt_gv_genrand_close_open(void) DSFMT_PST_INLINE;
221215 DSFMT_PRE_INLINE double dsfmt_gv_genrand_open_close(void) DSFMT_PST_INLINE;
@@ -230,11 +224,31 @@ DSFMT_PRE_INLINE void dsfmt_gv_fill_array_close1_open2(double array[], int size)
230224 DSFMT_PST_INLINE;
231225 DSFMT_PRE_INLINE void dsfmt_gv_init_gen_rand(uint32_t seed) DSFMT_PST_INLINE;
232226 DSFMT_PRE_INLINE void dsfmt_gv_init_by_array(uint32_t init_key[],
233- int key_length) DSFMT_PST_INLINE;
227+ int key_length) DSFMT_PST_INLINE;
234228 DSFMT_PRE_INLINE void dsfmt_init_gen_rand(dsfmt_t *dsfmt, uint32_t seed)
235229 DSFMT_PST_INLINE;
236230 DSFMT_PRE_INLINE void dsfmt_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[],
237- int key_length) DSFMT_PST_INLINE;
231+ int key_length) DSFMT_PST_INLINE;
232+
233+/**
234+ * This function generates and returns unsigned 32-bit integer.
235+ * This is slower than SFMT, only for convenience usage.
236+ * dsfmt_init_gen_rand() or dsfmt_init_by_array() must be called
237+ * before this function.
238+ * @param dsfmt dsfmt internal state date
239+ * @return double precision floating point pseudorandom number
240+ */
241+inline static uint32_t dsfmt_genrand_uint32(dsfmt_t *dsfmt) {
242+ uint32_t r;
243+ uint64_t *psfmt64 = &dsfmt->status[0].u[0];
244+
245+ if (dsfmt->idx >= DSFMT_N64) {
246+ dsfmt_gen_rand_all(dsfmt);
247+ dsfmt->idx = 0;
248+ }
249+ r = psfmt64[dsfmt->idx++] & 0xffffffffU;
250+ return r;
251+}
238252
239253 /**
240254 * This function generates and returns double precision pseudorandom
@@ -250,17 +264,27 @@ inline static double dsfmt_genrand_close1_open2(dsfmt_t *dsfmt) {
250264 double *psfmt64 = &dsfmt->status[0].d[0];
251265
252266 if (dsfmt->idx >= DSFMT_N64) {
253- dsfmt_gen_rand_all(dsfmt);
254- dsfmt->idx = 0;
267+ dsfmt_gen_rand_all(dsfmt);
268+ dsfmt->idx = 0;
255269 }
256270 r = psfmt64[dsfmt->idx++];
257271 return r;
258272 }
259273
260274 /**
275+ * This function generates and returns unsigned 32-bit integer.
276+ * This is slower than SFMT, only for convenience usage.
277+ * dsfmt_gv_init_gen_rand() or dsfmt_gv_init_by_array() must be called
278+ * before this function. This function uses \b global variables.
279+ * @return double precision floating point pseudorandom number
280+ */
281+inline static uint32_t dsfmt_gv_genrand_uint32(void) {
282+ return dsfmt_genrand_uint32(&dsfmt_global_data);
283+}
284+
285+/**
261286 * This function generates and returns double precision pseudorandom
262- * number which distributes uniformly in the range [1, 2). This is
263- * the primitive and faster than generating numbers in other ranges.
287+ * number which distributes uniformly in the range [1, 2).
264288 * dsfmt_gv_init_gen_rand() or dsfmt_gv_init_by_array() must be called
265289 * before this function. This function uses \b global variables.
266290 * @return double precision floating point pseudorandom number
@@ -326,13 +350,13 @@ inline static double dsfmt_gv_genrand_open_close(void) {
326350 inline static double dsfmt_genrand_open_open(dsfmt_t *dsfmt) {
327351 double *dsfmt64 = &dsfmt->status[0].d[0];
328352 union {
329- double d;
330- uint64_t u;
353+ double d;
354+ uint64_t u;
331355 } r;
332356
333357 if (dsfmt->idx >= DSFMT_N64) {
334- dsfmt_gen_rand_all(dsfmt);
335- dsfmt->idx = 0;
358+ dsfmt_gen_rand_all(dsfmt);
359+ dsfmt->idx = 0;
336360 }
337361 r.d = dsfmt64[dsfmt->idx++];
338362 r.u |= 1;
@@ -441,7 +465,7 @@ inline static void dsfmt_gv_init_gen_rand(uint32_t seed) {
441465 * @param key_length the length of init_key.
442466 */
443467 inline static void dsfmt_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[],
444- int key_length) {
468+ int key_length) {
445469 dsfmt_chk_init_by_array(dsfmt, init_key, key_length, DSFMT_MEXP);
446470 }
447471
@@ -605,7 +629,7 @@ inline static void fill_array_close1_open2(double array[], int size) {
605629 }
606630 #endif /* DSFMT_DO_NOT_USE_OLD_NAMES */
607631
608-#ifdef _cplusplus
632+#if defined(__cplusplus)
609633 }
610634 #endif
611635
--- a/win32gl/dev/psychlopswin32.cbp
+++ b/win32gl/dev/psychlopswin32.cbp
@@ -149,10 +149,10 @@
149149 <Target title="VC12">
150150 <Option output="psychlopswin32vc12.lib" prefix_auto="0" extension_auto="0" />
151151 <Option working_dir="" />
152- <Option object_output=".objs_vc10" />
152+ <Option object_output=".objs_vc12" />
153153 <Option deps_output=".deps_bcc" />
154154 <Option type="2" />
155- <Option compiler="microsoft_visual_c_2013" />
155+ <Option compiler="copy_of_microsoft_visual_c_2010" />
156156 <Option projectCompilerOptionsRelation="1" />
157157 <Option projectLinkerOptionsRelation="1" />
158158 <Option projectResourceIncludeDirsRelation="2" />
@@ -161,7 +161,7 @@
161161 <Add option="/GA" />
162162 <Add option="/EHs" />
163163 <Add option="/GR" />
164- <Add option="/Ox" />
164+ <Add option="/W4" />
165165 <Add option="/DPSYCHLOPS_PLATFORM_WIN32GL" />
166166 </Compiler>
167167 <Linker>
--- a/win32gl/test/Psychlops_win32cblibtest.cbp
+++ b/win32gl/test/Psychlops_win32cblibtest.cbp
@@ -145,7 +145,7 @@
145145 <Option output="Psychlops_win32cblibtest_vc12.exe" prefix_auto="0" extension_auto="0" />
146146 <Option object_output=".objs_vc10" />
147147 <Option type="1" />
148- <Option compiler="microsoft_visual_c_2013_vc12" />
148+ <Option compiler="copy_of_microsoft_visual_c_2010" />
149149 <Option projectCompilerOptionsRelation="1" />
150150 <Compiler>
151151 <Add option="/GA" />
Show on old repository browser