mirror of
https://github.com/openhwgroup/cvw
synced 2025-02-11 06:05:49 +00:00
Updated global history branch predictcor with the gshare improvements.
This commit is contained in:
parent
a9a7054e2f
commit
392716a608
@ -85,41 +85,37 @@ module bpred (
|
|||||||
logic [3:0] WrongPredInstrClassD;
|
logic [3:0] WrongPredInstrClassD;
|
||||||
|
|
||||||
|
|
||||||
//************ new resolve issues
|
|
||||||
logic BTBTargetWrongE;
|
logic BTBTargetWrongE;
|
||||||
logic RASTargetWrongE;
|
logic RASTargetWrongE;
|
||||||
logic JumpOrTakenBranchE;
|
logic JumpOrTakenBranchE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logic [`XLEN-1:0] PredPCD, PredPCE, RASPCD, RASPCE;
|
logic [`XLEN-1:0] PredPCD, PredPCE, RASPCD, RASPCE;
|
||||||
|
|
||||||
|
|
||||||
// Part 1 branch direction prediction
|
// Part 1 branch direction prediction
|
||||||
// look into the 2 port Sram model. something is wrong.
|
// look into the 2 port Sram model. something is wrong.
|
||||||
if (`BPRED_TYPE == "BPTWOBIT") begin:Predictor
|
if (`BPRED_TYPE == "BPTWOBIT") begin:Predictor
|
||||||
twoBitPredictor DirPredictor(.clk, .reset, .StallF, .StallD, .StallE, .StallM, .FlushD, .FlushE, .FlushM,
|
twoBitPredictor #(`BPRED_SIZE) DirPredictor(.clk, .reset, .StallF, .StallD, .StallE, .StallM, .FlushD, .FlushE, .FlushM,
|
||||||
.PCNextF, .PCM, .DirPredictionF, .DirPredictionWrongE,
|
.PCNextF, .PCM, .DirPredictionF, .DirPredictionWrongE,
|
||||||
.BranchInstrE(InstrClassE[0]), .BranchInstrM(InstrClassM[0]), .PCSrcE);
|
.BranchInstrE(InstrClassE[0]), .BranchInstrM(InstrClassM[0]), .PCSrcE);
|
||||||
|
|
||||||
end else if (`BPRED_TYPE == "BPGLOBAL") begin:Predictor
|
end else if (`BPRED_TYPE == "BPGLOBAL") begin:Predictor
|
||||||
globalhistory DirPredictor(.clk, .reset, .StallF, .StallD, .StallE, .StallM, .FlushD, .FlushE, .FlushM,
|
globalhistory #(`BPRED_SIZE) DirPredictor(.clk, .reset, .StallF, .StallD, .StallE, .StallM, .FlushD, .FlushE, .FlushM,
|
||||||
.PCNextF, .PCM, .DirPredictionF, .DirPredictionWrongE,
|
.PCNextF, .PCM, .DirPredictionF, .DirPredictionWrongE,
|
||||||
.BranchInstrE(InstrClassE[0]), .BranchInstrM(InstrClassM[0]), .PCSrcE);
|
.BranchInstrE(InstrClassE[0]), .BranchInstrM(InstrClassM[0]), .PCSrcE);
|
||||||
|
|
||||||
end else if (`BPRED_TYPE == "BPSPECULATIVEGLOBAL") begin:Predictor
|
end else if (`BPRED_TYPE == "BPSPECULATIVEGLOBAL") begin:Predictor
|
||||||
speculativeglobalhistory #(10) DirPredictor(.clk, .reset, .StallF, .StallD, .StallE, .StallM, .StallW, .FlushD, .FlushE, .FlushM, .FlushW,
|
speculativeglobalhistory #(`BPRED_SIZE) DirPredictor(.clk, .reset, .StallF, .StallD, .StallE, .StallM, .StallW, .FlushD, .FlushE, .FlushM, .FlushW,
|
||||||
.PCNextF, .PCF, .PCD, .PCE, .PCM, .DirPredictionF, .DirPredictionWrongE,
|
.DirPredictionF, .DirPredictionWrongE,
|
||||||
.BranchInstrF(PredInstrClassF[0]), .BranchInstrD(InstrClassD[0]), .BranchInstrE(InstrClassE[0]), .BranchInstrM(InstrClassM[0]),
|
.BranchInstrF(PredInstrClassF[0]), .BranchInstrD(InstrClassD[0]), .BranchInstrE(InstrClassE[0]), .BranchInstrM(InstrClassM[0]),
|
||||||
.BranchInstrW(InstrClassW[0]), .WrongPredInstrClassD, .PCSrcE);
|
.BranchInstrW(InstrClassW[0]), .WrongPredInstrClassD, .PCSrcE);
|
||||||
|
|
||||||
end else if (`BPRED_TYPE == "BPGSHARE") begin:Predictor
|
end else if (`BPRED_TYPE == "BPGSHARE") begin:Predictor
|
||||||
gshare DirPredictor(.clk, .reset, .StallF, .StallD, .StallE, .StallM, .FlushD, .FlushE, .FlushM,
|
gshare #(`BPRED_SIZE) DirPredictor(.clk, .reset, .StallF, .StallD, .StallE, .StallM, .FlushD, .FlushE, .FlushM,
|
||||||
.PCNextF, .PCE, .DirPredictionF, .DirPredictionWrongE,
|
.PCNextF, .PCE, .DirPredictionF, .DirPredictionWrongE,
|
||||||
.BranchInstrE(InstrClassE[0]), .BranchInstrM(InstrClassM[0]), .PCSrcE);
|
.BranchInstrE(InstrClassE[0]), .BranchInstrM(InstrClassM[0]), .PCSrcE);
|
||||||
|
|
||||||
end else if (`BPRED_TYPE == "BPSPECULATIVEGSHARE") begin:Predictor
|
end else if (`BPRED_TYPE == "BPSPECULATIVEGSHARE") begin:Predictor
|
||||||
speculativegshare DirPredictor(.clk, .reset, .StallF, .StallD, .StallE, .StallM, .StallW, .FlushD, .FlushE, .FlushM, .FlushW,
|
speculativegshare #(`BPRED_SIZE) DirPredictor(.clk, .reset, .StallF, .StallD, .StallE, .StallM, .StallW, .FlushD, .FlushE, .FlushM, .FlushW,
|
||||||
.PCNextF, .PCF, .PCD, .PCE, .PCM, .DirPredictionF, .DirPredictionWrongE,
|
.PCNextF, .PCF, .PCD, .PCE, .PCM, .DirPredictionF, .DirPredictionWrongE,
|
||||||
.BranchInstrF(PredInstrClassF[0]), .BranchInstrD(InstrClassD[0]), .BranchInstrE(InstrClassE[0]), .BranchInstrM(InstrClassM[0]),
|
.BranchInstrF(PredInstrClassF[0]), .BranchInstrD(InstrClassD[0]), .BranchInstrE(InstrClassE[0]), .BranchInstrM(InstrClassM[0]),
|
||||||
.BranchInstrW(InstrClassW[0]), .WrongPredInstrClassD, .PCSrcE);
|
.BranchInstrW(InstrClassW[0]), .WrongPredInstrClassD, .PCSrcE);
|
||||||
@ -139,7 +135,6 @@ module bpred (
|
|||||||
-----/\----- EXCLUDED -----/\----- */
|
-----/\----- EXCLUDED -----/\----- */
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
// this predictor will have two pieces of data,
|
// this predictor will have two pieces of data,
|
||||||
// 1) A direction (1 = Taken, 0 = Not Taken)
|
// 1) A direction (1 = Taken, 0 = Not Taken)
|
||||||
// 2) Any information which is necessary for the predictor to build its next state.
|
// 2) Any information which is necessary for the predictor to build its next state.
|
||||||
@ -260,7 +255,6 @@ module bpred (
|
|||||||
// branch class prediction wrong.
|
// branch class prediction wrong.
|
||||||
assign WrongPredInstrClassD = PredInstrClassD ^ InstrClassD;
|
assign WrongPredInstrClassD = PredInstrClassD ^ InstrClassD;
|
||||||
|
|
||||||
|
|
||||||
// Selects the BP or PC+2/4.
|
// Selects the BP or PC+2/4.
|
||||||
mux2 #(`XLEN) pcmux0(PCPlus2or4F, BPPredPCF, SelBPPredF, PCNext0F);
|
mux2 #(`XLEN) pcmux0(PCPlus2or4F, BPPredPCF, SelBPPredF, PCNext0F);
|
||||||
// If the prediction is wrong select the correct address.
|
// If the prediction is wrong select the correct address.
|
||||||
@ -293,7 +287,4 @@ module bpred (
|
|||||||
flopenrc #(`XLEN) RASTargetDReg(clk, reset, FlushD, ~StallD, RASPCF, RASPCD);
|
flopenrc #(`XLEN) RASTargetDReg(clk, reset, FlushD, ~StallD, RASPCF, RASPCD);
|
||||||
flopenrc #(`XLEN) RASTargetEReg(clk, reset, FlushE, ~StallE, RASPCD, RASPCE);
|
flopenrc #(`XLEN) RASTargetEReg(clk, reset, FlushE, ~StallE, RASPCD, RASPCE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
endmodule
|
endmodule
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
///////////////////////////////////////////
|
///////////////////////////////////////////
|
||||||
// globalHistoryPredictor.sv
|
// speculativeglobalhistory.sv
|
||||||
//
|
//
|
||||||
// Written: Shreya Sanghai
|
// Written: Shreya Sanghai
|
||||||
// Email: ssanghai@hmc.edu
|
// Email: ssanghai@hmc.edu
|
||||||
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
`include "wally-config.vh"
|
`include "wally-config.vh"
|
||||||
|
|
||||||
module speculativeglobalhistory #(parameter k = 10) (
|
module speculativeglobalhistory #(parameter int k = 10 ) (
|
||||||
input logic clk,
|
input logic clk,
|
||||||
input logic reset,
|
input logic reset,
|
||||||
input logic StallF, StallD, StallE, StallM, StallW,
|
input logic StallF, StallD, StallE, StallM, StallW,
|
||||||
@ -36,7 +36,6 @@ module speculativeglobalhistory #(parameter k = 10) (
|
|||||||
output logic [1:0] DirPredictionF,
|
output logic [1:0] DirPredictionF,
|
||||||
output logic DirPredictionWrongE,
|
output logic DirPredictionWrongE,
|
||||||
// update
|
// update
|
||||||
input logic [`XLEN-1:0] PCNextF, PCF, PCD, PCE, PCM,
|
|
||||||
input logic BranchInstrF, BranchInstrD, BranchInstrE, BranchInstrM, BranchInstrW,
|
input logic BranchInstrF, BranchInstrD, BranchInstrE, BranchInstrM, BranchInstrW,
|
||||||
input logic [3:0] WrongPredInstrClassD,
|
input logic [3:0] WrongPredInstrClassD,
|
||||||
input logic PCSrcE
|
input logic PCSrcE
|
||||||
@ -49,14 +48,14 @@ module speculativeglobalhistory #(parameter k = 10) (
|
|||||||
logic [1:0] NewDirPredictionF, NewDirPredictionD, NewDirPredictionE;
|
logic [1:0] NewDirPredictionF, NewDirPredictionD, NewDirPredictionE;
|
||||||
|
|
||||||
logic [k-1:0] GHRF;
|
logic [k-1:0] GHRF;
|
||||||
logic [k:0] GHRD, OldGHRE, GHRE, GHRM, GHRW;
|
logic GHRExtraF;
|
||||||
logic [k-1:0] GHRNextF;
|
logic [k-1:0] GHRD, GHRE, GHRM, GHRW;
|
||||||
logic [k:-1] GHRNextD, OldGHRD;
|
logic [k-1:0] GHRNextF;
|
||||||
logic [k:0] GHRNextE, GHRNextM, GHRNextW;
|
logic [k-1:0] GHRNextD;
|
||||||
|
logic [k-1:0] GHRNextE, GHRNextM, GHRNextW;
|
||||||
logic [k-1:0] IndexNextF, IndexF;
|
logic [k-1:0] IndexNextF, IndexF;
|
||||||
logic [k-1:0] IndexD, IndexE;
|
logic [k-1:0] IndexD, IndexE;
|
||||||
|
|
||||||
logic [`XLEN-1:0] PCW;
|
|
||||||
|
|
||||||
logic [1:0] ForwardNewDirPrediction, ForwardDirPredictionF;
|
logic [1:0] ForwardNewDirPrediction, ForwardDirPredictionF;
|
||||||
|
|
||||||
@ -102,30 +101,42 @@ module speculativeglobalhistory #(parameter k = 10) (
|
|||||||
satCounter2 BPDirUpdateE(.BrDir(PCSrcE), .OldState(DirPredictionE), .NewState(NewDirPredictionE));
|
satCounter2 BPDirUpdateE(.BrDir(PCSrcE), .OldState(DirPredictionE), .NewState(NewDirPredictionE));
|
||||||
|
|
||||||
// GHR pipeline
|
// GHR pipeline
|
||||||
assign GHRNextF = FlushD ? GHRNextD[k:1] :
|
// this version fails the regression test do to pessimistic x propagation.
|
||||||
BranchInstrF ? {DirPredictionF[1], GHRF[k-1:1]} :
|
// assign GHRNextF = FlushD | DirPredictionWrongE ? GHRNextD[k-1:0] :
|
||||||
GHRF;
|
// BranchInstrF ? {DirPredictionF[1], GHRF[k-1:1]} :
|
||||||
|
// GHRF;
|
||||||
|
|
||||||
|
always_comb begin
|
||||||
|
if(FlushD | DirPredictionWrongE) begin
|
||||||
|
GHRNextF = GHRNextD[k-1:0];
|
||||||
|
end else if(BranchInstrF) GHRNextF = {DirPredictionF[1], GHRF[k-1:1]};
|
||||||
|
else GHRNextF = GHRF;
|
||||||
|
end
|
||||||
|
|
||||||
flopenr #(k) GHRFReg(clk, reset, (~StallF) | FlushD, GHRNextF, GHRF);
|
flopenr #(k) GHRFReg(clk, reset, (~StallF) | FlushD, GHRNextF, GHRF);
|
||||||
|
flopenr #(1) GHRFExtraReg(clk, reset, (~StallF) | FlushD, GHRF[0], GHRExtraF);
|
||||||
|
|
||||||
assign GHRNextD = FlushD ? {GHRNextE, GHRNextE[0]} : {DirPredictionF[1], GHRF, GHRF[0]};
|
// use with out instruction class prediction
|
||||||
flopenr #(k+2) GHRDReg(clk, reset, (~StallD) | FlushD, GHRNextD, OldGHRD);
|
//assign GHRNextD = FlushD ? GHRNextE[k-1:0] : GHRF[k-1:0];
|
||||||
assign GHRD = WrongPredInstrClassD[0] & BranchInstrD ? {DirPredictionD[1], OldGHRD[k:1]} : // shift right
|
// with instruction class prediction
|
||||||
WrongPredInstrClassD[0] & ~BranchInstrD ? OldGHRD[k-1:-1] : // shift left
|
assign GHRNextD = (FlushD | DirPredictionWrongE) ? GHRNextE[k-1:0] :
|
||||||
OldGHRD[k:0];
|
WrongPredInstrClassD[0] & BranchInstrD ? {DirPredictionD[1], GHRF[k-1:1]} : // shift right
|
||||||
|
WrongPredInstrClassD[0] & ~BranchInstrD ? {GHRF[k-2:0], GHRExtraF}: // shift left
|
||||||
|
GHRF[k-1:0];
|
||||||
|
|
||||||
assign GHRNextE = FlushE ? GHRNextM : GHRD;
|
flopenr #(k) GHRDReg(clk, reset, (~StallD) | FlushD, GHRNextD, GHRD);
|
||||||
flopenr #(k+1) GHREReg(clk, reset, (~StallE) | FlushE, GHRNextE, OldGHRE);
|
|
||||||
assign GHRE = BranchInstrE ? {PCSrcE, OldGHRE[k-1:0]} : OldGHRE;
|
assign GHRNextE = BranchInstrE & ~FlushM ? {PCSrcE, GHRD[k-2:0]} : // if the branch is not flushed
|
||||||
|
FlushE ? GHRNextM : // branch is flushed
|
||||||
|
GHRD;
|
||||||
|
flopenr #(k) GHREReg(clk, reset, (~StallE) | FlushE, GHRNextE, GHRE);
|
||||||
|
|
||||||
assign GHRNextM = FlushM ? GHRNextW : GHRE;
|
assign GHRNextM = FlushM ? GHRNextW : GHRE;
|
||||||
flopenr #(k+1) GHRMReg(clk, reset, (~StallM) | FlushM, GHRNextM, GHRM);
|
flopenr #(k) GHRMReg(clk, reset, (~StallM) | FlushM, GHRNextM, GHRM);
|
||||||
|
|
||||||
assign GHRNextW = FlushW ? GHRW : GHRM;
|
assign GHRNextW = FlushW ? GHRW : GHRM;
|
||||||
flopenr #(k+1) GHRWReg(clk, reset, (BranchInstrM & ~StallW) | FlushW, GHRNextW, GHRW);
|
flopenr #(k) GHRWReg(clk, reset, (BranchInstrW & ~StallW) | FlushW, GHRNextW, GHRW);
|
||||||
|
|
||||||
assign DirPredictionWrongE = PCSrcE != DirPredictionE[1] & BranchInstrE;
|
assign DirPredictionWrongE = PCSrcE != DirPredictionE[1] & BranchInstrE;
|
||||||
|
|
||||||
flopenr #(`XLEN) PCWReg(clk, reset, ~StallW, PCM, PCW);
|
|
||||||
|
|
||||||
endmodule
|
endmodule
|
||||||
|
Loading…
Reference in New Issue
Block a user