-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from kalhorghazal/forwarding
Add forwarding
- Loading branch information
Showing
10 changed files
with
188 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
`include "settings.h" | ||
|
||
module Forwarding_Unit ( | ||
input enable, | ||
input [`REG_FILE_DEPTH-1:0] src1, | ||
input [`REG_FILE_DEPTH-1:0] src2, | ||
input [`REG_FILE_DEPTH-1:0] MEM_dest, | ||
input [`REG_FILE_DEPTH-1:0] WB_dest, | ||
input MEM_WB_en, | ||
input WB_WB_en, | ||
output reg [1:0] sel_src1, | ||
output reg [1:0] sel_src2 | ||
); | ||
|
||
always @(*) begin | ||
sel_src1 = `FORWARDING_SEL_NOP; | ||
sel_src2 = `FORWARDING_SEL_NOP; | ||
if(enable) begin | ||
if ((src1 == MEM_dest) && (MEM_WB_en == 1'b1)) | ||
sel_src1 = `FORWARDING_SEL_MEM; | ||
else if ((src1 == WB_dest) && (WB_WB_en == 1'b1)) | ||
sel_src1 = `FORWARDING_SEL_WB; | ||
if ((src2 == MEM_dest) && (MEM_WB_en == 1'b1)) | ||
sel_src2 = `FORWARDING_SEL_MEM; | ||
else if ((src2 == WB_dest) && (WB_WB_en == 1'b1)) | ||
sel_src2 = `FORWARDING_SEL_WB; | ||
end | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,45 @@ | ||
`include "settings.h" | ||
|
||
module Hazard_Detection_Unit ( | ||
input enableForwarding, | ||
input [`REG_FILE_DEPTH-1:0] src1, | ||
input [`REG_FILE_DEPTH-1:0] src2, | ||
input [`REG_FILE_DEPTH-1:0] EXE_dest, | ||
input [`REG_FILE_DEPTH-1:0] MEM_dest, | ||
input EXE_WB_en, | ||
input MEM_WB_en, | ||
input EXE_memread_en, | ||
input has_src1, | ||
input has_src2, | ||
output reg hazard_detected | ||
); | ||
|
||
always @(*) begin | ||
if ((src1 == EXE_dest) && (EXE_WB_en == 1'b1) && (has_src1 == 1'b1)) begin | ||
hazard_detected = 1'b1; | ||
always @(*) begin | ||
hazard_detected = 1'b0; | ||
if(~enableForwarding) begin | ||
if ((src1 == EXE_dest) && (EXE_WB_en == 1'b1) && (has_src1 == 1'b1)) begin | ||
hazard_detected = 1'b1; | ||
end | ||
else if ((src1 == MEM_dest) && (MEM_WB_en == 1'b1) && (has_src1 == 1'b1)) begin | ||
hazard_detected = 1'b1; | ||
end | ||
else if ((src2 == EXE_dest) && (EXE_WB_en == 1'b1) && (has_src2 == 1'b1)) begin | ||
hazard_detected = 1'b1; | ||
end | ||
else if ((src2 == MEM_dest) && (MEM_WB_en == 1'b1) && (has_src2 == 1'b1)) begin | ||
hazard_detected = 1'b1; | ||
end | ||
end | ||
else if ((src1 == MEM_dest) && (MEM_WB_en == 1'b1) && (has_src1 == 1'b1)) begin | ||
hazard_detected = 1'b1; | ||
end | ||
else if ((src2 == EXE_dest) && (EXE_WB_en == 1'b1) && (has_src2 == 1'b1)) begin | ||
hazard_detected = 1'b1; | ||
end | ||
else if ((src2 == MEM_dest) && (MEM_WB_en == 1'b1) && (has_src2 == 1'b1)) begin | ||
hazard_detected = 1'b1; | ||
end | ||
else begin | ||
hazard_detected = 1'b0; | ||
end | ||
end | ||
else begin | ||
if(EXE_memread_en) begin | ||
if ((src1 == EXE_dest) && (EXE_WB_en == 1'b1) && (has_src1 == 1'b1)) begin | ||
hazard_detected = 1'b1; | ||
end | ||
else if ((src2 == EXE_dest) && (EXE_WB_en == 1'b1) && (has_src2 == 1'b1)) begin | ||
hazard_detected = 1'b1; | ||
end | ||
end | ||
end | ||
end | ||
|
||
endmodule | ||
|
Oops, something went wrong.