-
Notifications
You must be signed in to change notification settings - Fork 0
/
top.sv
280 lines (238 loc) · 7.96 KB
/
top.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
`timescale 1ns / 1ps
module top(
input reset,
input sys_clk_pin,
//input sys_clk_2,
input [3:0] switches,
input set,
input [9:0] inputs,
output logic [15:0] r1
);
logic clk, f_clk;
main_clock CLK_MANAGER(
.s_clk(clk),
.f_clk,
.reset,
.clk_in1(sys_clk_pin)
);
//for testing
//assign clk = sys_clk_2;
//assign f_clk = sys_clk_pin;
//assign clk = sys_clk_pin;
logic [159:0] reg_inputs, direct_inputs;
always_ff @(posedge clk) begin
if(reset) begin
direct_inputs <= 0;
end else if(set) begin
direct_inputs <= reg_inputs;
end
case(switches)
4'b0000: reg_inputs[9:0] <= inputs;
4'b0001: reg_inputs[19:10] <= inputs;
4'b0010: reg_inputs[29:20] <= inputs;
4'b0011: reg_inputs[39:30] <= inputs;
4'b0100: reg_inputs[49:40] <= inputs;
4'b0101: reg_inputs[59:50] <= inputs;
4'b0110: reg_inputs[69:60] <= inputs;
4'b0111: reg_inputs[79:70] <= inputs;
4'b1000: reg_inputs[89:80] <= inputs;
4'b1001: reg_inputs[99:90] <= inputs;
4'b1010: reg_inputs[109:100] <= inputs;
4'b1011: reg_inputs[119:110] <= inputs;
4'b1100: reg_inputs[129:120] <= inputs;
4'b1101: reg_inputs[139:130] <= inputs;
4'b1110: reg_inputs[149:140] <= inputs;
4'b1111: reg_inputs[159:150] <= inputs;
endcase
end
//fetch ifcs and vars
branch_fb_ifc branch_fb[2]();
assign branch_fb[0].if_branch = 0;
assign branch_fb[0].if_prediction_correct = 1;
assign branch_fb[0].outcome = NOT_TAKEN;
assign branch_fb[0].cp_addr = 0;
assign branch_fb[0].branch_pc = 0;
assign branch_fb[0].new_pc = 0;
assign branch_fb[1].if_branch = 0;
assign branch_fb[1].if_prediction_correct = 1;
assign branch_fb[1].outcome = NOT_TAKEN;
assign branch_fb[1].cp_addr = 0;
assign branch_fb[1].branch_pc = 0;
assign branch_fb[1].new_pc = 0;
logic if_recall;
branch_fb_decode_ifc branch_fb_dec();
logic ext_stall_fetch, ext_flush_fetch;
assign ext_flush_fetch = if_recall;
fetch_out_ifc fetch_out[2]();
logic [31:0] fetch_addr;
logic fetch_addr_valid;
logic [63:0] fetched_data;
assign fetch_addr = direct_inputs[31:0];
assign fetch_addr_valid = direct_inputs[32];
assign fetched_data = direct_inputs[96:33];
//decode ifcs and vars
logic ext_stall_dec, ext_flush_dec;
assign ext_flush_dec = if_recall;
decode_out_ifc dec_out[2]();
//rename ifcs and vars
logic ext_stall_ren, ext_flush_ren;
//assign ext_stall_ren = 0;
assign ext_flush_ren = if_recall;
wb_ifc wb[4]();
wb_ifc wb_s1[4]();
wb_ifc wb_s2[4]();
rename_out_ifc ren_out[2]();
logic int_stall_ren;
logic [$clog2(`AL_SIZE)-1:0] al_front_ptr, al_back_ptr;
logic [$clog2(`AL_SIZE)-1:0] oldest_branch_al_addr;
logic no_checkpoints;
assign ext_stall_dec = int_stall_ren;
assign ext_stall_fetch = int_stall_ren;
logic [$clog2(`AL_SIZE)-1:0] new_front, old_front, back;
assign if_recall = branch_fb[0].if_branch && ~branch_fb[0].if_prediction_correct;
assign new_front = branch_fb[0].al_addr;
assign old_front = al_front_ptr;
assign back = al_back_ptr;
//issue ifcs and vars
logic ext_stall_iss;
aiq_ifc aiq_issue_out[2]();
miq_ifc miq_issue_out[2]();
//reg file ifcs and vars
logic ext_stall_reg;
aiq_ifc aiq_reg_out[2]();
miq_ifc miq_reg_out[2]();
logic [31:0] reg_out [8];
//execute stage vars
logic [31:0] reg_in_arith [4];
logic [31:0] reg_in_mem [4];
wb_ifc arith_wb[2]();
wb_ifc mem_wb[2]();
assign wb[0].valid = arith_wb[0].valid;
assign wb[0].al_idx = arith_wb[0].al_idx;
assign wb[0].data = arith_wb[0].data;
assign wb[0].rd = arith_wb[0].rd;
assign wb[0].uses_rd = arith_wb[0].uses_rd;
assign wb[1].valid = arith_wb[1].valid;
assign wb[1].al_idx = arith_wb[1].al_idx;
assign wb[1].data = arith_wb[1].data;
assign wb[1].rd = arith_wb[1].rd;
assign wb[1].uses_rd = arith_wb[1].uses_rd;
assign wb[2].valid = mem_wb[0].valid;
assign wb[2].al_idx = mem_wb[0].al_idx;
assign wb[2].data = mem_wb[0].data;
assign wb[2].rd = mem_wb[0].rd;
assign wb[2].uses_rd = mem_wb[0].uses_rd;
assign wb[3].valid = mem_wb[1].valid;
assign wb[3].al_idx = mem_wb[1].al_idx;
assign wb[3].data = mem_wb[1].data;
assign wb[3].rd = mem_wb[1].rd;
assign wb[3].uses_rd = mem_wb[1].uses_rd;
assign reg_in_arith[0] = reg_out[0];
assign reg_in_arith[1] = reg_out[1];
assign reg_in_arith[2] = reg_out[2];
assign reg_in_arith[3] = reg_out[3];
assign reg_in_mem[0] = reg_out[4];
assign reg_in_mem[1] = reg_out[5];
assign reg_in_mem[2] = reg_out[6];
assign reg_in_mem[3] = reg_out[7];
fetch_stage FETCH_STAGE(
.clk, .reset,
.branch_fb,
.decode_fb(branch_fb_dec),
.ext_stall(ext_stall_fetch),
.ext_flush(ext_flush_fetch),
.o_instr(fetch_out)
//.fetch_addr,
//.fetch_addr_valid,
//.fetched_data
);
decode_stage DECODE_STAGE(
.clk, .reset,
.ext_stall(ext_stall_dec),
.ext_flush(ext_flush_dec),
.i_fetch(fetch_out),
.o_decode(dec_out),
.o_fb(branch_fb_dec)
);
rename_stage RENAME_STAGE(
.clk, .reset,
.ext_stall(ext_stall_ren),
.ext_flush(ext_flush_ren),
.i_decode(dec_out),
.i_branch_fb(branch_fb),
.i_wb(wb),
.o_renamed(ren_out),
.oldest_branch_al_addr,
.no_checkpoints,
.int_stall(int_stall_ren),
.al_front_ptr_reg(al_front_ptr),
.al_back_ptr_reg(al_back_ptr)
);
issue_stage ISSUE_STAGE(
.clk, .reset,
.ext_stall(ext_stall_reg),
.i_ren_aiq(ren_out),
.i_ren_ioiq(ren_out),
.if_recall,
.new_front,
.old_front,
.back,
.i_wb(wb),
//.bbt,
.o_iq(aiq_issue_out),
.o_miq(miq_issue_out),
.oldest_branch_al_addr,
.no_checkpoints,
.int_stall(ext_stall_ren)
);
fast_reg_file FRF(
.clk, .f_clk, .reset, .ext_stall(1'b0),
.if_recall, .new_front, .old_front, .back,
.i_wb(wb),
.i_aiq(aiq_issue_out),
.i_miq(miq_issue_out),
.o_regs(reg_out),
.o_aiq(aiq_reg_out),
.o_miq(miq_reg_out),
.int_stall(ext_stall_reg)
);
arith_ex_stage ARITH_EX_STAGE(
.clk, .if_recall, .new_front, .old_front, .back,
.i_aiq(aiq_reg_out),
.i_regs(reg_in_arith),
.o_wb(arith_wb),
.o_fb(branch_fb)
);
t_mem_stage MEM_STAGE(
.clk, .if_recall, .new_front, .old_front, .back,
.i_miq(miq_reg_out),
.i_regs(reg_in_mem),
.o_wb(mem_wb)
);
/*write_back_stage WRITE_BACK_STAGE(
.clk, .if_recall, .new_front, .old_front, .back,
.i_wb(wb),
.o_wb_s1(wb_s1),
.o_wb_s2(wb_s2)
);*/
always_comb begin
case(switches)
4'b0000: r1 = wb[0].data[15:0];
4'b0001: r1 = wb[0].data[31:16];
4'b0010: r1 = wb[1].data[15:0];
4'b0011: r1 = wb[1].data[31:16];
4'b0100: r1 = wb[2].data[15:0];
4'b0101: r1 = wb[2].data[31:16];
4'b0110: r1 = wb[3].data[15:0];
4'b0111: r1 = wb[3].data[31:16];
4'b1000: r1 = wb[0].data[15:0];
4'b1001: r1 = wb[0].data[31:16];
4'b1010: r1 = wb[0].data[15:0];
4'b1011: r1 = wb[0].data[31:16];
4'b1100: r1 = wb[0].data[15:0];
4'b1101: r1 = wb[0].data[31:16];
4'b1110: r1 = wb[0].data[15:0];
4'b1111: r1 = wb[0].data[31:16];
endcase
end
endmodule