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 10

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

powered by: WebSVN 2.1.0

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