Skip to content

Commit c19108f

Browse files
committed
a
1 parent 8092066 commit c19108f

File tree

243 files changed

+34601
-5405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+34601
-5405
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

RicsV_Pipelined310524/EX_MEM.v

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module EX_MEM (
2+
input clk,
3+
input reset,
4+
input RegWrite_E, MemWrite_E,
5+
input [1:0] ResultSrc_E,
6+
input [31:0] ALUResult_E, Mux_RD2E_out, PCPlus4_E,
7+
input [31:0] Rd_E,
8+
output reg RegWrite_M, MemWrite_M,
9+
output reg [1:0] ResultSrc_M,
10+
output reg [31:0] ALUResult_M, WriteData_M, PCPlus4_M,
11+
output reg [31:0] Rd_M
12+
);
13+
always @(posedge clk or negedge reset) begin
14+
if (!reset) begin
15+
RegWrite_M <= 1'b0;
16+
MemWrite_M <= 1'b0;
17+
ResultSrc_M <= 2'b00;
18+
ALUResult_M <= 32'b0;
19+
WriteData_M <= 32'b0;
20+
Rd_M <= 32'b0;
21+
PCPlus4_M <= 32'b0;
22+
end else begin
23+
RegWrite_M <= RegWrite_E;
24+
MemWrite_M <= MemWrite_E;
25+
ResultSrc_M <= ResultSrc_E;
26+
ALUResult_M <= ALUResult_E;
27+
WriteData_M <= Mux_RD2E_out;
28+
Rd_M <= Rd_E;
29+
PCPlus4_M <= PCPlus4_E;
30+
end
31+
end
32+
endmodule

RicsV_Pipelined310524/Hazard_Unit.v

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module Hazard_Unit(
2+
input [4:0] Rs1_E, Rs2_E, Rs1_D, Rs2_D,
3+
input [4:0] Rd_M, Rd_W, Rd_E,
4+
input ResultSrc_E0,
5+
input RegWrite_M, RegWrite_W,
6+
output reg [1:0] ForwardA_E, ForwardB_E,
7+
output reg Stall_F, Stall_D, Flush_E
8+
);
9+
10+
// load word stall signal
11+
wire lwStall;
12+
assign lwStall = ((Rs1_D == Rd_E) || (Rs2_D == Rd_E)) && ResultSrc_E0;
13+
14+
// Assign stall and flush signals
15+
always @(*) begin
16+
Stall_F = lwStall;
17+
Stall_D = lwStall;
18+
Flush_E = lwStall;
19+
end
20+
21+
// Forwarding logic
22+
always @(*) begin
23+
// Initialize outputs
24+
ForwardA_E = 2'b00;
25+
ForwardB_E = 2'b00;
26+
27+
// Forwarding logic for A
28+
if ((Rs1_E == Rd_M) && RegWrite_M)
29+
ForwardA_E = 2'b10;
30+
else if ((Rs1_E == Rd_W) && RegWrite_W)
31+
ForwardA_E = 2'b01;
32+
33+
// Forwarding logic for B
34+
if ((Rs2_E == Rd_M) && RegWrite_M)
35+
ForwardB_E = 2'b10;
36+
else if ((Rs2_E == Rd_W) && RegWrite_W)
37+
ForwardB_E = 2'b01;
38+
end
39+
endmodule

RicsV_Pipelined310524/ID_EX.v

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
module ID_EX (
2+
input clk,
3+
input reset,
4+
input Flush_E,
5+
input RegWrite_D, MemWrite_D, Jump_D, Branch_D, ALUSrc_D,
6+
input [1:0] ResultSrc_D,
7+
input [3:0] ALUControl_D,
8+
input [31:0] RD1_D, RD2_D, Extimm_D, PCplus4_D, PC_D,
9+
input [31:0] Rs1_D, Rs2_D, Rd_D,
10+
output reg RegWrite_E, MemWrite_E, Jump_E, Branch_E, ALUSrc_E,
11+
output reg [1:0] ResultSrc_E,
12+
output reg [3:0] ALUControl_E,
13+
output reg [31:0] RD1_E, RD2_E, Extimm_E, PCplus4_E, PC_E,
14+
output reg [31:0] Rs1_E, Rs2_E, Rd_E
15+
);
16+
always @(posedge clk or negedge reset) begin
17+
if (!reset) begin
18+
RegWrite_E <= 1'b0;
19+
MemWrite_E <= 1'b0;
20+
Jump_E <= 1'b0;
21+
Branch_E <= 1'b0;
22+
ALUSrc_E <= 1'b0;
23+
ResultSrc_E <= 2'b00;
24+
ALUControl_E <= 4'b0000;
25+
RD1_E <= 32'b0;
26+
RD2_E <= 32'b0;
27+
PC_E <= 32'b0;
28+
Rs1_E <= 32'b0;
29+
Rs2_E <= 32'b0;
30+
Rd_E <= 32'b0;
31+
Extimm_E <= 32'b0;
32+
PCplus4_E <= 32'b0;
33+
end else if (!Flush_E) begin
34+
RegWrite_E <= RegWrite_D;
35+
MemWrite_E <= MemWrite_D;
36+
Jump_E <= Jump_D;
37+
Branch_E <= Branch_D;
38+
ALUSrc_E <= ALUSrc_D;
39+
ResultSrc_E <= ResultSrc_D;
40+
ALUControl_E <= ALUControl_D;
41+
RD1_E <= RD1_D;
42+
RD2_E <= RD2_D;
43+
PC_E <= PC_D;
44+
Rs1_E <= Rs1_D;
45+
Rs2_E <= Rs2_D;
46+
Rd_E <= Rd_D;
47+
Extimm_E <= Extimm_D;
48+
PCplus4_E <= PCplus4_D;
49+
end else begin
50+
RegWrite_E <= 1'b0;
51+
MemWrite_E <= 1'b0;
52+
Jump_E <= 1'b0;
53+
Branch_E <= 1'b0;
54+
ALUSrc_E <= 1'b0;
55+
ResultSrc_E <= 2'b00;
56+
ALUControl_E <= 4'b0000;
57+
RD1_E <= 32'b0;
58+
RD2_E <= 32'b0;
59+
PC_E <= 32'b0;
60+
Rs1_E <= 32'b0;
61+
Rs2_E <= 32'b0;
62+
Rd_E <= 32'b0;
63+
Extimm_E <= 32'b0;
64+
PCplus4_E <= 32'b0;
65+
end
66+
end
67+
endmodule

RicsV_Pipelined310524/IF_ID.v

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module IF_ID (
2+
input clk,
3+
input reset,
4+
input Stall_D,
5+
input [31:0] Instr,
6+
input [31:0] PCplus4_out,
7+
input [31:0] PC_out,
8+
output reg [31:0] Instruction_D,
9+
output reg [31:0] PCplus4_D,
10+
output reg [31:0] PC_D
11+
);
12+
always @(posedge clk or negedge reset) begin
13+
if (!reset) begin
14+
Instruction_D <= 32'b0;
15+
PCplus4_D <= 32'b0;
16+
PC_D <= 32'b0;
17+
end else begin
18+
if (!Stall_D) begin
19+
Instruction_D <= Instr;
20+
PCplus4_D <= PCplus4_out;
21+
PC_D <= PC_out;
22+
end
23+
end
24+
end
25+
endmodule

0 commit comments

Comments
 (0)