OpenCores
URL https://opencores.org/ocsvn/systemc_rng/systemc_rng/trunk

Subversion Repositories systemc_rng

[/] [systemc_rng/] [trunk/] [rtl/] [systemc/] [rng.cpp] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jcastillo
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Random Number Generator Top                                 ////
4
////                                                              ////
5
////  This file is part of the SystemC RNG project                ////
6
////                                                              ////
7
////  Description:                                                ////
8
////  Top file of random number generator                         ////
9
////                                                              ////
10
////  To Do:                                                      ////
11
////   - nothing                                                  ////
12
////                                                              ////
13
////  Author(s):                                                  ////
14 11 jcastillo
////      - Javier Castillo, javier.castillo@urjc.es              ////
15 2 jcastillo
////                                                              ////
16 11 jcastillo
////  This core is provided by Universidad Rey Juan Carlos        ////
17
////  http://www.escet.urjc.es/~jmartine                          ////
18 2 jcastillo
////                                                              ////
19
//////////////////////////////////////////////////////////////////////
20
////                                                              ////
21
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
22
////                                                              ////
23
//// This source file may be used and distributed without         ////
24
//// restriction provided that this copyright statement is not    ////
25
//// removed from the file and that any derivative work contains  ////
26
//// the original copyright notice and the associated disclaimer. ////
27
////                                                              ////
28
//// This source file is free software; you can redistribute it   ////
29
//// and/or modify it under the terms of the GNU Lesser General   ////
30
//// Public License as published by the Free Software Foundation; ////
31
//// either version 2.1 of the License, or (at your option) any   ////
32
//// later version.                                               ////
33
////                                                              ////
34
//// This source is distributed in the hope that it will be       ////
35
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
36
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
37
//// PURPOSE.  See the GNU Lesser General Public License for more ////
38
//// details.                                                     ////
39
////                                                              ////
40
//// You should have received a copy of the GNU Lesser General    ////
41
//// Public License along with this source; if not, download it   ////
42
//// from http://www.opencores.org/lgpl.shtml                     ////
43
////                                                              ////
44
//////////////////////////////////////////////////////////////////////
45
//
46
// CVS Revision History
47
//
48
// $Log: not supported by cvs2svn $
49 11 jcastillo
// Revision 1.5  2005/07/30 20:07:26  jcastillo
50
// Correct bit 28. Correct assignation to bit 31
51
//
52 10 jcastillo
// Revision 1.4  2005/07/29 09:12:41  jcastillo
53
// Correct bit 28 of CASR
54
//
55 9 jcastillo
// Revision 1.3  2004/09/23 09:45:30  jcastillo
56
// Macro removed
57
//
58 8 jcastillo
// Revision 1.2  2004/08/30 17:01:50  jcastillo
59
// Used indent command
60
//
61 6 jcastillo
// Revision 1.1.1.1  2004/08/19 14:27:14  jcastillo
62
// First import
63
//
64 2 jcastillo
 
65
#include "rng.h"
66
 
67 6 jcastillo
void
68
rng::combinate ()
69
{
70
  if (!reset.read ())
71
    {
72
      number_o.write (0);
73
    }
74
  else
75
    {
76 8 jcastillo
      number_o.write (LFSR_reg.read ().range (31, 0) ^ CASR_reg.read ().range (31, 0));
77 6 jcastillo
    }
78 2 jcastillo
}
79
 
80 6 jcastillo
void
81
rng::LFSR ()
82
{
83
 
84
  sc_uint < 43 > LFSR_var;
85
  bool outbit;
86
 
87
  if (!reset.read ())
88
    {
89
      LFSR_reg.write (1);
90
    }
91
  else
92
    {
93
      if (loadseed_i.read ())
94
        {
95 10 jcastillo
          LFSR_var.range (42, 32) = 0;
96 6 jcastillo
          LFSR_var.range (31, 0) = seed_i.read ();
97
          LFSR_reg.write (LFSR_var);
98
 
99
        }
100
      else
101
        {
102
          LFSR_var = LFSR_reg.read ();
103
 
104
          outbit = LFSR_var[42];
105
          LFSR_var[42] = LFSR_var[41];
106
          LFSR_var[41] = LFSR_var[40] ^ outbit;
107
          LFSR_var[40] = LFSR_var[39];
108
          LFSR_var[39] = LFSR_var[38];
109
          LFSR_var[38] = LFSR_var[37];
110
          LFSR_var[37] = LFSR_var[36];
111
          LFSR_var[36] = LFSR_var[35];
112
          LFSR_var[35] = LFSR_var[34];
113
          LFSR_var[34] = LFSR_var[33];
114
          LFSR_var[33] = LFSR_var[32];
115
          LFSR_var[32] = LFSR_var[31];
116
          LFSR_var[31] = LFSR_var[30];
117
          LFSR_var[30] = LFSR_var[29];
118
          LFSR_var[29] = LFSR_var[28];
119
          LFSR_var[28] = LFSR_var[27];
120
          LFSR_var[27] = LFSR_var[26];
121
          LFSR_var[26] = LFSR_var[25];
122
          LFSR_var[25] = LFSR_var[24];
123
          LFSR_var[24] = LFSR_var[23];
124
          LFSR_var[23] = LFSR_var[22];
125
          LFSR_var[22] = LFSR_var[21];
126
          LFSR_var[21] = LFSR_var[20];
127
          LFSR_var[20] = LFSR_var[19] ^ outbit;
128
          LFSR_var[19] = LFSR_var[18];
129
          LFSR_var[18] = LFSR_var[17];
130
          LFSR_var[17] = LFSR_var[16];
131
          LFSR_var[16] = LFSR_var[15];
132
          LFSR_var[15] = LFSR_var[14];
133
          LFSR_var[14] = LFSR_var[13];
134
          LFSR_var[13] = LFSR_var[12];
135
          LFSR_var[12] = LFSR_var[11];
136
          LFSR_var[11] = LFSR_var[10];
137
          LFSR_var[10] = LFSR_var[9];
138
          LFSR_var[9] = LFSR_var[8];
139
          LFSR_var[8] = LFSR_var[7];
140
          LFSR_var[7] = LFSR_var[6];
141
          LFSR_var[6] = LFSR_var[5];
142
          LFSR_var[5] = LFSR_var[4];
143
          LFSR_var[4] = LFSR_var[3];
144
          LFSR_var[3] = LFSR_var[2];
145
          LFSR_var[2] = LFSR_var[1];
146
          LFSR_var[1] = LFSR_var[0] ^ outbit;
147
          LFSR_var[0] = LFSR_var[42];
148
 
149
          LFSR_reg.write (LFSR_var);
150
        }
151
    }
152 2 jcastillo
}
153
 
