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.
sl@0
     1
/* 
sl@0
     2
   A C-program for MT19937, with initialization improved 2002/1/26.
sl@0
     3
   Coded by Takuji Nishimura and Makoto Matsumoto.
sl@0
     4
sl@0
     5
   Before using, initialize the state by using init_genrand(seed)  
sl@0
     6
   or init_by_array(init_key, key_length).
sl@0
     7
sl@0
     8
   Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
sl@0
     9
   All rights reserved.                          
sl@0
    10
sl@0
    11
   Redistribution and use in source and binary forms, with or without
sl@0
    12
   modification, are permitted provided that the following conditions
sl@0
    13
   are met:
sl@0
    14
sl@0
    15
     1. Redistributions of source code must retain the above copyright
sl@0
    16
        notice, this list of conditions and the following disclaimer.
sl@0
    17
sl@0
    18
     2. Redistributions in binary form must reproduce the above copyright
sl@0
    19
        notice, this list of conditions and the following disclaimer in the
sl@0
    20
        documentation and/or other materials provided with the distribution.
sl@0
    21
sl@0
    22
     3. The names of its contributors may not be used to endorse or promote 
sl@0
    23
        products derived from this software without specific prior written 
sl@0
    24
        permission.
sl@0
    25
sl@0
    26
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
sl@0
    27
   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
sl@0
    28
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
sl@0
    29
   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
sl@0
    30
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
sl@0
    31
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
sl@0
    32
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
sl@0
    33
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
sl@0
    34
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
sl@0
    35
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
sl@0
    36
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
sl@0
    37
sl@0
    38
sl@0
    39
   Any feedback is very welcome.
sl@0
    40
   http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
sl@0
    41
   email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
sl@0
    42
*/
sl@0
    43
//Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
sl@0
    44
sl@0
    45
#ifdef HAVE_CONFIG_H
sl@0
    46
#include <config.h>
sl@0
    47
#endif
sl@0
    48
sl@0
    49
#include <liboil/liboilfunction.h>
sl@0
    50
sl@0
    51
/* Period parameters */  
sl@0
    52
#define N 624
sl@0
    53
#define M 397
sl@0
    54
#define MATRIX_A 0x9908b0dfUL   /* constant vector a */
sl@0
    55
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
sl@0
    56
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
sl@0
    57
sl@0
    58
sl@0
    59
OIL_DEFINE_CLASS(mt19937, "uint32_t *d_624, uint32_t *i_624");
sl@0
    60
#if 0
sl@0
    61
OIL_DEFINE_CLASS(mt19937x8, "uint32_t *d_624x8, uint32_t *i_624x8");
sl@0
    62
#endif
sl@0
    63
sl@0
    64
/* mag01[x] = x * MATRIX_A  for x=0,1 */
sl@0
    65
static const uint32_t mag01[2]={0x0UL, MATRIX_A};
sl@0
    66
sl@0
    67
static void
sl@0
    68
mt19937_ref (uint32_t *d, uint32_t *mt)
sl@0
    69
{
sl@0
    70
  uint32_t y;
sl@0
    71
  int kk;
sl@0
    72
sl@0
    73
  for (kk=0;kk<N-M;kk++) {
sl@0
    74
      y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
sl@0
    75
      mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
sl@0
    76
  }
sl@0
    77
  for (;kk<N-1;kk++) {
sl@0
    78
      y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
sl@0
    79
      mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
sl@0
    80
  }
sl@0
    81
  y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
sl@0
    82
  mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
sl@0
    83
sl@0
    84
  for(kk=0;kk<N;kk++){
sl@0
    85
    y = mt[kk];
sl@0
    86
sl@0
    87
    /* Tempering */
sl@0
    88
    y ^= (y >> 11);
sl@0
    89
    y ^= (y << 7) & 0x9d2c5680UL;
sl@0
    90
    y ^= (y << 15) & 0xefc60000UL;
sl@0
    91
    y ^= (y >> 18);
sl@0
    92
sl@0
    93
    d[kk] = y;
sl@0
    94
  }
sl@0
    95
}
sl@0
    96
OIL_DEFINE_IMPL_REF (mt19937_ref, mt19937);
sl@0
    97
sl@0
    98
sl@0
    99
sl@0
   100
#if 0
sl@0
   101
/* There's no point in doing this in parallel, since the above class
sl@0
   102
 * is handled by MMX quite well */
sl@0
   103
static void
sl@0
   104
