From 08e9149e2098f321cbd6746c815f733ac1d33542 Mon Sep 17 00:00:00 2001 From: Shreya Sanghai Date: Tue, 16 Mar 2021 11:24:17 -0400 Subject: [PATCH 1/5] made performance counters count branch misprediction --- wally-pipelined/src/privileged/csr.sv | 2 +- wally-pipelined/src/privileged/csrc.sv | 5 +++-- wally-pipelined/src/privileged/privileged.sv | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/wally-pipelined/src/privileged/csr.sv b/wally-pipelined/src/privileged/csr.sv index 5d3c24a4..11892286 100644 --- a/wally-pipelined/src/privileged/csr.sv +++ b/wally-pipelined/src/privileged/csr.sv @@ -33,7 +33,7 @@ module csr ( input logic [`XLEN-1:0] PCM, SrcAM, input logic CSRReadM, CSRWriteM, TrapM, MTrapM, STrapM, UTrapM, mretM, sretM, uretM, input logic TimerIntM, ExtIntM, SwIntM, - input logic InstrValidW, FloatRegWriteW, LoadStallD, + input logic InstrValidW, FloatRegWriteW, LoadStallD, BPPredWrongE, input logic [1:0] NextPrivilegeModeM, PrivilegeModeW, input logic [`XLEN-1:0] CauseM, NextFaultMtvalM, output logic [1:0] STATUS_MPP, diff --git a/wally-pipelined/src/privileged/csrc.sv b/wally-pipelined/src/privileged/csrc.sv index ae14f0f3..57bac3c2 100644 --- a/wally-pipelined/src/privileged/csrc.sv +++ b/wally-pipelined/src/privileged/csrc.sv @@ -29,7 +29,7 @@ module csrc ( input logic clk, reset, - input logic InstrValidW, LoadStallD, CSRMWriteM, + input logic InstrValidW, LoadStallD, CSRMWriteM, BPPredWrongE, input logic [11:0] CSRAdrM, input logic [1:0] PrivilegeModeW, input logic [`XLEN-1:0] CSRWriteValM, @@ -62,7 +62,8 @@ module csrc ( assign MCOUNTEN[1] = 1'b0; assign MCOUNTEN[2] = InstrValidW; assign MCOUNTEN[3] = LoadStallD; - assign MCOUNTEN[`COUNTERS:4] = 0; + assign MCOUNTEN[4] = BPPredWrongE; + assign MCOUNTEN[`COUNTERS:5] = 0; genvar j; generate diff --git a/wally-pipelined/src/privileged/privileged.sv b/wally-pipelined/src/privileged/privileged.sv index a01fa557..cd18492a 100644 --- a/wally-pipelined/src/privileged/privileged.sv +++ b/wally-pipelined/src/privileged/privileged.sv @@ -36,7 +36,7 @@ module privileged ( output logic [`XLEN-1:0] CSRReadValW, output logic [`XLEN-1:0] PrivilegedNextPCM, output logic RetM, TrapM, - input logic InstrValidW, FloatRegWriteW, LoadStallD, + input logic InstrValidW, FloatRegWriteW, LoadStallD, BPPredWrongE, input logic PrivilegedM, input logic InstrMisalignedFaultM, InstrAccessFaultF, IllegalIEUInstrFaultD, input logic LoadMisalignedFaultM, LoadAccessFaultM, From 9eed875886fa797979c2fcda706d1eddeea0226c Mon Sep 17 00:00:00 2001 From: Shreya Sanghai Date: Tue, 16 Mar 2021 16:06:40 -0400 Subject: [PATCH 2/5] added global history branch predictor --- .../config/busybear/wally-config.vh | 1 + .../config/coremark/wally-config.vh | 1 + wally-pipelined/config/rv32ic/wally-config.vh | 1 + wally-pipelined/config/rv64ic/wally-config.vh | 1 + .../config/rv64icfd/wally-config.vh | 1 + wally-pipelined/src/ifu/bpred.sv | 34 ++++-- .../src/ifu/globalHistoryPredictor.sv | 110 ++++++++++++++++++ .../testbench/testbench-imperas.sv | 2 +- 8 files changed, 142 insertions(+), 9 deletions(-) create mode 100644 wally-pipelined/src/ifu/globalHistoryPredictor.sv diff --git a/wally-pipelined/config/busybear/wally-config.vh b/wally-pipelined/config/busybear/wally-config.vh index dc4d6451..f61df428 100644 --- a/wally-pipelined/config/busybear/wally-config.vh +++ b/wally-pipelined/config/busybear/wally-config.vh @@ -89,3 +89,4 @@ `define TWO_BIT_PRELOAD "../config/busybear/twoBitPredictor.txt" `define BTB_PRELOAD "../config/busybear/BTBPredictor.txt" +`define BPTYPE "BPGLOBAL" // BPGLOBAL or BPTWOBIT diff --git a/wally-pipelined/config/coremark/wally-config.vh b/wally-pipelined/config/coremark/wally-config.vh index 69a490fb..0418a1b8 100644 --- a/wally-pipelined/config/coremark/wally-config.vh +++ b/wally-pipelined/config/coremark/wally-config.vh @@ -92,3 +92,4 @@ `define TWO_BIT_PRELOAD "../config/coremark/twoBitPredictor.txt" `define BTB_PRELOAD "../config/coremark/BTBPredictor.txt" +`define BPTYPE "BPGLOBAL" // BPGLOBAL or BPTWOBIT diff --git a/wally-pipelined/config/rv32ic/wally-config.vh b/wally-pipelined/config/rv32ic/wally-config.vh index e68f8416..0f9e1eaf 100644 --- a/wally-pipelined/config/rv32ic/wally-config.vh +++ b/wally-pipelined/config/rv32ic/wally-config.vh @@ -88,3 +88,4 @@ `define TWO_BIT_PRELOAD "../config/rv32ic/twoBitPredictor.txt" `define BTB_PRELOAD "../config/rv32ic/BTBPredictor.txt" +`define BPTYPE "BPGLOBAL" // BPGLOBAL or BPTWOBIT diff --git a/wally-pipelined/config/rv64ic/wally-config.vh b/wally-pipelined/config/rv64ic/wally-config.vh index 6fa71272..390417d6 100644 --- a/wally-pipelined/config/rv64ic/wally-config.vh +++ b/wally-pipelined/config/rv64ic/wally-config.vh @@ -91,3 +91,4 @@ `define TWO_BIT_PRELOAD "../config/rv64ic/twoBitPredictor.txt" `define BTB_PRELOAD "../config/rv64ic/BTBPredictor.txt" +`define BPTYPE "BPGLOBAL" // BPGLOBAL or BPTWOBIT diff --git a/wally-pipelined/config/rv64icfd/wally-config.vh b/wally-pipelined/config/rv64icfd/wally-config.vh index be8d7c8a..c907df53 100644 --- a/wally-pipelined/config/rv64icfd/wally-config.vh +++ b/wally-pipelined/config/rv64icfd/wally-config.vh @@ -91,3 +91,4 @@ `define TWO_BIT_PRELOAD "../config/rv64icfd/twoBitPredictor.txt" `define BTB_PRELOAD "../config/rv64icfd/BTBPredictor.txt" +`define BPTYPE "BPGLOBAL" // BPGLOBAL or BPTWOBIT diff --git a/wally-pipelined/src/ifu/bpred.sv b/wally-pipelined/src/ifu/bpred.sv index 35ac6cfb..ad0f25d5 100644 --- a/wally-pipelined/src/ifu/bpred.sv +++ b/wally-pipelined/src/ifu/bpred.sv @@ -66,14 +66,32 @@ module bpred // Part 1 branch direction prediction - 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)); + end +endgenerate + // this predictor will have two pieces of data, // 1) A direction (1 = Taken, 0 = Not Taken) diff --git a/wally-pipelined/src/ifu/globalHistoryPredictor.sv b/wally-pipelined/src/ifu/globalHistoryPredictor.sv new file mode 100644 index 00000000..58e3f514 --- /dev/null +++ b/wally-pipelined/src/ifu/globalHistoryPredictor.sv @@ -0,0 +1,110 @@ +/////////////////////////////////////////// +// 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, + 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, /// *** need to add as input from bpred.sv + 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 [1:0] PredictionMemory; + logic DoForwarding, DoForwardingF; + logic [1:0] UpdatePredictionF; + + // for gshare xor the PC with the GHR + // TODO: change in sram memory2 module + // assign UpdatePCIndex = GHRE ^ UpdatePC; + // assign LookUpPCIndex = LookUpPC ^ GHR; + // 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(GHRF), + .RD1(PredictionMemory), + .REN1(1'b1), + .WA1(GHRE), + .WD1(UpdatePrediction), + .WEN1(UpdateEN), + .BitWEN1(2'b11)); + + + // need to forward when updating to the same address as reading. + // first we compare to see if the update and lookup addreses are the same + assign DoForwarding = GHRF == GHRE; + + // register the update value and the forwarding signal into the Fetch stage + // TODO: add stall logic *** + flopr #(1) DoForwardingReg(.clk(clk), + .reset(reset), + .d(DoForwarding), + .q(DoForwardingF)); + + flopr #(2) UpdatePredictionReg(.clk(clk), + .reset(reset), + .d(UpdatePrediction), + .q(UpdatePredictionF)); + + assign Prediction = DoForwardingF ? UpdatePredictionF : PredictionMemory; + + //pipeline for GHR + flopenrc #(k) GHRDReg(.clk(clk), + .reset(reset), + .en(~StallD), + .clear(FlushD), + .d(GHRF), + .q(GHRD)); + + flopenrc #(k) GHREReg(.clk(clk), + .reset(reset), + .en(~StallE), + .clear(FlushE), + .d(GHRD), + .q(GHRE)); + +endmodule diff --git a/wally-pipelined/testbench/testbench-imperas.sv b/wally-pipelined/testbench/testbench-imperas.sv index 3c9c4cc9..916420a9 100644 --- a/wally-pipelined/testbench/testbench-imperas.sv +++ b/wally-pipelined/testbench/testbench-imperas.sv @@ -474,7 +474,7 @@ string tests32i[] = { // initialize the branch predictor initial begin - $readmemb(`TWO_BIT_PRELOAD, dut.hart.ifu.bpred.DirPredictor.memory.memory); + $readmemb(`TWO_BIT_PRELOAD, dut.hart.ifu.bpred.Predictor.DirPredictor.PHT.memory); $readmemb(`BTB_PRELOAD, dut.hart.ifu.bpred.TargetPredictor.memory.memory); end From 36f0631203a182e1c655dd8798ae61fb36888008 Mon Sep 17 00:00:00 2001 From: Shreya Sanghai Date: Tue, 16 Mar 2021 17:03:01 -0400 Subject: [PATCH 3/5] added gshare and global history predictor --- .../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 | 14 ++- wally-pipelined/src/ifu/gshare.sv | 109 ++++++++++++++++++ 7 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 wally-pipelined/src/ifu/gshare.sv diff --git a/wally-pipelined/config/busybear/wally-config.vh b/wally-pipelined/config/busybear/wally-config.vh index f61df428..c0ef03b8 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 +`define BPTYPE "BPGLOBAL" // BPGLOBAL or BPTWOBIT or BPGSHARE diff --git a/wally-pipelined/config/coremark/wally-config.vh b/wally-pipelined/config/coremark/wally-config.vh index 0418a1b8..9263f21e 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 +`define BPTYPE "BPGLOBAL" // BPGLOBAL or BPTWOBIT or BPGSHARE diff --git a/wally-pipelined/config/rv32ic/wally-config.vh b/wally-pipelined/config/rv32ic/wally-config.vh index 0f9e1eaf..1d8321b6 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 +`define BPTYPE "BPGLOBAL" // BPGLOBAL or BPTWOBIT or BPGSHARE diff --git a/wally-pipelined/config/rv64ic/wally-config.vh b/wally-pipelined/config/rv64ic/wally-config.vh index 390417d6..4031e6df 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 +`define BPTYPE "BPGLOBAL" // BPGLOBAL or BPTWOBIT or BPGSHARE diff --git a/wally-pipelined/config/rv64icfd/wally-config.vh b/wally-pipelined/config/rv64icfd/wally-config.vh index c907df53..89557d8b 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 +`define BPTYPE "BPGLOBAL" // BPGLOBAL or BPTWOBIT or BPGSHARE diff --git a/wally-pipelined/src/ifu/bpred.sv b/wally-pipelined/src/ifu/bpred.sv index ad0f25d5..b4a11a37 100644 --- a/wally-pipelined/src/ifu/bpred.sv +++ b/wally-pipelined/src/ifu/bpred.sv @@ -89,7 +89,19 @@ generate .UpdateEN(InstrClassE[0]), .PCSrcE(PCSrcE), .UpdatePrediction(UpdateBPPredE)); - end + 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 diff --git a/wally-pipelined/src/ifu/gshare.sv b/wally-pipelined/src/ifu/gshare.sv new file mode 100644 index 00000000..e76954a3 --- /dev/null +++ b/wally-pipelined/src/ifu/gshare.sv @@ -0,0 +1,109 @@ +/////////////////////////////////////////// +// gshare.sv +// +// Written: Shreya Sanghai +// Email: ssanghai@hmc.edu +// Created: March 16, 2021 +// Modified: +// +// Purpose: Gshare 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 gsharePredictor + #(parameter int k = 10 + ) + (input logic clk, + input logic reset, + 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] LookUpPCIndex, UpdatePCIndex; + logic [1:0] PredictionMemory; + logic DoForwarding, DoForwardingF; + logic [1:0] UpdatePredictionF; + + // for gshare xor the PC with the GHR + assign UpdatePCIndex = GHRE ^ UpdatePC[k-1:0]; + assign LookUpPCIndex = LookUpPC ^ GHRF[k-1:0]; + // 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)); + + + // need to forward when updating to the same address as reading. + // first we compare to see if the update and lookup addreses are the same + assign DoForwarding = LookUpPCIndex == UpdatePCIndex; + + // register the update value and the forwarding signal into the Fetch stage + // TODO: add stall logic *** + flopr #(1) DoForwardingReg(.clk(clk), + .reset(reset), + .d(DoForwarding), + .q(DoForwardingF)); + + flopr #(2) UpdatePredictionReg(.clk(clk), + .reset(reset), + .d(UpdatePrediction), + .q(UpdatePredictionF)); + + assign Prediction = DoForwardingF ? UpdatePredictionF : PredictionMemory; + + //pipeline for GHR + flopenrc #(k) LookUpDReg(.clk(clk), + .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)); + +endmodule From 8f4051543cfb3ce584b8960ed25074194ffbbebc Mon Sep 17 00:00:00 2001 From: Ross Thompson Date: Thu, 18 Mar 2021 16:00:09 -0500 Subject: [PATCH 4/5] Fixed minor bug with the size of gshare. --- wally-pipelined/regression/wave.do | 14 ++++++-------- wally-pipelined/src/ifu/globalHistoryPredictor.sv | 3 +-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/wally-pipelined/regression/wave.do b/wally-pipelined/regression/wave.do index c37d657b..3de025fb 100644 --- a/wally-pipelined/regression/wave.do +++ b/wally-pipelined/regression/wave.do @@ -23,11 +23,9 @@ add wave -noupdate -group HDU -expand -group Flush -color Yellow /testbench/dut/ add wave -noupdate -group HDU -expand -group Stall -color Orange /testbench/dut/hart/StallF add wave -noupdate -group HDU -expand -group Stall -color Orange /testbench/dut/hart/StallD add wave -noupdate -group Bpred -expand -group direction -divider Update -add wave -noupdate -group Bpred -expand -group direction /testbench/dut/hart/ifu/bpred/DirPredictor/UpdatePC -add wave -noupdate -group Bpred -expand -group direction /testbench/dut/hart/ifu/bpred/DirPredictor/UpdateEN -add wave -noupdate -group Bpred -expand -group direction /testbench/dut/hart/ifu/bpred/DirPredictor/UpdatePCIndex -add wave -noupdate -group Bpred -expand -group direction /testbench/dut/hart/ifu/bpred/DirPredictor/UpdatePrediction -add wave -noupdate -group Bpred -expand -group direction /testbench/dut/hart/ifu/bpred/DirPredictor/memory/memory +add wave -noupdate -group Bpred -expand -group direction /testbench/dut/hart/ifu/bpred/Predictor/DirPredictor/UpdatePC +add wave -noupdate -group Bpred -expand -group direction /testbench/dut/hart/ifu/bpred/Predictor/DirPredictor/UpdateEN +add wave -noupdate -group Bpred -expand -group direction /testbench/dut/hart/ifu/bpred/Predictor/DirPredictor/UpdatePrediction add wave -noupdate -group Bpred -group {bp wrong} /testbench/dut/hart/ifu/bpred/TargetWrongE add wave -noupdate -group Bpred -group {bp wrong} /testbench/dut/hart/ifu/bpred/FallThroughWrongE add wave -noupdate -group Bpred -group {bp wrong} /testbench/dut/hart/ifu/bpred/PredictionDirWrongE @@ -130,8 +128,8 @@ add wave -noupdate -expand -group PCS /testbench/dut/hart/PCE add wave -noupdate -expand -group PCS /testbench/dut/hart/PCM add wave -noupdate -expand -group PCS /testbench/dut/hart/ifu/PCW TreeUpdate [SetDefaultTree] -WaveRestoreCursors {{Cursor 2} {3758805 ns} 0} {{Cursor 3} {4351471 ns} 0} -quietly wave cursor active 2 +WaveRestoreCursors {{Cursor 2} {3758805 ns} 0} +quietly wave cursor active 1 configure wave -namecolwidth 250 configure wave -valuecolwidth 229 configure wave -justifyvalue left @@ -146,4 +144,4 @@ configure wave -griddelta 40 configure wave -timeline 0 configure wave -timelineunits ns update -WaveRestoreZoom {4351320 ns} {4351862 ns} +WaveRestoreZoom {1644110 ns} {15262484 ns} diff --git a/wally-pipelined/src/ifu/globalHistoryPredictor.sv b/wally-pipelined/src/ifu/globalHistoryPredictor.sv index 58e3f514..b9addb38 100644 --- a/wally-pipelined/src/ifu/globalHistoryPredictor.sv +++ b/wally-pipelined/src/ifu/globalHistoryPredictor.sv @@ -41,7 +41,6 @@ module globalHistoryPredictor input logic [1:0] UpdatePrediction ); - localparam int Depth = 2^k; logic [k-1:0] GHRF, GHRD, GHRE; flopenr #(k) GlobalHistoryRegister(.clk(clk), @@ -63,7 +62,7 @@ module globalHistoryPredictor // 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), + SRAM2P1R1W #(k, 2) PHT(.clk(clk), .reset(reset), .RA1(GHRF), .RD1(PredictionMemory), From 1091dd10c12300fa23252c6498dc97e8e7c39565 Mon Sep 17 00:00:00 2001 From: Ross Thompson Date: Thu, 18 Mar 2021 16:05:59 -0500 Subject: [PATCH 5/5] 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 c0ef03b8..780976f3 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 9263f21e..97947467 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 1d8321b6..db1b2470 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 4031e6df..bb437e83 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 89557d8b..14978722 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 b4a11a37..38d95948 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 e76954a3..a1c5bbc7 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