Update contrib.
2 A C-program for MT19937, with initialization improved 2002/1/26.
3 Coded by Takuji Nishimura and Makoto Matsumoto.
5 Before using, initialize the state by using init_genrand(seed)
6 or init_by_array(init_key, key_length).
8 Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions
15 1. Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
18 2. Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
22 3. The names of its contributors may not be used to endorse or promote
23 products derived from this software without specific prior written
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 Any feedback is very welcome.
40 http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
41 email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
43 //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
49 #include <liboil/liboilfunction.h>
51 /* Period parameters */
54 #define MATRIX_A 0x9908b0dfUL /* constant vector a */
55 #define UPPER_MASK 0x80000000UL /* most significant w-r bits */
56 #define LOWER_MASK 0x7fffffffUL /* least significant r bits */
59 OIL_DEFINE_CLASS(mt19937, "uint32_t *d_624, uint32_t *i_624");
61 OIL_DEFINE_CLASS(mt19937x8, "uint32_t *d_624x8, uint32_t *i_624x8");
64 /* mag01[x] = x * MATRIX_A for x=0,1 */
65 static const uint32_t mag01[2]={0x0UL, MATRIX_A};
68 mt19937_ref (uint32_t *d, uint32_t *mt)
73 for (kk=0;kk<N-M;kk++) {
74 y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
75 mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
78 y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
79 mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
81 y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
82 mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
89 y ^= (y << 7) & 0x9d2c5680UL;
90 y ^= (y << 15) & 0xefc60000UL;
96 OIL_DEFINE_IMPL_REF (mt19937_ref, mt19937);
101 /* There's no point in doing this in parallel, since the above class
102 * is handled by MMX quite well */
104 mt19937x8_ref (uint32_t *d, uint32_t *mt)
111 for (kk=0;kk<N-M;kk++) {
112 y = (mt[kk*8+i]&UPPER_MASK)|(mt[(kk+1)*8+i]&LOWER_MASK);
113 mt[kk*8+i] = mt[(kk+M)*8+i] ^ (y >> 1) ^ mag01[y & 0x1UL];
116 y = (mt[kk*8+i]&UPPER_MASK)|(mt[(kk+1)*8+i]&LOWER_MASK);
117 mt[kk*8+i] = mt[(kk+(M-N))*8+i] ^ (y >> 1) ^ mag01[y & 0x1UL];
119 y = (mt[(N-1)*8+i]&UPPER_MASK)|(mt[0*8+i]&LOWER_MASK);
120 mt[(N-1)*8+i] = mt[(M-1)*8+i] ^ (y >> 1) ^ mag01[y & 0x1UL];
127 y ^= (y << 7) & 0x9d2c5680UL;
128 y ^= (y << 15) & 0xefc60000UL;
135 OIL_DEFINE_IMPL_REF (mt19937x8_ref, mt19937x8);
142 OilFunctionClass* __oil_function_class_mt19937() {
143 return &_oil_function_class_mt19937;
150 OilFunctionClass* __oil_function_class_mt19937x8() {
151 return &_oil_function_class_mt19937x8;
159 OilFunctionImpl* __oil_function_impl_mt19937_ref() {
160 return &_oil_function_impl_mt19937_ref;
166 OilFunctionImpl* __oil_function_impl_mt19937x8_ref() {
167 return &_oil_function_impl_mt19937x8_ref;
175 EXPORT_C void** _oil_function_class_ptr_mt19937 () {
176 oil_function_class_ptr_mt19937 = __oil_function_class_mt19937();
177 return &oil_function_class_ptr_mt19937->func;
184 EXPORT_C void** _oil_function_class_ptr_mt19937x8 () {
185 oil_function_class_ptr_mt19937x8 = __oil_function_class_mt19937x8();
186 return &oil_function_class_ptr_mt19937x8->func;