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

Subversion Repositories aemb

[/] [aemb/] [branches/] [DEV_SYBREON/] [rtl/] [verilog/] [aeMB2_regf.v] - Blame information for rev 194

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 81 sybreon
/* $Id: aeMB2_regf.v,v 1.3 2007-12-13 20:12:11 sybreon Exp $
2 78 sybreon
**
3
** AEMB2 REGISTER FILE
4
**
5
** Copyright (C) 2004-2007 Shawn Tan Ser Ngiap <shawn.tan@aeste.net>
6
**
7
** This file is part of AEMB.
8
**
9
** AEMB is free software: you can redistribute it and/or modify it
10
** under the terms of the GNU Lesser General Public License as
11
** published by the Free Software Foundation, either version 3 of the
12
** License, or (at your option) any later version.
13
**
14
** AEMB is distributed in the hope that it will be useful, but WITHOUT
15
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
17
** Public License for more details.
18
**
19
** You should have received a copy of the GNU Lesser General Public
20
** License along with AEMB. If not, see <http://www.gnu.org/licenses/>.
21
*/
22
 
23
module aeMB2_regf (/*AUTOARG*/
24
   // Outputs
25
   dwb_dat_o, cwb_dat_o, rREGD_OF, rREGA_OF, rREGB_OF,
26
   // Inputs
27
   dwb_dat_i, dwb_ack_i, cwb_dat_i, cwb_ack_i, rRA_IF, rRB_IF, rRD_IF,
28
   rRD_MA, rOPM_OF, rOPA_OF, rOPC_OF, rPC_MA, rMUL_MA, rRES_MA,
29
   rOPD_MA, rSEL_MA, clk_i, rst_i, ena_i, pha_i
30
   );
31 80 sybreon
   parameter TXE = 1;
32 81 sybreon
   parameter MUL = 1;
33
 
34 78 sybreon
   // DWB
35
   output [31:0] dwb_dat_o;
36
   input [31:0]  dwb_dat_i;
37
   input         dwb_ack_i;
38
 
39
   // FSL
40
   output [31:0] cwb_dat_o;
41
   input [31:0]  cwb_dat_i;
42
   input         cwb_ack_i;
43
 
44
   // INTERNAL
45
   output [31:0] rREGD_OF,
46
                 rREGA_OF,
47
                 rREGB_OF;
48
 
49
   input [4:0]    rRA_IF,
50
                 rRB_IF,
51
                 rRD_IF,
52
                 rRD_MA;
53
 
54
   input [31:0]  rOPM_OF;
55
   input [31:0]  rOPA_OF;
56
   input [5:0]    rOPC_OF;
57
 
58
 
59
   input [31:2]  rPC_MA; ///< link PC
60
   input [31:0]  rMUL_MA; ///< multiplier 2nd stage
61
   input [31:0]  rRES_MA;
62
 
63
   input [2:0]    rOPD_MA;
64
   input [3:0]    rSEL_MA; ///< data select info
65
 
66
   // SYSTEM
67
   input         clk_i,
68
                 rst_i,
69
                 ena_i,
70
                 pha_i;
71
 
72
   /*AUTOREG*/
73
   // Beginning of automatic regs (for this module's undeclared outputs)
74
   reg [31:0]            cwb_dat_o;
75
   reg [31:0]            dwb_dat_o;
76
   // End of automatics
77
 
78
 
79 80 sybreon
   /*
80
    LATCH FSL/RAM.
81
 
82
    This is done on completion of a bus cycle, regardless of the
83
    pipeline status. It's safe to do this as the data is only written
84
    to the registers later. */
85 78 sybreon
 
86
   reg [31:0]            rCWB_MA,
87
                        rDWB_MA;
88
 
89
   always @(posedge clk_i)
90
     if (rst_i) begin
91
        /*AUTORESET*/
92
        // Beginning of autoreset for uninitialized flops
93
        rCWB_MA <= 32'h0;
94
        rDWB_MA <= 32'h0;
95
        // End of automatics
96
     end else begin
97
        if (dwb_ack_i) rDWB_MA <= #1 dwb_dat_i;
98
        if (cwb_ack_i) rCWB_MA <= #1 cwb_dat_i;
99
     end
100
 
101 80 sybreon
   /*
102 81 sybreon
    LOAD RESIZER
103 80 sybreon
 
104
    Resize the latched data for writing into the register. It also
105
    acts as a selector between FSL and DWB. */
106 78 sybreon
 
107
   reg [31:0]     rMEM;
108
   always @(/*AUTOSENSE*/rCWB_MA or rDWB_MA or rSEL_MA) begin
109
      case (rSEL_MA)
110
        // 8'bits
111
        4'h8: rMEM <= {24'd0, rDWB_MA[31:24]};
112
        4'h4: rMEM <= {24'd0, rDWB_MA[23:16]};
113
        4'h2: rMEM <= {24'd0, rDWB_MA[15:8]};
114
        4'h1: rMEM <= {24'd0, rDWB_MA[7:0]};
115
        // 16'bits
116
        4'hC: rMEM <= {16'd0, rDWB_MA[31:16]};
