File: array_8h_source.html

package info (click to toggle)
librandom123 1.09%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,284 kB
  • sloc: cpp: 4,849; ansic: 4,407; perl: 108; sh: 37; makefile: 3
file content (376 lines) | stat: -rw-r--r-- 36,795 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Random123-1.09: Random123/array.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javaScript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<div class="tabs"><ul class="tablist"><li style="padding-left: 1.5em; font-weight: bold">Random123-1.09  Documentation</li></ul></div>
<!-- Generated by Doxygen 1.7.1 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Search');
--></script>
<div class="navigation" id="top">
  <div class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<h1>Random123/array.h</h1>  </div>
</div>
<div class="contents">
<a href="array_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment">Copyright 2010-2011, D. E. Shaw Research.</span>
<a name="l00003"></a>00003 <span class="comment">All rights reserved.</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment">Redistribution and use in source and binary forms, with or without</span>
<a name="l00006"></a>00006 <span class="comment">modification, are permitted provided that the following conditions are</span>
<a name="l00007"></a>00007 <span class="comment">met:</span>
<a name="l00008"></a>00008 <span class="comment"></span>
<a name="l00009"></a>00009 <span class="comment">* Redistributions of source code must retain the above copyright</span>
<a name="l00010"></a>00010 <span class="comment">  notice, this list of conditions, and the following disclaimer.</span>
<a name="l00011"></a>00011 <span class="comment"></span>
<a name="l00012"></a>00012 <span class="comment">* Redistributions in binary form must reproduce the above copyright</span>
<a name="l00013"></a>00013 <span class="comment">  notice, this list of conditions, and the following disclaimer in the</span>
<a name="l00014"></a>00014 <span class="comment">  documentation and/or other materials provided with the distribution.</span>
<a name="l00015"></a>00015 <span class="comment"></span>
<a name="l00016"></a>00016 <span class="comment">* Neither the name of D. E. Shaw Research nor the names of its</span>
<a name="l00017"></a>00017 <span class="comment">  contributors may be used to endorse or promote products derived from</span>
<a name="l00018"></a>00018 <span class="comment">  this software without specific prior written permission.</span>
<a name="l00019"></a>00019 <span class="comment"></span>
<a name="l00020"></a>00020 <span class="comment">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span>
<a name="l00021"></a>00021 <span class="comment">&quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span>
<a name="l00022"></a>00022 <span class="comment">LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR</span>
<a name="l00023"></a>00023 <span class="comment">A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT</span>
<a name="l00024"></a>00024 <span class="comment">OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
<a name="l00025"></a>00025 <span class="comment">SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT</span>
<a name="l00026"></a>00026 <span class="comment">LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</span>
<a name="l00027"></a>00027 <span class="comment">DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</span>
<a name="l00028"></a>00028 <span class="comment">THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
<a name="l00029"></a>00029 <span class="comment">(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE</span>
<a name="l00030"></a>00030 <span class="comment">OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<a name="l00031"></a>00031 <span class="comment">*/</span>
<a name="l00032"></a>00032 <span class="preprocessor">#ifndef _r123array_dot_h__</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#define _r123array_dot_h__</span>
<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="compilerfeatures_8h.html">features/compilerfeatures.h</a>&quot;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &quot;<a class="code" href="sse_8h.html">features/sse.h</a>&quot;</span>
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 <span class="preprocessor">#ifndef __cplusplus</span>
<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="preprocessor">#define CXXMETHODS(_N, W, T)</span>
<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">#define CXXOVERLOADS(_N, W, T)</span>
<a name="l00040"></a>00040 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00041"></a>00041 <span class="preprocessor"></span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &lt;stddef.h&gt;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &lt;algorithm&gt;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &lt;stdexcept&gt;</span>
<a name="l00045"></a>00045 <span class="preprocessor">#include &lt;iterator&gt;</span>
<a name="l00046"></a>00046 <span class="preprocessor">#include &lt;limits&gt;</span>
<a name="l00047"></a>00047 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00048"></a>00048 
<a name="l00068"></a>00068 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> value_type&gt;
<a name="l00069"></a>00069 <span class="keyword">inline</span> R123_CUDA_DEVICE value_type <a class="code" href="sse_8h.html#a99c42d1da8da3a4a273556a7817b5c1f">assemble_from_u32</a>(uint32_t *p32){
<a name="l00070"></a>00070     value_type v=0;
<a name="l00071"></a>00071     <span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i=0; i&lt;(3+<span class="keyword">sizeof</span>(value_type))/4; ++i)
<a name="l00072"></a>00072         v |= ((value_type)(*p32++)) &lt;&lt; (32*i);
<a name="l00073"></a>00073     <span class="keywordflow">return</span> v;
<a name="l00074"></a>00074 }
<a name="l00075"></a>00075 
<a name="l00076"></a>00076 <span class="comment">// Work-alike methods and typedefs modeled on std::array:</span>
<a name="l00077"></a>00077 <span class="preprocessor">#define CXXMETHODS(_N, W, T)                                            \</span>
<a name="l00078"></a>00078 <span class="preprocessor">    typedef T value_type;                                               \</span>
<a name="l00079"></a>00079 <span class="preprocessor">    typedef T* iterator;                                                \</span>
<a name="l00080"></a>00080 <span class="preprocessor">    typedef const T* const_iterator;                                    \</span>
<a name="l00081"></a>00081 <span class="preprocessor">    typedef value_type&amp; reference;                                      \</span>
<a name="l00082"></a>00082 <span class="preprocessor">    typedef const value_type&amp; const_reference;                          \</span>
<a name="l00083"></a>00083 <span class="preprocessor">    typedef size_t size_type;                                           \</span>
<a name="l00084"></a>00084 <span class="preprocessor">    typedef ptrdiff_t difference_type;                                  \</span>
<a name="l00085"></a>00085 <span class="preprocessor">    typedef T* pointer;                                                 \</span>
<a name="l00086"></a>00086 <span class="preprocessor">    typedef const T* const_pointer;                                     \</span>
<a name="l00087"></a>00087 <span class="preprocessor">    typedef std::reverse_iterator&lt;iterator&gt; reverse_iterator;           \</span>
<a name="l00088"></a>00088 <span class="preprocessor">    typedef std::reverse_iterator&lt;const_iterator&gt; const_reverse_iterator; \</span>
<a name="l00089"></a>00089 <span class="preprocessor">    </span><span class="comment">/* Boost.array has static_size.  C++11 specializes tuple_size */</span>    \
<a name="l00090"></a>00090     enum {static_size = _N};                                            \
<a name="l00091"></a>00091     R123_CUDA_DEVICE reference operator[](size_type i){return v[i];}                     \
<a name="l00092"></a>00092     R123_CUDA_DEVICE const_reference operator[](size_type i) const {return v[i];}        \
<a name="l00093"></a>00093     R123_CUDA_DEVICE reference at(size_type i){ if(i &gt;=  _N) R123_THROW(std::out_of_range(&quot;array index out of range&quot;)); return (*this)[i]; } \
<a name="l00094"></a>00094     R123_CUDA_DEVICE const_reference at(size_type i) const { if(i &gt;=  _N) R123_THROW(std::out_of_range(&quot;array index out of range&quot;)); return (*this)[i]; } \
<a name="l00095"></a>00095     R123_CUDA_DEVICE size_type size() const { return  _N; }                              \
<a name="l00096"></a>00096     R123_CUDA_DEVICE size_type max_size() const { return _N; }                           \
<a name="l00097"></a>00097     R123_CUDA_DEVICE bool empty() const { return _N==0; };                               \
<a name="l00098"></a>00098     R123_CUDA_DEVICE iterator begin() { return &amp;v[0]; }                                  \
<a name="l00099"></a>00099     R123_CUDA_DEVICE iterator end() { return &amp;v[_N]; }                                   \
<a name="l00100"></a>00100     R123_CUDA_DEVICE const_iterator begin() const { return &amp;v[0]; }                      \
<a name="l00101"></a>00101     R123_CUDA_DEVICE const_iterator end() const { return &amp;v[_N]; }                       \
<a name="l00102"></a>00102     R123_CUDA_DEVICE const_iterator cbegin() const { return &amp;v[0]; }                     \
<a name="l00103"></a>00103     R123_CUDA_DEVICE const_iterator cend() const { return &amp;v[_N]; }                      \
<a name="l00104"></a>00104     R123_CUDA_DEVICE reverse_iterator rbegin(){ return reverse_iterator(end()); }        \
<a name="l00105"></a>00105     R123_CUDA_DEVICE const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); } \
<a name="l00106"></a>00106     R123_CUDA_DEVICE reverse_iterator rend(){ return reverse_iterator(begin()); }        \
<a name="l00107"></a>00107     R123_CUDA_DEVICE const_reverse_iterator rend() const{ return const_reverse_iterator(begin()); } \
<a name="l00108"></a>00108     R123_CUDA_DEVICE const_reverse_iterator crbegin() const{ return const_reverse_iterator(cend()); } \
<a name="l00109"></a>00109     R123_CUDA_DEVICE const_reverse_iterator crend() const{ return const_reverse_iterator(cbegin()); } \
<a name="l00110"></a>00110     R123_CUDA_DEVICE pointer data(){ return &amp;v[0]; }                                     \
<a name="l00111"></a>00111     R123_CUDA_DEVICE const_pointer data() const{ return &amp;v[0]; }                         \
<a name="l00112"></a>00112     R123_CUDA_DEVICE reference front(){ return v[0]; }                                   \
<a name="l00113"></a>00113     R123_CUDA_DEVICE const_reference front() const{ return v[0]; }                       \
<a name="l00114"></a>00114     R123_CUDA_DEVICE reference back(){ return v[_N-1]; }                                 \
<a name="l00115"></a>00115     R123_CUDA_DEVICE const_reference back() const{ return v[_N-1]; }                     \
<a name="l00116"></a>00116     R123_CUDA_DEVICE bool operator==(const r123array##_N##x##W&amp; rhs) const{ \
<a name="l00117"></a>00117         <span class="comment">/* CUDA3 does not have std::equal */</span> \
<a name="l00118"></a>00118         for (size_t i = 0; i &lt; _N; ++i) \
<a name="l00119"></a>00119             if (v[i] != rhs.v[i]) return false; \
<a name="l00120"></a>00120         return true; \
<a name="l00121"></a>00121     } \
<a name="l00122"></a>00122     R123_CUDA_DEVICE bool operator!=(const r123array##_N##x##W&amp; rhs) const{ return !(*this == rhs); } \
<a name="l00123"></a>00123     <span class="comment">/* CUDA3 does not have std::fill_n */</span> \
<a name="l00124"></a>00124     R123_CUDA_DEVICE void fill(const value_type&amp; val){ for (size_t i = 0; i &lt; _N; ++i) v[i] = val; } \
<a name="l00125"></a>00125     R123_CUDA_DEVICE void swap(r123array##_N##x##W&amp; rhs){ \
<a name="l00126"></a>00126         <span class="comment">/* CUDA3 does not have std::swap_ranges */</span> \
<a name="l00127"></a>00127         for (size_t i = 0; i &lt; _N; ++i) { \
<a name="l00128"></a>00128             T tmp = v[i]; \
<a name="l00129"></a>00129             v[i] = rhs.v[i]; \
<a name="l00130"></a>00130             rhs.v[i] = tmp; \
<a name="l00131"></a>00131         } \
<a name="l00132"></a>00132     } \
<a name="l00133"></a>00133     R123_CUDA_DEVICE r123array##_N##x##W&amp; incr(R123_ULONG_LONG n=1){                         \
<a name="l00134"></a>00134         <span class="comment">/* This test is tricky because we&#39;re trying to avoid spurious   \</span>
<a name="l00135"></a>00135 <span class="comment">           complaints about illegal shifts, yet still be compile-time   \</span>
<a name="l00136"></a>00136 <span class="comment">           evaulated. */</span>                                                \
<a name="l00137"></a>00137         if(sizeof(T)&lt;sizeof(n) &amp;&amp; n&gt;&gt;((sizeof(T)&lt;sizeof(n))?8*sizeof(T):0) ) \
<a name="l00138"></a>00138             return incr_carefully(n);                                   \
<a name="l00139"></a>00139         if(n==1){                                                       \
<a name="l00140"></a>00140             ++v[0];                                                     \
<a name="l00141"></a>00141             if(_N==1 || R123_BUILTIN_EXPECT(!!v[0], 1)) return *this;   \
<a name="l00142"></a>00142         }else{                                                          \
<a name="l00143"></a>00143             v[0] += n;                                                  \
<a name="l00144"></a>00144             if(_N==1 || R123_BUILTIN_EXPECT(n&lt;=v[0], 1)) return *this;  \
<a name="l00145"></a>00145         }                                                               \
<a name="l00146"></a>00146         <span class="comment">/* We expect that the N==?? tests will be                       \</span>
<a name="l00147"></a>00147 <span class="comment">           constant-folded/optimized away by the compiler, so only the  \</span>
<a name="l00148"></a>00148 <span class="comment">           overflow tests (!!v[i]) remain to be done at runtime.  For  \</span>
<a name="l00149"></a>00149 <span class="comment">           small values of N, it would be better to do this as an       \</span>
<a name="l00150"></a>00150 <span class="comment">           uncondtional sequence of adc.  An experiment/optimization    \</span>
<a name="l00151"></a>00151 <span class="comment">           for another day...                                           \</span>
<a name="l00152"></a>00152 <span class="comment">           N.B.  The weird subscripting: v[_N&gt;3?3:0] is to silence      \</span>
<a name="l00153"></a>00153 <span class="comment">           a spurious error from icpc                                   \</span>
<a name="l00154"></a>00154 <span class="comment">           */</span>                                                           \
<a name="l00155"></a>00155         ++v[_N&gt;1?1:0];                                                  \
<a name="l00156"></a>00156         if(_N==2 || R123_BUILTIN_EXPECT(!!v[_N&gt;1?1:0], 1)) return *this; \
<a name="l00157"></a>00157         ++v[_N&gt;2?2:0];                                                  \
<a name="l00158"></a>00158         if(_N==3 || R123_BUILTIN_EXPECT(!!v[_N&gt;2?2:0], 1)) return *this;  \
<a name="l00159"></a>00159         ++v[_N&gt;3?3:0];                                                  \
<a name="l00160"></a>00160         for(size_t i=4; i&lt;_N; ++i){                                     \
<a name="l00161"></a>00161             if( R123_BUILTIN_EXPECT(!!v[i-1], 1) ) return *this;        \
<a name="l00162"></a>00162             ++v[i];                                                     \
<a name="l00163"></a>00163         }                                                               \
<a name="l00164"></a>00164         return *this;                                                   \
<a name="l00165"></a>00165     }                                                                   \
<a name="l00166"></a>00166     <span class="comment">/* seed(SeedSeq) would be a constructor if having a constructor */</span>  \
<a name="l00167"></a>00167     <span class="comment">/* didn&#39;t cause headaches with defaults */</span>                          \
<a name="l00168"></a>00168     template &lt;typename SeedSeq&gt;                                         \
<a name="l00169"></a>00169     R123_CUDA_DEVICE static r123array##_N##x##W seed(SeedSeq &amp;ss){      \
<a name="l00170"></a>00170         r123array##_N##x##W ret;                                        \
<a name="l00171"></a>00171         const size_t Ngen = _N*((3+sizeof(value_type))/4);              \
<a name="l00172"></a>00172         uint32_t u32[Ngen];                                             \
<a name="l00173"></a>00173         uint32_t *p32 = &amp;u32[0];                                        \
<a name="l00174"></a>00174         ss.generate(&amp;u32[0], &amp;u32[Ngen]);                               \
<a name="l00175"></a>00175         for(size_t i=0; i&lt;_N; ++i){                                     \
<a name="l00176"></a>00176             ret.v[i] = assemble_from_u32&lt;value_type&gt;(p32);              \
<a name="l00177"></a>00177             p32 += (3+sizeof(value_type))/4;                            \
<a name="l00178"></a>00178         }                                                               \
<a name="l00179"></a>00179         return ret;                                                     \
<a name="l00180"></a>00180     }                                                                   \
<a name="l00181"></a>00181 protected:                                                              \
<a name="l00182"></a>00182     R123_CUDA_DEVICE r123array##_N##x##W&amp; incr_carefully(R123_ULONG_LONG n){ \
<a name="l00183"></a>00183         <span class="comment">/* n may be greater than the maximum value of a single value_type */</span> \
<a name="l00184"></a>00184         value_type vtn;                                                 \
<a name="l00185"></a>00185         vtn = n;                                                        \
<a name="l00186"></a>00186         v[0] += n;                                                      \
<a name="l00187"></a>00187         const unsigned rshift = 8* ((sizeof(n)&gt;sizeof(value_type))? sizeof(value_type) : 0); \
<a name="l00188"></a>00188         for(size_t i=1; i&lt;_N; ++i){                                     \
<a name="l00189"></a>00189             if(rshift){                                                 \
<a name="l00190"></a>00190                 n &gt;&gt;= rshift;                                           \
<a name="l00191"></a>00191             }else{                                                      \
<a name="l00192"></a>00192                 n=0;                                                    \
<a name="l00193"></a>00193             }                                                           \
<a name="l00194"></a>00194             if( v[i-1] &lt; vtn )                                          \
<a name="l00195"></a>00195                 ++n;                                                    \
<a name="l00196"></a>00196             if( n==0 ) break;                                           \
<a name="l00197"></a>00197             vtn = n;                                                    \
<a name="l00198"></a>00198             v[i] += n;                                                  \
<a name="l00199"></a>00199         }                                                               \
<a name="l00200"></a>00200         return *this;                                                   \
<a name="l00201"></a>00201     }                                                                   \
<a name="l00202"></a>00202     
<a name="l00203"></a>00203                                                                         
<a name="l00204"></a>00204 <span class="comment">// There are several tricky considerations for the insertion and extraction</span>
<a name="l00205"></a>00205 <span class="comment">// operators:</span>
<a name="l00206"></a>00206 <span class="comment">// - we would like to be able to print r123array16x8 as a sequence of 16 integers,</span>
<a name="l00207"></a>00207 <span class="comment">//   not as 16 bytes.</span>
<a name="l00208"></a>00208 <span class="comment">// - we would like to be able to print r123array1xm128i.</span>
<a name="l00209"></a>00209 <span class="comment">// - we do not want an int conversion operator in r123m128i because it causes</span>
<a name="l00210"></a>00210 <span class="comment">//   lots of ambiguity problems with automatic promotions.</span>
<a name="l00211"></a>00211 <span class="comment">// Solution: r123arrayinsertable and r123arrayextractable</span>
<a name="l00212"></a>00212 
<a name="l00213"></a>00213 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T&gt;
<a name="l00214"></a>00214 <span class="keyword">struct </span>r123arrayinsertable{
<a name="l00215"></a>00215     <span class="keyword">const</span> T&amp; v;
<a name="l00216"></a>00216     r123arrayinsertable(<span class="keyword">const</span> T&amp; t_) : v(t_) {} 
<a name="l00217"></a>00217     <span class="keyword">friend</span> std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const r123arrayinsertable&lt;T&gt;&amp; t){
<a name="l00218"></a>00218         <span class="keywordflow">return</span> os &lt;&lt; t.v;
<a name="l00219"></a>00219     }
<a name="l00220"></a>00220 };
<a name="l00221"></a>00221 
<a name="l00222"></a>00222 <span class="keyword">template</span>&lt;&gt;
<a name="l00223"></a>00223 <span class="keyword">struct </span>r123arrayinsertable&lt;uint8_t&gt;{
<a name="l00224"></a>00224     <span class="keyword">const</span> uint8_t&amp; v;
<a name="l00225"></a>00225     r123arrayinsertable(<span class="keyword">const</span> uint8_t&amp; t_) : v(t_) {} 
<a name="l00226"></a>00226     <span class="keyword">friend</span> std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const r123arrayinsertable&lt;uint8_t&gt;&amp; t){
<a name="l00227"></a>00227         <span class="keywordflow">return</span> os &lt;&lt; (int)t.v;
<a name="l00228"></a>00228     }
<a name="l00229"></a>00229 };
<a name="l00230"></a>00230 
<a name="l00231"></a>00231 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T&gt;
<a name="l00232"></a>00232 <span class="keyword">struct </span>r123arrayextractable{
<a name="l00233"></a>00233     T&amp; v;
<a name="l00234"></a>00234     r123arrayextractable(T&amp; t_) : v(t_) {}
<a name="l00235"></a>00235     <span class="keyword">friend</span> std::istream&amp; <a class="code" href="array_8h.html#ace3112deae6709884feac904b1c260a1">operator&gt;&gt;</a>(std::istream&amp; is, r123arrayextractable&lt;T&gt;&amp; t){
<a name="l00236"></a>00236         <span class="keywordflow">return</span> is &gt;&gt; t.v;
<a name="l00237"></a>00237     }
<a name="l00238"></a>00238 };
<a name="l00239"></a>00239 
<a name="l00240"></a>00240 <span class="keyword">template</span>&lt;&gt;
<a name="l00241"></a>00241 <span class="keyword">struct </span>r123arrayextractable&lt;uint8_t&gt;{
<a name="l00242"></a>00242     uint8_t&amp; v;
<a name="l00243"></a>00243     r123arrayextractable(uint8_t&amp; t_) : v(t_) {} 
<a name="l00244"></a>00244     <span class="keyword">friend</span> std::istream&amp; <a class="code" href="array_8h.html#ace3112deae6709884feac904b1c260a1">operator&gt;&gt;</a>(std::istream&amp; is, r123arrayextractable&lt;uint8_t&gt;&amp; t){
<a name="l00245"></a>00245         <span class="keywordtype">int</span> i;
<a name="l00246"></a>00246         is &gt;&gt;  i;
<a name="l00247"></a>00247         t.v = i;
<a name="l00248"></a>00248         <span class="keywordflow">return</span> is;
<a name="l00249"></a>00249     }
<a name="l00250"></a>00250 };
<a name="l00251"></a>00251 
<a name="l00252"></a>00252 <span class="preprocessor">#define CXXOVERLOADS(_N, W, T)                                          \</span>
<a name="l00253"></a>00253 <span class="preprocessor">                                                                        \</span>
<a name="l00254"></a>00254 <span class="preprocessor">inline std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const r123array##_N##x##W&amp; a){   \</span>
<a name="l00255"></a>00255 <span class="preprocessor">    os &lt;&lt; r123arrayinsertable&lt;T&gt;(a.v[0]);                                  \</span>
<a name="l00256"></a>00256 <span class="preprocessor">    for(size_t i=1; i&lt;_N; ++i)                                          \</span>
<a name="l00257"></a>00257 <span class="preprocessor">        os &lt;&lt; &quot; &quot; &lt;&lt; r123arrayinsertable&lt;T&gt;(a.v[i]);                       \</span>
<a name="l00258"></a>00258 <span class="preprocessor">    return os;                                                          \</span>
<a name="l00259"></a>00259 <span class="preprocessor">}                                                                       \</span>
<a name="l00260"></a>00260 <span class="preprocessor">                                                                        \</span>
<a name="l00261"></a>00261 <span class="preprocessor">inline std::istream&amp; operator&gt;&gt;(std::istream&amp; is, r123array##_N##x##W&amp; a){         \</span>
<a name="l00262"></a>00262 <span class="preprocessor">    for(size_t i=0; i&lt;_N; ++i){                                         \</span>
<a name="l00263"></a>00263 <span class="preprocessor">        r123arrayextractable&lt;T&gt; x(a.v[i]);                                 \</span>
<a name="l00264"></a>00264 <span class="preprocessor">        is &gt;&gt; x;                                                        \</span>
<a name="l00265"></a>00265 <span class="preprocessor">    }                                                                   \</span>
<a name="l00266"></a>00266 <span class="preprocessor">    return is;                                                          \</span>
<a name="l00267"></a>00267 <span class="preprocessor">}                                                                       \</span>
<a name="l00268"></a>00268 <span class="preprocessor">                                                                        \</span>
<a name="l00269"></a>00269 <span class="preprocessor">namespace r123{                                                        \</span>
<a name="l00270"></a>00270 <span class="preprocessor"> typedef r123array##_N##x##W Array##_N##x##W;                          \</span>
<a name="l00271"></a>00271 <span class="preprocessor">}</span>
<a name="l00272"></a>00272 <span class="preprocessor"></span>                                                                        
<a name="l00273"></a>00273 <span class="preprocessor">#endif </span><span class="comment">/* __cplusplus */</span>
<a name="l00274"></a>00274 
<a name="l00275"></a>00275 <span class="comment">/* _r123array_tpl expands to a declaration of struct r123arrayNxW.  </span>
<a name="l00276"></a>00276 <span class="comment"></span>
<a name="l00277"></a>00277 <span class="comment">   In C, it&#39;s nothing more than a struct containing an array of N</span>
<a name="l00278"></a>00278 <span class="comment">   objects of type T.</span>
<a name="l00279"></a>00279 <span class="comment"></span>
<a name="l00280"></a>00280 <span class="comment">   In C++ it&#39;s the same, but endowed with an assortment of member</span>
<a name="l00281"></a>00281 <span class="comment">   functions, typedefs and friends.  In C++, r123arrayNxW looks a lot</span>
<a name="l00282"></a>00282 <span class="comment">   like std::array&lt;T,N&gt;, has most of the capabilities of a container,</span>
<a name="l00283"></a>00283 <span class="comment">   and satisfies the requirements outlined in compat/Engine.hpp for</span>
<a name="l00284"></a>00284 <span class="comment">   counter and key types.  ArrayNxW, in the r123 namespace is</span>
<a name="l00285"></a>00285 <span class="comment">   a typedef equivalent to r123arrayNxW.</span>
<a name="l00286"></a>00286 <span class="comment">*/</span>
<a name="l00287"></a>00287 
<a name="l00288"></a>00288 <span class="preprocessor">#define _r123array_tpl(_N, W, T)                   \</span>
<a name="l00289"></a>00289 <span class="preprocessor">                        \</span>
<a name="l00290"></a><a class="code" href="array_8h.html#ace3112deae6709884feac904b1c260a1">00290</a> <span class="preprocessor">                            \</span>
<a name="l00291"></a><a class="code" href="array_8h.html#a41bb2d7e99cf51ca5927a074d1424a03">00291</a> <span class="preprocessor">struct r123array##_N##x##W{                         \</span>
<a name="l00292"></a><a class="code" href="array_8h.html#a2782402f8b3941e104e01c317fd4b099">00292</a> <span class="preprocessor"> T v[_N];                                       \</span>
<a name="l00293"></a><a class="code" href="array_8h.html#ae63a28cc2f1e69f63a4402c8b83663b4">00293</a> <span class="preprocessor"> CXXMETHODS(_N, W, T)                           \</span>
<a name="l00294"></a>00294 <span class="preprocessor">};                                              \</span>
<a name="l00295"></a><a class="code" href="array_8h.html#a3cdf7b897463996d6eda01443dd669c5">00295</a> <span class="preprocessor">                                                \</span>
<a name="l00296"></a><a class="code" href="array_8h.html#a7b32dd7601d0a11b72583a841abc8fca">00296</a> <span class="preprocessor">CXXOVERLOADS(_N, W, T)</span>
<a name="l00297"></a><a class="code" href="array_8h.html#a60aa3cdbb34ced56c0c7c82371f2b30c">00297</a> <span class="preprocessor"></span>
<a name="l00300"></a>00300 _r123array_tpl(1, 32, uint32_t)  <span class="comment">/* r123array1x32 */</span>
<a name="l00301"></a>00301 _r123array_tpl(2, 32, uint32_t)  <span class="comment">/* r123array2x32 */</span>
<a name="l00302"></a><a class="code" href="array_8h.html#af831caf1f33e800dad6a659523525a78">00302</a> _r123array_tpl(4, 32, uint32_t)  <span class="comment">/* r123array4x32 */</span>
<a name="l00303"></a>00303 _r123array_tpl(8, 32, uint32_t)  <span class="comment">/* r123array8x32 */</span>
<a name="l00304"></a>00304 
<a name="l00305"></a>00305 _r123array_tpl(1, 64, uint64_t)  <span class="comment">/* r123array1x64 */</span>
<a name="l00306"></a>00306 _r123array_tpl(2, 64, uint64_t)  <span class="comment">/* r123array2x64 */</span>
<a name="l00307"></a>00307 _r123array_tpl(4, 64, uint64_t)  <span class="comment">/* r123array4x64 */</span>
<a name="l00308"></a>00308 
<a name="l00309"></a><a class="code" href="array_8h.html#a9b64205709c0daaea3b05bbf7ea5a322">00309</a> _r123array_tpl(16, 8, uint8_t)  <span class="comment">/* r123array16x8 for ARSsw, AESsw */</span>
<a name="l00310"></a>00310 
<a name="l00311"></a>00311 <span class="preprocessor">#if R123_USE_SSE</span>
<a name="l00312"></a>00312 <span class="preprocessor"></span>_r123array_tpl(1, m128i, <a class="code" href="structr123m128i.html">r123m128i</a>) <span class="comment">/* r123array1x128i for ARSni, AESni */</span>
<a name="l00313"></a>00313 <span class="preprocessor">#endif</span>
<a name="l00314"></a>00314 <span class="preprocessor"></span>
<a name="l00315"></a>00315 <span class="comment">/* In C++, it&#39;s natural to use sizeof(a::value_type), but in C it&#39;s</span>
<a name="l00316"></a>00316 <span class="comment">   pretty convoluted to figure out the width of the value_type of an</span>
<a name="l00317"></a>00317 <span class="comment">   r123arrayNxW:</span>
<a name="l00318"></a>00318 <span class="comment">*/</span>
<a name="l00319"></a>00319 <span class="preprocessor">#define R123_W(a)   (8*sizeof(((a *)0)-&gt;v[0]))</span>
<a name="l00320"></a>00320 <span class="preprocessor"></span>
<a name="l00325"></a>00325 <span class="preprocessor">#endif</span>
<a name="l00326"></a>00326 <span class="preprocessor"></span>
</pre></div></div>
</div>
<!--- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&nbsp;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&nbsp;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&nbsp;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&nbsp;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&nbsp;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&nbsp;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&nbsp;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&nbsp;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&nbsp;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&nbsp;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&nbsp;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<hr class="footer"/><address class="footer"><small>Generated on Mon Mar 7 2016 18:34:00 for Random123-1.09 by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.1 </small></address>
</body>
</html>