From 37f6dbde93dddde9f701ebc4e231169a79aadde3 Mon Sep 17 00:00:00 2001 From: Jonathan Woodruff Date: Wed, 12 Jan 2022 16:08:33 +0000 Subject: [PATCH] Timing optimisation for Tournament Predictor. Start global-history-indexed lookups in the previous cycle. This is a general timing optimisation that should be pushed upstream at some point. --- src_Core/RISCY_OOO/procs/lib/Btb.bsv | 5 ++++- src_Core/RISCY_OOO/procs/lib/TourPred.bsv | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src_Core/RISCY_OOO/procs/lib/Btb.bsv b/src_Core/RISCY_OOO/procs/lib/Btb.bsv index a1d9059..2b92d72 100644 --- a/src_Core/RISCY_OOO/procs/lib/Btb.bsv +++ b/src_Core/RISCY_OOO/procs/lib/Btb.bsv @@ -131,7 +131,10 @@ module mkBtbCore(NextAddrPred#(hashSz)) // Start SupSizeX2 BTB lookups, but ensure to lookup in the appropriate // bank for the alignment of each potential branch. for (Integer i = 0; i < valueOf(SupSizeX2); i = i + 1) begin - BtbAddr a = unpack(pack(getBtbAddr(pc)) + fromInteger(i)); + // Only add lower bits for timing. + BtbAddr a = getBtbAddr(pc); + a = unpack({a.tag, {a.index,a.bank} + fromInteger(i)}); + //BtbAddr a = unpack(pack(getBtbAddr(pc)) + fromInteger(i)); fullRecords[a.bank].lookupStart(MapKeyIndex{key: hash(a.tag), index: a.index}); compressedRecords[a.bank].lookupStart(MapKeyIndex{key: hash(a.tag), index: a.index}); end diff --git a/src_Core/RISCY_OOO/procs/lib/TourPred.bsv b/src_Core/RISCY_OOO/procs/lib/TourPred.bsv index d751f0d..7cd680b 100644 --- a/src_Core/RISCY_OOO/procs/lib/TourPred.bsv +++ b/src_Core/RISCY_OOO/procs/lib/TourPred.bsv @@ -114,6 +114,8 @@ module mkTourPred(DirPredictor#(TourTrainInfo)); endfunction TourGlobalHist curGHist = gHistReg.history; // global history: MSB is the latest branch + Reg#(Vector#(SupSize, Bool)) globalTakenVec <- mkRegU; + Reg#(Vector#(SupSize, Bool)) useLocalVec <- mkRegU; Vector#(SupSize, DirPred#(TourTrainInfo)) predIfc; for(Integer i = 0; i < valueof(SupSize); i = i+1) begin @@ -127,12 +129,11 @@ module mkTourPred(DirPredictor#(TourTrainInfo)); // all previous branch in this cycle must be not taken // otherwise this branch should be on wrong path // because all inst in same cycle are fetched consecutively - TourGlobalHist globalHist = curGHist >> predCnt[i]; // get global prediction - Bool globalTaken = isTaken(globalBht.sub(globalHist)); + Bool globalTaken = globalTakenVec[predCnt[i]]; // make choice - Bool useLocal = isTaken(choiceBht.sub(globalHist)); + Bool useLocal = useLocalVec[predCnt[i]]; Bool taken = useLocal ? localTaken : globalTaken; // record prediction @@ -145,7 +146,7 @@ module mkTourPred(DirPredictor#(TourTrainInfo)); return DirPredResult { taken: taken, train: TourTrainInfo { - globalHist: globalHist, + globalHist: curGHist >> predCnt[i], localHist: localHist, globalTaken: globalTaken, localTaken: localTaken @@ -158,6 +159,14 @@ module mkTourPred(DirPredictor#(TourTrainInfo)); (* fire_when_enabled, no_implicit_conditions *) rule canonGlobalHist; gHistReg.addHistory(predRes[valueof(SupSize)], predCnt[valueof(SupSize)]); + // Buffer useLocalVec + // Reproduce next history; this would ideally be done in GlobalBrHistReg to avoid duplicating logic. + TourGlobalHist nHist = truncate({predRes[valueof(SupSize)], curGHist} >> predCnt[valueof(SupSize)]); + function Bool globalTakenLookup (Integer i) = isTaken(globalBht.sub(nHist >> i)); + function Bool useLocalLookup (Integer i) = isTaken(choiceBht.sub(nHist >> i)); + globalTakenVec <= genWith(globalTakenLookup); + useLocalVec <= genWith(useLocalLookup); + // Reset counters and prediction. predRes[valueof(SupSize)] <= 0; predCnt[valueof(SupSize)] <= 0; endrule