117
        4'h3: rMEM <= {16'd0, rDWB_MA[15:0]};
118
        // 32'bits
119
        4'h0: rMEM <= rCWB_MA;
120
        4'hF: rMEM <= rDWB_MA;
121
        default: rMEM <= 32'hX;
122 80 sybreon
      endcase // case (rSEL_MA)
123
   end // always @ (...
124 78 sybreon
 
125 81 sybreon
   /*
126
    WRITE BACK
127
 
128
    The appropriate data to write into the register file is selected.
129
    */
130 78 sybreon
 
131
   wire [31:0] wREGW;
132
   reg [31:0] rREGD;
133
   always @(/*AUTOSENSE*/rMEM or rMUL_MA or rOPD_MA or rPC_MA
134
            or rRES_MA or wREGW)
135
      case (rOPD_MA)
136
        3'o0: rREGD <= rRES_MA; // ALU
137
        3'o1: rREGD <= {rPC_MA, 2'o0}; // PCLNK
138
        3'o2: rREGD <= rMEM; // RAM/FSL
139 81 sybreon
        3'o3: rREGD <= (MUL) ? rMUL_MA : 32'hX; // Multiplier
140 78 sybreon
        3'o7: rREGD <= wREGW; // Unchanged
141
        default: rREGD <= 32'hX; // Undefined   
142 80 sybreon
      endcase // case (rOPD_MA)
143 78 sybreon
 
144
   /*
145 80 sybreon
    REGISTER FILE
146
 
147 81 sybreon
    Multi-banked dual-port register file. This should be inferred as
148 80 sybreon
    distributed RAM in an FPGA. */
149 78 sybreon
 
150
   reg [31:0]     rRAMA [(32<<TXE)-1:0],
151
                 rRAMB [(32<<TXE)-1:0],
152
                 rRAMD [(32<<TXE)-1:0];
153
 
154
   wire [TXE+4:0] wRA = {!pha_i, rRA_IF};
155
   wire [TXE+4:0] wRB = {!pha_i, rRB_IF};
156
   wire [TXE+4:0] wRD = {!pha_i, rRD_IF};
157
   wire [TXE+4:0] wRW = {pha_i, rRD_MA};
158
 
159
   assign        rREGA_OF = rRAMA[wRA];
160
   assign        rREGB_OF = rRAMB[wRB];
161
   assign        rREGD_OF = rRAMD[wRD];
162
   assign        wREGW = rRAMD[wRW];
163
 
164
   always @(posedge clk_i)
165 81 sybreon
     if ((ena_i & |rRD_MA) | rst_i) begin
166 78 sybreon
        rRAMA[wRW] <= #1 rREGD;
167
        rRAMB[wRW] <= #1 rREGD;
168
        rRAMD[wRW] <= #1 rREGD;
169
     end
170
 
171 80 sybreon
   /*
172
    STORE SIZER
173
 
174 81 sybreon
    This resizes the data to be placed on the data bus. To make it
175
    easy, it merely replicates the data across the whole bus. It
176
    relies on the byte select signal to indicate which lanes to
177
    use. */
178 78 sybreon
 
179
   always @(posedge clk_i)
180
     if (rst_i) begin
181
        /*AUTORESET*/
182
        // Beginning of autoreset for uninitialized flops
183
        cwb_dat_o <= 32'h0;
184
        dwb_dat_o <= 32'h0;
185
        // End of automatics
186 80 sybreon
     end else if (ena_i) begin
187 78 sybreon
        case (rOPC_OF[1:0])
188
          2'o0: dwb_dat_o <= #1 {(4){rOPM_OF[7:0]}};
189
          2'o1: dwb_dat_o <= #1 {(2){rOPM_OF[15:0]}};
190
          2'o2: dwb_dat_o <= #1 rOPM_OF;
191
          default: dwb_dat_o <= #1 32'hX;
192
        endcase // case (rOPC_OF[1:0])
193
 
194
        case (rOPC_OF[1:0])
195
          2'o3: cwb_dat_o <= #1 rOPA_OF;
196
          default: cwb_dat_o <= #1 32'hX;
197
        endcase // case (rOPC_OF[1:0])
198
 
199 80 sybreon
     end // if (ena_i)
200 78 sybreon
 
201 81 sybreon
   // synopsys translate_off   
202
   /* random initial condition for RAM */
203 78 sybreon
   integer r;
204
   initial begin
205
      for (r=0; r<128; r=r+1) begin
206
         rRAMA[r] <= $random;
207
         rRAMB[r] <= $random;
208
         rRAMD[r] <= $random;
209 80 sybreon
      end
210 78 sybreon
   end
211
   // synopsys translate_on
212
 
213
endmodule // aeMB2_regf
214
 
215 80 sybreon
/* $Log: not supported by cvs2svn $
216 81 sybreon
/* Revision 1.2  2007/12/12 19:16:59  sybreon
217
/* Minor optimisations (~10% faster)
218
/*
219 80 sybreon
/* Revision 1.1  2007/12/11 00:43:17  sybreon
220
/* initial import
221
/* */

powered by: WebSVN 2.1.0

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