1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
---|
3 | <title>mixpp: random_dsfmt.h Source File</title> |
---|
4 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
---|
5 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
---|
6 | </head><body> |
---|
7 | <!-- Generated by Doxygen 1.5.8 --> |
---|
8 | <script type="text/javascript"> |
---|
9 | <!-- |
---|
10 | function changeDisplayState (e){ |
---|
11 | var num=this.id.replace(/[^[0-9]/g,''); |
---|
12 | var button=this.firstChild; |
---|
13 | var sectionDiv=document.getElementById('dynsection'+num); |
---|
14 | if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){ |
---|
15 | sectionDiv.style.display='block'; |
---|
16 | button.src='open.gif'; |
---|
17 | }else{ |
---|
18 | sectionDiv.style.display='none'; |
---|
19 | button.src='closed.gif'; |
---|
20 | } |
---|
21 | } |
---|
22 | function initDynSections(){ |
---|
23 | var divs=document.getElementsByTagName('div'); |
---|
24 | var sectionCounter=1; |
---|
25 | for(var i=0;i<divs.length-1;i++){ |
---|
26 | if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){ |
---|
27 | var header=divs[i]; |
---|
28 | var section=divs[i+1]; |
---|
29 | var button=header.firstChild; |
---|
30 | if (button!='IMG'){ |
---|
31 | divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild); |
---|
32 | button=document.createElement('img'); |
---|
33 | divs[i].insertBefore(button,divs[i].firstChild); |
---|
34 | } |
---|
35 | header.style.cursor='pointer'; |
---|
36 | header.onclick=changeDisplayState; |
---|
37 | header.id='dynheader'+sectionCounter; |
---|
38 | button.src='closed.gif'; |
---|
39 | section.id='dynsection'+sectionCounter; |
---|
40 | section.style.display='none'; |
---|
41 | section.style.marginLeft='14px'; |
---|
42 | sectionCounter++; |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | window.onload = initDynSections; |
---|
47 | --> |
---|
48 | </script> |
---|
49 | <div class="navigation" id="top"> |
---|
50 | <div class="tabs"> |
---|
51 | <ul> |
---|
52 | <li><a href="main.html"><span>Main Page</span></a></li> |
---|
53 | <li><a href="pages.html"><span>Related Pages</span></a></li> |
---|
54 | <li><a href="modules.html"><span>Modules</span></a></li> |
---|
55 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
56 | <li class="current"><a href="files.html"><span>Files</span></a></li> |
---|
57 | </ul> |
---|
58 | </div> |
---|
59 | <div class="tabs"> |
---|
60 | <ul> |
---|
61 | <li><a href="files.html"><span>File List</span></a></li> |
---|
62 | <li><a href="globals.html"><span>File Members</span></a></li> |
---|
63 | </ul> |
---|
64 | </div> |
---|
65 | <h1>random_dsfmt.h</h1><a href="random__dsfmt_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 |
---|
66 | <a name="l00029"></a>00029 <span class="preprocessor">#ifndef RANDOM_DSFMT_H</span> |
---|
67 | <a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#define RANDOM_DSFMT_H</span> |
---|
68 | <a name="l00031"></a>00031 <span class="preprocessor"></span> |
---|
69 | <a name="l00032"></a>00032 <span class="preprocessor">#include <<a class="code" href="itcompat_8h.html" title="IT++ compatibility types and functions.">itpp/base/itcompat.h</a>></span> |
---|
70 | <a name="l00033"></a>00033 <span class="preprocessor">#include <<a class="code" href="vec_8h.html" title="Templated Vector Class Definitions.">itpp/base/vec.h</a>></span> |
---|
71 | <a name="l00034"></a>00034 <span class="preprocessor">#include <cstring></span> <span class="comment">// required for memset()</span> |
---|
72 | <a name="l00035"></a>00035 <span class="preprocessor">#include <ctime></span> |
---|
73 | <a name="l00036"></a>00036 <span class="preprocessor">#include <limits></span> |
---|
74 | <a name="l00037"></a>00037 |
---|
75 | <a name="l00038"></a>00038 <span class="preprocessor">#if defined(__SSE2__)</span> |
---|
76 | <a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor"># include <emmintrin.h></span> |
---|
77 | <a name="l00040"></a>00040 <span class="preprocessor">#endif</span> |
---|
78 | <a name="l00041"></a>00041 <span class="preprocessor"></span> |
---|
79 | <a name="l00042"></a>00042 <span class="keyword">namespace </span>itpp |
---|
80 | <a name="l00043"></a>00043 { |
---|
81 | <a name="l00044"></a>00044 |
---|
82 | <a name="l00092"></a>00092 <span class="keyword">template</span> <<span class="keywordtype">int</span> MEXP, <span class="keywordtype">int</span> POS1, <span class="keywordtype">int</span> SL1, uint64_t MSK1, uint64_t MSK2, |
---|
83 | <a name="l00093"></a>00093 uint32_t MSK32_1, uint32_t MSK32_2, |
---|
84 | <a name="l00094"></a>00094 uint32_t MSK32_3, uint32_t MSK32_4, |
---|
85 | <a name="l00095"></a>00095 uint64_t FIX1, uint64_t FIX2, uint64_t PCV1, uint64_t PCV2> |
---|
86 | <a name="l00096"></a><a class="code" href="classitpp_1_1DSFMT.html">00096</a> <span class="keyword">class </span><a class="code" href="classitpp_1_1DSFMT.html" title="C++ implementation of dSFMT random number generatorThe DSFMT class implements parts...">DSFMT</a> { |
---|
87 | <a name="l00097"></a>00097 <span class="keyword">public</span>: |
---|
88 | <a name="l00099"></a><a class="code" href="classitpp_1_1DSFMT.html#cde8cc225ca1f756343fb037b99ffe32">00099</a> <a class="code" href="classitpp_1_1DSFMT.html#cde8cc225ca1f756343fb037b99ffe32" title="Default constructor.">DSFMT</a>() { <span class="keywordflow">if</span> (!initialized) <a class="code" href="classitpp_1_1DSFMT.html#011ceb3e531789398265b1503bc0cced" title="Initialise the generator with a new seed.">init_gen_rand</a>(4257U); } |
---|
89 | <a name="l00101"></a><a class="code" href="classitpp_1_1DSFMT.html#c87fddf046d11a5490b39590fa2112f1">00101</a> <a class="code" href="classitpp_1_1DSFMT.html#c87fddf046d11a5490b39590fa2112f1" title="Constructor using a certain seed.">DSFMT</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> seed) { <a class="code" href="classitpp_1_1DSFMT.html#011ceb3e531789398265b1503bc0cced" title="Initialise the generator with a new seed.">init_gen_rand</a>(seed); } |
---|
90 | <a name="l00102"></a>00102 |
---|
91 | <a name="l00104"></a><a class="code" href="classitpp_1_1DSFMT.html#d8fa1b788118b95eaf44810e0b884d80">00104</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1DSFMT.html#d8fa1b788118b95eaf44810e0b884d80" title="Set the seed to a semi-random value (based on hashed time and clock).">randomize</a>() { <a class="code" href="classitpp_1_1DSFMT.html#011ceb3e531789398265b1503bc0cced" title="Initialise the generator with a new seed.">init_gen_rand</a>(hash(time(0), clock())); } |
---|
92 | <a name="l00106"></a><a class="code" href="classitpp_1_1DSFMT.html#defa66a466571c23b8ec388b3b23b037">00106</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1DSFMT.html#defa66a466571c23b8ec388b3b23b037" title="Reset the generator with the same seed as used last time.">reset</a>() { <a class="code" href="classitpp_1_1DSFMT.html#011ceb3e531789398265b1503bc0cced" title="Initialise the generator with a new seed.">init_gen_rand</a>(last_seed); } |
---|
93 | <a name="l00108"></a><a class="code" href="classitpp_1_1DSFMT.html#7127262cdb61c9ae9fc7765ac08f1e89">00108</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1DSFMT.html#7127262cdb61c9ae9fc7765ac08f1e89" title="Initialise the generator with a new seed (.">reset</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> seed) { <a class="code" href="classitpp_1_1DSFMT.html#011ceb3e531789398265b1503bc0cced" title="Initialise the generator with a new seed.">init_gen_rand</a>(seed); } |
---|
94 | <a name="l00109"></a>00109 |
---|
95 | <a name="l00111"></a><a class="code" href="classitpp_1_1DSFMT.html#ab2af1395a13a573e9bdeab13b5cf9ff">00111</a> <span class="keywordtype">double</span> <a class="code" href="classitpp_1_1DSFMT.html#ab2af1395a13a573e9bdeab13b5cf9ff" title="Return a uniformly distributed (0,1) value.">random_01</a>() { <span class="keywordflow">return</span> <a class="code" href="classitpp_1_1DSFMT.html#186d6072f3c58313d28faa35f41b376f" title="Generate uniform (0, 1) double pseudorandom number.">genrand_open_open</a>(); } |
---|
96 | <a name="l00113"></a><a class="code" href="classitpp_1_1DSFMT.html#d978ed6de775129d1bbeb7078d1be70b">00113</a> <span class="keywordtype">double</span> <a class="code" href="classitpp_1_1DSFMT.html#d978ed6de775129d1bbeb7078d1be70b" title="Return a uniformly distributed [0,1) value.">random_01_lclosed</a>() { <span class="keywordflow">return</span> <a class="code" href="classitpp_1_1DSFMT.html#8ff79b50d0b3ae41bf2e8d4d2fc06099" title="Generate uniform [0, 1) double pseudorandom number.">genrand_close_open</a>(); } |
---|
97 | <a name="l00115"></a><a class="code" href="classitpp_1_1DSFMT.html#00c9116b8836b601965abfe5fd144670">00115</a> <span class="keywordtype">double</span> <a class="code" href="classitpp_1_1DSFMT.html#00c9116b8836b601965abfe5fd144670" title="Return a uniformly distributed (0,1] value.">random_01_rclosed</a>() { <span class="keywordflow">return</span> <a class="code" href="classitpp_1_1DSFMT.html#b61104ac9de7e52f9462c41c8ffe4606" title="Generate uniform (0, 1] double pseudorandom number.">genrand_open_close</a>(); } |
---|
98 | <a name="l00117"></a><a class="code" href="classitpp_1_1DSFMT.html#b645ea1ba2a18932ba6817455450a4af">00117</a> uint32_t <a class="code" href="classitpp_1_1DSFMT.html#b645ea1ba2a18932ba6817455450a4af" title="Return a uniformly distributed [0, UINT_MAX) value.">random_int</a>() { <span class="keywordflow">return</span> <a class="code" href="classitpp_1_1DSFMT.html#e9f77c7cbc6831b9622212ba7f3caaec" title="Generate uniform [0, UINT_MAX) integer pseudorandom number.">genrand_uint32</a>(); } |
---|
99 | <a name="l00118"></a>00118 |
---|
100 | <a name="l00120"></a><a class="code" href="classitpp_1_1DSFMT.html#376bebd678a04ee0ef5ac4ba8c5aaa07">00120</a> ivec <a class="code" href="classitpp_1_1DSFMT.html#376bebd678a04ee0ef5ac4ba8c5aaa07" title="Return current state of generator in the form of ivec.">get_state</a>()<span class="keyword"> const </span>{ |
---|
101 | <a name="l00121"></a>00121 <span class="keywordtype">int</span> <a class="code" href="group__matrix__functions.html#g3c1a2b0972c6a8e1215eb3f76d7c7512" title="Length of vector.">size</a> = (N + 1) * 4; |
---|
102 | <a name="l00122"></a>00122 uint32_t *psfmt = &status[0].u32[0]; |
---|
103 | <a name="l00123"></a>00123 ivec state(size + 1); <span class="comment">// size + 1 to save idx variable in the same vec</span> |
---|
104 | <a name="l00124"></a>00124 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < size; ++i) { |
---|
105 | <a name="l00125"></a>00125 state(i) = psfmt[i]; |
---|
106 | <a name="l00126"></a>00126 } |
---|
107 | <a name="l00127"></a>00127 state(size) = idx; |
---|
108 | <a name="l00128"></a>00128 <span class="keywordflow">return</span> state; |
---|
109 | <a name="l00129"></a>00129 } |
---|
110 | <a name="l00130"></a>00130 |
---|
111 | <a name="l00132"></a><a class="code" href="classitpp_1_1DSFMT.html#848705b585c6ce3ebba989ec21ccac9e">00132</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1DSFMT.html#848705b585c6ce3ebba989ec21ccac9e" title="Resume the state of the generator from a previously saved ivec.">set_state</a>(<span class="keyword">const</span> ivec &state) { |
---|
112 | <a name="l00133"></a>00133 <span class="keywordtype">int</span> <a class="code" href="group__matrix__functions.html#g3c1a2b0972c6a8e1215eb3f76d7c7512" title="Length of vector.">size</a> = (N + 1) * 4; |
---|
113 | <a name="l00134"></a>00134 <a class="code" href="group__errorhandlingfunc.html#gd5c34b291e5018534fd2344486e2b5a1" title="Abort if t is not true.">it_assert</a>(state.size() == size + 1, <span class="stringliteral">"Random_Generator::set_state(): "</span> |
---|
114 | <a name="l00135"></a>00135 <span class="stringliteral">"Invalid state initialization vector"</span>); |
---|
115 | <a name="l00136"></a>00136 uint32_t *psfmt = &status[0].u32[0]; |
---|
116 | <a name="l00137"></a>00137 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < size; ++i) { |
---|
117 | <a name="l00138"></a>00138 psfmt[i] = state(i); |
---|
118 | <a name="l00139"></a>00139 } |
---|
119 | <a name="l00140"></a>00140 idx = state(size); |
---|
120 | <a name="l00141"></a>00141 } |
---|
121 | <a name="l00142"></a>00142 |
---|
122 | <a name="l00150"></a><a class="code" href="classitpp_1_1DSFMT.html#011ceb3e531789398265b1503bc0cced">00150</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1DSFMT.html#011ceb3e531789398265b1503bc0cced" title="Initialise the generator with a new seed.">init_gen_rand</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> seed) { |
---|
123 | <a name="l00151"></a>00151 uint32_t *psfmt = &status[0].u32[0]; |
---|
124 | <a name="l00152"></a>00152 psfmt[idxof(0)] = seed; |
---|
125 | <a name="l00153"></a>00153 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i < (N + 1) * 4; i++) { |
---|
126 | <a name="l00154"></a>00154 psfmt[idxof(i)] = 1812433253UL |
---|
127 | <a name="l00155"></a>00155 * (psfmt[idxof(i - 1)] ^ (psfmt[idxof(i - 1)] >> 30)) + i; |
---|
128 | <a name="l00156"></a>00156 } |
---|
129 | <a name="l00157"></a>00157 initial_mask(); |
---|
130 | <a name="l00158"></a>00158 period_certification(); |
---|
131 | <a name="l00159"></a>00159 idx = Nx2; |
---|
132 | <a name="l00160"></a>00160 <span class="preprocessor">#if defined(__SSE2__)</span> |
---|
133 | <a name="l00161"></a>00161 <span class="preprocessor"></span> sse2_param_mask = _mm_set_epi32(MSK32_3, MSK32_4, MSK32_1, MSK32_2); |
---|
134 | <a name="l00162"></a>00162 <span class="preprocessor">#endif</span> |
---|
135 | <a name="l00163"></a>00163 <span class="preprocessor"></span> initialized = <span class="keyword">true</span>; |
---|
136 | <a name="l00164"></a>00164 last_seed = seed; |
---|
137 | <a name="l00165"></a>00165 } |
---|
138 | <a name="l00166"></a>00166 |
---|
139 | <a name="l00168"></a><a class="code" href="classitpp_1_1DSFMT.html#e9f77c7cbc6831b9622212ba7f3caaec">00168</a> <span class="keyword">static</span> uint32_t <a class="code" href="classitpp_1_1DSFMT.html#e9f77c7cbc6831b9622212ba7f3caaec" title="Generate uniform [0, UINT_MAX) integer pseudorandom number.">genrand_uint32</a>() { |
---|
140 | <a name="l00169"></a>00169 uint64_t *psfmt64 = &status[0].u[0]; |
---|
141 | <a name="l00170"></a>00170 <span class="keywordflow">if</span> (idx >= Nx2) { |
---|
142 | <a name="l00171"></a>00171 dsfmt_gen_rand_all(); |
---|
143 | <a name="l00172"></a>00172 idx = 0; |
---|
144 | <a name="l00173"></a>00173 } |
---|
145 | <a name="l00174"></a>00174 <span class="keywordflow">return</span> psfmt64[idx++] & 0xffffffffU; |
---|
146 | <a name="l00175"></a>00175 } |
---|
147 | <a name="l00176"></a>00176 |
---|
148 | <a name="l00186"></a><a class="code" href="classitpp_1_1DSFMT.html#c4ee81c771e7b000f8ac59dc018f641f">00186</a> <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="classitpp_1_1DSFMT.html#c4ee81c771e7b000f8ac59dc018f641f" title="Generate uniform [1, 2) double pseudorandom number.">genrand_close1_open2</a>() { |
---|
149 | <a name="l00187"></a>00187 <span class="keywordtype">double</span> *psfmt64 = &status[0].d[0]; |
---|
150 | <a name="l00188"></a>00188 <span class="keywordflow">if</span> (idx >= Nx2) { |
---|
151 | <a name="l00189"></a>00189 dsfmt_gen_rand_all(); |
---|
152 | <a name="l00190"></a>00190 idx = 0; |
---|
153 | <a name="l00191"></a>00191 } |
---|
154 | <a name="l00192"></a>00192 <span class="keywordflow">return</span> psfmt64[idx++]; |
---|
155 | <a name="l00193"></a>00193 } |
---|
156 | <a name="l00194"></a>00194 |
---|
157 | <a name="l00203"></a><a class="code" href="classitpp_1_1DSFMT.html#8ff79b50d0b3ae41bf2e8d4d2fc06099">00203</a> <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="classitpp_1_1DSFMT.html#8ff79b50d0b3ae41bf2e8d4d2fc06099" title="Generate uniform [0, 1) double pseudorandom number.">genrand_close_open</a>() { <span class="keywordflow">return</span> <a class="code" href="classitpp_1_1DSFMT.html#c4ee81c771e7b000f8ac59dc018f641f" title="Generate uniform [1, 2) double pseudorandom number.">genrand_close1_open2</a>() - 1.0; } |
---|
158 | <a name="l00204"></a>00204 |
---|
159 | <a name="l00213"></a><a class="code" href="classitpp_1_1DSFMT.html#b61104ac9de7e52f9462c41c8ffe4606">00213</a> <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="classitpp_1_1DSFMT.html#b61104ac9de7e52f9462c41c8ffe4606" title="Generate uniform (0, 1] double pseudorandom number.">genrand_open_close</a>() { <span class="keywordflow">return</span> 2.0 - <a class="code" href="classitpp_1_1DSFMT.html#c4ee81c771e7b000f8ac59dc018f641f" title="Generate uniform [1, 2) double pseudorandom number.">genrand_close1_open2</a>(); } |
---|
160 | <a name="l00214"></a>00214 |
---|
161 | <a name="l00223"></a><a class="code" href="classitpp_1_1DSFMT.html#186d6072f3c58313d28faa35f41b376f">00223</a> <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="classitpp_1_1DSFMT.html#186d6072f3c58313d28faa35f41b376f" title="Generate uniform (0, 1) double pseudorandom number.">genrand_open_open</a>() { |
---|
162 | <a name="l00224"></a>00224 <span class="keywordtype">double</span> *dsfmt64 = &status[0].d[0]; |
---|
163 | <a name="l00225"></a>00225 <span class="keyword">union </span>{ |
---|
164 | <a name="l00226"></a>00226 <span class="keywordtype">double</span> d; |
---|
165 | <a name="l00227"></a>00227 uint64_t u; |
---|
166 | <a name="l00228"></a>00228 } r; |
---|
167 | <a name="l00229"></a>00229 |
---|
168 | <a name="l00230"></a>00230 <span class="keywordflow">if</span> (idx >= Nx2) { |
---|
169 | <a name="l00231"></a>00231 dsfmt_gen_rand_all(); |
---|
170 | <a name="l00232"></a>00232 idx = 0; |
---|
171 | <a name="l00233"></a>00233 } |
---|
172 | <a name="l00234"></a>00234 r.d = dsfmt64[idx++]; |
---|
173 | <a name="l00235"></a>00235 r.u |= 1; |
---|
174 | <a name="l00236"></a>00236 <span class="keywordflow">return</span> r.d - 1.0; |
---|
175 | <a name="l00237"></a>00237 } |
---|
176 | <a name="l00238"></a>00238 |
---|
177 | <a name="l00239"></a>00239 |
---|
178 | <a name="l00240"></a>00240 <span class="keyword">private</span>: |
---|
179 | <a name="l00241"></a>00241 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> N = (MEXP - 128) / 104 + 1; |
---|
180 | <a name="l00242"></a>00242 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> Nx2 = N * 2; |
---|
181 | <a name="l00243"></a>00243 <span class="keyword">static</span> <span class="keyword">const</span> uint64_t LOW_MASK = 0x000fffffffffffffULL; |
---|
182 | <a name="l00244"></a>00244 <span class="keyword">static</span> <span class="keyword">const</span> uint64_t HIGH_CONST = 0x3ff0000000000000ULL; |
---|
183 | <a name="l00245"></a>00245 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> SR = 12U; |
---|
184 | <a name="l00246"></a>00246 <span class="preprocessor">#if defined(__SSE2__)</span> |
---|
185 | <a name="l00247"></a>00247 <span class="preprocessor"></span> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> SSE2_SHUFF = 0x1bU; |
---|
186 | <a name="l00248"></a>00248 <span class="preprocessor">#endif // __SSE2__</span> |
---|
187 | <a name="l00249"></a>00249 <span class="preprocessor"></span> |
---|
188 | <a name="l00251"></a>00251 <span class="keyword">union </span>W128_T { |
---|
189 | <a name="l00252"></a>00252 <span class="preprocessor">#if defined(__SSE2__)</span> |
---|
190 | <a name="l00253"></a>00253 <span class="preprocessor"></span> __m128i si; |
---|
191 | <a name="l00254"></a>00254 __m128d <a class="code" href="group__lpc.html#g093af26787d37630cd33fe28499be6a5" title="Spectral distortion between two vectors, in dB, up to highest frequency highestfreq...">sd</a>; |
---|
192 | <a name="l00255"></a>00255 <span class="preprocessor">#endif // __SSE2__</span> |
---|
193 | <a name="l00256"></a>00256 <span class="preprocessor"></span> uint64_t u[2]; |
---|
194 | <a name="l00257"></a>00257 uint32_t u32[4]; |
---|
195 | <a name="l00258"></a>00258 <span class="keywordtype">double</span> d[2]; |
---|
196 | <a name="l00259"></a>00259 }; |
---|
197 | <a name="l00261"></a>00261 <span class="keyword">typedef</span> <span class="keyword">union </span>W128_T w128_t; |
---|
198 | <a name="l00263"></a>00263 <span class="keyword">static</span> w128_t status[N + 1]; |
---|
199 | <a name="l00265"></a>00265 <span class="keyword">static</span> <span class="keywordtype">int</span> idx; |
---|
200 | <a name="l00267"></a>00267 <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> last_seed; |
---|
201 | <a name="l00268"></a>00268 |
---|
202 | <a name="l00270"></a>00270 <span class="keyword">static</span> <span class="keywordtype">bool</span> initialized; |
---|
203 | <a name="l00272"></a>00272 <span class="keyword">static</span> <span class="keywordtype">bool</span> bigendian; |
---|
204 | <a name="l00273"></a>00273 |
---|
205 | <a name="l00274"></a>00274 <span class="preprocessor">#if defined(__SSE2__)</span> |
---|
206 | <a name="l00276"></a>00276 <span class="preprocessor"> static __m128i sse2_param_mask;</span> |
---|
207 | <a name="l00277"></a>00277 <span class="preprocessor"></span><span class="preprocessor">#endif // __SSE2__</span> |
---|
208 | <a name="l00278"></a>00278 <span class="preprocessor"></span> |
---|
209 | <a name="l00285"></a>00285 <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> hash(time_t t, clock_t c) |
---|
210 | <a name="l00286"></a>00286 { |
---|
211 | <a name="l00287"></a>00287 <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> differ = 0; <span class="comment">// guarantee time-based seeds will change</span> |
---|
212 | <a name="l00288"></a>00288 |
---|
213 | <a name="l00289"></a>00289 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> h1 = 0; |
---|
214 | <a name="l00290"></a>00290 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *p = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *) &t; |
---|
215 | <a name="l00291"></a>00291 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i < <span class="keyword">sizeof</span>(t); ++i) { |
---|
216 | <a name="l00292"></a>00292 h1 *= <a class="code" href="group__protocol.html#g3e4e78a5230c444344a135c661163ef2" title="ADD DOCUMENTATION HERE.">std::numeric_limits<unsigned char>::max</a>() + 2U; |
---|
217 | <a name="l00293"></a>00293 h1 += p[i]; |
---|
218 | <a name="l00294"></a>00294 } |
---|
219 | <a name="l00295"></a>00295 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> h2 = 0; |
---|
220 | <a name="l00296"></a>00296 p = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *) &c; |
---|
221 | <a name="l00297"></a>00297 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> j = 0; j < <span class="keyword">sizeof</span>(c); ++j) { |
---|
222 | <a name="l00298"></a>00298 h2 *= <a class="code" href="group__protocol.html#g3e4e78a5230c444344a135c661163ef2" title="ADD DOCUMENTATION HERE.">std::numeric_limits<unsigned char>::max</a>() + 2U; |
---|
223 | <a name="l00299"></a>00299 h2 += p[j]; |
---|
224 | <a name="l00300"></a>00300 } |
---|
225 | <a name="l00301"></a>00301 <span class="keywordflow">return</span> (h1 + differ++) ^ h2; |
---|
226 | <a name="l00302"></a>00302 } |
---|
227 | <a name="l00303"></a>00303 |
---|
228 | <a name="l00308"></a>00308 <span class="keyword">static</span> <span class="keywordtype">int</span> idxof(<span class="keywordtype">int</span> i) { <span class="keywordflow">return</span> (bigendian ? (i ^ 1) : i); } |
---|
229 | <a name="l00309"></a>00309 |
---|
230 | <a name="l00314"></a>00314 <span class="keyword">static</span> <span class="keywordtype">void</span> initial_mask() { |
---|
231 | <a name="l00315"></a>00315 uint64_t *psfmt = &status[0].u[0]; |
---|
232 | <a name="l00316"></a>00316 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < Nx2; i++) { |
---|
233 | <a name="l00317"></a>00317 psfmt[i] = (psfmt[i] & LOW_MASK) | HIGH_CONST; |
---|
234 | <a name="l00318"></a>00318 } |
---|
235 | <a name="l00319"></a>00319 } |
---|
236 | <a name="l00320"></a>00320 |
---|
237 | <a name="l00322"></a>00322 <span class="keyword">static</span> <span class="keywordtype">void</span> period_certification() { |
---|
238 | <a name="l00323"></a>00323 uint64_t pcv[2] = {PCV1, PCV2}; |
---|
239 | <a name="l00324"></a>00324 uint64_t tmp[2]; |
---|
240 | <a name="l00325"></a>00325 uint64_t inner; |
---|
241 | <a name="l00326"></a>00326 |
---|
242 | <a name="l00327"></a>00327 tmp[0] = (status[N].u[0] ^ FIX1); |
---|
243 | <a name="l00328"></a>00328 tmp[1] = (status[N].u[1] ^ FIX2); |
---|
244 | <a name="l00329"></a>00329 |
---|
245 | <a name="l00330"></a>00330 inner = tmp[0] & pcv[0]; |
---|
246 | <a name="l00331"></a>00331 inner ^= tmp[1] & pcv[1]; |
---|
247 | <a name="l00332"></a>00332 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 32; i > 0; i >>= 1) { |
---|
248 | <a name="l00333"></a>00333 inner ^= inner >> i; |
---|
249 | <a name="l00334"></a>00334 } |
---|
250 | <a name="l00335"></a>00335 inner &= 1; |
---|
251 | <a name="l00336"></a>00336 <span class="comment">/* check OK */</span> |
---|
252 | <a name="l00337"></a>00337 <span class="keywordflow">if</span> (inner == 1) { |
---|
253 | <a name="l00338"></a>00338 <span class="keywordflow">return</span>; |
---|
254 | <a name="l00339"></a>00339 } |
---|
255 | <a name="l00340"></a>00340 <span class="comment">/* check NG, and modification */</span> |
---|
256 | <a name="l00341"></a>00341 <span class="preprocessor">#if (PCV2 & 1) == 1</span> |
---|
257 | <a name="l00342"></a>00342 <span class="preprocessor"></span> status[N].u[1] ^= 1; |
---|
258 | <a name="l00343"></a>00343 <span class="preprocessor">#else</span> |
---|
259 | <a name="l00344"></a>00344 <span class="preprocessor"></span> uint64_t work; |
---|
260 | <a name="l00345"></a>00345 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i >= 0; i--) { |
---|
261 | <a name="l00346"></a>00346 work = 1; |
---|
262 | <a name="l00347"></a>00347 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < 64; j++) { |
---|
263 | <a name="l00348"></a>00348 <span class="keywordflow">if</span> ((work & pcv[i]) != 0) { |
---|
264 | <a name="l00349"></a>00349 status[N].u[i] ^= work; |
---|
265 | <a name="l00350"></a>00350 <span class="keywordflow">return</span>; |
---|
266 | <a name="l00351"></a>00351 } |
---|
267 | <a name="l00352"></a>00352 work = work << 1; |
---|
268 | <a name="l00353"></a>00353 } |
---|
269 | <a name="l00354"></a>00354 } |
---|
270 | <a name="l00355"></a>00355 <span class="preprocessor">#endif // (PCV2 & 1) == 1</span> |
---|
271 | <a name="l00356"></a>00356 <span class="preprocessor"></span> <span class="keywordflow">return</span>; |
---|
272 | <a name="l00357"></a>00357 } |
---|
273 | <a name="l00358"></a>00358 |
---|
274 | <a name="l00366"></a>00366 <span class="keyword">static</span> <span class="keywordtype">void</span> do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *lung) { |
---|
275 | <a name="l00367"></a>00367 <span class="preprocessor">#if defined(__SSE2__)</span> |
---|
276 | <a name="l00368"></a>00368 <span class="preprocessor"></span> __m128i x = a->si; |
---|
277 | <a name="l00369"></a>00369 __m128i z = _mm_slli_epi64(x, SL1); |
---|
278 | <a name="l00370"></a>00370 __m128i y = _mm_shuffle_epi32(lung->si, SSE2_SHUFF); |
---|
279 | <a name="l00371"></a>00371 z = _mm_xor_si128(z, b->si); |
---|
280 | <a name="l00372"></a>00372 y = _mm_xor_si128(y, z); |
---|
281 | <a name="l00373"></a>00373 |
---|
282 | <a name="l00374"></a>00374 __m128i v = _mm_srli_epi64(y, SR); |
---|
283 | <a name="l00375"></a>00375 __m128i w = _mm_and_si128(y, sse2_param_mask); |
---|
284 | <a name="l00376"></a>00376 v = _mm_xor_si128(v, x); |
---|
285 | <a name="l00377"></a>00377 v = _mm_xor_si128(v, w); |
---|
286 | <a name="l00378"></a>00378 r->si = v; |
---|
287 | <a name="l00379"></a>00379 lung->si = y; |
---|
288 | <a name="l00380"></a>00380 <span class="preprocessor">#else // standard C++</span> |
---|
289 | <a name="l00381"></a>00381 <span class="preprocessor"></span> uint64_t t0 = a->u[0]; |
---|
290 | <a name="l00382"></a>00382 uint64_t t1 = a->u[1]; |
---|
291 | <a name="l00383"></a>00383 uint64_t L0 = lung->u[0]; |
---|
292 | <a name="l00384"></a>00384 uint64_t L1 = lung->u[1]; |
---|
293 | <a name="l00385"></a>00385 lung->u[0] = (t0 << SL1) ^ (L1 >> 32) ^ (L1 << 32) ^ b->u[0]; |
---|
294 | <a name="l00386"></a>00386 lung->u[1] = (t1 << SL1) ^ (L0 >> 32) ^ (L0 << 32) ^ b->u[1]; |
---|
295 | <a name="l00387"></a>00387 r->u[0] = (lung->u[0] >> SR) ^ (lung->u[0] & MSK1) ^ t0; |
---|
296 | <a name="l00388"></a>00388 r->u[1] = (lung->u[1] >> SR) ^ (lung->u[1] & MSK2) ^ t1; |
---|
297 | <a name="l00389"></a>00389 <span class="preprocessor">#endif // __SSE2__</span> |
---|
298 | <a name="l00390"></a>00390 <span class="preprocessor"></span> } |
---|
299 | <a name="l00391"></a>00391 |
---|
300 | <a name="l00396"></a>00396 <span class="keyword">static</span> <span class="keywordtype">void</span> dsfmt_gen_rand_all() { |
---|
301 | <a name="l00397"></a>00397 <span class="keywordtype">int</span> i; |
---|
302 | <a name="l00398"></a>00398 w128_t lung = status[N]; |
---|
303 | <a name="l00399"></a>00399 do_recursion(&status[0], &status[0], &status[POS1], &lung); |
---|
304 | <a name="l00400"></a>00400 <span class="keywordflow">for</span> (i = 1; i < N - POS1; i++) { |
---|
305 | <a name="l00401"></a>00401 do_recursion(&status[i], &status[i], &status[i + POS1], &lung); |
---|
306 | <a name="l00402"></a>00402 } |
---|
307 | <a name="l00403"></a>00403 <span class="keywordflow">for</span> (; i < N; i++) { |
---|
308 | <a name="l00404"></a>00404 do_recursion(&status[i], &status[i], &status[i + POS1 - N], &lung); |
---|
309 | <a name="l00405"></a>00405 } |
---|
310 | <a name="l00406"></a>00406 status[N] = lung; |
---|
311 | <a name="l00407"></a>00407 } |
---|
312 | <a name="l00408"></a>00408 |
---|
313 | <a name="l00409"></a>00409 }; |
---|
314 | <a name="l00410"></a>00410 |
---|
315 | <a name="l00411"></a>00411 |
---|
316 | <a name="l00412"></a>00412 <span class="comment">// ----------------------------------------------------------------------</span> |
---|
317 | <a name="l00413"></a>00413 <span class="comment">// typedefs of different RNG</span> |
---|
318 | <a name="l00414"></a>00414 <span class="comment">// ----------------------------------------------------------------------</span> |
---|
319 | <a name="l00415"></a>00415 |
---|
320 | <a name="l00416"></a>00416 <span class="keyword">typedef</span> DSFMT<521, 3, 25, |
---|
321 | <a name="l00417"></a>00417 0x000fbfefff77efffULL, 0x000ffeebfbdfbfdfULL, |
---|
322 | <a name="l00418"></a>00418 0x000fbfefU, 0xff77efffU, 0x000ffeebU, 0xfbdfbfdfU, |
---|
323 | <a name="l00419"></a>00419 0xcfb393d661638469ULL, 0xc166867883ae2adbULL, |
---|
324 | <a name="l00420"></a>00420 0xccaa588000000000ULL, 0x0000000000000001ULL> DSFMT_521_RNG; |
---|
325 | <a name="l00421"></a>00421 |
---|
326 | <a name="l00422"></a>00422 <span class="keyword">typedef</span> DSFMT<1279, 9, 19, |
---|
327 | <a name="l00423"></a>00423 0x000efff7ffddffeeULL, 0x000fbffffff77fffULL, |
---|
328 | <a name="l00424"></a>00424 0x000efff7U, 0xffddffeeU, 0x000fbfffU, 0xfff77fffU, |
---|
329 | <a name="l00425"></a>00425 0xb66627623d1a31beULL, 0x04b6c51147b6109bULL, |
---|
330 | <a name="l00426"></a>00426 0x7049f2da382a6aebULL, 0xde4ca84a40000001ULL> DSFMT_1279_RNG; |
---|
331 | <a name="l00427"></a>00427 |
---|
332 | <a name="l00428"></a>00428 <span class="keyword">typedef</span> DSFMT<2203, 7, 19, |
---|
333 | <a name="l00429"></a>00429 0x000fdffff5edbfffULL, 0x000f77fffffffbfeULL, |
---|
334 | <a name="l00430"></a>00430 0x000fdfffU, 0xf5edbfffU, 0x000f77ffU, 0xfffffbfeU, |
---|
335 | <a name="l00431"></a>00431 0xb14e907a39338485ULL, 0xf98f0735c637ef90ULL, |
---|
336 | <a name="l00432"></a>00432 0x8000000000000000ULL, 0x0000000000000001ULL> DSFMT_2203_RNG; |
---|
337 | <a name="l00433"></a>00433 |
---|
338 | <a name="l00434"></a>00434 <span class="keyword">typedef</span> DSFMT<4253, 19, 19, |
---|
339 | <a name="l00435"></a>00435 0x0007b7fffef5feffULL, 0x000ffdffeffefbfcULL, |
---|
340 | <a name="l00436"></a>00436 0x0007b7ffU, 0xfef5feffU, 0x000ffdffU, 0xeffefbfcU, |
---|
341 | <a name="l00437"></a>00437 0x80901b5fd7a11c65ULL, 0x5a63ff0e7cb0ba74ULL, |
---|
342 | <a name="l00438"></a>00438 0x1ad277be12000000ULL, 0x0000000000000001ULL> DSFMT_4253_RNG; |
---|
343 | <a name="l00439"></a>00439 |
---|
344 | <a name="l00440"></a>00440 <span class="keyword">typedef</span> DSFMT<11213, 37, 19, |
---|
345 | <a name="l00441"></a>00441 0x000ffffffdf7fffdULL, 0x000ffffffdf7fffdULL, |
---|
346 | <a name="l00442"></a>00442 0x000fffffU, 0xfdf7fffdU, 0x000dffffU, 0xfff6bfffU, |
---|
347 | <a name="l00443"></a>00443 0xd0ef7b7c75b06793ULL, 0x9c50ff4caae0a641ULL, |
---|
348 | <a name="l00444"></a>00444 0x8234c51207c80000ULL, 0x0000000000000001ULL> DSFMT_11213_RNG; |
---|
349 | <a name="l00445"></a>00445 |
---|
350 | <a name="l00446"></a>00446 <span class="keyword">typedef</span> DSFMT<19937, 117, 19, |
---|
351 | <a name="l00447"></a>00447 0x000ffafffffffb3fULL, 0x000ffdfffc90fffdULL, |
---|
352 | <a name="l00448"></a>00448 0x000ffaffU, 0xfffffb3fU, 0x000ffdffU, 0xfc90fffdU, |
---|
353 | <a name="l00449"></a>00449 0x90014964b32f4329ULL, 0x3b8d12ac548a7c7aULL, |
---|
354 | <a name="l00450"></a>00450 0x3d84e1ac0dc82880ULL, 0x0000000000000001ULL> DSFMT_19937_RNG; |
---|
355 | <a name="l00451"></a>00451 |
---|
356 | <a name="l00452"></a>00452 |
---|
357 | <a name="l00453"></a>00453 } <span class="comment">// namespace itpp</span> |
---|
358 | <a name="l00454"></a>00454 |
---|
359 | <a name="l00455"></a>00455 <span class="preprocessor">#endif // #ifndef RANDOM_DSFMT_H</span> |
---|
360 | </pre></div></div> |
---|
361 | <hr size="1"><address style="text-align: right;"><small>Generated on Tue Jun 2 10:02:12 2009 for mixpp by |
---|
362 | <a href="http://www.doxygen.org/index.html"> |
---|
363 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address> |
---|
364 | </body> |
---|
365 | </html> |
---|