2021-03-16 20:06:40 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// globalHistoryPredictor.sv
|
|
|
|
//
|
|
|
|
// Written: Shreya Sanghai
|
|
|
|
// Email: ssanghai@hmc.edu
|
|
|
|
// Created: March 16, 2021
|
|
|
|
// Modified:
|
|
|
|
//
|
|
|
|
// Purpose: Global History Branch predictor with parameterized global history register
|
|
|
|
//
|
|
|
|
// A component of the Wally configurable RISC-V project.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2021 Harvey Mudd College & Oklahoma State University
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
|
|
|
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
|
|
|
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
|
|
|
|
// is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
|
|
|
// OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
|
|
|
`include "wally-config.vh"
|
|
|
|
|
|
|
|
module globalHistoryPredictor
|
|
|
|
#(parameter int k = 10
|
|
|
|
)
|
|
|
|
(input logic clk,
|
|
|
|
input logic reset,
|
2021-05-25 19:26:22 +00:00
|
|
|
input logic StallF, StallD, StallE, FlushF, FlushD, FlushE,
|
2021-03-16 20:06:40 +00:00
|
|
|
input logic [`XLEN-1:0] LookUpPC,
|
|
|
|
output logic [1:0] Prediction,
|
|
|
|
// update
|
|
|
|
input logic [`XLEN-1:0] UpdatePC,
|
2021-05-28 04:06:28 +00:00
|
|
|
input logic UpdateEN, PCSrcE,
|
|
|
|
input logic SpeculativeUpdateEn, BPPredDirWrongE,
|
2021-03-16 20:06:40 +00:00
|
|
|
input logic [1:0] UpdatePrediction
|
2021-05-25 19:26:22 +00:00
|
|
|
|
2021-03-16 20:06:40 +00:00
|
|
|
);
|
2021-05-28 04:06:28 +00:00
|
|
|
logic [k-1:0] GHRF, GHRFNext, GHRD, GHRE, GHRLookup;
|
|
|
|
|
|
|
|
logic FlushedD, FlushedE;
|
|
|
|
|
|
|
|
|
|
|
|
// if the prediction is wrong we need to restore the ghr.
|
|
|
|
assign GHRFNext = BPPredDirWrongE ? {PCSrcE, GHRE[k-1:1]} :
|
|
|
|
{Prediction[1], GHRF[k-1:1]};
|
2021-03-16 20:06:40 +00:00
|
|
|
|
2021-05-25 19:26:22 +00:00
|
|
|
flopenr #(k) GlobalHistoryRegister(.clk(clk),
|
|
|
|
.reset(reset),
|
2021-05-28 04:06:28 +00:00
|
|
|
.en((UpdateEN & BPPredDirWrongE) | (SpeculativeUpdateEn)),
|
2021-05-25 19:26:22 +00:00
|
|
|
.d(GHRFNext),
|
|
|
|
.q(GHRF));
|
2021-04-01 16:52:40 +00:00
|
|
|
|
2021-05-28 04:06:28 +00:00
|
|
|
// if actively updating the GHR at the time of prediction we want to us
|
|
|
|
// GHRFNext as the lookup rather than GHRF.
|
|
|
|
|
|
|
|
assign GHRLookup = UpdateEN ? GHRFNext : GHRF;
|
|
|
|
|
2021-03-16 20:06:40 +00:00
|
|
|
// Make Prediction by reading the correct address in the PHT and also update the new address in the PHT
|
2021-05-25 19:26:22 +00:00
|
|
|
SRAM2P1R1W #(k, 2) PHT(.clk(clk),
|
|
|
|
.reset(reset),
|
|
|
|
.RA1(GHRF),
|
|
|
|
.RD1(Prediction),
|
|
|
|
.REN1(~StallF),
|
2021-05-28 04:06:28 +00:00
|
|
|
.WA1(GHRE),
|
2021-05-25 19:26:22 +00:00
|
|
|
.WD1(UpdatePrediction),
|
|
|
|
.WEN1(UpdateEN),
|
|
|
|
.BitWEN1(2'b11));
|
2021-03-16 20:06:40 +00:00
|
|
|
|
2021-05-28 04:06:28 +00:00
|
|
|
flopenr #(k) GlobalHistoryRegisterD(.clk(clk),
|
|
|
|
.reset(reset),
|
|
|
|
.en(~StallD & ~FlushedE),
|
|
|
|
.d(GHRF),
|
|
|
|
.q(GHRD));
|
|
|
|
|
|
|
|
flopenr #(k) GlobalHistoryRegisterE(.clk(clk),
|
|
|
|
.reset(reset),
|
|
|
|
.en(~StallE & ~ FlushedE),
|
|
|
|
.d(GHRD),
|
|
|
|
.q(GHRE));
|
|
|
|
|
|
|
|
|
|
|
|
flopenr #(1) flushedDReg(.clk(clk),
|
|
|
|
.reset(reset),
|
|
|
|
.en(~StallD),
|
|
|
|
.d(FlushD),
|
|
|
|
.q(FlushedD));
|
|
|
|
|
|
|
|
flopenr #(1) flushedEReg(.clk(clk),
|
|
|
|
.reset(reset),
|
|
|
|
.en(~StallE),
|
|
|
|
.d(FlushE | FlushedD),
|
|
|
|
.q(FlushedE));
|
|
|
|
|
2021-03-16 20:06:40 +00:00
|
|
|
|
|
|
|
endmodule
|