Now have global history working correctly.

This commit is contained in:
Ross Thompson 2021-06-01 10:57:43 -05:00
parent f6c88666cf
commit 857f59ab5c
8 changed files with 38 additions and 235 deletions

View File

@ -4,12 +4,12 @@ ROOT := ..
LIBRARY_DIRS := LIBRARY_DIRS :=
LIBRARY_FILES := LIBRARY_FILES :=
MARCH :=-march=rv64ic MARCH :=-march=rv64imfdc
MABI :=-mabi=lp64 MABI :=-mabi=lp64d
LINK_FLAGS :=$(MARCH) $(MABI) -nostartfiles LINK_FLAGS :=$(MARCH) $(MABI) -nostartfiles
AFLAGS =$(MARCH) $(MABI) -march=rv64ic -mabi=lp64 -W AFLAGS =$(MARCH) $(MABI) -W
CFLAGS =$(MARCH) $(MABI) -march=rv64ic -mabi=lp64 -mcmodel=medany -O2 CFLAGS =$(MARCH) $(MABI) -mcmodel=medany -O2
AS=riscv64-unknown-elf-as AS=riscv64-unknown-elf-as
CC=riscv64-unknown-elf-gcc CC=riscv64-unknown-elf-gcc
AR=riscv64-unknown-elf-ar AR=riscv64-unknown-elf-ar

View File

@ -5,6 +5,7 @@ int fail();
int simple_csrbr_test(); int simple_csrbr_test();
int lbu_test(); int lbu_test();
int icache_spill_test(); int icache_spill_test();
void global_hist_0_space_test();
void global_hist_1_space_test(); void global_hist_1_space_test();
void global_hist_2_space_test(); void global_hist_2_space_test();
void global_hist_3_space_test(); void global_hist_3_space_test();

View File

@ -4,7 +4,8 @@ int main(){
//int res = icache_spill_test(); //int res = icache_spill_test();
global_hist_3_space_test(); global_hist_3_space_test();
global_hist_2_space_test(); global_hist_2_space_test();
global_hist_1_space_test(); global_hist_1_space_test();
global_hist_0_space_test();
int res = 1; int res = 1;
if (res < 0) { if (res < 0) {
fail(); fail();

View File

@ -32,7 +32,7 @@
`define XLEN 64 `define XLEN 64
//`define MISA (32'h00000105) //`define MISA (32'h00000105)
`define MISA (32'h00000104 | 1<<5 | 1<<18 | 1 << 20 | 1 << 12 | 1 << 0) `define MISA (32'h00000104 | 1 << 5 | 1 << 3 | 1 << 18 | 1 << 20 | 1 << 12 | 1 << 0)
`define A_SUPPORTED ((`MISA >> 0) % 2 == 1) `define A_SUPPORTED ((`MISA >> 0) % 2 == 1)
`define C_SUPPORTED ((`MISA >> 2) % 2 == 1) `define C_SUPPORTED ((`MISA >> 2) % 2 == 1)
`define D_SUPPORTED ((`MISA >> 3) % 2 == 1) `define D_SUPPORTED ((`MISA >> 3) % 2 == 1)
@ -107,8 +107,8 @@
/* verilator lint_off ASSIGNDLY */ /* verilator lint_off ASSIGNDLY */
/* verilator lint_off PINCONNECTEMPTY */ /* verilator lint_off PINCONNECTEMPTY */
`define TWO_BIT_PRELOAD "../config/rv64icfd/twoBitPredictor.txt" `define TWO_BIT_PRELOAD "../config/rv64BP/twoBitPredictor.txt"
`define BTB_PRELOAD "../config/rv64icfd/BTBPredictor.txt" `define BTB_PRELOAD "../config/rv64BP/BTBPredictor.txt"
`define BPRED_ENABLED 1 `define BPRED_ENABLED 1
//`define BPTYPE "BPGSHARE" // BPGLOBAL or BPTWOBIT or BPGSHARE //`define BPTYPE "BPGSHARE" // BPGLOBAL or BPTWOBIT or BPGSHARE
`define BPTYPE "BPGLOBAL" // BPTWOBIT or "BPGSHARE" or BPLOCALPAg or BPGSHARE `define BPTYPE "BPGLOBAL" // BPTWOBIT or "BPGSHARE" or BPLOCALPAg or BPGSHARE