mt19937x8_ref (uint32_t *d, uint32_t *mt)
sl@0
   105
{
sl@0
   106
  uint32_t y;
sl@0
   107
  int kk;
sl@0
   108
  int i;
sl@0
   109
sl@0
   110
  for(i=0;i<8;i++){
sl@0
   111
    for (kk=0;kk<N-M;kk++) {
sl@0
   112
        y = (mt[kk*8+i]&UPPER_MASK)|(mt[(kk+1)*8+i]&LOWER_MASK);
sl@0
   113
        mt[kk*8+i] = mt[(kk+M)*8+i] ^ (y >> 1) ^ mag01[y & 0x1UL];
sl@0
   114
    }
sl@0
   115
    for (;kk<N-1;kk++) {
sl@0
   116
        y = (mt[kk*8+i]&UPPER_MASK)|(mt[(kk+1)*8+i]&LOWER_MASK);
sl@0
   117
        mt[kk*8+i] = mt[(kk+(M-N))*8+i] ^ (y >> 1) ^ mag01[y & 0x1UL];
sl@0
   118
    }
sl@0
   119
    y = (mt[(N-1)*8+i]&UPPER_MASK)|(mt[0*8+i]&LOWER_MASK);
sl@0
   120
    mt[(N-1)*8+i] = mt[(M-1)*8+i] ^ (y >> 1) ^ mag01[y & 0x1UL];
sl@0
   121
sl@0
   122
    for(kk=0;kk<N;kk++){
sl@0
   123
      y = mt[kk*8 + i];
sl@0
   124
sl@0
   125
      /* Tempering */
sl@0
   126
      y ^= (y >> 11);
sl@0
   127
      y ^= (y << 7) & 0x9d2c5680UL;
sl@0
   128
      y ^= (y << 15) & 0xefc60000UL;
sl@0
   129
      y ^= (y >> 18);
sl@0
   130
sl@0
   131
      d[kk*8 + i] = y;
sl@0
   132
    }
sl@0
   133
  }
sl@0
   134
}
sl@0
   135
OIL_DEFINE_IMPL_REF (mt19937x8_ref, mt19937x8);
sl@0
   136
#endif
sl@0
   137
sl@0
   138
sl@0
   139
sl@0
   140
#ifdef	__SYMBIAN32__
sl@0
   141
 
sl@0
   142
OilFunctionClass* __oil_function_class_mt19937() {
sl@0
   143
		return &_oil_function_class_mt19937;
sl@0
   144
}
sl@0
   145
#endif
sl@0
   146
sl@0
   147
#if 0
sl@0
   148
#ifdef	__SYMBIAN32__
sl@0
   149
 
sl@0
   150
OilFunctionClass* __oil_function_class_mt19937x8() {
sl@0
   151
		return &_oil_function_class_mt19937x8;
sl@0
   152
}
sl@0
   153
#endif
sl@0
   154
#endif
sl@0
   155
sl@0
   156
sl@0
   157
#ifdef	__SYMBIAN32__
sl@0
   158
 
sl@0
   159
OilFunctionImpl* __oil_function_impl_mt19937_ref() {
sl@0
   160
		return &_oil_function_impl_mt19937_ref;
sl@0
   161
}
sl@0
   162
#endif
sl@0
   163
#if 0
sl@0
   164
#ifdef	__SYMBIAN32__
sl@0
   165
 
sl@0
   166
OilFunctionImpl* __oil_function_impl_mt19937x8_ref() {
sl@0
   167
		return &_oil_function_impl_mt19937x8_ref;
sl@0
   168
}
sl@0
   169
#endif
sl@0
   170
#endif
sl@0
   171
sl@0
   172
sl@0
   173
#ifdef	__SYMBIAN32__
sl@0
   174
 
sl@0
   175
EXPORT_C void** _oil_function_class_ptr_mt19937 ()	{
sl@0
   176
	oil_function_class_ptr_mt19937 = __oil_function_class_mt19937();
sl@0
   177
	return &oil_function_class_ptr_mt19937->func;
sl@0
   178
	}
sl@0
   179
#endif
sl@0
   180
sl@0
   181
#if 0
sl@0
   182
#ifdef	__SYMBIAN32__
sl@0
   183
 
sl@0
   184
EXPORT_C void** _oil_function_class_ptr_mt19937x8 ()	{
sl@0
   185
	oil_function_class_ptr_mt19937x8 = __oil_function_class_mt19937x8();
sl@0
   186
	return &oil_function_class_ptr_mt19937x8->func;
sl@0
   187
	}
sl@0
   188
#endif
sl@0
   189
#endif