1/* 2 * Copyright (c) 2018 Metempsy Technology Consulting 3 * All rights reserved. 4 * 5 * Copyright (c) 2006 INRIA (Institut National de Recherche en 6 * Informatique et en Automatique / French National Research Institute 7 * for Computer Science and Applied Mathematics) 8 * 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions are 13 * met: redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer; 15 * redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution; 18 * neither the name of the copyright holders nor the names of its 19 * contributors may be used to endorse or promote products derived from 20 * this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 * Author: André Seznec, Pau Cabre, Javier Bueno 35 * 36 */ 37 38/* 39 * TAGE-SC-L branch predictor base class (devised by Andre Seznec) 40 * It consits of a TAGE + a statistical corrector (SC) + a loop predictor (L) 41 */ 42 43#ifndef __CPU_PRED_TAGE_SC_L 44#define __CPU_PRED_TAGE_SC_L 45 46#include "cpu/pred/ltage.hh" 47#include "cpu/pred/statistical_corrector.hh" 48#include "params/TAGE_SC_L.hh" 49#include "params/TAGE_SC_L_LoopPredictor.hh" 50#include "params/TAGE_SC_L_TAGE.hh" 51 52class TAGE_SC_L_TAGE : public TAGEBase { 53 const unsigned firstLongTagTable; 54 const unsigned longTagsSize; 55 const unsigned shortTagsSize; 56 57 const unsigned logTagTableSize; 58 59 const unsigned shortTagsTageFactor; 60 const unsigned longTagsTageFactor; 61 62 const bool truncatePathHist; 63 64 public: 65 struct BranchInfo : public TAGEBase::BranchInfo { 66 bool lowConf; 67 bool highConf; 68 bool altConf; 69 bool medConf; 70 BranchInfo(TAGEBase &tage) : TAGEBase::BranchInfo(tage), 71 lowConf(false), highConf(false), altConf(false), medConf(false) 72 {} 73 virtual ~BranchInfo() 74 {} 75 }; 76 77 virtual TAGEBase::BranchInfo *makeBranchInfo() override; 78 79 TAGE_SC_L_TAGE(const TAGE_SC_L_TAGEParams *p) 80 : TAGEBase(p), 81 firstLongTagTable(p->firstLongTagTable), 82 longTagsSize(p->longTagsSize), 83 shortTagsSize(p->shortTagsSize), 84 logTagTableSize(p->logTagTableSize), 85 shortTagsTageFactor(p->shortTagsTageFactor), 86 longTagsTageFactor(p->longTagsTageFactor), 87 truncatePathHist(p->truncatePathHist) 88 {} 89 90 void calculateParameters() override; 91 92 void buildTageTables() override; 93 94 void calculateIndicesAndTags( 95 ThreadID tid, Addr branch_pc, TAGEBase::BranchInfo* bi) override; 96 97 unsigned getUseAltIdx(TAGEBase::BranchInfo* bi, Addr branch_pc) override; 98 99 void updateHistories( 100 ThreadID tid, Addr branch_pc, bool taken, TAGEBase::BranchInfo* b, 101 bool speculative, const StaticInstPtr &inst, 102 Addr target) override; 103 104 int bindex(Addr pc_in) const override; 105 int gindex(ThreadID tid, Addr pc, int bank) const override; 106 virtual int gindex_ext(int index, int bank) const = 0; 107 int F(int phist, int size, int bank) const override; 108 109 virtual uint16_t gtag(ThreadID tid, Addr pc, int bank) const override = 0; 110 111 void squash(ThreadID tid, bool taken, TAGEBase::BranchInfo *bi, 112 Addr target) override; 113 114 void updatePathAndGlobalHistory( 115 ThreadHistory & tHist, int brtype, bool taken, 116 Addr branch_pc, Addr target); 117 118 void adjustAlloc(bool & alloc, bool taken, bool pred_taken) override; 119 120 virtual void handleAllocAndUReset(bool alloc, bool taken, 121 TAGEBase::BranchInfo* bi, int nrand) override = 0; 122 123 void handleUReset() override; 124 125 virtual void handleTAGEUpdate( 126 Addr branch_pc, bool taken, TAGEBase::BranchInfo* bi) override = 0; 127 128 int calcDep(TAGEBase::BranchInfo* bi); 129 130 bool getBimodePred(Addr branch_pc, 131 TAGEBase::BranchInfo* tage_bi) const override; 132 133 void extraAltCalc(TAGEBase::BranchInfo* bi) override; 134 135}; 136 137class TAGE_SC_L_LoopPredictor : public LoopPredictor 138{ 139 public: 140 TAGE_SC_L_LoopPredictor(TAGE_SC_L_LoopPredictorParams *p) 141 : LoopPredictor(p) 142 {} 143 144 virtual bool calcConf(int index) const override; 145 virtual bool optionalAgeInc() const override; 146}; 147 148class TAGE_SC_L: public LTAGE 149{ 150 StatisticalCorrector *statisticalCorrector; 151 public: 152 TAGE_SC_L(const TAGE_SC_LParams *params); 153 154 bool predict( 155 ThreadID tid, Addr branch_pc, bool cond_branch, void* &b) override; 156 157 void regStats() override; 158 159 void update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history, 160 bool squashed, const StaticInstPtr & inst, 161 Addr corrTarget = MaxAddr) override; 162 163 protected: 164 165 struct TageSCLBranchInfo : public LTageBranchInfo 166 { 167 StatisticalCorrector::BranchInfo *scBranchInfo; 168 169 TageSCLBranchInfo(TAGEBase &tage, StatisticalCorrector &sc, 170 LoopPredictor &lp) 171 : LTageBranchInfo(tage, lp), scBranchInfo(sc.makeBranchInfo()) 172 {} 173 174 virtual ~TageSCLBranchInfo() 175 { 176 delete scBranchInfo; 177 } 178 }; 179 180 // more provider types 181 enum { 182 SC = LAST_LTAGE_PROVIDER_TYPE + 1 183 }; 184 185}; 186 187#endif // __CPU_PRED_TAGE_SC_L 188 189