From 9386e6a5247f9f53939bff59e7709f623a5fcea7 Mon Sep 17 00:00:00 2001 From: Ross Thompson Date: Thu, 18 Mar 2021 16:05:59 -0500 Subject: [PATCH] Switched to gshare from global history. Fixed a few minor bugs. --- .../config/busybear/wally-config.vh | 2 +- .../config/coremark/wally-config.vh | 2 +- wally-pipelined/config/rv32ic/wally-config.vh | 2 +- wally-pipelined/config/rv64ic/wally-config.vh | 2 +- .../config/rv64icfd/wally-config.vh | 2 +- wally-pipelined/src/ifu/bpred.sv | 62 +++++++++--------- wally-pipelined/src/ifu/gshare.sv | 64 +++++++++---------- 7 files changed, 68 insertions(+), 68 deletions(-) diff --git a/wally-pipelined/config/busybear/wally-config.vh b/wally-pipelined/config/busybear/wally-config.vh index c0ef03b8f..780976f3f 100644 --- a/wally-pipelined/config/busybear/wally-config.vh +++ b/wally-pipelined/config/busybear/wally-config.vh @@ -89,4 +89,4 @@ `define TWO_BIT_PRELOAD "../config/busybear/twoBitPredictor.txt" `define BTB_PRELOAD "../config/busybear/BTBPredictor.txt" -`define BPTYPE "BPGLOBAL" // BPGLOBAL or BPTWOBIT or BPGSHARE +`define BPTYPE "BPGSHARE" // BPGLOBAL or BPTWOBIT or BPGSHARE diff --git a/wally-pipelined/config/coremark/wally-config.vh b/wally-pipelined/config/coremark/wally-config.vh index 9263f21ee..979474672 100644 --- a/wally-pipelined/config/coremark/wally-config.vh +++ b/wally-pipelined/config/coremark/wally-config.vh @@ -92,4 +92,4 @@ `define TWO_BIT_PRELOAD "../config/coremark/twoBitPredictor.txt" `define BTB_PRELOAD "../config/coremark/BTBPredictor.txt" -`define BPTYPE "BPGLOBAL" // BPGLOBAL or BPTWOBIT or BPGSHARE +`define BPTYPE "BPGSHARE" // BPGLOBAL or BPTWOBIT or BPGSHARE diff --git a/wally-pipelined/config/rv32ic/wally-config.vh b/wally-pipelined/config/rv32ic/wally-config.vh index 1d8321b67..db1b24708 100644 --- a/wally-pipelined/config/rv32ic/wally-config.vh +++ b/wally-pipelined/config/rv32ic/wally-config.vh @@ -88,4 +88,4 @@ `define TWO_BIT_PRELOAD "../config/rv32ic/twoBitPredictor.txt" `define BTB_PRELOAD "../config/rv32ic/BTBPredictor.txt" -`define BPTYPE "BPGLOBAL" // BPGLOBAL or BPTWOBIT or BPGSHARE +`define BPTYPE "BPGSHARE" // BPGLOBAL or BPTWOBIT or BPGSHARE diff --git a/wally-pipelined/config/rv64ic/wally-config.vh b/wally-pipelined/config/rv64ic/wally-config.vh index 4031e6df4..bb437e834 100644 --- a/wally-pipelined/config/rv64ic/wally-config.vh +++ b/wally-pipelined/config/rv64ic/wally-config.vh @@ -91,4 +91,4 @@ `define TWO_BIT_PRELOAD "../config/rv64ic/twoBitPredictor.txt" `define BTB_PRELOAD "../config/rv64ic/BTBPredictor.txt" -`define BPTYPE "BPGLOBAL" // BPGLOBAL or BPTWOBIT or BPGSHARE +`define BPTYPE "BPGSHARE" // BPGLOBAL or BPTWOBIT or BPGSHARE diff --git a/wally-pipelined/config/rv64icfd/wally-config.vh b/wally-pipelined/config/rv64icfd/wally-config.vh index 89557d8bb..149787227 100644 --- a/wally-pipelined/config/rv64icfd/wally-config.vh +++ b/wally-pipelined/config/rv64icfd/wally-config.vh @@ -91,4 +91,4 @@ `define TWO_BIT_PRELOAD "../config/rv64icfd/twoBitPredictor.txt" `define BTB_PRELOAD "../config/rv64icfd/BTBPredictor.txt" -`define BPTYPE "BPGLOBAL" // BPGLOBAL or BPTWOBIT or BPGSHARE +`define BPTYPE "BPGSHARE" // BPGLOBAL or BPTWOBIT or BPGSHARE diff --git a/wally-pipelined/src/ifu/bpred.sv b/wally-pipelined/src/ifu/bpred.sv index b4a11a379..38d959484 100644 --- a/wally-pipelined/src/ifu/bpred.sv +++ b/wally-pipelined/src/ifu/bpred.sv @@ -66,43 +66,43 @@ module bpred // Part 1 branch direction prediction -generate - if (`BPTYPE == "BPTWOBIT") begin:Predictor - twoBitPredictor DirPredictor(.clk(clk), - .reset(reset), - .LookUpPC(PCNextF), - .Prediction(BPPredF), - // update - .UpdatePC(PCE), - .UpdateEN(InstrClassE[0]), - .UpdatePrediction(UpdateBPPredE)); + generate + if (`BPTYPE == "BPTWOBIT") begin:Predictor + twoBitPredictor DirPredictor(.clk(clk), + .reset(reset), + .LookUpPC(PCNextF), + .Prediction(BPPredF), + // update + .UpdatePC(PCE), + .UpdateEN(InstrClassE[0]), + .UpdatePrediction(UpdateBPPredE)); end else if (`BPTYPE == "BPGLOBAL") begin:Predictor globalHistoryPredictor DirPredictor(.clk(clk), - .reset(reset), - .*, // Stalls and flushes - .LookUpPC(PCNextF), - .Prediction(BPPredF), - // update - .UpdatePC(PCE), - .UpdateEN(InstrClassE[0]), - .PCSrcE(PCSrcE), - .UpdatePrediction(UpdateBPPredE)); + .reset(reset), + .*, // Stalls and flushes + .LookUpPC(PCNextF), + .Prediction(BPPredF), + // update + .UpdatePC(PCE), + .UpdateEN(InstrClassE[0]), + .PCSrcE(PCSrcE), + .UpdatePrediction(UpdateBPPredE)); end else if (`BPTYPE == "BPGSHARE") begin:Predictor - globalHistoryPredictor DirPredictor(.clk(clk), - .reset(reset), - .*, // Stalls and flushes - .LookUpPC(PCNextF), - .Prediction(BPPredF), - // update - .UpdatePC(PCE), - .UpdateEN(InstrClassE[0]), - .PCSrcE(PCSrcE), - .UpdatePrediction(UpdateBPPredE)); - end -endgenerate + gsharePredictor DirPredictor(.clk(clk), + .reset(reset), + .*, // Stalls and flushes + .LookUpPC(PCNextF), + .Prediction(BPPredF), + // update + .UpdatePC(PCE), + .UpdateEN(InstrClassE[0]), + .PCSrcE(PCSrcE), + .UpdatePrediction(UpdateBPPredE)); + end + endgenerate // this predictor will have two pieces of data, diff --git a/wally-pipelined/src/ifu/gshare.sv b/wally-pipelined/src/ifu/gshare.sv index e76954a3a..a1c5bbc7a 100644 --- a/wally-pipelined/src/ifu/gshare.sv +++ b/wally-pipelined/src/ifu/gshare.sv @@ -32,45 +32,45 @@ module gsharePredictor ) (input logic clk, input logic reset, - input logic StallF, StallD, StallE, FlushF, FlushD, FlushE, + input logic StallF, StallD, StallE, FlushF, FlushD, FlushE, input logic [`XLEN-1:0] LookUpPC, output logic [1:0] Prediction, // update input logic [`XLEN-1:0] UpdatePC, input logic UpdateEN, PCSrcE, input logic [1:0] UpdatePrediction - + ); - localparam int Depth = 2^k; - logic [k-1:0] GHRF, GHRD, GHRE; - - flopenr #(k) GlobalHistoryRegister(.clk(clk), - .reset(reset), - .en(UpdateEN), - .d({PCSrcE, GHRF[k-1:1] }), - .q(GHRF)); - + logic [k-1:0] GHRF, GHRD, GHRE; + logic [k-1:0] LookUpPCIndexD, LookUpPCIndexE; logic [k-1:0] LookUpPCIndex, UpdatePCIndex; logic [1:0] PredictionMemory; logic DoForwarding, DoForwardingF; logic [1:0] UpdatePredictionF; + flopenr #(k) GlobalHistoryRegister(.clk(clk), + .reset(reset), + .en(UpdateEN), + .d({PCSrcE, GHRF[k-1:1] }), + .q(GHRF)); + + // for gshare xor the PC with the GHR - assign UpdatePCIndex = GHRE ^ UpdatePC[k-1:0]; - assign LookUpPCIndex = LookUpPC ^ GHRF[k-1:0]; + assign UpdatePCIndex = GHRE ^ UpdatePC[k:1]; + assign LookUpPCIndex = GHRF ^ LookUpPC[k:1]; // Make Prediction by reading the correct address in the PHT and also update the new address in the PHT // GHR referes to the address that the past k branches points to in the prediction stage // GHRE refers to the address that the past k branches points to in the exectution stage - SRAM2P1R1W #(Depth, 2) PHT(.clk(clk), - .reset(reset), - .RA1(LookUpPCIndex), - .RD1(PredictionMemory), - .REN1(1'b1), - .WA1(UpdatePCIndex), - .WD1(UpdatePrediction), - .WEN1(UpdateEN), - .BitWEN1(2'b11)); + SRAM2P1R1W #(k, 2) PHT(.clk(clk), + .reset(reset), + .RA1(LookUpPCIndex), + .RD1(PredictionMemory), + .REN1(1'b1), + .WA1(UpdatePCIndex), + .WD1(UpdatePrediction), + .WEN1(UpdateEN), + .BitWEN1(2'b11)); // need to forward when updating to the same address as reading. @@ -93,17 +93,17 @@ module gsharePredictor //pipeline for GHR flopenrc #(k) LookUpDReg(.clk(clk), - .reset(reset), - .en(~StallD), - .clear(FlushD), - .d(LookUpPCIndex), - .q(LookUpPCIndexD)); + .reset(reset), + .en(~StallD), + .clear(FlushD), + .d(LookUpPCIndex), + .q(LookUpPCIndexD)); flopenrc #(k) LookUpEReg(.clk(clk), - .reset(reset), - .en(~StallE), - .clear(FlushE), - .d(LookUpPCIndexD), - .q(LookUpPCIndexE)); + .reset(reset), + .en(~StallE), + .clear(FlushE), + .d(LookUpPCIndexD), + .q(LookUpPCIndexE)); endmodule