1 |
2 |
azmathmoos |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// Copyright (C) 2014-2015 Azmath Moosa ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This source file may be used and distributed without ////
|
6 |
|
|
//// restriction provided that this copyright statement is not ////
|
7 |
|
|
//// removed from the file and that any derivative work contains ////
|
8 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
9 |
|
|
//// ////
|
10 |
|
|
//// This source file is free software; you can redistribute it ////
|
11 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
12 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
13 |
|
|
//// either version 3 of the License, or (at your option) any ////
|
14 |
|
|
//// later version. ////
|
15 |
|
|
//// ////
|
16 |
|
|
//// This source is distributed in the hope that it will be ////
|
17 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
18 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
19 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
20 |
|
|
//// details. ////
|
21 |
|
|
//// ////
|
22 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
23 |
|
|
//// Public License along with this source; if not, download it ////
|
24 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
25 |
|
|
//// ////
|
26 |
|
|
//////////////////////////////////////////////////////////////////////
|
27 |
|
|
`timescale 1ns / 1ps
|
28 |
|
|
`include "Configuration.v"
|
29 |
|
|
|
30 |
|
|
module FluidCore(
|
31 |
|
|
input [0:`inst_w] exInstruction,
|
32 |
|
|
input Clk,
|
33 |
|
|
input RST,
|
34 |
|
|
input [0:`intr_msb] Interrupt,
|
35 |
|
|
output [0:`pc_w] exInstAddr,
|
36 |
|
|
output [0:`memory_bus_w] exMemoryAddr,
|
37 |
|
|
inout [0:`dpw] exMemoryData,
|
38 |
|
|
output exMemoryClk,
|
39 |
|
|
output exMemoryWrite
|
40 |
|
|
);
|
41 |
|
|
|
42 |
|
|
wire Return, linked;
|
43 |
|
|
wire wb_write, write_intr, write_uop, intr, branch;
|
44 |
|
|
wire [0:`pc_w] intr_vector;
|
45 |
|
|
wire [0:`uop_vector_msb] uop_vector;
|
46 |
|
|
wire [0:`uop_msb] uop;
|
47 |
|
|
wire [0:4] bubble_lines;
|
48 |
|
|
wire stall_IF_ID_EX, load_hazard;
|
49 |
|
|
Staller Staller_inst(.Clk(Clk),.RST(RST),.bubble(branch|Return),.bubble_lines(bubble_lines),.load_hazard(load_hazard),.stall(stall_IF_ID_EX));
|
50 |
|
|
|
51 |
|
|
wire [0:`IF_ID_reg_w] IF_ID_reg_in, IF_ID_reg_out;
|
52 |
|
|
P_Reg #(`IF_ID_reg_w) IF_ID_reg(.Clk(Clk),.RST(RST),.stall(stall_IF_ID_EX),.bubble(bubble_lines[0]),.prev_stage(IF_ID_reg_in),.next_stage(IF_ID_reg_out));
|
53 |
|
|
|
54 |
|
|
wire [0:`ID_EX_reg_w] ID_EX_reg_in, ID_EX_reg_out;
|
55 |
|
|
P_Reg #(`ID_EX_reg_w) ID_EX_reg(.Clk(Clk),.RST(RST),.stall(stall_IF_ID_EX),.bubble(bubble_lines[1]),.prev_stage(ID_EX_reg_in),.next_stage(ID_EX_reg_out));
|
56 |
|
|
|
57 |
|
|
wire [0:`EX_MEM_reg_w] EX_MEM_reg_in, EX_MEM_reg_out;
|
58 |
|
|
P_Reg #(`EX_MEM_reg_w) EX_MEM_reg(.Clk(Clk),.RST(RST),.stall(stall_IF_ID_EX),.bubble(bubble_lines[2]),.prev_stage(EX_MEM_reg_in),.next_stage(EX_MEM_reg_out));
|
59 |
|
|
|
60 |
|
|
wire [0:`MEM_WB_reg_w] MEM_WB_reg_in, MEM_WB_reg_out;
|
61 |
|
|
P_Reg #(`MEM_WB_reg_w) MEM_WB_reg(.Clk(Clk),.RST(RST),.stall(0),.bubble(bubble_lines[3]),.prev_stage(MEM_WB_reg_in),.next_stage(MEM_WB_reg_out));
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
wire [0:`dpw] op_reg_a, op_reg_b, wb_data;
|
65 |
|
|
wire [0:`reg_sel_w] reg_a, reg_b;
|
66 |
|
|
wire [0:`bc_msb] wb_dst;
|
67 |
|
|
wire [0:`pc_w] branch_target;
|
68 |
|
|
wire [0:3] stkFlag;
|
69 |
|
|
|
70 |
|
|
//------Forwarding Logic-----------//
|
71 |
|
|
wire s_EX_MEM_reg, s_ID_EX_reg, rrr_adm, rri_adm, not_ID_EX_branch, not_EX_MEM_branch, ID_EX_load, not_branch;
|
72 |
|
|
wire [0:`reg_sel_w] d_EX_MEM_reg, d_ID_EX_reg;
|
73 |
|
|
wire [0:`dpw] b_EX_MEM_reg, b_MEM_WB_reg;
|
74 |
|
|
wire [0:1] reg_src_A, reg_src_B, st_src;
|
75 |
|
|
wire [0:2] load_hazard_abs;
|
76 |
|
|
wire [0:3] adm;
|
77 |
|
|
wire [0:`type_msb] t_ID_EX_reg, t_EX_MEM_reg, t_IF_ID_reg;
|
78 |
|
|
/*
|
79 |
|
|
d prefixed wires carry previous stage destination registers, these are compared with current inst's dest reg
|
80 |
|
|
if they match, current inst is associated with some bits to specify fwding from that stage
|
81 |
|
|
*/
|
82 |
|
|
assign s_EX_MEM_reg = bubble_lines[3]; //actual reg is populated a cycle after so sample it after a cycle hence 3 instead of 2
|
83 |
|
|
assign s_ID_EX_reg = bubble_lines[2]; //same as above
|
84 |
|
|
assign t_ID_EX_reg = ID_EX_reg_out[0:`type_msb];
|
85 |
|
|
assign t_EX_MEM_reg = EX_MEM_reg_out[0:`type_msb];
|
86 |
|
|
assign d_ID_EX_reg = ID_EX_reg_out[`type_msb+1+`wb_dst_msb+1+`mod_sel_msb+1+`operation_msb+1:`type_msb+1+`wb_dst_msb+1+`mod_sel_msb+1+`operation_msb+1+`bc_msb];
|
87 |
|
|
assign d_EX_MEM_reg = EX_MEM_reg_out[`type_msb+1+`wb_dst_msb+1:`type_msb+1+`wb_dst_msb+1+`bc_msb];
|
88 |
|
|
assign b_EX_MEM_reg = EX_MEM_reg_out[`type_msb+1+`wb_dst_msb+1+`bc_msb+1+`dpw+1:`type_msb+1+`wb_dst_msb+1+`bc_msb+1+`dpw+1+`dpw];
|
89 |
|
|
assign b_MEM_WB_reg = MEM_WB_reg_out[`type_msb+1+`wb_dst_msb+1+`reg_sel_w+1:`type_msb+1+`wb_dst_msb+1+`reg_sel_w+1+`dpw];
|
90 |
|
|
assign not_ID_EX_branch = ~(t_ID_EX_reg == `type_branch);//(|(t_ID_EX_reg ^ `type_branch));
|
91 |
|
|
assign not_EX_MEM_branch = ~(t_EX_MEM_reg == `type_branch);// (|(t_EX_MEM_reg ^ `type_branch));
|
92 |
|
|
assign ID_EX_load = (t_ID_EX_reg == `type_load);//~(|(t_ID_EX_reg ^ `type_load));
|
93 |
|
|
assign fw_c_1 = s_ID_EX_reg & not_branch & not_ID_EX_branch;
|
94 |
|
|
assign fw_c_2 = s_EX_MEM_reg & not_branch & not_EX_MEM_branch;
|
95 |
|
|
//--------Clock and Reset Behaviour--------//
|
96 |
|
|
|
97 |
|
|
//always@(posedge Clk or posedge RST) begin
|
98 |
|
|
// if (RST) begin
|
99 |
|
|
//
|
100 |
|
|
// ID_EX_reg <= 0;
|
101 |
|
|
// EX_MEM_reg <= 0;
|
102 |
|
|
// MEM_WB_reg <= 0;
|
103 |
|
|
// end
|
104 |
|
|
// else begin
|
105 |
|
|
//
|
106 |
|
|
// ID_EX_reg <= ID_EX_reg_wire;
|
107 |
|
|
// EX_MEM_reg <= EX_MEM_reg_wire;
|
108 |
|
|
// MEM_WB_reg <= MEM_WB_reg_wire;
|
109 |
|
|
// end
|
110 |
|
|
//end
|
111 |
|
|
|
112 |
|
|
//--------Sub Modules-------------------//
|
113 |
|
|
|
114 |
|
|
//Instruction Fetch Stage
|
115 |
|
|
IF_Stage IF_Stage_inst (
|
116 |
|
|
.Clk(Clk),
|
117 |
|
|
.RST(RST),
|
118 |
|
|
.intr(intr),
|
119 |
|
|
.stkFlag(stkFlag),
|
120 |
|
|
.return_back(Return),
|
121 |
|
|
.linked(linked),
|
122 |
|
|
.intr_vector(intr_vector),
|
123 |
|
|
.exInstruction(exInstruction),
|
124 |
|
|
.exInstAddr(exInstAddr),
|
125 |
|
|
.IF_ID_reg(IF_ID_reg_in),
|
126 |
|
|
.branch_target(branch_target),
|
127 |
|
|
.branch(branch),
|
128 |
|
|
.stall(stall_IF_ID_EX)
|
129 |
|
|
);
|
130 |
|
|
|
131 |
|
|
//Register File
|
132 |
|
|
Reg_File Reg_File_inst (
|
133 |
|
|
.Clk(Clk),
|
134 |
|
|
.RST(RST),
|
135 |
|
|
.reg_a(reg_a),
|
136 |
|
|
.reg_b(reg_b),
|
137 |
|
|
.wb_reg(wb_dst),
|
138 |
|
|
.op_a(op_reg_a),
|
139 |
|
|
.op_b(op_reg_b),
|
140 |
|
|
.word(wb_data),
|
141 |
|
|
.write(wb_write)
|
142 |
|
|
);
|
143 |
|
|
|
144 |
|
|
//----Operand Forwarding----//
|
145 |
|
|
Reg_Hist Reg_Hist_inst (
|
146 |
|
|
//.Clk(Clk),
|
147 |
|
|
//.RST(RST),
|
148 |
|
|
//.s_ID_EX_reg(s_ID_EX_reg),
|
149 |
|
|
//.s_EX_MEM_reg(s_EX_MEM_reg),
|
150 |
|
|
.ID_EX_reg(d_ID_EX_reg),
|
151 |
|
|
.EX_MEM_reg(d_EX_MEM_reg),
|
152 |
|
|
//.ID_EX_type(t_ID_EX_reg),
|
153 |
|
|
.nxt_reg_A(IF_ID_reg_out[`uop_vector_msb+1+`bc_msb+1+`reg_sel_w+1:`uop_vector_msb+1+`bc_msb+1+`reg_sel_w+1+`reg_sel_w]),
|
154 |
|
|
.nxt_reg_B(IF_ID_reg_out[`uop_vector_msb+1+`bc_msb+1:`uop_vector_msb+1+`bc_msb+1+`reg_sel_w]),
|
155 |
|
|
.st_reg(IF_ID_reg_out[`uop_vector_msb+1+`bc_msb-`reg_sel_w:`uop_vector_msb+1+`bc_msb]),
|
156 |
|
|
//.type(t_IF_ID_reg),
|
157 |
|
|
.reg_src_A(reg_src_A),
|
158 |
|
|
.reg_src_B(reg_src_B),
|
159 |
|
|
.load_hazard(load_hazard),
|
160 |
|
|
.load_hazard_abs(load_hazard_abs),
|
161 |
|
|
.st_src(st_src),
|
162 |
|
|
.rrr_adm(rrr_adm),
|
163 |
|
|
.rri_adm(rri_adm),
|
164 |
|
|
//.not_ID_EX_branch(not_ID_EX_branch),
|
165 |
|
|
//.not_EX_MEM_branch(not_EX_MEM_branch),
|
166 |
|
|
.ID_EX_load(ID_EX_load),
|
167 |
|
|
//.not_branch(not_branch),
|
168 |
|
|
.fw_c_1(fw_c_1),
|
169 |
|
|
.fw_c_2(fw_c_2)
|
170 |
|
|
//.stall(stall_IF_ID_EX)
|
171 |
|
|
);
|
172 |
|
|
//Instruction Decode Stage
|
173 |
|
|
ID_Stage ID_Stage_inst (
|
174 |
|
|
.Clk(Clk),
|
175 |
|
|
.RST(RST),
|
176 |
|
|
.IF_ID_reg(IF_ID_reg_out),
|
177 |
|
|
.RF_a(reg_a),
|
178 |
|
|
.RF_b(reg_b),
|
179 |
|
|
.RF_op_a(op_reg_a),
|
180 |
|
|
.RF_op_b(op_reg_b),
|
181 |
|
|
.ID_EX_reg(ID_EX_reg_in),
|
182 |
|
|
.reg_src_A(reg_src_A),
|
183 |
|
|
.reg_src_B(reg_src_B),
|
184 |
|
|
//.curr_type(t_IF_ID_reg),
|
185 |
|
|
.load_hazard_abs(load_hazard_abs),
|
186 |
|
|
.st_src(st_src),
|
187 |
|
|
.rrr_adm(rrr_adm),
|
188 |
|
|
.rri_adm(rri_adm),
|
189 |
|
|
.not_branch(not_branch),
|
190 |
|
|
.uop_vector(uop_vector),
|
191 |
|
|
.uop(uop)
|
192 |
|
|
);
|
193 |
|
|
|
194 |
|
|
//uOP Store
|
195 |
|
|
uOP_Store uOP_Store_inst(
|
196 |
|
|
.Clk(Clk),
|
197 |
|
|
.uop_vector(uop_vector),
|
198 |
|
|
.uop(uop),
|
199 |
|
|
.write(write_uop),
|
200 |
|
|
.write_vector(wb_dst),
|
201 |
|
|
.write_uop(wb_data)
|
202 |
|
|
);
|
203 |
|
|
|
204 |
|
|
//Execute Stage
|
205 |
|
|
EX_Stage EX_Stage_inst (
|
206 |
|
|
.Clk(Clk),
|
207 |
|
|
.RST(RST),
|
208 |
|
|
.ret(Return),
|
209 |
|
|
.stkFlag(stkFlag),
|
210 |
|
|
.ID_EX_reg(ID_EX_reg_out),
|
211 |
|
|
.EX_MEM_reg(EX_MEM_reg_in),
|
212 |
|
|
.b_EX_MEM_reg(b_EX_MEM_reg),
|
213 |
|
|
.b_MEM_WB_reg(b_MEM_WB_reg)
|
214 |
|
|
);
|
215 |
|
|
|
216 |
|
|
//Memory Stage
|
217 |
|
|
MEM_Stage MEM_Stage_inst (
|
218 |
|
|
.Clk(Clk),
|
219 |
|
|
.RST(RST),
|
220 |
|
|
.linked(linked),
|
221 |
|
|
.EX_MEM_reg(EX_MEM_reg_out),
|
222 |
|
|
.MEM_WB_reg(MEM_WB_reg_in),
|
223 |
|
|
.ex_mem_addr(exMemoryAddr),
|
224 |
|
|
.ex_mem_data(exMemoryData),
|
225 |
|
|
.mem_Clk(exMemoryClk),
|
226 |
|
|
.mem_wr(exMemoryWrite),
|
227 |
|
|
.branch_target(branch_target),
|
228 |
|
|
.branch(branch),
|
229 |
|
|
.return_back(Return)
|
230 |
|
|
);
|
231 |
|
|
|
232 |
|
|
//Write Back Stage
|
233 |
|
|
WB_Stage WB_Stage_inst (
|
234 |
|
|
.Clk(Clk),
|
235 |
|
|
.RST(RST),
|
236 |
|
|
.MEM_WB_reg(MEM_WB_reg_out),
|
237 |
|
|
.wb_dst(wb_dst),
|
238 |
|
|
.wb_data(wb_data),
|
239 |
|
|
.write_rf(wb_write),
|
240 |
|
|
.write_intr(write_intr),
|
241 |
|
|
.write_uop(write_uop),
|
242 |
|
|
.branch(branch),
|
243 |
|
|
.bubble_free(bubble_lines[4])
|
244 |
|
|
);
|
245 |
|
|
|
246 |
|
|
//Interrupt Unit
|
247 |
|
|
interrupt_unit interrupt_unit_inst(
|
248 |
|
|
.Clk(Clk),
|
249 |
|
|
.return_back(Return),
|
250 |
|
|
.intr_req(Interrupt),
|
251 |
|
|
.intr_inx(wb_dst),
|
252 |
|
|
.intr(intr),
|
253 |
|
|
.vector(intr_vector),
|
254 |
|
|
.new_vector(wb_data),
|
255 |
|
|
.write(write_intr)
|
256 |
|
|
);
|
257 |
|
|
|
258 |
|
|
endmodule
|