os/ossrv/genericopenlibs/liboil/src/ref/mt19937ar.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /* 
     2    A C-program for MT19937, with initialization improved 2002/1/26.
     3    Coded by Takuji Nishimura and Makoto Matsumoto.
     4 
     5    Before using, initialize the state by using init_genrand(seed)  
     6    or init_by_array(init_key, key_length).
     7 
     8    Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
     9    All rights reserved.                          
    10 
    11    Redistribution and use in source and binary forms, with or without
    12    modification, are permitted provided that the following conditions
    13    are met:
    14 
    15      1. Redistributions of source code must retain the above copyright
    16         notice, this list of conditions and the following disclaimer.
    17 
    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.
    21 
    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 
    24         permission.
    25 
    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.
    37 
    38 
    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)
    42 */
    43 //Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
    44 
    45 #ifdef HAVE_CONFIG_H
    46 #include <config.h>
    47 #endif
    48 
    49 #include <liboil/liboilfunction.h>
    50 
    51 /* Period parameters */  
    52 #define N 624
    53 #define M 397
    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 */
    57 
    58 
    59 OIL_DEFINE_CLASS(mt19937, "uint32_t *d_624, uint32_t *i_624");
    60 #if 0
    61 OIL_DEFINE_CLASS(mt19937x8, "uint32_t *d_624x8, uint32_t *i_624x8");
    62 #endif
    63 
    64 /* mag01[x] = x * MATRIX_A  for x=0,1 */
    65 static const uint32_t mag01[2]={0x0UL, MATRIX_A};
    66 
    67 static void
    68 mt19937_ref (uint32_t *d, uint32_t *mt)
    69 {
    70   uint32_t y;
    71   int kk;
    72 
    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];
    76   }
    77   for (;kk<N-1;kk++) {
    78       y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
    79       mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
    80   }
    81   y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
    82   mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
    83 
    84   for(kk=0;kk<N;kk++){
    85     y = mt[kk];
    86 
    87     /* Tempering */
    88     y ^= (y >> 11);
    89     y ^= (y << 7) & 0x9d2c5680UL;
    90     y ^= (y << 15) & 0xefc60000UL;
    91     y ^= (y >> 18);
    92 
    93     d[kk] = y;
    94   }
    95 }
    96 OIL_DEFINE_IMPL_REF (mt19937_ref, mt19937);
    97 
    98 
    99 
   100 #if 0
   101 /* There's no point in doing this in parallel, since the above class
   102  * is handled by MMX quite well */
   103 static void
   104 mt19937x8_ref (uint32_t *d, uint32_t *mt)
   105 {
   106   uint32_t y;
   107   int kk;
   108   int i;
   109 
   110   for(i=0;i<8;i++){
   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];
   114     }
   115     for (;kk<N-1;kk++) {
   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];
   118     }
   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];
   121 
   122     for(kk=0;kk<N;kk++){
   123       y = mt[kk*8 + i];
   124 
   125       /* Tempering */
   126       y ^= (y >> 11);
   127       y ^= (y << 7) & 0x9d2c5680UL;
   128       y ^= (y << 15) & 0xefc60000UL;
   129       y ^= (y >> 18);
   130 
   131       d[kk*8 + i] = y;
   132     }
   133   }
   134 }
   135 OIL_DEFINE_IMPL_REF (mt19937x8_ref, mt19937x8);
   136 #endif
   137 
   138 
   139 
   140 #ifdef	__SYMBIAN32__
   141  
   142 OilFunctionClass* __oil_function_class_mt19937() {
   143 		return &_oil_function_class_mt19937;
   144 }
   145 #endif
   146 
   147 #if 0
   148 #ifdef	__SYMBIAN32__
   149  
   150 OilFunctionClass* __oil_function_class_mt19937x8() {
   151 		return &_oil_function_class_mt19937x8;
   152 }
   153 #endif
   154 #endif
   155 
   156 
   157 #ifdef	__SYMBIAN32__
   158  
   159 OilFunctionImpl* __oil_function_impl_mt19937_ref() {
   160 		return &_oil_function_impl_mt19937_ref;
   161 }
   162 #endif
   163 #if 0
   164 #ifdef	__SYMBIAN32__
   165  
   166 OilFunctionImpl* __oil_function_impl_mt19937x8_ref() {
   167 		return &_oil_function_impl_mt19937x8_ref;
   168 }
   169 #endif
   170 #endif
   171 
   172 
   173 #ifdef	__SYMBIAN32__
   174  
   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;
   178 	}
   179 #endif
   180 
   181 #if 0
   182 #ifdef	__SYMBIAN32__
   183  
   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;
   187 	}
   188 #endif
   189 #endif