1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/liboil/src/ref/mt19937ar.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,189 @@
1.4 +/*
1.5 + A C-program for MT19937, with initialization improved 2002/1/26.
1.6 + Coded by Takuji Nishimura and Makoto Matsumoto.
1.7 +
1.8 + Before using, initialize the state by using init_genrand(seed)
1.9 + or init_by_array(init_key, key_length).
1.10 +
1.11 + Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
1.12 + All rights reserved.
1.13 +
1.14 + Redistribution and use in source and binary forms, with or without
1.15 + modification, are permitted provided that the following conditions
1.16 + are met:
1.17 +
1.18 + 1. Redistributions of source code must retain the above copyright
1.19 + notice, this list of conditions and the following disclaimer.
1.20 +
1.21 + 2. Redistributions in binary form must reproduce the above copyright
1.22 + notice, this list of conditions and the following disclaimer in the
1.23 + documentation and/or other materials provided with the distribution.
1.24 +
1.25 + 3. The names of its contributors may not be used to endorse or promote
1.26 + products derived from this software without specific prior written
1.27 + permission.
1.28 +
1.29 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1.30 + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1.31 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1.32 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
1.33 + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
1.34 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
1.35 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
1.36 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
1.37 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
1.38 + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1.39 + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.40 +
1.41 +
1.42 + Any feedback is very welcome.
1.43 + http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
1.44 + email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
1.45 +*/
1.46 +//Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.47 +
1.48 +#ifdef HAVE_CONFIG_H
1.49 +#include <config.h>
1.50 +#endif
1.51 +
1.52 +#include <liboil/liboilfunction.h>
1.53 +
1.54 +/* Period parameters */
1.55 +#define N 624
1.56 +#define M 397
1.57 +#define MATRIX_A 0x9908b0dfUL /* constant vector a */
1.58 +#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
1.59 +#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
1.60 +
1.61 +
1.62 +OIL_DEFINE_CLASS(mt19937, "uint32_t *d_624, uint32_t *i_624");
1.63 +#if 0
1.64 +OIL_DEFINE_CLASS(mt19937x8, "uint32_t *d_624x8, uint32_t *i_624x8");
1.65 +#endif
1.66 +
1.67 +/* mag01[x] = x * MATRIX_A for x=0,1 */
1.68 +static const uint32_t mag01[2]={0x0UL, MATRIX_A};
1.69 +
1.70 +static void
1.71 +mt19937_ref (uint32_t *d, uint32_t *mt)
1.72 +{
1.73 + uint32_t y;
1.74 + int kk;
1.75 +
1.76 + for (kk=0;kk<N-M;kk++) {
1.77 + y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
1.78 + mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
1.79 + }
1.80 + for (;kk<N-1;kk++) {
1.81 + y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
1.82 + mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
1.83 + }
1.84 + y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
1.85 + mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
1.86 +
1.87 + for(kk=0;kk<N;kk++){
1.88 + y = mt[kk];
1.89 +
1.90 + /* Tempering */
1.91 + y ^= (y >> 11);
1.92 + y ^= (y << 7) & 0x9d2c5680UL;
1.93 + y ^= (y << 15) & 0xefc60000UL;
1.94 + y ^= (y >> 18);
1.95 +
1.96 + d[kk] = y;
1.97 + }
1.98 +}
1.99 +OIL_DEFINE_IMPL_REF (mt19937_ref, mt19937);
1.100 +
1.101 +
1.102 +
1.103 +#if 0
1.104 +/* There's no point in doing this in parallel, since the above class
1.105 + * is handled by MMX quite well */
1.106 +static void
1.107 +mt19937x8_ref (uint32_t *d, uint32_t *mt)
1.108 +{
1.109 + uint32_t y;
1.110 + int kk;
1.111 + int i;
1.112 +
1.113 + for(i=0;i<8;i++){
1.114 + for (kk=0;kk<N-M;kk++) {
1.115 + y = (mt[kk*8+i]&UPPER_MASK)|(mt[(kk+1)*8+i]&LOWER_MASK);
1.116 + mt[kk*8+i] = mt[(kk+M)*8+i] ^ (y >> 1) ^ mag01[y & 0x1UL];
1.117 + }
1.118 + for (;kk<N-1;kk++) {
1.119 + y = (mt[kk*8+i]&UPPER_MASK)|(mt[(kk+1)*8+i]&LOWER_MASK);
1.120 + mt[kk*8+i] = mt[(kk+(M-N))*8+i] ^ (y >> 1) ^ mag01[y & 0x1UL];
1.121 + }
1.122 + y = (mt[(N-1)*8+i]&UPPER_MASK)|(mt[0*8+i]&LOWER_MASK);
1.123 + mt[(N-1)*8+i] = mt[(M-1)*8+i] ^ (y >> 1) ^ mag01[y & 0x1UL];
1.124 +
1.125 + for(kk=0;kk<N;kk++){
1.126 + y = mt[kk*8 + i];
1.127 +
1.128 + /* Tempering */
1.129 + y ^= (y >> 11);
1.130 + y ^= (y << 7) & 0x9d2c5680UL;
1.131 + y ^= (y << 15) & 0xefc60000UL;
1.132 + y ^= (y >> 18);
1.133 +
1.134 + d[kk*8 + i] = y;
1.135 + }
1.136 + }
1.137 +}
1.138 +OIL_DEFINE_IMPL_REF (mt19937x8_ref, mt19937x8);
1.139 +#endif
1.140 +
1.141 +
1.142 +
1.143 +#ifdef __SYMBIAN32__
1.144 +
1.145 +OilFunctionClass* __oil_function_class_mt19937() {
1.146 + return &_oil_function_class_mt19937;
1.147 +}
1.148 +#endif
1.149 +
1.150 +#if 0
1.151 +#ifdef __SYMBIAN32__
1.152 +
1.153 +OilFunctionClass* __oil_function_class_mt19937x8() {
1.154 + return &_oil_function_class_mt19937x8;
1.155 +}
1.156 +#endif
1.157 +#endif
1.158 +
1.159 +
1.160 +#ifdef __SYMBIAN32__
1.161 +
1.162 +OilFunctionImpl* __oil_function_impl_mt19937_ref() {
1.163 + return &_oil_function_impl_mt19937_ref;
1.164 +}
1.165 +#endif
1.166 +#if 0
1.167 +#ifdef __SYMBIAN32__
1.168 +
1.169 +OilFunctionImpl* __oil_function_impl_mt19937x8_ref() {
1.170 + return &_oil_function_impl_mt19937x8_ref;
1.171 +}
1.172 +#endif
1.173 +#endif
1.174 +
1.175 +
1.176 +#ifdef __SYMBIAN32__
1.177 +
1.178 +EXPORT_C void** _oil_function_class_ptr_mt19937 () {
1.179 + oil_function_class_ptr_mt19937 = __oil_function_class_mt19937();
1.180 + return &oil_function_class_ptr_mt19937->func;
1.181 + }
1.182 +#endif
1.183 +
1.184 +#if 0
1.185 +#ifdef __SYMBIAN32__
1.186 +
1.187 +EXPORT_C void** _oil_function_class_ptr_mt19937x8 () {
1.188 + oil_function_class_ptr_mt19937x8 = __oil_function_class_mt19937x8();
1.189 + return &oil_function_class_ptr_mt19937x8->func;
1.190 + }
1.191 +#endif
1.192 +#endif