View File

@ -89,30 +89,29 @@ module bpred
globalHistoryPredictor DirPredictor(.clk(clk), globalHistoryPredictor DirPredictor(.clk(clk),
.reset(reset), .reset(reset),
.*, // Stalls and flushes .*, // Stalls and flushes
.LookUpPC(PCNextF), .PCNextF(PCNextF),
.BPPredF(BPPredF), .BPPredF(BPPredF),
// update // update
.BPPredD(BPPredD),
.InstrClassE(InstrClassE), .InstrClassE(InstrClassE),
.BPInstrClassE(BPInstrClassE), .BPInstrClassE(BPInstrClassE),
.BPPredDirWrongE(BPPredDirWrongE), .BPPredDirWrongE(BPPredDirWrongE),
.UpdatePC(PCE), .PCE(PCE),
.PCSrcE(PCSrcE), .PCSrcE(PCSrcE),
.UpdatePrediction(UpdateBPPredE)); .UpdateBPPredE(UpdateBPPredE));
end else if (`BPTYPE == "BPGSHARE") begin:Predictor end else if (`BPTYPE == "BPGSHARE") begin:Predictor
gsharePredictor DirPredictor(.clk(clk), gsharePredictor DirPredictor(.clk(clk),
.reset(reset), .reset(reset),
.*, // Stalls and flushes .*, // Stalls and flushes
.LookUpPC(PCNextF), .PCNextF(PCNextF),
.Prediction(BPPredF), .BPPredF(BPPredF),
// update // update
.UpdatePC(PCE), .InstrClassE(InstrClassE),
.UpdateEN(InstrClassE[0] & ~StallE), .BPInstrClassE(BPInstrClassE),
.SpeculativeUpdateEn(BPInstrClassF[0] & ~StallF), .BPPredDirWrongE(BPPredDirWrongE),
.BPPredDirWrongE(BPPredDirWrongE), .PCE(PCE),
.PCSrcE(PCSrcE), .PCSrcE(PCSrcE),
.UpdatePrediction(UpdateBPPredE)); .UpdateBPPredE(UpdateBPPredE));
end end
else if (`BPTYPE == "BPLOCALPAg") begin:Predictor else if (`BPTYPE == "BPLOCALPAg") begin:Predictor

View File

