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 2

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
 
50
#include "rng.h"
51
 
52
void rng::combinate(){
53
        if(!reset.read()){
54
                number_o.write(0);
55
        }else{
56
           number_o.write(LFSR_reg.read().range(31,0)^CASR_reg.read().range(31,0));
57
        }
58
}
59
 
60
void rng::LFSR(){
61
 
62
        sc_uint<43> LFSR_var;
63
        bool outbit;
64
 
65
        if(!reset.read()){
66
                LFSR_reg.write(1);
67
        }else{
68
                if(loadseed_i.read()){
69
                        LFSR_var.range(42,31)=0;
70
                        LFSR_var.range(31,0)=seed_i.read();
71
                        LFSR_reg.write(LFSR_var);
72
 
73
                }else{
74
                  LFSR_var=LFSR_reg.read();
75
 
76
                  outbit=LFSR_var[42];
77
                  LFSR_var[42]=LFSR_var[41];
78
                  LFSR_var[41]=LFSR_var[40]^outbit;
79
                  LFSR_var[40]=LFSR_var[39];
80
                  LFSR_var[39]=LFSR_var[38];
81
                  LFSR_var[38]=LFSR_var[37];
82
                  LFSR_var[37]=LFSR_var[36];
83
                  LFSR_var[36]=LFSR_var[35];
84
                  LFSR_var[35]=LFSR_var[34];
85
                  LFSR_var[34]=LFSR_var[33];
86
                  LFSR_var[33]=LFSR_var[32];
87
                  LFSR_var[32]=LFSR_var[31];
88
                  LFSR_var[31]=LFSR_var[30];
89
                  LFSR_var[30]=LFSR_var[29];
90
                  LFSR_var[29]=LFSR_var[28];
91
                  LFSR_var[28]=LFSR_var[27];
92
                  LFSR_var[27]=LFSR_var[26];
93
                  LFSR_var[26]=LFSR_var[25];
94
                  LFSR_var[25]=LFSR_var[24];
95
                  LFSR_var[24]=LFSR_var[23];
96
                  LFSR_var[23]=LFSR_var[22];
97
                  LFSR_var[22]=LFSR_var[21];
98
                  LFSR_var[21]=LFSR_var[20];
99
                  LFSR_var[20]=LFSR_var[19]^outbit;
100
                  LFSR_var[19]=LFSR_var[18];
101
                  LFSR_var[18]=LFSR_var[17];
102
                  LFSR_var[17]=LFSR_var[16];
103
                  LFSR_var[16]=LFSR_var[15];
104
                  LFSR_var[15]=LFSR_var[14];
105
                  LFSR_var[14]=LFSR_var[13];
106
                  LFSR_var[13]=LFSR_var[12];
107
                  LFSR_var[12]=LFSR_var[11];
108
                  LFSR_var[11]=LFSR_var[10];
109
                  LFSR_var[10]=LFSR_var[9];
110
                  LFSR_var[9]=LFSR_var[8];
111
                  LFSR_var[8]=LFSR_var[7];
112
                  LFSR_var[7]=LFSR_var[6];
113
                  LFSR_var[6]=LFSR_var[5];
114
                  LFSR_var[5]=LFSR_var[4];
115
                  LFSR_var[4]=LFSR_var[3];
116
                  LFSR_var[3]=LFSR_var[2];
117
                  LFSR_var[2]=LFSR_var[1];
118
                  LFSR_var[1]=LFSR_var[0]^outbit;
119
                  LFSR_var[0]=LFSR_var[42];
120
 
121
          LFSR_reg.write(LFSR_var);
122
          }
123
  }
124
}
125
 
126
void rng::CASR(){
127
 
128
        sc_uint<43> CASR_var,CASR_out;
129
 
130
        if(!reset.read()){
131
                CASR_reg.write(1);
132
        }else{
133
                if(loadseed_i.read()){
134
                        CASR_var.range(36,31)=0;
135
                        CASR_var.range(31,0)=seed_i.read();
136
                        CASR_reg.write(CASR_var);
137
 
138
                }else{
139
                  CASR_var=CASR_reg.read();
140
 
141
                  CASR_out[36]=CASR_var[35]^CASR_var[0] ;
142
                  CASR_out[35]=CASR_var[34]^CASR_var[36] ;
143
                  CASR_out[34]=CASR_var[33]^CASR_var[35] ;
144
                  CASR_out[33]=CASR_var[32]^CASR_var[34] ;
145
                  CASR_out[32]=CASR_var[31]^CASR_var[33] ;
146
                  CASR_out[31]=CASR_var[30]^CASR_var[32] ;
147
                  CASR_out[30]=CASR_var[29]^CASR_var[31] ;
148
                  CASR_out[29]=CASR_var[28]^CASR_var[30] ;
149
                  CASR_out[28]=CASR_var[27]^CASR_var[29] ;
150
                  CASR_out[27]=CASR_var[26]^CASR_var[28] ;
151
                  CASR_out[26]=CASR_var[25]^CASR_var[27] ;
152
                  CASR_out[25]=CASR_var[24]^CASR_var[26] ;
153
                  CASR_out[24]=CASR_var[23]^CASR_var[25] ;
154
                  CASR_out[23]=CASR_var[22]^CASR_var[24] ;
155
                  CASR_out[22]=CASR_var[21]^CASR_var[23] ;
156
                  CASR_out[21]=CASR_var[20]^CASR_var[22] ;
157
                  CASR_out[20]=CASR_var[19]^CASR_var[21] ;
158
                  CASR_out[19]=CASR_var[18]^CASR_var[20] ;
159
                  CASR_out[18]=CASR_var[17]^CASR_var[19] ;
160
                  CASR_out[17]=CASR_var[16]^CASR_var[18] ;
161
                  CASR_out[16]=CASR_var[15]^CASR_var[17] ;
162
                  CASR_out[15]=CASR_var[14]^CASR_var[16] ;
163
                  CASR_out[14]=CASR_var[13]^CASR_var[15] ;
164
                  CASR_out[13]=CASR_var[12]^CASR_var[14] ;
165
                  CASR_out[12]=CASR_var[11]^CASR_var[13] ;
166
                  CASR_out[11]=CASR_var[10]^CASR_var[12] ;
167
                  CASR_out[10]=CASR_var[9]^CASR_var[11] ;
168
                  CASR_out[9]=CASR_var[8]^CASR_var[10] ;
169
                  CASR_out[8]=CASR_var[7]^CASR_var[9] ;
170
                  CASR_out[7]=CASR_var[6]^CASR_var[8] ;
171
                  CASR_out[6]=CASR_var[5]^CASR_var[7] ;
172
                  CASR_out[5]=CASR_var[4]^CASR_var[6] ;
173
                  CASR_out[4]=CASR_var[3]^CASR_var[5] ;
174
                  CASR_out[3]=CASR_var[2]^CASR_var[4] ;
175
                  CASR_out[2]=CASR_var[1]^CASR_var[3] ;
176
                  CASR_out[1]=CASR_var[0]^CASR_var[2] ;
177
                  CASR_out[0]=CASR_var[36]^CASR_var[1] ;
178
 
179
          CASR_reg.write(CASR_out);
180
          }
181
  }
182
}

powered by: WebSVN 2.1.0

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