154 6 jcastillo
void
155
rng::CASR ()
156
{
157
 
158 8 jcastillo
  sc_uint < 37 > CASR_var, CASR_out;
159 6 jcastillo
 
160
  if (!reset.read ())
161
    {
162
      CASR_reg.write (1);
163
    }
164
  else
165
    {
166
      if (loadseed_i.read ())
167
        {
168 10 jcastillo
          CASR_var.range (36, 32) = 0;
169 6 jcastillo
          CASR_var.range (31, 0) = seed_i.read ();
170
          CASR_reg.write (CASR_var);
171
 
172
        }
173
      else
174
        {
175
          CASR_var = CASR_reg.read ();
176
 
177
          CASR_out[36] = CASR_var[35] ^ CASR_var[0];
178
          CASR_out[35] = CASR_var[34] ^ CASR_var[36];
179
          CASR_out[34] = CASR_var[33] ^ CASR_var[35];
180
          CASR_out[33] = CASR_var[32] ^ CASR_var[34];
181
          CASR_out[32] = CASR_var[31] ^ CASR_var[33];
182
          CASR_out[31] = CASR_var[30] ^ CASR_var[32];
183
          CASR_out[30] = CASR_var[29] ^ CASR_var[31];
184
          CASR_out[29] = CASR_var[28] ^ CASR_var[30];
185 10 jcastillo
          CASR_out[28] = CASR_var[27] ^ CASR_var[29];
186
          CASR_out[27] = CASR_var[26] ^ CASR_var[27] ^ CASR_var[28];
187 6 jcastillo
          CASR_out[26] = CASR_var[25] ^ CASR_var[27];
188
          CASR_out[25] = CASR_var[24] ^ CASR_var[26];
189
          CASR_out[24] = CASR_var[23] ^ CASR_var[25];
190
          CASR_out[23] = CASR_var[22] ^ CASR_var[24];
191
          CASR_out[22] = CASR_var[21] ^ CASR_var[23];
192
          CASR_out[21] = CASR_var[20] ^ CASR_var[22];
193
          CASR_out[20] = CASR_var[19] ^ CASR_var[21];
194
          CASR_out[19] = CASR_var[18] ^ CASR_var[20];
195
          CASR_out[18] = CASR_var[17] ^ CASR_var[19];
196
          CASR_out[17] = CASR_var[16] ^ CASR_var[18];
197
          CASR_out[16] = CASR_var[15] ^ CASR_var[17];
198
          CASR_out[15] = CASR_var[14] ^ CASR_var[16];
199
          CASR_out[14] = CASR_var[13] ^ CASR_var[15];
200
          CASR_out[13] = CASR_var[12] ^ CASR_var[14];
201
          CASR_out[12] = CASR_var[11] ^ CASR_var[13];
202
          CASR_out[11] = CASR_var[10] ^ CASR_var[12];
203
          CASR_out[10] = CASR_var[9] ^ CASR_var[11];
204
          CASR_out[9] = CASR_var[8] ^ CASR_var[10];
205
          CASR_out[8] = CASR_var[7] ^ CASR_var[9];
206
          CASR_out[7] = CASR_var[6] ^ CASR_var[8];
207
          CASR_out[6] = CASR_var[5] ^ CASR_var[7];
208
          CASR_out[5] = CASR_var[4] ^ CASR_var[6];
209
          CASR_out[4] = CASR_var[3] ^ CASR_var[5];
210
          CASR_out[3] = CASR_var[2] ^ CASR_var[4];
211
          CASR_out[2] = CASR_var[1] ^ CASR_var[3];
212
          CASR_out[1] = CASR_var[0] ^ CASR_var[2];
213
          CASR_out[0] = CASR_var[36] ^ CASR_var[1];
214
 
215
          CASR_reg.write (CASR_out);
216
        }
217
    }
218 2 jcastillo
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.