-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
336 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
`timescale 1ns / 1ps | ||
`include "../defines/defines.svh" | ||
module Predictor( | ||
input clk, | ||
input rst, | ||
// 注意:此处的recover接的是regfile的recover,需要等分支指令提交进来了再进行恢复 | ||
input recover, | ||
input [31:0] br_PC, | ||
input IF3_isBR, | ||
input IF3_isJ, | ||
output PredInfo pred_info, | ||
output reg pred_taken, | ||
input commit_valid, | ||
input PredInfo committed_pred_info, | ||
input [31:0] committed_target, | ||
input committed_branch_taken, | ||
input committed_mispred | ||
); | ||
// 虽然是竞争的分支预测,也需要对两个进行更新 | ||
// 两个具有一周期延时的预测器 | ||
GlobalHistPred pred_info_global_o; | ||
LocalHistPred pred_info_local_o; | ||
BHREntry bhr; | ||
GlobalHist ghist; | ||
wire pred_taken_global, pred_taken_local; | ||
CPHTIndex CPHT_index, CPHT_index_update; | ||
CPHT_Entry [1023:0] CPHT; | ||
wire [31:0] br_PC_dly; | ||
// 内部拥有1级的pipeline | ||
LocalHistPred committed_pred_info_local; | ||
assign committed_pred_info_local.bht_index = committed_pred_info.bht_index; | ||
assign committed_pred_info_local.pht_index = committed_pred_info.pht_index; | ||
LocalHistPredictor localhist( | ||
.clk(clk), | ||
.rst(rst), | ||
.br_PC(br_PC), | ||
.pred_info(pred_info_local_o), | ||
.bhr(bhr), | ||
.pred_taken(pred_taken_local), | ||
.commit_update(commit_valid), | ||
.committed_pred_info(committed_pred_info_local), | ||
.committed_taken(committed_branch_taken), | ||
.br_PC_out(br_PC_dly) | ||
); | ||
|
||
GlobalHistPred committed_pred_info_global; | ||
assign committed_pred_info_global.pht_index_g = committed_pred_info.pht_index_g; | ||
GlobalHistPredictor globalhist( | ||
.clk(clk), | ||
.rst(rst), | ||
.br_PC(br_PC), | ||
.recover(recover), | ||
.pred_info(pred_info_global_o), | ||
.ghist(ghist), | ||
.pred_taken(pred_taken_global), | ||
// For updating global histroy | ||
.pred_valid_local(IF3_isBR || IF3_isJ), // ToDo | ||
.pred_taken_local(pred_taken || IF3_isJ), | ||
.commit_update(commit_valid), | ||
.committed_pred_info(committed_pred_info_global), | ||
.committed_taken(committed_branch_taken) | ||
); | ||
|
||
|
||
// Stage 2: Take the output and select the working predictor | ||
|
||
assign CPHT_index_update = committed_pred_info.cpht_index ; | ||
assign CPHT_index= ghist[19:10] ^ ghist[9:0] ^ br_PC_dly[12:3]; | ||
|
||
always @(posedge clk) begin | ||
if(rst) begin | ||
for(integer i = 0; i < 1024; i++) begin | ||
CPHT[i] <= 0; | ||
end | ||
end else if(commit_valid) begin | ||
// TODO | ||
if(committed_pred_info.use_global && committed_mispred) begin | ||
CPHT[CPHT_index_update] <= CPHT[CPHT_index_update] == 2'b00 ? 2'b00 : CPHT[CPHT_index_update] - 2'b01; | ||
end else begin | ||
CPHT[CPHT_index_update] <= CPHT[CPHT_index_update] == 2'b11 ? 2'b11 : CPHT[CPHT_index_update] + 2'b01; | ||
end | ||
end | ||
end | ||
|
||
wire pred_taken_o, use_global_o; | ||
assign pred_taken_o = CPHT[CPHT_index] == 1 ? pred_taken_global : pred_taken_local; | ||
assign use_global_o = CPHT[CPHT_index] == 1; | ||
|
||
// Output logic | ||
PredInfo pred_info_o; | ||
assign pred_info_o.bht_index = pred_info_local_o.bht_index; | ||
assign pred_info_o.pht_index = pred_info_local_o.pht_index; | ||
assign pred_info_o.pht_index_g = pred_info_global_o.pht_index_g; | ||
assign pred_info_o.cpht_index = CPHT_index; | ||
assign pred_info_o.use_global = use_global_o; | ||
always @(posedge clk) begin | ||
if(rst) begin | ||
pred_info <= 0; | ||
pred_taken <= 0; | ||
end else begin | ||
pred_info <= pred_info_o; | ||
pred_taken <= pred_taken_o; | ||
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
`timescale 1ns / 1ps | ||
`include "../defines/defines.svh" | ||
|
||
module GlobalHistPredictor( | ||
input clk, | ||
input rst, | ||
input recover, | ||
input [31:0] br_PC, | ||
output GlobalHistPred pred_info, | ||
output GlobalHist ghist, | ||
output pred_taken, | ||
input pred_valid_local, | ||
input pred_taken_local, | ||
input commit_update, | ||
input GlobalHistPred committed_pred_info, | ||
input committed_taken | ||
); | ||
// 2 Pipeline stage | ||
// 1 Cycle Delay | ||
// Output is not registered | ||
GlobalHist ghist_committed; | ||
|
||
PHTEntry [1023:0] PHT; | ||
PHTEntry current_ph; | ||
PHTIndex_G pht_index, pht_index_r; | ||
assign pht_index = ghist[19:10] ^ ghist[9:0] ^ br_PC[12:3]; // TODO | ||
|
||
// Pipeline Register | ||
always @(posedge clk) begin | ||
if(rst) begin | ||
pht_index_r <= 0; | ||
end else begin | ||
pht_index_r <= pht_index; | ||
end | ||
end | ||
|
||
assign current_ph = PHT[pht_index_r]; | ||
assign pred_taken = current_ph[1]; | ||
assign pred_info.pht_index_g = pht_index_r; | ||
|
||
|
||
PHTEntry pht_inc; | ||
PHTEntry pht_dec; | ||
|
||
assign pht_inc = PHT[committed_pred_info.pht_index_g] == 2'b11 ? 2'b11 : PHT[committed_pred_info.pht_index_g] + 2'b01; | ||
assign pht_dec = PHT[committed_pred_info.pht_index_g] == 2'b00 ? 2'b00 : PHT[committed_pred_info.pht_index_g] - 2'b01; | ||
|
||
// Update of global history(speculatively) | ||
always @(posedge clk) begin | ||
if(rst) begin | ||
ghist <= 0; | ||
end else if(recover) begin | ||
ghist <= ghist_committed; | ||
end else if(pred_valid_local) begin | ||
ghist <= { ghist[`GHLEN-2:0], pred_taken_local }; | ||
end | ||
end | ||
// Update the committed global history | ||
always @(posedge clk) begin | ||
if(rst) begin | ||
ghist_committed <= 0; | ||
end else if(commit_update) begin | ||
ghist_committed <= { ghist_committed[`GHLEN-2:0], committed_taken }; | ||
end | ||
end | ||
// Update logic | ||
always @(posedge clk) begin | ||
if(rst) begin | ||
for(integer i=0;i<1024;i++) begin | ||
PHT[i] <= 0; | ||
end | ||
end else if(commit_update) begin | ||
PHT[committed_pred_info.pht_index_g] <= committed_taken ? pht_inc : pht_dec; | ||
end | ||
end | ||
|
||
endmodule |
Oops, something went wrong.