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 |
|
|
//// - Javier Castillo, jcastilo@opencores.org ////
|
15 |
|
|
//// ////
|
16 |
|
|
//// This core is provided by OpenSoc ////
|
17 |
|
|
//// http://www.opensocdesign.com ////
|
18 |
|
|
//// ////
|
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 |
8 |
jcastillo |
// Revision 1.2 2004/08/30 17:01:50 jcastillo
|
50 |
|
|
// Used indent command
|
51 |
|
|
//
|
52 |
6 |
jcastillo |
// Revision 1.1.1.1 2004/08/19 14:27:14 jcastillo
|
53 |
|
|
// First import
|
54 |
|
|
//
|
55 |
2 |
jcastillo |
|
56 |
|
|
#include "rng.h"
|
57 |
|
|
|
58 |
6 |
jcastillo |
void
|
59 |
|
|
rng::combinate ()
|
60 |
|
|
{
|
61 |
|
|
if (!reset.read ())
|
62 |
|
|
{
|
63 |
|
|
number_o.write (0);
|
64 |
|
|
}
|
65 |
|
|
else
|
66 |
|
|
{
|
67 |
8 |
jcastillo |
number_o.write (LFSR_reg.read ().range (31, 0) ^ CASR_reg.read ().range (31, 0));
|
68 |
6 |
jcastillo |
}
|
69 |
2 |
jcastillo |
}
|
70 |
|
|
|
71 |
6 |
jcastillo |
void
|
72 |
|
|
rng::LFSR ()
|
73 |
|
|
{
|
74 |
|
|
|
75 |
|
|
sc_uint < 43 > LFSR_var;
|
76 |
|
|
bool outbit;
|
77 |
|
|
|
78 |
|
|
if (!reset.read ())
|
79 |
|
|
{
|
80 |
|
|
LFSR_reg.write (1);
|
81 |
|
|
}
|
82 |
|
|
else
|
83 |
|
|
{
|
84 |
|
|
if (loadseed_i.read ())
|
85 |
|
|
{
|
86 |
|
|
LFSR_var.range (42, 31) = 0;
|
87 |
|
|
LFSR_var.range (31, 0) = seed_i.read ();
|
88 |
|
|
LFSR_reg.write (LFSR_var);
|
89 |
|
|
|
90 |
|
|
}
|
91 |
|
|
else
|
92 |
|
|
{
|
93 |
|
|
LFSR_var = LFSR_reg.read ();
|
94 |
|
|
|
95 |
|
|
outbit = LFSR_var[42];
|
96 |
|
|
LFSR_var[42] = LFSR_var[41];
|
97 |
|
|
LFSR_var[41] = LFSR_var[40] ^ outbit;
|
98 |
|
|
LFSR_var[40] = LFSR_var[39];
|
99 |
|
|
LFSR_var[39] = LFSR_var[38];
|
100 |
|
|
LFSR_var[38] = LFSR_var[37];
|
101 |
|
|
LFSR_var[37] = LFSR_var[36];
|
102 |
|
|
LFSR_var[36] = LFSR_var[35];
|
103 |
|
|
LFSR_var[35] = LFSR_var[34];
|
104 |
|
|
LFSR_var[34] = LFSR_var[33];
|
105 |
|
|
LFSR_var[33] = LFSR_var[32];
|
106 |
|
|
LFSR_var[32] = LFSR_var[31];
|
107 |
|
|
LFSR_var[31] = LFSR_var[30];
|
108 |
|
|
LFSR_var[30] = LFSR_var[29];
|
109 |
|
|
LFSR_var[29] = LFSR_var[28];
|
110 |
|
|
LFSR_var[28] = LFSR_var[27];
|
111 |
|
|
LFSR_var[27] = LFSR_var[26];
|
112 |
|
|
LFSR_var[26] = LFSR_var[25];
|
113 |
|
|
LFSR_var[25] = LFSR_var[24];
|
114 |
|
|
LFSR_var[24] = LFSR_var[23];
|
115 |
|
|
LFSR_var[23] = LFSR_var[22];
|
116 |
|
|
LFSR_var[22] = LFSR_var[21];
|
117 |
|
|
LFSR_var[21] = LFSR_var[20];
|
118 |
|
|
LFSR_var[20] = LFSR_var[19] ^ outbit;
|
119 |
|
|
LFSR_var[19] = LFSR_var[18];
|
120 |
|
|
LFSR_var[18] = LFSR_var[17];
|
121 |
|
|
LFSR_var[17] = LFSR_var[16];
|
122 |
|
|
LFSR_var[16] = LFSR_var[15];
|
123 |
|
|
LFSR_var[15] = LFSR_var[14];
|
124 |
|
|
LFSR_var[14] = LFSR_var[13];
|
125 |
|
|
LFSR_var[13] = LFSR_var[12];
|
126 |
|
|
LFSR_var[12] = LFSR_var[11];
|
127 |
|
|
LFSR_var[11] = LFSR_var[10];
|
128 |
|
|
LFSR_var[10] = LFSR_var[9];
|
129 |
|
|
LFSR_var[9] = LFSR_var[8];
|
130 |
|
|
LFSR_var[8] = LFSR_var[7];
|
131 |
|
|
LFSR_var[7] = LFSR_var[6];
|
132 |
|
|
LFSR_var[6] = LFSR_var[5];
|
133 |
|
|
LFSR_var[5] = LFSR_var[4];
|
134 |
|
|
LFSR_var[4] = LFSR_var[3];
|
135 |
|
|
LFSR_var[3] = LFSR_var[2];
|
136 |
|
|
LFSR_var[2] = LFSR_var[1];
|
137 |
|
|
LFSR_var[1] = LFSR_var[0] ^ outbit;
|
138 |
|
|
LFSR_var[0] = LFSR_var[42];
|
139 |
|
|
|
140 |
|
|
LFSR_reg.write (LFSR_var);
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
2 |
jcastillo |
}
|
144 |
|
|
|
145 |
6 |
jcastillo |
void
|
146 |
|
|
rng::CASR ()
|
147 |
|
|
{
|
148 |
|
|
|
149 |
8 |
jcastillo |
sc_uint < 37 > CASR_var, CASR_out;
|
150 |
6 |
jcastillo |
|
151 |
|
|
if (!reset.read ())
|
152 |
|
|
{
|
153 |
|
|
CASR_reg.write (1);
|
154 |
|
|
}
|
155 |
|
|
else
|
156 |
|
|
{
|
157 |
|
|
if (loadseed_i.read ())
|
158 |
|
|
{
|
159 |
|
|
CASR_var.range (36, 31) = 0;
|
160 |
|
|
CASR_var.range (31, 0) = seed_i.read ();
|
161 |
|
|
CASR_reg.write (CASR_var);
|
162 |
|
|
|
163 |
|
|
}
|
164 |
|
|
else
|
165 |
|
|
{
|
166 |
|
|
CASR_var = CASR_reg.read ();
|
167 |
|
|
|
168 |
|
|
CASR_out[36] = CASR_var[35] ^ CASR_var[0];
|
169 |
|
|
CASR_out[35] = CASR_var[34] ^ CASR_var[36];
|
170 |
|
|
CASR_out[34] = CASR_var[33] ^ CASR_var[35];
|
171 |
|
|
CASR_out[33] = CASR_var[32] ^ CASR_var[34];
|
172 |
|
|
CASR_out[32] = CASR_var[31] ^ CASR_var[33];
|
173 |
|
|
CASR_out[31] = CASR_var[30] ^ CASR_var[32];
|
174 |
|
|
CASR_out[30] = CASR_var[29] ^ CASR_var[31];
|
175 |
|
|
CASR_out[29] = CASR_var[28] ^ CASR_var[30];
|
176 |
|
|
CASR_out[28] = CASR_var[27] ^ CASR_var[29];
|
177 |
|
|
CASR_out[27] = CASR_var[26] ^ CASR_var[28];
|
178 |
|
|
CASR_out[26] = CASR_var[25] ^ CASR_var[27];
|
179 |
|
|
CASR_out[25] = CASR_var[24] ^ CASR_var[26];
|
180 |
|
|
CASR_out[24] = CASR_var[23] ^ CASR_var[25];
|
181 |
|
|
CASR_out[23] = CASR_var[22] ^ CASR_var[24];
|
182 |
|
|
CASR_out[22] = CASR_var[21] ^ CASR_var[23];
|
183 |
|
|
CASR_out[21] = CASR_var[20] ^ CASR_var[22];
|
184 |
|
|
CASR_out[20] = CASR_var[19] ^ CASR_var[21];
|
185 |
|
|
CASR_out[19] = CASR_var[18] ^ CASR_var[20];
|
186 |
|
|
CASR_out[18] = CASR_var[17] ^ CASR_var[19];
|
187 |
|
|
CASR_out[17] = CASR_var[16] ^ CASR_var[18];
|
188 |
|
|
CASR_out[16] = CASR_var[15] ^ CASR_var[17];
|
189 |
|
|
CASR_out[15] = CASR_var[14] ^ CASR_var[16];
|
190 |
|
|
CASR_out[14] = CASR_var[13] ^ CASR_var[15];
|
191 |
|
|
CASR_out[13] = CASR_var[12] ^ CASR_var[14];
|
192 |
|
|
CASR_out[12] = CASR_var[11] ^ CASR_var[13];
|
193 |
|
|
CASR_out[11] = CASR_var[10] ^ CASR_var[12];
|
194 |
|
|
CASR_out[10] = CASR_var[9] ^ CASR_var[11];
|
195 |
|
|
CASR_out[9] = CASR_var[8] ^ CASR_var[10];
|
196 |
|
|
CASR_out[8] = CASR_var[7] ^ CASR_var[9];
|
197 |
|
|
CASR_out[7] = CASR_var[6] ^ CASR_var[8];
|
198 |
|
|
CASR_out[6] = CASR_var[5] ^ CASR_var[7];
|
199 |
|
|
CASR_out[5] = CASR_var[4] ^ CASR_var[6];
|
200 |
|
|
CASR_out[4] = CASR_var[3] ^ CASR_var[5];
|
201 |
|
|
CASR_out[3] = CASR_var[2] ^ CASR_var[4];
|
202 |
|
|
CASR_out[2] = CASR_var[1] ^ CASR_var[3];
|
203 |
|
|
CASR_out[1] = CASR_var[0] ^ CASR_var[2];
|
204 |
|
|
CASR_out[0] = CASR_var[36] ^ CASR_var[1];
|
205 |
|
|
|
206 |
|
|
CASR_reg.write (CASR_out);
|
207 |
|
|
}
|
208 |
|
|
}
|
209 |
2 |
jcastillo |
}
|