Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add(branch_manager.cpp, Branch_Manager.sv): Added module and test for branch manager #112

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions dv/branch_manager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <catch2/catch_test_macros.hpp>
#include <VBranch_Manager.h>
#include <cstdint>
#include <stdlib.h>
#include <math.h>

TEST_CASE("") {

VBranch_Manager model;

//Initialize Module
model.rstn = 1;
model.clk = 0;
model.eval();
model.rstn_h = 0;
model.eval();


//Test Module
for (int i = 0; i < 1000; i++) {

}
}
34 changes: 34 additions & 0 deletions rtl/Branch_Manager.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Branch_Manager (
input clk, rstn, pred_taken, act_taken
input [WordSize - 1:0] pred_pc, pred_addr
output logic flush
output logic [WordSize - 1:0] npc
);

logic restart;

always @ (posedge clk or negedge rstn_h) begin
if (!rstn) begin
restart <= 1;
flush <= 0;
npc <= 0;
end
else begin
if ((pred_taken != act_taken) && !restart) begin
flush <= 1;
case(act_taken)
0: npc <= pred_pc + 4
1: npc <= pred_addr
endcase
end
else begin
flush <= 0;
case(pred_taken)
0: npc <= pred_pc + 4
1: npc <= pred_addr
endcase
end
if (restart) restart <= 0;
end
end
endmodule