BranchPredictor.py revision 13627
1# Copyright (c) 2012 Mark D. Hill and David A. Wood 2# Copyright (c) 2015 The University of Wisconsin 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer; 9# redistributions in binary form must reproduce the above copyright 10# notice, this list of conditions and the following disclaimer in the 11# documentation and/or other materials provided with the distribution; 12# neither the name of the copyright holders nor the names of its 13# contributors may be used to endorse or promote products derived from 14# this software without specific prior written permission. 15# 16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27# 28# Authors: Nilay Vaish and Dibakar Gope 29 30from m5.SimObject import SimObject 31from m5.params import * 32from m5.proxy import * 33 34class BranchPredictor(SimObject): 35 type = 'BranchPredictor' 36 cxx_class = 'BPredUnit' 37 cxx_header = "cpu/pred/bpred_unit.hh" 38 abstract = True 39 40 numThreads = Param.Unsigned(Parent.numThreads, "Number of threads") 41 BTBEntries = Param.Unsigned(4096, "Number of BTB entries") 42 BTBTagSize = Param.Unsigned(16, "Size of the BTB tags, in bits") 43 RASSize = Param.Unsigned(16, "RAS size") 44 instShiftAmt = Param.Unsigned(2, "Number of bits to shift instructions by") 45 46 useIndirect = Param.Bool(True, "Use indirect branch predictor") 47 indirectHashGHR = Param.Bool(True, "Hash branch predictor GHR") 48 indirectHashTargets = Param.Bool(True, "Hash path history targets") 49 indirectSets = Param.Unsigned(256, "Cache sets for indirect predictor") 50 indirectWays = Param.Unsigned(2, "Ways for indirect predictor") 51 indirectTagSize = Param.Unsigned(16, "Indirect target cache tag bits") 52 indirectPathLength = Param.Unsigned(3, 53 "Previous indirect targets to use for path history") 54 55 56 57class LocalBP(BranchPredictor): 58 type = 'LocalBP' 59 cxx_class = 'LocalBP' 60 cxx_header = "cpu/pred/2bit_local.hh" 61 62 localPredictorSize = Param.Unsigned(2048, "Size of local predictor") 63 localCtrBits = Param.Unsigned(2, "Bits per counter") 64 65 66class TournamentBP(BranchPredictor): 67 type = 'TournamentBP' 68 cxx_class = 'TournamentBP' 69 cxx_header = "cpu/pred/tournament.hh" 70 71 localPredictorSize = Param.Unsigned(2048, "Size of local predictor") 72 localCtrBits = Param.Unsigned(2, "Bits per counter") 73 localHistoryTableSize = Param.Unsigned(2048, "size of local history table") 74 globalPredictorSize = Param.Unsigned(8192, "Size of global predictor") 75 globalCtrBits = Param.Unsigned(2, "Bits per counter") 76 choicePredictorSize = Param.Unsigned(8192, "Size of choice predictor") 77 choiceCtrBits = Param.Unsigned(2, "Bits of choice counters") 78 79 80class BiModeBP(BranchPredictor): 81 type = 'BiModeBP' 82 cxx_class = 'BiModeBP' 83 cxx_header = "cpu/pred/bi_mode.hh" 84 85 globalPredictorSize = Param.Unsigned(8192, "Size of global predictor") 86 globalCtrBits = Param.Unsigned(2, "Bits per counter") 87 choicePredictorSize = Param.Unsigned(8192, "Size of choice predictor") 88 choiceCtrBits = Param.Unsigned(2, "Bits of choice counters") 89 90class TAGEBase(SimObject): 91 type = 'TAGEBase' 92 cxx_class = 'TAGEBase' 93 cxx_header = "cpu/pred/tage_base.hh" 94 95 numThreads = Param.Unsigned(Parent.numThreads, "Number of threads") 96 instShiftAmt = Param.Unsigned(Parent.instShiftAmt, 97 "Number of bits to shift instructions by") 98 99 nHistoryTables = Param.Unsigned(7, "Number of history tables") 100 minHist = Param.Unsigned(5, "Minimum history size of TAGE") 101 maxHist = Param.Unsigned(130, "Maximum history size of TAGE") 102 103 tagTableTagWidths = VectorParam.Unsigned( 104 [0, 9, 9, 10, 10, 11, 11, 12], "Tag size in TAGE tag tables") 105 logTagTableSizes = VectorParam.Int( 106 [13, 9, 9, 9, 9, 9, 9, 9], "Log2 of TAGE table sizes") 107 logRatioBiModalHystEntries = Param.Unsigned(2, 108 "Log num of prediction entries for a shared hysteresis bit " \ 109 "for the Bimodal") 110 111 tagTableCounterBits = Param.Unsigned(3, "Number of tag table counter bits") 112 tagTableUBits = Param.Unsigned(2, "Number of tag table u bits") 113 114 histBufferSize = Param.Unsigned(2097152, 115 "A large number to track all branch histories(2MEntries default)") 116 117 pathHistBits = Param.Unsigned(16, "Path history size") 118 logUResetPeriod = Param.Unsigned(18, 119 "Log period in number of branches to reset TAGE useful counters") 120 numUseAltOnNa = Param.Unsigned(1, "Number of USE_ALT_ON_NA counters") 121 useAltOnNaBits = Param.Unsigned(4, "Size of the USE_ALT_ON_NA counter") 122 123 maxNumAlloc = Param.Unsigned(1, 124 "Max number of TAGE entries allocted on mispredict") 125 126 # List of enabled TAGE tables. If empty, all are enabled 127 noSkip = VectorParam.Bool([], "Vector of enabled TAGE tables") 128 129 speculativeHistUpdate = Param.Bool(True, 130 "Use speculative update for histories") 131 132# TAGE branch predictor as described in https://www.jilp.org/vol8/v8paper1.pdf 133# The default sizes below are for the 8C-TAGE configuration (63.5 Kbits) 134class TAGE(BranchPredictor): 135 type = 'TAGE' 136 cxx_class = 'TAGE' 137 cxx_header = "cpu/pred/tage.hh" 138 tage = Param.TAGEBase(TAGEBase(), "Tage object") 139 140class LTAGE_TAGE(TAGEBase): 141 nHistoryTables = 12 142 minHist = 4 143 maxHist = 640 144 tagTableTagWidths = [0, 7, 7, 8, 8, 9, 10, 11, 12, 12, 13, 14, 15] 145 logTagTableSizes = [14, 10, 10, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9] 146 logUResetPeriod = 19 147 148class LoopPredictor(SimObject): 149 type = 'LoopPredictor' 150 cxx_class = 'LoopPredictor' 151 cxx_header = 'cpu/pred/loop_predictor.hh' 152 153 logSizeLoopPred = Param.Unsigned(8, "Log size of the loop predictor") 154 withLoopBits = Param.Unsigned(7, "Size of the WITHLOOP counter") 155 loopTableAgeBits = Param.Unsigned(8, "Number of age bits per loop entry") 156 loopTableConfidenceBits = Param.Unsigned(2, 157 "Number of confidence bits per loop entry") 158 loopTableTagBits = Param.Unsigned(14, "Number of tag bits per loop entry") 159 loopTableIterBits = Param.Unsigned(14, "Nuber of iteration bits per loop") 160 logLoopTableAssoc = Param.Unsigned(2, "Log loop predictor associativity") 161 162 # Parameters for enabling modifications to the loop predictor 163 # They have been copied from TAGE-GSC-IMLI 164 # (http://www.irisa.fr/alf/downloads/seznec/TAGE-GSC-IMLI.tar) 165 # 166 # All of them should be disabled to match the original LTAGE implementation 167 # (http://hpca23.cse.tamu.edu/taco/camino/cbp2/cbp-src/realistic-seznec.h) 168 169 # Add speculation 170 useSpeculation = Param.Bool(False, "Use speculation") 171 172 # Add hashing for calculating the loop table index 173 useHashing = Param.Bool(False, "Use hashing") 174 175 # Add a direction bit to the loop table entries 176 useDirectionBit = Param.Bool(False, "Use direction info") 177 178 # If true, use random to decide whether to allocate or not, and only try 179 # with one entry 180 restrictAllocation = Param.Bool(False, 181 "Restrict the allocation conditions") 182 183 initialLoopIter = Param.Unsigned(1, "Initial iteration number") 184 initialLoopAge = Param.Unsigned(255, "Initial age value") 185 optionalAgeReset = Param.Bool(True, 186 "Reset age bits optionally in some cases") 187 188 189# LTAGE branch predictor as described in 190# https://www.irisa.fr/caps/people/seznec/L-TAGE.pdf 191# It is basically a TAGE predictor plus a loop predictor 192# The differnt TAGE sizes are updated according to the paper values (256 Kbits) 193class LTAGE(TAGE): 194 type = 'LTAGE' 195 cxx_class = 'LTAGE' 196 cxx_header = "cpu/pred/ltage.hh" 197 198 tage = LTAGE_TAGE() 199 loop_predictor = Param.LoopPredictor(LoopPredictor(), "Loop predictor") 200