-
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.
Revert "refactor: Formatting and syntax fixes"
This reverts commit 97856a1.
- Loading branch information
1 parent
cf99a84
commit 8a84a25
Showing
17 changed files
with
293 additions
and
382 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 |
---|---|---|
@@ -1,48 +1,44 @@ | ||
//Branch Address Conditions | ||
parameter PC = 0; //Case when branch_addr = pc + imm | ||
parameter RD = 1; //Case when branch_addr = imm + rs1d | ||
parameter PC = 0; //Case when branch_addr = pc + imm | ||
parameter RD = 1; //Case when branch_addr = imm + rs1d | ||
|
||
module Branch_Addr_Calc #( | ||
module Branch_Addr_Calc # ( | ||
WordSize = 32 | ||
) ( | ||
input addr_mode, | ||
input branch_taken, | ||
input [WordSize - 1:0] imm, | ||
input [WordSize - 1:0] rs1d, | ||
input [WordSize - 1:0] pc_in, | ||
output logic [WordSize - 1:0] branch_addr, | ||
output logic [WordSize - 1:0] npc | ||
)( | ||
input addr_mode, branch_taken, | ||
input [WordSize - 1:0] imm, rs1d, pc_in, | ||
output logic [WordSize - 1:0] branch_addr, npc | ||
); | ||
|
||
always_comb begin | ||
case (addr_mode) | ||
PC: | ||
case (branch_taken) | ||
1'b0: begin | ||
branch_addr = pc_in + imm; | ||
npc = pc_in; | ||
always_comb begin | ||
case(addr_mode) | ||
PC: | ||
case (branch_taken) | ||
1'b0: begin | ||
branch_addr = pc_in + imm; | ||
npc = pc_in; | ||
end | ||
1'b1: begin | ||
branch_addr = pc_in + imm; | ||
npc = branch_addr; | ||
end | ||
endcase | ||
RD: | ||
case (branch_taken) | ||
1'b0: begin | ||
branch_addr = imm + rs1d; | ||
npc = pc_in; | ||
end | ||
1'b1: begin | ||
branch_addr = imm + rs1d; | ||
npc = branch_addr; | ||
end | ||
endcase | ||
default: begin | ||
branch_addr = pc_in + imm; | ||
npc = pc_in; | ||
end | ||
1'b1: begin | ||
branch_addr = pc_in + imm; | ||
npc = branch_addr; | ||
end | ||
endcase | ||
RD: | ||
case (branch_taken) | ||
1'b0: begin | ||
branch_addr = imm + rs1d; | ||
npc = pc_in; | ||
end | ||
1'b1: begin | ||
branch_addr = imm + rs1d; | ||
npc = branch_addr; | ||
end | ||
endcase | ||
default: begin | ||
branch_addr = pc_in + imm; | ||
npc = pc_in; | ||
end | ||
endcase | ||
end | ||
end | ||
|
||
endmodule | ||
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,28 +1,28 @@ | ||
|
||
//Branch condition definitions | ||
parameter NE = 2'h0; //Non branching instruction | ||
parameter ALU = 2'h1; //Branch condition is < or != | ||
parameter NALU = 2'h2; //Branch condition is >= or = | ||
parameter AL = 2'h3; //Jump instruction | ||
parameter NE = 2'h0; //Non branching instruction | ||
parameter ALU = 2'h1; //Branch condition is < or != | ||
parameter NALU = 2'h2; //Branch condition is >= or = | ||
parameter AL = 2'h3; //Jump instruction | ||
|
||
|
||
|
||
module Branch_Eval #( | ||
WordSize = 32 | ||
) ( | ||
WordSize = 32 | ||
)( | ||
input [WordSize - 1:0] alu_out, | ||
input [1:0] branch_cond, | ||
output logic act_taken | ||
); | ||
|
||
always_comb begin | ||
case (branch_cond) | ||
NE: act_taken = 0; | ||
ALU: act_taken = |alu_out; | ||
NALU: act_taken = ~(|alu_out); | ||
AL: act_taken = 1; | ||
always_comb begin | ||
case(branch_cond) | ||
NE: act_taken = 0; | ||
ALU: act_taken = |alu_out; | ||
NALU: act_taken = ~(|alu_out); | ||
AL: act_taken = 1; | ||
endcase | ||
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,39 +1,36 @@ | ||
module Branch_Manager #( | ||
WordSize = 32 | ||
) ( | ||
input clk, | ||
input rstn, | ||
input pred_taken, | ||
input act_taken, | ||
input [WordSize - 1:0] pred_pc, | ||
input [WordSize - 1:0] pred_addr, | ||
WordSize = 32 | ||
)( | ||
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; | ||
logic restart; | ||
|
||
always_ff @(posedge clk or negedge rstn) begin | ||
always @ (posedge clk or negedge rstn) begin | ||
if (!rstn) begin | ||
restart <= 1; | ||
flush <= 0; | ||
npc <= 0; | ||
end else begin | ||
restart <= 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; | ||
case(act_taken) | ||
0: npc <= pred_pc + 4; | ||
1: npc <= pred_addr; | ||
endcase | ||
end else begin | ||
end | ||
else begin | ||
flush <= 0; | ||
case (pred_taken) | ||
0: npc <= pred_pc + 4; | ||
1: npc <= pred_addr; | ||
case(pred_taken) | ||
0: npc <= pred_pc + 4; | ||
1: npc <= pred_addr; | ||
endcase | ||
end | ||
if (restart) restart <= 0; | ||
end | ||
end | ||
endmodule | ||
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,40 +1,38 @@ | ||
module Branch_Predictor ( | ||
input clk, | ||
input rstn_h, | ||
input act_taken, | ||
input pred_taken, | ||
input [1:0] branch_occr, | ||
input [1:0] branch_cond, | ||
input clk, rstn_h, act_taken, pred_taken, | ||
input [1:0] branch_occr, branch_cond, | ||
output logic branch_taken | ||
); | ||
logic curr_pred, incorrect_pred; | ||
logic curr_pred, incorrect_pred; | ||
|
||
always_ff @(posedge clk or negedge rstn_h) begin | ||
always @ (posedge clk or negedge rstn_h) begin | ||
if (!rstn_h) begin | ||
curr_pred <= 0; | ||
incorrect_pred <= 0; | ||
end else begin | ||
end | ||
else begin | ||
if (^branch_cond == 0) begin | ||
curr_pred <= curr_pred; | ||
incorrect_pred <= incorrect_pred; | ||
end else if (act_taken ^ pred_taken == 0) begin | ||
end | ||
else if (act_taken ^ pred_taken == 0) begin | ||
curr_pred <= curr_pred; | ||
incorrect_pred <= 0; | ||
end else if (incorrect_pred) begin | ||
end | ||
else if (incorrect_pred) begin | ||
curr_pred <= ~curr_pred; | ||
incorrect_pred <= 1; | ||
end else begin | ||
end | ||
else begin | ||
curr_pred <= curr_pred; | ||
incorrect_pred <= 1; | ||
end | ||
end | ||
end | ||
|
||
always_comb begin | ||
case (branch_occr[1]) | ||
0: branch_taken = branch_occr[0]; | ||
1: branch_taken = curr_pred; | ||
end | ||
always_comb begin | ||
case(branch_occr[1]) | ||
0: branch_taken = branch_occr[0]; | ||
1: branch_taken = curr_pred; | ||
endcase | ||
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,54 +1,20 @@ | ||
module Con_EX #( | ||
WordSize = 32 | ||
) ( | ||
input clk, | ||
input rstn, | ||
input branch_taken_in, | ||
input [1:0] a_sel, | ||
input [1:0] b_sel, | ||
input [WordSize - 1:0] imm, | ||
input [WordSize - 1:0] pc_in, | ||
input [WordSize - 1:0] rs1d, | ||
input [WordSize - 1:0] rs2d_in, | ||
input [WordSize - 1:0] branch_addr_in, | ||
input [4:0] rdn_in, | ||
input [5:0] alu_mode, | ||
output logic branch_taken, | ||
output logic [4:0] rdn, | ||
output logic [WordSize - 1:0] pc, | ||
output logic [WordSize - 1:0] branch_addr, | ||
output logic [WordSize - 1:0] rs2d, | ||
output logic [WordSize - 1:0] alu_out | ||
WordSize = 32 | ||
)( | ||
input clk, rstn, branch_taken_in, | ||
input[1:0] a_sel, b_sel, | ||
input[WordSize - 1:0] imm, pc_in, rs1d, rs2d_in, branch_addr_in, | ||
input[4:0] rdn_in, | ||
input[5:0] alu_mode, | ||
output logic branch_taken, | ||
output logic [4:0] rdn, | ||
output logic [WordSize - 1:0] pc, branch_addr, rs2d, alu_out | ||
); | ||
|
||
logic [WordSize - 1:0] a, b; | ||
|
||
logic [WordSize - 1:0] a, b; | ||
IDEX #(WordSize) id_ex_latch(.clk(clk), .rstn(rstn), .branch_taken_in(branch_taken_in), .a_sel(a_sel), .b_sel(b_sel), .imm(imm), .pc_in(pc_in), .rs1d(rs1d), .rs2d_in(rs2d_in), .branch_addr_in(branch_addr_in), .rdn_in(rdn_in), .branch_taken(branch_taken), .rdn(rdn), .pc(pc), .branch_addr(branch_addr), .rs2d(rs2d), .a(a), .b(b)); | ||
|
||
IDEX #(WordSize) id_ex_latch ( | ||
.clk(clk), | ||
.rstn(rstn), | ||
.branch_taken_in(branch_taken_in), | ||
.a_sel(a_sel), | ||
.b_sel(b_sel), | ||
.imm(imm), | ||
.pc_in(pc_in), | ||
.rs1d(rs1d), | ||
.rs2d_in(rs2d_in), | ||
.branch_addr_in(branch_addr_in), | ||
.rdn_in(rdn_in), | ||
.branch_taken(branch_taken), | ||
.rdn(rdn), | ||
.pc(pc), | ||
.branch_addr(branch_addr), | ||
.rs2d(rs2d), | ||
.a(a), | ||
.b(b) | ||
); | ||
Alu #(WordSize) alu_modulemake(.a(a), .b(b), .alu_mode(alu_mode), .alu_out(alu_out)); | ||
|
||
Alu #(WordSize) alu_modulemake ( | ||
.a(a), | ||
.b(b), | ||
.alu_mode(alu_mode), | ||
.alu_out(alu_out) | ||
); | ||
|
||
endmodule | ||
endmodule |
Oops, something went wrong.