@ -33,19 +33,18 @@ module globalHistoryPredictor
(input logic clk, (input logic clk,
input logic reset, 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, input logic [`XLEN-1:0] PCNextF,
output logic [1:0] BPPredF, output logic [1:0] BPPredF,
// update // update
input logic [1:0] BPPredD,
input logic [4:0] InstrClassE, input logic [4:0] InstrClassE,
input logic [4:0] BPInstrClassE, input logic [4:0] BPInstrClassE,
input logic [4:0] BPInstrClassD, input logic [4:0] BPInstrClassD,
input logic [4:0] BPInstrClassF, input logic [4:0] BPInstrClassF,
input logic BPPredDirWrongE, input logic BPPredDirWrongE,
input logic [`XLEN-1:0] UpdatePC, input logic [`XLEN-1:0] PCE,
input logic PCSrcE, input logic PCSrcE,
input logic [1:0] UpdatePrediction input logic [1:0] UpdateBPPredE
); );
logic [k+1:0] GHR, GHRNext; logic [k+1:0] GHR, GHRNext;
@ -54,17 +53,10 @@ module globalHistoryPredictor
logic BPClassWrongNonCFI; logic BPClassWrongNonCFI;
logic BPClassWrongCFI; logic BPClassWrongCFI;
logic BPClassRightNonCFI; logic BPClassRightNonCFI;
/* -----\/----- EXCLUDED -----\/-----
logic [k-1:0] GHRD, GHRE, GHRLookup;
logic FlushedD, FlushedE;
-----/\----- EXCLUDED -----/\----- */
logic [6:0] GHRMuxSel; logic [6:0] GHRMuxSel;
logic GHRUpdateEN; logic GHRUpdateEN;
logic [k-1:0] GHRLookup;
assign BPClassRightNonCFI = ~BPInstrClassE[0] & ~InstrClassE[0]; assign BPClassRightNonCFI = ~BPInstrClassE[0] & ~InstrClassE[0];
assign BPClassWrongCFI = ~BPInstrClassE[0] & InstrClassE[0]; assign BPClassWrongCFI = ~BPInstrClassE[0] & InstrClassE[0];
@ -75,15 +67,9 @@ module globalHistoryPredictor
// GHR update selection, 1 hot encoded. // GHR update selection, 1 hot encoded.
assign GHRMuxSel[0] = ~BPInstrClassF[0] & (BPClassRightNonCFI | BPClassRightBPRight); assign GHRMuxSel[0] = ~BPInstrClassF[0] & (BPClassRightNonCFI | BPClassRightBPRight);
assign GHRMuxSel[1] = BPClassWrongCFI & ~BPInstrClassD[0]; assign GHRMuxSel[1] = BPClassWrongCFI & ~BPInstrClassD[0];
assign GHRMuxSel[3] = (BPClassRightBPWrong & ~BPInstrClassD[0]) | (BPClassWrongCFI & BPInstrClassD[0]);
assign GHRMuxSel[2] = BPClassWrongNonCFI & ~BPInstrClassD[0]; assign GHRMuxSel[2] = BPClassWrongNonCFI & ~BPInstrClassD[0];
assign GHRMuxSel[3] = (BPClassRightBPWrong & ~BPInstrClassD[0]) | (BPClassWrongCFI & BPInstrClassD[0]);
assign GHRMuxSel[4] = BPClassWrongNonCFI & BPInstrClassD[0]; assign GHRMuxSel[4] = BPClassWrongNonCFI & BPInstrClassD[0];
assign GHRMuxSel[5] = InstrClassE[0] & BPClassRightBPWrong & BPInstrClassD[0]; assign GHRMuxSel[5] = InstrClassE[0] & BPClassRightBPWrong & BPInstrClassD[0];
assign GHRMuxSel[6] = BPInstrClassF[0] & (BPClassRightNonCFI | (InstrClassE[0] & BPClassRightBPRight)); assign GHRMuxSel[6] = BPInstrClassF[0] & (BPClassRightNonCFI | (InstrClassE[0] & BPClassRightBPRight));
@ -99,7 +85,6 @@ module globalHistoryPredictor
7'b001_0000: GHRNext = {2'b00, GHR[k+1:2]}; // repair 2 7'b001_0000: GHRNext = {2'b00, GHR[k+1:2]}; // repair 2
7'b010_0000: GHRNext = {1'b0, GHR[k+1:2], PCSrcE}; // branch update + repair 1 7'b010_0000: GHRNext = {1'b0, GHR[k+1:2], PCSrcE}; // branch update + repair 1
7'b100_0000: GHRNext = {GHR[k-2+2:0], BPPredF[1]}; // speculative update 7'b100_0000: GHRNext = {GHR[k-2+2:0], BPPredF[1]}; // speculative update
//7'b100_0000: GHRNext = {k+1{1'bx}}; // speculative update
default: GHRNext = GHR[k-1+2:0]; default: GHRNext = GHR[k-1+2:0];
endcase endcase
end end
@ -113,50 +98,23 @@ module globalHistoryPredictor
// if actively updating the GHR at the time of prediction we want to us // if actively updating the GHR at the time of prediction we want to us
// GHRNext as the lookup rather than GHR. // GHRNext as the lookup rather than GHR.
//assign GHRLookup = GHRUpdateEN ? GHRNext : GHR;
assign PHTUpdateAdr0 = InstrClassE[0] ? GHR[k:1] : GHR[k-1:0]; assign PHTUpdateAdr0 = InstrClassE[0] ? GHR[k:1] : GHR[k-1:0];
assign PHTUpdateAdr1 = InstrClassE[0] ? GHR[k+1:2] : GHR[k:1]; assign PHTUpdateAdr1 = InstrClassE[0] ? GHR[k+1:2] : GHR[k:1];
assign PHTUpdateAdr = BPInstrClassD[0] ? PHTUpdateAdr1 : PHTUpdateAdr0; assign PHTUpdateAdr = BPInstrClassD[0] ? PHTUpdateAdr1 : PHTUpdateAdr0;
assign PHTUpdateEN = InstrClassE[0] & ~StallE; assign PHTUpdateEN = InstrClassE[0] & ~StallE;
assign GHRLookup = |GHRMuxSel[6:1] ? GHRNext[k-1:0] : GHR[k-1:0];
// Make Prediction by reading the correct address in the PHT and also update the new address in the PHT // Make Prediction by reading the correct address in the PHT and also update the new address in the PHT
SRAM2P1R1W #(k, 2) PHT(.clk(clk), SRAM2P1R1W #(k, 2) PHT(.clk(clk),
.reset(reset), .reset(reset),
.RA1(GHR[k-1:0]), //.RA1(GHR[k-1:0]),
.RA1(GHRLookup),
.RD1(BPPredF), .RD1(BPPredF),
.REN1(~StallF), .REN1(~StallF),
.WA1(PHTUpdateAdr), .WA1(PHTUpdateAdr),
.WD1(UpdatePrediction), .WD1(UpdateBPPredE),
.WEN1(PHTUpdateEN), .WEN1(PHTUpdateEN),
.BitWEN1(2'b11)); .BitWEN1(2'b11));
/* -----\/----- EXCLUDED -----\/-----
flopenr #(k) GlobalHistoryRegisterD(.clk(clk),
.reset(reset),
.en(~StallD & ~FlushedE),
.d(GHR),
.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));
-----/\----- EXCLUDED -----/\----- */
endmodule endmodule

View File

@ -1,159 +0,0 @@
///////////////////////////////////////////
// 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 SpeculativeUpdateEn, BPPredDirWrongE,
input logic [1:0] UpdatePrediction
);
logic [k-1:0] GHRF, GHRFNext, 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;
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]};
flopenr #(k) GlobalHistoryRegister(.clk(clk),
.reset(reset),
.en((UpdateEN & BPPredDirWrongE) | (SpeculativeUpdateEn)),
.d(GHRFNext),
.q(GHRF));
// for gshare xor the PC with the GHR
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 #(k, 2) PHT(.clk(clk),
.reset(reset),
.RA1(LookUpPCIndex),
.RD1(Prediction),
.REN1(~StallF),
.WA1(UpdatePCIndex),
.WD1(UpdatePrediction),
.WEN1(UpdateEN),
.BitWEN1(2'b11));
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));
/* -----\/----- EXCLUDED -----\/-----
// 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;
-----/\----- EXCLUDED -----/\----- */
//pipeline for GHR
/* -----\/----- EXCLUDED -----\/-----
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));
-----/\----- EXCLUDED -----/\----- */
/* flopenrc #(k) GHRRegD(.clk(clk),
.reset(reset),
.en(~StallD),
.clear(FlushD),
.d(GHRF),
.q(GHRD));
flopenrc #(k) GHRRegE(.clk(clk),
.reset(reset),
.en(~StallE),
.clear(FlushE),
.d(GHRD),
.q(GHRE));
*/
endmodule

View File

@ -438,8 +438,11 @@ string tests32f[] = '{
string testsBP64[] = '{ string testsBP64[] = '{
"rv64BP/simple", "10000", "rv64BP/simple", "10000",
"rv64BP/mmm", "1000000",
"rv64BP/linpack_bench", "1000000",
"rv64BP/sieve", "1000000",
"rv64BP/qsort", "1000000", "rv64BP/qsort", "1000000",
"rv64BP/sieve", "1000000" "rv64BP/dhrystone", "1000000"
}; };
string tests64p[] = '{ string tests64p[] = '{