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

Subversion Repositories thor

[/] [thor/] [trunk/] [rtl/] [verilog/] [Thor_vregfile2w6r.v] - Blame information for rev 42

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 42 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2013,2015  Robert Finch, Stratford
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch<remove>@finitron.ca
7
//       ||
8
//
9
// This source file is free software: you can redistribute it and/or modify 
10
// it under the terms of the GNU Lesser General Public License as published 
11
// by the Free Software Foundation, either version 3 of the License, or     
12
// (at your option) any later version.                                      
13
//                                                                          
14
// This source file is distributed in the hope that it will be useful,      
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
17
// GNU General Public License for more details.                             
18
//                                                                          
19
// You should have received a copy of the GNU General Public License        
20
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
21
//
22
//
23
// Register file with two write ports and six read ports.
24
// ============================================================================
25
//
26
module Thor_vregfile2w6r(clk, wr0, wr1, wa0, wa1, i0, i1,
27
        rclk, ra0, ra1, ra2, ra3, ra4, ra5, ra6, ra7,
28
        o0, o1, o2, o3, o4, o5, o6, o7);
29
parameter WID=32;
30
input clk;
31
input wr0;
32
input wr1;
33
input [6:0] wa0;
34
input [6:0] wa1;
35
input [WID-1:0] i0;
36
input [WID-1:0] i1;
37
input rclk;
38
input [6:0] ra0;
39
input [6:0] ra1;
40
input [6:0] ra2;
41
input [6:0] ra3;
42
input [6:0] ra4;
43
input [6:0] ra5;
44
input [6:0] ra6;
45
input [6:0] ra7;
46
output [WID-1:0] o0;
47
output [WID-1:0] o1;
48
output [WID-1:0] o2;
49
output [WID-1:0] o3;
50
output [WID-1:0] o4;
51
output [WID-1:0] o5;
52
output [WID-1:0] o6;
53
output [WID-1:0] o7;
54
 
55
reg [WID-1:0] regs0 [0:127];
56
reg [WID-1:0] regs1 [0:127];
57
reg [6:0] rra0,rra1,rra2,rra3,rra4,rra5,rra6,rra7;
58
 
59
reg whichreg [0:127];    // tracks which register file is the valid one for a given register
60
 
61
// We only care about what's in the regs to begin with in simulation. In sim
62
// the 'x' values propagate screwing things up. In real hardware there's no such
63
// thing as an 'x'.
64
`define SIMULATION
65
`ifdef SIMULATION
66
integer n;
67
initial begin
68
    for (n = 0; n < 128; n = n + 1)
69
    begin
70
        regs0[n] = 0;
71
        regs1[n] = 0;
72
        whichreg[n] = 0;
73
    end
74
end
75
`endif
76
 
77
 
78
assign o0 =
79
        (wr1 && (rra0==wa1)) ? i1 :
80
        (wr0 && (rra0==wa0)) ? i0 :
81
        whichreg[rra0]==1'b0 ? regs0[rra0] : regs1[rra0];
82
assign o1 =
83
        (wr1 && (rra1==wa1)) ? i1 :
84
        (wr0 && (rra1==wa0)) ? i0 :
85
        whichreg[rra1]==1'b0 ? regs0[rra1] : regs1[rra1];
86
assign o2 =
87
        (wr1 && (rra2==wa1)) ? i1 :
88
        (wr0 && (rra2==wa0)) ? i0 :
89
        whichreg[rra2]==1'b0 ? regs0[rra2] : regs1[rra2];
90
assign o3 =
91
        (wr1 && (rra3==wa1)) ? i1 :
92
        (wr0 && (rra3==wa0)) ? i0 :
93
        whichreg[rra3]==1'b0 ? regs0[rra3] : regs1[rra3];
94
assign o4 =
95
    (wr1 && (rra4==wa1)) ? i1 :
96
    (wr0 && (rra4==wa0)) ? i0 :
97
    whichreg[rra4]==1'b0 ? regs0[rra4] : regs1[rra4];
98
assign o5 =
99
    (wr1 && (rra5==wa1)) ? i1 :
100
    (wr0 && (rra5==wa0)) ? i0 :
101
    whichreg[rra5]==1'b0 ? regs0[rra5] : regs1[rra5];
102
assign o6 =
103
    (wr1 && (rra6==wa1)) ? i1 :
104
    (wr0 && (rra6==wa0)) ? i0 :
105
    whichreg[rra6]==1'b0 ? regs0[rra6] : regs1[rra6];
106
assign o7 =
107
    (wr1 && (rra7==wa1)) ? i1 :
108
    (wr0 && (rra7==wa0)) ? i0 :
109
    whichreg[rra7]==1'b0 ? regs0[rra7] : regs1[rra7];
110
 
111
always @(posedge clk)
112
        if (wr0)
113
                regs0[wa0] <= i0;
114
 
115
always @(posedge clk)
116
        if (wr1)
117
                regs1[wa1] <= i1;
118
 
119
always @(posedge rclk) rra0 <= ra0;
120
always @(posedge rclk) rra1 <= ra1;
121
always @(posedge rclk) rra2 <= ra2;
122
always @(posedge rclk) rra3 <= ra3;
123
always @(posedge rclk) rra4 <= ra4;
124
always @(posedge rclk) rra5 <= ra5;
125
always @(posedge rclk) rra6 <= ra6;
126
always @(posedge rclk) rra7 <= ra7;
127
 
128
always @(posedge clk)
129
        // writing three registers at once
130
        if (wr0 && wr1 && wa0==wa1)             // Two ports writing the same address
131
                whichreg[wa0] <= 1'b1;          // port one is the valid one
132
        // writing two registers
133
        else if (wr0 && wr1) begin
134
                whichreg[wa0] <= 1'b0;
135
                whichreg[wa1] <= 1'b1;
136
        end
137
        // writing a single register
138
        else if (wr0)
139
                whichreg[wa0] <= 1'b0;
140
        else if (wr1)
141
                whichreg[wa1] <= 1'b1;
142
 
143
endmodule

powered by: WebSVN 2.1.0

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