1 | // ========== Copyright Header Begin ========================================== |
---|
2 | // |
---|
3 | // OpenSPARC T1 Processor File: bw_r_irf_register.v |
---|
4 | // Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. |
---|
5 | // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. |
---|
6 | // |
---|
7 | // The above named program is free software; you can redistribute it and/or |
---|
8 | // modify it under the terms of the GNU General Public |
---|
9 | // License version 2 as published by the Free Software Foundation. |
---|
10 | // |
---|
11 | // The above named program is distributed in the hope that it will be |
---|
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | // General Public License for more details. |
---|
15 | // |
---|
16 | // You should have received a copy of the GNU General Public |
---|
17 | // License along with this work; if not, write to the Free Software |
---|
18 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
19 | // |
---|
20 | // ========== Copyright Header End ============================================ |
---|
21 | `ifdef FPGA_SYN_1THREAD |
---|
22 | |
---|
23 | `ifdef FPGA_SYN_SAVE_BRAM |
---|
24 | |
---|
25 | |
---|
26 | module bw_r_irf_register(clk, wren, save, save_addr, restore, restore_addr, wr_data, rd_data); |
---|
27 | input clk; |
---|
28 | input wren; |
---|
29 | input save; |
---|
30 | input [2:0] save_addr; |
---|
31 | input restore; |
---|
32 | input [2:0] restore_addr; |
---|
33 | input [71:0] wr_data; |
---|
34 | output [71:0] rd_data; |
---|
35 | `ifdef FPGA_SYN_ALTERA |
---|
36 | reg [35:0] window[15:0]/* synthesis syn_ramstyle = block_ram*/; // syn_ramstyle = no_rw_check */; |
---|
37 | `else |
---|
38 | reg [35:0] window[15:0]/* synthesis syn_ramstyle = block_ram syn_ramstyle = no_rw_check */; |
---|
39 | `endif |
---|
40 | reg [71:0] onereg; |
---|
41 | |
---|
42 | initial onereg = 72'h0; |
---|
43 | |
---|
44 | assign rd_data = onereg; |
---|
45 | |
---|
46 | reg [71:0] restore_data; |
---|
47 | wire [71:0] wrdata = restore ? restore_data : wr_data; |
---|
48 | |
---|
49 | wire wr_en = wren | restore; |
---|
50 | |
---|
51 | always @(posedge clk) begin |
---|
52 | if(wr_en) onereg <= wrdata; |
---|
53 | end |
---|
54 | |
---|
55 | wire [2:0] addr = save ? save_addr : restore_addr; |
---|
56 | |
---|
57 | wire [3:0] addr1 = {1'b1, addr}; |
---|
58 | wire [3:0] addr0 = {1'b0, addr}; |
---|
59 | |
---|
60 | always @(negedge clk) begin |
---|
61 | if(save) window[addr1] <= wren ? wr_data[71:36] : rd_data[71:36]; |
---|
62 | else restore_data[71:36] <= window[addr1]; |
---|
63 | end |
---|
64 | |
---|
65 | always @(negedge clk) begin |
---|
66 | if(save) window[addr0] <= wren ? wr_data[35:0] : rd_data[35:0]; |
---|
67 | else restore_data[35:0] <= window[addr0]; |
---|
68 | end |
---|
69 | |
---|
70 | |
---|
71 | endmodule |
---|
72 | |
---|
73 | |
---|
74 | `else |
---|
75 | |
---|
76 | |
---|
77 | module bw_r_irf_register(clk, wren, save, save_addr, restore, restore_addr, wr_data, rd_data); |
---|
78 | input clk; |
---|
79 | input wren; |
---|
80 | input save; |
---|
81 | input [2:0] save_addr; |
---|
82 | input restore; |
---|
83 | input [2:0] restore_addr; |
---|
84 | input [71:0] wr_data; |
---|
85 | output [71:0] rd_data; |
---|
86 | `ifdef FPGA_SYN_ALTERA |
---|
87 | reg [71:0] window[7:0]/* synthesis syn_ramstyle = block_ram*/; // syn_ramstyle = no_rw_check */; |
---|
88 | `else |
---|
89 | reg [71:0] window[7:0]/* synthesis syn_ramstyle = block_ram syn_ramstyle = no_rw_check */; |
---|
90 | `endif |
---|
91 | reg [71:0] onereg; |
---|
92 | |
---|
93 | reg [2:0] rd_addr; |
---|
94 | reg [2:0] wr_addr; |
---|
95 | reg save_d; |
---|
96 | `ifdef FPGA_SYN_ALTERA |
---|
97 | integer k; |
---|
98 | |
---|
99 | initial |
---|
100 | begin |
---|
101 | for (k = 0; k < 8 ; k = k + 1) |
---|
102 | begin |
---|
103 | window[k] = 72'h0; |
---|
104 | end |
---|
105 | end |
---|
106 | `endif |
---|
107 | |
---|
108 | initial |
---|
109 | begin |
---|
110 | onereg = 72'b0; |
---|
111 | wr_addr = 3'h0; |
---|
112 | rd_addr = 3'h0; |
---|
113 | end |
---|
114 | |
---|
115 | always @(negedge clk) begin |
---|
116 | rd_addr = restore_addr; |
---|
117 | end |
---|
118 | |
---|
119 | always @(posedge clk) begin |
---|
120 | wr_addr <= save_addr; |
---|
121 | end |
---|
122 | always @(posedge clk) begin |
---|
123 | save_d <= save; |
---|
124 | end |
---|
125 | |
---|
126 | assign rd_data = onereg; |
---|
127 | |
---|
128 | wire [71:0] restore_data = window[rd_addr]; |
---|
129 | wire [71:0] wrdata = restore ? restore_data : wr_data; |
---|
130 | |
---|
131 | wire wr_en = wren | (restore & (wr_addr != rd_addr)); |
---|
132 | |
---|
133 | always @(posedge clk) begin |
---|
134 | if(wr_en) onereg <= wrdata; |
---|
135 | end |
---|
136 | |
---|
137 | always @(negedge clk) begin |
---|
138 | if(save_d) window[wr_addr] <= rd_data; |
---|
139 | end |
---|
140 | |
---|
141 | endmodule |
---|
142 | |
---|
143 | `endif |
---|
144 | |
---|
145 | `else |
---|
146 | |
---|
147 | |
---|
148 | module bw_r_irf_register(clk, wrens, save, save_addr, restore, restore_addr, wr_data0, wr_data1, wr_data2, wr_data3, rd_thread, rd_data); |
---|
149 | input clk; |
---|
150 | input [3:0] wrens; |
---|
151 | input save; |
---|
152 | input [4:0] save_addr; |
---|
153 | input restore; |
---|
154 | input [4:0] restore_addr; |
---|
155 | input [71:0] wr_data0; |
---|
156 | input [71:0] wr_data1; |
---|
157 | input [71:0] wr_data2; |
---|
158 | input [71:0] wr_data3; |
---|
159 | input [1:0] rd_thread; |
---|
160 | output [71:0] rd_data; |
---|
161 | `ifdef FPGA_SYN_ALTERA |
---|
162 | reg [71:0] window[31:0]/* synthesis syn_ramstyle = block_ram*/; // syn_ramstyle = no_rw_check */; |
---|
163 | `else |
---|
164 | reg [71:0] window[31:0]/* synthesis syn_ramstyle = block_ram syn_ramstyle = no_rw_check */; |
---|
165 | `endif |
---|
166 | reg [71:0] reg_th0, reg_th1, reg_th2, reg_th3; |
---|
167 | |
---|
168 | reg [4:0] rd_addr; |
---|
169 | reg [4:0] wr_addr; |
---|
170 | reg save_d; |
---|
171 | |
---|
172 | initial begin |
---|
173 | reg_th0 = 72'b0; |
---|
174 | reg_th1 = 72'b0; |
---|
175 | reg_th2 = 72'b0; |
---|
176 | reg_th3 = 72'b0; |
---|
177 | end |
---|
178 | |
---|
179 | bw_r_irf_72_4x1_mux mux4_1( |
---|
180 | .sel(rd_thread), |
---|
181 | .x0(reg_th0), |
---|
182 | .x1(reg_th1), |
---|
183 | .x2(reg_th2), |
---|
184 | .x3(reg_th3), |
---|
185 | .y(rd_data) |
---|
186 | ); |
---|
187 | |
---|
188 | always @(negedge clk) begin |
---|
189 | rd_addr = restore_addr; |
---|
190 | end |
---|
191 | |
---|
192 | wire [71:0] restore_data = window[rd_addr]; |
---|
193 | |
---|
194 | always @(posedge clk) begin |
---|
195 | wr_addr <= save_addr; |
---|
196 | end |
---|
197 | always @(posedge clk) begin |
---|
198 | save_d <= save; |
---|
199 | end |
---|
200 | |
---|
201 | wire [71:0] save_data; |
---|
202 | |
---|
203 | bw_r_irf_72_4x1_mux mux4_2( |
---|
204 | .sel(wr_addr[4:3]), |
---|
205 | .x0(reg_th0), |
---|
206 | .x1(reg_th1), |
---|
207 | .x2(reg_th2), |
---|
208 | .x3(reg_th3), |
---|
209 | .y(save_data) |
---|
210 | ); |
---|
211 | |
---|
212 | always @(negedge clk) begin |
---|
213 | if(save_d) window[wr_addr] <= save_data; |
---|
214 | end |
---|
215 | |
---|
216 | //Register implementation for 4 threads / 2 write & 1 restore port |
---|
217 | |
---|
218 | wire [3:0] restores = (1'b1 << rd_addr[4:3]) & {4{restore}}; |
---|
219 | //wire [3:0] wren1s = (1'b1 << wr1_th) & {4{wren1}}; |
---|
220 | //wire [3:0] wren2s = (1'b1 << wr2_th) & {4{wren2}}; |
---|
221 | |
---|
222 | wire [71:0] wrdata0, wrdata1, wrdata2, wrdata3; |
---|
223 | |
---|
224 | bw_r_irf_72_2x1_mux mux2_5( |
---|
225 | .sel(restores[0]), |
---|
226 | .x0(wr_data0), |
---|
227 | .x1(restore_data), |
---|
228 | .y(wrdata0) |
---|
229 | ); |
---|
230 | |
---|
231 | bw_r_irf_72_2x1_mux mux2_6( |
---|
232 | .sel(restores[1]), |
---|
233 | .x0(wr_data1), |
---|
234 | .x1(restore_data), |
---|
235 | .y(wrdata1) |
---|
236 | ); |
---|
237 | |
---|
238 | bw_r_irf_72_2x1_mux mux2_7( |
---|
239 | .sel(restores[2]), |
---|
240 | .x0(wr_data2), |
---|
241 | .x1(restore_data), |
---|
242 | .y(wrdata2) |
---|
243 | ); |
---|
244 | |
---|
245 | bw_r_irf_72_2x1_mux mux2_8( |
---|
246 | .sel(restores[3]), |
---|
247 | .x0(wr_data3), |
---|
248 | .x1(restore_data), |
---|
249 | .y(wrdata3) |
---|
250 | ); |
---|
251 | |
---|
252 | //wire [3:0] wr_en = wren1s | wren2s | (restores & {4{(wr_addr[4:0] != rd_addr[4:0])}}); |
---|
253 | wire [3:0] wr_en = wrens | (restores & {4{(wr_addr[4:0] != rd_addr[4:0])}}); |
---|
254 | |
---|
255 | //288 Flops |
---|
256 | always @(posedge clk) begin |
---|
257 | if(wr_en[0]) reg_th0 <= wrdata0; |
---|
258 | if(wr_en[1]) reg_th1 <= wrdata1; |
---|
259 | if(wr_en[2]) reg_th2 <= wrdata2; |
---|
260 | if(wr_en[3]) reg_th3 <= wrdata3; |
---|
261 | end |
---|
262 | |
---|
263 | endmodule |
---|
264 | |
---|
265 | |
---|
266 | module bw_r_irf_72_4x1_mux(sel, y, x0, x1, x2, x3); |
---|
267 | input [1:0] sel; |
---|
268 | input [71:0] x0; |
---|
269 | input [71:0] x1; |
---|
270 | input [71:0] x2; |
---|
271 | input [71:0] x3; |
---|
272 | output [71:0] y; |
---|
273 | reg [71:0] y; |
---|
274 | |
---|
275 | always @(sel or x0 or x1 or x2 or x3) |
---|
276 | case(sel) |
---|
277 | 2'b00: y = x0; |
---|
278 | 2'b01: y = x1; |
---|
279 | 2'b10: y = x2; |
---|
280 | 2'b11: y = x3; |
---|
281 | endcase |
---|
282 | |
---|
283 | endmodule |
---|
284 | |
---|
285 | |
---|
286 | module bw_r_irf_72_2x1_mux(sel, y, x0, x1); |
---|
287 | input sel; |
---|
288 | input [71:0] x0; |
---|
289 | input [71:0] x1; |
---|
290 | output [71:0] y; |
---|
291 | reg [71:0] y; |
---|
292 | |
---|
293 | always @(sel or x0 or x1) |
---|
294 | case(sel) |
---|
295 | 1'b0: y = x0; |
---|
296 | 1'b1: y = x1; |
---|
297 | endcase |
---|
298 | |
---|
299 | endmodule |
---|
300 | |
---|
301 | `endif |
---|
302 | |
---|
303 | |
---|