-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add(Pipeline_Reset.sv, pipeline_reset.cpp): Added Pipeline Reset Modu…
…le and Tests (#117) * add(Pipeline_Reset.sv): Pipeline Reset Implement * fix(branch_manager.cpp): FIxed random number gen * add(pipeline_reset.cpp): Added Pipeline Reset Test
- Loading branch information
1 parent
ed4b392
commit d3962ff
Showing
5 changed files
with
86 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <catch2/catch_test_macros.hpp> | ||
#include <VPipeline_Reset.h> | ||
#include <cstdint> | ||
#include <stdlib.h> | ||
#include <math.h> | ||
|
||
/* | ||
Note: | ||
The tests do not currently distinguish between High Z and 0 due to limitations of Verilator. | ||
The module could be modified to provide a test output that is 0 when rstn is 0 and 1 when rstn is High Z, | ||
but given the simplicity of this module that doesn't seem warrented at this point. | ||
*/ | ||
|
||
|
||
TEST_CASE("flush == 0") { | ||
VPipeline_Reset model; | ||
|
||
uint32_t npc_in; | ||
uint32_t npc_corr; | ||
|
||
for (int i = 0; i < 1000; i++) { | ||
npc_in = rand() % (int) (pow(2, 32) - 1); | ||
npc_corr = rand() % (int) (pow(2, 32) - 1); | ||
|
||
model.flush = 0; | ||
model.npc_in = npc_in; | ||
model.npc_corr = npc_corr; | ||
model.eval(); | ||
|
||
REQUIRE((uint32_t) model.npc == (uint32_t) npc_in); | ||
REQUIRE(model.rstn == 0); //Verilator translates High Z outputs to 0 | ||
|
||
} | ||
} | ||
|
||
TEST_CASE("flush == 1") { | ||
VPipeline_Reset model; | ||
|
||
uint32_t npc_in; | ||
uint32_t npc_corr; | ||
|
||
for (int i = 0; i < 1000; i++) { | ||
npc_in = rand() % (int) (pow(2, 32) - 1); | ||
npc_corr = rand() % (int) (pow(2, 32) - 1); | ||
|
||
model.flush = 1; | ||
model.npc_in = npc_in; | ||
model.npc_corr = npc_corr; | ||
model.eval(); | ||
|
||
REQUIRE((uint32_t) model.npc == (uint32_t) npc_corr); | ||
REQUIRE(model.rstn == 0); //Expect actual 0 output here, not High Z | ||
|
||
} | ||
} |
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,3 +1,3 @@ | ||
nyu_add_sv(core | ||
Alu.sv Branch_Eval.sv PC.sv IFID.sv MEMWB.sv GPR.sv EXMEM.sv Branch_Addr_Calc.sv IDEX.sv Branch_Predictor.sv | ||
Alu.sv Branch_Eval.sv PC.sv IFID.sv MEMWB.sv GPR.sv EXMEM.sv Branch_Addr_Calc.sv IDEX.sv Branch_Predictor.sv Pipeline_Reset.sv | ||
) |
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,22 @@ | ||
module Pipeline_Reset #( | ||
WordSize = 32 | ||
)( | ||
input [WordSize - 1:0] npc_in, npc_corr, | ||
input flush, | ||
output logic [WordSize - 1:0] npc, | ||
output logic rstn | ||
); | ||
|
||
always_comb begin | ||
case(flush) | ||
0: begin | ||
npc = npc_in; | ||
rstn = 1'bZ; | ||
end | ||
1: begin | ||
npc = npc_corr; | ||
rstn = 0; | ||
end | ||
endcase | ||
end | ||
endmodule |