sl@0: /* sl@0: A C-program for MT19937, with initialization improved 2002/1/26. sl@0: Coded by Takuji Nishimura and Makoto Matsumoto. sl@0: sl@0: Before using, initialize the state by using init_genrand(seed) sl@0: or init_by_array(init_key, key_length). sl@0: sl@0: Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, sl@0: All rights reserved. sl@0: sl@0: Redistribution and use in source and binary forms, with or without sl@0: modification, are permitted provided that the following conditions sl@0: are met: sl@0: sl@0: 1. Redistributions of source code must retain the above copyright sl@0: notice, this list of conditions and the following disclaimer. sl@0: sl@0: 2. Redistributions in binary form must reproduce the above copyright sl@0: notice, this list of conditions and the following disclaimer in the sl@0: documentation and/or other materials provided with the distribution. sl@0: sl@0: 3. The names of its contributors may not be used to endorse or promote sl@0: products derived from this software without specific prior written sl@0: permission. sl@0: sl@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS sl@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT sl@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR sl@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR sl@0: CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, sl@0: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, sl@0: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR sl@0: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF sl@0: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING sl@0: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS sl@0: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. sl@0: sl@0: sl@0: Any feedback is very welcome. sl@0: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html sl@0: email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) sl@0: */ sl@0: //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: sl@0: #ifdef HAVE_CONFIG_H sl@0: #include sl@0: #endif sl@0: sl@0: #include sl@0: sl@0: /* Period parameters */ sl@0: #define N 624 sl@0: #define M 397 sl@0: #define MATRIX_A 0x9908b0dfUL /* constant vector a */ sl@0: #define UPPER_MASK 0x80000000UL /* most significant w-r bits */ sl@0: #define LOWER_MASK 0x7fffffffUL /* least significant r bits */ sl@0: sl@0: sl@0: OIL_DEFINE_CLASS(mt19937, "uint32_t *d_624, uint32_t *i_624"); sl@0: #if 0 sl@0: OIL_DEFINE_CLASS(mt19937x8, "uint32_t *d_624x8, uint32_t *i_624x8"); sl@0: #endif sl@0: sl@0: /* mag01[x] = x * MATRIX_A for x=0,1 */ sl@0: static const uint32_t mag01[2]={0x0UL, MATRIX_A}; sl@0: sl@0: static void sl@0: mt19937_ref (uint32_t *d, uint32_t *mt) sl@0: { sl@0: uint32_t y; sl@0: int kk; sl@0: sl@0: for (kk=0;kk> 1) ^ mag01[y & 0x1UL]; sl@0: } sl@0: for (;kk> 1) ^ mag01[y & 0x1UL]; sl@0: } sl@0: y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK); sl@0: mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL]; sl@0: sl@0: for(kk=0;kk> 11); sl@0: y ^= (y << 7) & 0x9d2c5680UL; sl@0: y ^= (y << 15) & 0xefc60000UL; sl@0: y ^= (y >> 18); sl@0: sl@0: d[kk] = y; sl@0: } sl@0: } sl@0: OIL_DEFINE_IMPL_REF (mt19937_ref, mt19937); sl@0: sl@0: sl@0: sl@0: #if 0 sl@0: /* There's no point in doing this in parallel, since the above class sl@0: * is handled by MMX quite well */ sl@0: static void sl@0: mt19937x8_ref (uint32_t *d, uint32_t *mt) sl@0: { sl@0: uint32_t y; sl@0: int kk; sl@0: int i; sl@0: sl@0: for(i=0;i<8;i++){ sl@0: for (kk=0;kk> 1) ^ mag01[y & 0x1UL]; sl@0: } sl@0: for (;kk> 1) ^ mag01[y & 0x1UL]; sl@0: } sl@0: y = (mt[(N-1)*8+i]&UPPER_MASK)|(mt[0*8+i]&LOWER_MASK); sl@0: mt[(N-1)*8+i] = mt[(M-1)*8+i] ^ (y >> 1) ^ mag01[y & 0x1UL]; sl@0: sl@0: for(kk=0;kk> 11); sl@0: y ^= (y << 7) & 0x9d2c5680UL; sl@0: y ^= (y << 15) & 0xefc60000UL; sl@0: y ^= (y >> 18); sl@0: sl@0: d[kk*8 + i] = y; sl@0: } sl@0: } sl@0: } sl@0: OIL_DEFINE_IMPL_REF (mt19937x8_ref, mt19937x8); sl@0: #endif sl@0: sl@0: sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: OilFunctionClass* __oil_function_class_mt19937() { sl@0: return &_oil_function_class_mt19937; sl@0: } sl@0: #endif sl@0: sl@0: #if 0 sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: OilFunctionClass* __oil_function_class_mt19937x8() { sl@0: return &_oil_function_class_mt19937x8; sl@0: } sl@0: #endif sl@0: #endif sl@0: sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: OilFunctionImpl* __oil_function_impl_mt19937_ref() { sl@0: return &_oil_function_impl_mt19937_ref; sl@0: } sl@0: #endif sl@0: #if 0 sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: OilFunctionImpl* __oil_function_impl_mt19937x8_ref() { sl@0: return &_oil_function_impl_mt19937x8_ref; sl@0: } sl@0: #endif sl@0: #endif sl@0: sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: EXPORT_C void** _oil_function_class_ptr_mt19937 () { sl@0: oil_function_class_ptr_mt19937 = __oil_function_class_mt19937(); sl@0: return &oil_function_class_ptr_mt19937->func; sl@0: } sl@0: #endif sl@0: sl@0: #if 0 sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: EXPORT_C void** _oil_function_class_ptr_mt19937x8 () { sl@0: oil_function_class_ptr_mt19937x8 = __oil_function_class_mt19937x8(); sl@0: return &oil_function_class_ptr_mt19937x8->func; sl@0: } sl@0: #endif sl@0: #endif