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

Subversion Repositories thor

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 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_regfile2w6r(clk, wr0, wr1, wa0, wa1, i0, i1,
27
        rclk, ra0, ra1, ra2, ra3, ra4, ra5, o0, o1, o2, o3, o4, o5);
28
parameter WID=64;
29
input clk;
30
input wr0;
31
input wr1;
32 42 robfinch
input [7:0] wa0;
33
input [7:0] wa1;
34 3 robfinch
input [WID-1:0] i0;
35
input [WID-1:0] i1;
36
input rclk;
37 42 robfinch
input [7:0] ra0;
38
input [7:0] ra1;
39
input [7:0] ra2;
40
input [7:0] ra3;
41
input [7:0] ra4;
42
input [7:0] ra5;
43 3 robfinch
output [WID-1:0] o0;
44
output [WID-1:0] o1;
45
output [WID-1:0] o2;
46
output [WID-1:0] o3;
47
output [WID-1:0] o4;
48
output [WID-1:0] o5;
49
 
50 42 robfinch
reg [WID-1:0] regs0 [0:255];
51
reg [WID-1:0] regs1 [0:255];
52
reg [7:0] rra0,rra1,rra2,rra3,rra4,rra5;
53 3 robfinch
 
54 42 robfinch
reg whichreg [0:255];    // tracks which register file is the valid one for a given register
55 3 robfinch
 
56
// We only care about what's in the regs to begin with in simulation. In sim
57
// the 'x' values propagate screwing things up. In real hardware there's no such
58
// thing as an 'x'.
59
`define SIMULATION
60
`ifdef SIMULATION
61
integer n;
62
initial begin
63
    for (n = 0; n < 64; n = n + 1)
64
    begin
65
        regs0[n] = 0;
66
        regs1[n] = 0;
67
        whichreg[n] = 0;
68
    end
69
end
70
`endif
71
 
72
 
73 42 robfinch
assign o0 = rra0[5:0]==6'd0 ? {WID{1'b0}} :
74 3 robfinch
        (wr1 && (rra0==wa1)) ? i1 :
75
        (wr0 && (rra0==wa0)) ? i0 :
76
        whichreg[rra0]==1'b0 ? regs0[rra0] : regs1[rra0];
77 42 robfinch
assign o1 = rra1[5:0]==6'd0 ? {WID{1'b0}} :
78 3 robfinch
        (wr1 && (rra1==wa1)) ? i1 :
79
        (wr0 && (rra1==wa0)) ? i0 :
80
        whichreg[rra1]==1'b0 ? regs0[rra1] : regs1[rra1];
81 42 robfinch
assign o2 = rra2[5:0]==6'd0 ? {WID{1'b0}} :
82 3 robfinch
        (wr1 && (rra2==wa1)) ? i1 :
83
        (wr0 && (rra2==wa0)) ? i0 :
84
        whichreg[rra2]==1'b0 ? regs0[rra2] : regs1[rra2];
85 42 robfinch
assign o3 = rra3[5:0]==6'd0 ? {WID{1'b0}} :
86 3 robfinch
        (wr1 && (rra3==wa1)) ? i1 :
87
        (wr0 && (rra3==wa0)) ? i0 :
88
        whichreg[rra3]==1'b0 ? regs0[rra3] : regs1[rra3];
89 42 robfinch
assign o4 = rra4[5:0]==6'd0 ? {WID{1'b0}} :
90 3 robfinch
    (wr1 && (rra4==wa1)) ? i1 :
91
    (wr0 && (rra4==wa0)) ? i0 :
92
    whichreg[rra4]==1'b0 ? regs0[rra4] : regs1[rra4];
93 42 robfinch
assign o5 = rra5[5:0]==6'd0 ? {WID{1'b0}} :
94 3 robfinch
    (wr1 && (rra5==wa1)) ? i1 :
95
    (wr0 && (rra5==wa0)) ? i0 :
96
    whichreg[rra5]==1'b0 ? regs0[rra5] : regs1[rra5];
97
 
98
always @(posedge clk)
99
        if (wr0)
100
                regs0[wa0] <= i0;
101
 
102
always @(posedge clk)
103
        if (wr1)
104
                regs1[wa1] <= i1;
105
 
106
always @(posedge rclk) rra0 <= ra0;
107
always @(posedge rclk) rra1 <= ra1;
108
always @(posedge rclk) rra2 <= ra2;
109
always @(posedge rclk) rra3 <= ra3;
110
always @(posedge rclk) rra4 <= ra4;
111
always @(posedge rclk) rra5 <= ra5;
112
 
113
always @(posedge clk)
114
        // writing three registers at once
115
        if (wr0 && wr1 && wa0==wa1)             // Two ports writing the same address
116
                whichreg[wa0] <= 1'b1;          // port one is the valid one
117
        // writing two registers
118
        else if (wr0 && wr1) begin
119
                whichreg[wa0] <= 1'b0;
120
                whichreg[wa1] <= 1'b1;
121
        end
122
        // writing a single register
123
        else if (wr0)
124
                whichreg[wa0] <= 1'b0;
125
        else if (wr1)
126
                whichreg[wa1] <= 1'b1;
127
 
128
endmodule

powered by: WebSVN 2.1.0

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