BranchPredictor.py revision 13627
19480Snilay@cs.wisc.edu# Copyright (c) 2012 Mark D. Hill and David A. Wood 210785Sgope@wisc.edu# Copyright (c) 2015 The University of Wisconsin 39480Snilay@cs.wisc.edu# All rights reserved. 49480Snilay@cs.wisc.edu# 59480Snilay@cs.wisc.edu# Redistribution and use in source and binary forms, with or without 69480Snilay@cs.wisc.edu# modification, are permitted provided that the following conditions are 79480Snilay@cs.wisc.edu# met: redistributions of source code must retain the above copyright 89480Snilay@cs.wisc.edu# notice, this list of conditions and the following disclaimer; 99480Snilay@cs.wisc.edu# redistributions in binary form must reproduce the above copyright 109480Snilay@cs.wisc.edu# notice, this list of conditions and the following disclaimer in the 119480Snilay@cs.wisc.edu# documentation and/or other materials provided with the distribution; 129480Snilay@cs.wisc.edu# neither the name of the copyright holders nor the names of its 139480Snilay@cs.wisc.edu# contributors may be used to endorse or promote products derived from 149480Snilay@cs.wisc.edu# this software without specific prior written permission. 159480Snilay@cs.wisc.edu# 169480Snilay@cs.wisc.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 179480Snilay@cs.wisc.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 189480Snilay@cs.wisc.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 199480Snilay@cs.wisc.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 209480Snilay@cs.wisc.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 219480Snilay@cs.wisc.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 229480Snilay@cs.wisc.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 239480Snilay@cs.wisc.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 249480Snilay@cs.wisc.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 259480Snilay@cs.wisc.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 269480Snilay@cs.wisc.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 279480Snilay@cs.wisc.edu# 2810785Sgope@wisc.edu# Authors: Nilay Vaish and Dibakar Gope 299480Snilay@cs.wisc.edu 309480Snilay@cs.wisc.edufrom m5.SimObject import SimObject 319480Snilay@cs.wisc.edufrom m5.params import * 3213432Spau.cabre@metempsy.comfrom m5.proxy import * 339480Snilay@cs.wisc.edu 349480Snilay@cs.wisc.educlass BranchPredictor(SimObject): 359480Snilay@cs.wisc.edu type = 'BranchPredictor' 369480Snilay@cs.wisc.edu cxx_class = 'BPredUnit' 379480Snilay@cs.wisc.edu cxx_header = "cpu/pred/bpred_unit.hh" 3810785Sgope@wisc.edu abstract = True 399480Snilay@cs.wisc.edu 4013432Spau.cabre@metempsy.com numThreads = Param.Unsigned(Parent.numThreads, "Number of threads") 4110785Sgope@wisc.edu BTBEntries = Param.Unsigned(4096, "Number of BTB entries") 4210785Sgope@wisc.edu BTBTagSize = Param.Unsigned(16, "Size of the BTB tags, in bits") 4310785Sgope@wisc.edu RASSize = Param.Unsigned(16, "RAS size") 4410785Sgope@wisc.edu instShiftAmt = Param.Unsigned(2, "Number of bits to shift instructions by") 4510785Sgope@wisc.edu 4611433Smitch.hayenga@arm.com useIndirect = Param.Bool(True, "Use indirect branch predictor") 4711433Smitch.hayenga@arm.com indirectHashGHR = Param.Bool(True, "Hash branch predictor GHR") 4811433Smitch.hayenga@arm.com indirectHashTargets = Param.Bool(True, "Hash path history targets") 4911433Smitch.hayenga@arm.com indirectSets = Param.Unsigned(256, "Cache sets for indirect predictor") 5011433Smitch.hayenga@arm.com indirectWays = Param.Unsigned(2, "Ways for indirect predictor") 5111433Smitch.hayenga@arm.com indirectTagSize = Param.Unsigned(16, "Indirect target cache tag bits") 5211433Smitch.hayenga@arm.com indirectPathLength = Param.Unsigned(3, 5311433Smitch.hayenga@arm.com "Previous indirect targets to use for path history") 5411433Smitch.hayenga@arm.com 5511433Smitch.hayenga@arm.com 5610785Sgope@wisc.edu 5710785Sgope@wisc.educlass LocalBP(BranchPredictor): 5810785Sgope@wisc.edu type = 'LocalBP' 5910785Sgope@wisc.edu cxx_class = 'LocalBP' 6010785Sgope@wisc.edu cxx_header = "cpu/pred/2bit_local.hh" 6110785Sgope@wisc.edu 629480Snilay@cs.wisc.edu localPredictorSize = Param.Unsigned(2048, "Size of local predictor") 639480Snilay@cs.wisc.edu localCtrBits = Param.Unsigned(2, "Bits per counter") 6410785Sgope@wisc.edu 6510785Sgope@wisc.edu 6610785Sgope@wisc.educlass TournamentBP(BranchPredictor): 6710785Sgope@wisc.edu type = 'TournamentBP' 6810785Sgope@wisc.edu cxx_class = 'TournamentBP' 6910785Sgope@wisc.edu cxx_header = "cpu/pred/tournament.hh" 7010785Sgope@wisc.edu 7110785Sgope@wisc.edu localPredictorSize = Param.Unsigned(2048, "Size of local predictor") 7210785Sgope@wisc.edu localCtrBits = Param.Unsigned(2, "Bits per counter") 7310785Sgope@wisc.edu localHistoryTableSize = Param.Unsigned(2048, "size of local history table") 749480Snilay@cs.wisc.edu globalPredictorSize = Param.Unsigned(8192, "Size of global predictor") 759480Snilay@cs.wisc.edu globalCtrBits = Param.Unsigned(2, "Bits per counter") 769480Snilay@cs.wisc.edu choicePredictorSize = Param.Unsigned(8192, "Size of choice predictor") 779480Snilay@cs.wisc.edu choiceCtrBits = Param.Unsigned(2, "Bits of choice counters") 789480Snilay@cs.wisc.edu 799480Snilay@cs.wisc.edu 8010785Sgope@wisc.educlass BiModeBP(BranchPredictor): 8110785Sgope@wisc.edu type = 'BiModeBP' 8210785Sgope@wisc.edu cxx_class = 'BiModeBP' 8310785Sgope@wisc.edu cxx_header = "cpu/pred/bi_mode.hh" 8410785Sgope@wisc.edu 8510785Sgope@wisc.edu globalPredictorSize = Param.Unsigned(8192, "Size of global predictor") 8610785Sgope@wisc.edu globalCtrBits = Param.Unsigned(2, "Bits per counter") 8710785Sgope@wisc.edu choicePredictorSize = Param.Unsigned(8192, "Size of choice predictor") 8810785Sgope@wisc.edu choiceCtrBits = Param.Unsigned(2, "Bits of choice counters") 8910785Sgope@wisc.edu 9013626Sjairo.balart@metempsy.comclass TAGEBase(SimObject): 9113626Sjairo.balart@metempsy.com type = 'TAGEBase' 9213626Sjairo.balart@metempsy.com cxx_class = 'TAGEBase' 9313626Sjairo.balart@metempsy.com cxx_header = "cpu/pred/tage_base.hh" 9413626Sjairo.balart@metempsy.com 9513626Sjairo.balart@metempsy.com numThreads = Param.Unsigned(Parent.numThreads, "Number of threads") 9613626Sjairo.balart@metempsy.com instShiftAmt = Param.Unsigned(Parent.instShiftAmt, 9713626Sjairo.balart@metempsy.com "Number of bits to shift instructions by") 9813454Spau.cabre@metempsy.com 9913454Spau.cabre@metempsy.com nHistoryTables = Param.Unsigned(7, "Number of history tables") 10013494Spau.cabre@metempsy.com minHist = Param.Unsigned(5, "Minimum history size of TAGE") 10113494Spau.cabre@metempsy.com maxHist = Param.Unsigned(130, "Maximum history size of TAGE") 10213454Spau.cabre@metempsy.com 10313454Spau.cabre@metempsy.com tagTableTagWidths = VectorParam.Unsigned( 10413454Spau.cabre@metempsy.com [0, 9, 9, 10, 10, 11, 11, 12], "Tag size in TAGE tag tables") 10513454Spau.cabre@metempsy.com logTagTableSizes = VectorParam.Int( 10613454Spau.cabre@metempsy.com [13, 9, 9, 9, 9, 9, 9, 9], "Log2 of TAGE table sizes") 10713454Spau.cabre@metempsy.com logRatioBiModalHystEntries = Param.Unsigned(2, 10813454Spau.cabre@metempsy.com "Log num of prediction entries for a shared hysteresis bit " \ 10913454Spau.cabre@metempsy.com "for the Bimodal") 11013454Spau.cabre@metempsy.com 11113454Spau.cabre@metempsy.com tagTableCounterBits = Param.Unsigned(3, "Number of tag table counter bits") 11213454Spau.cabre@metempsy.com tagTableUBits = Param.Unsigned(2, "Number of tag table u bits") 11313454Spau.cabre@metempsy.com 11413454Spau.cabre@metempsy.com histBufferSize = Param.Unsigned(2097152, 11513454Spau.cabre@metempsy.com "A large number to track all branch histories(2MEntries default)") 11613454Spau.cabre@metempsy.com 11713454Spau.cabre@metempsy.com pathHistBits = Param.Unsigned(16, "Path history size") 11813454Spau.cabre@metempsy.com logUResetPeriod = Param.Unsigned(18, 11913454Spau.cabre@metempsy.com "Log period in number of branches to reset TAGE useful counters") 12013626Sjairo.balart@metempsy.com numUseAltOnNa = Param.Unsigned(1, "Number of USE_ALT_ON_NA counters") 12113454Spau.cabre@metempsy.com useAltOnNaBits = Param.Unsigned(4, "Size of the USE_ALT_ON_NA counter") 12213454Spau.cabre@metempsy.com 12313626Sjairo.balart@metempsy.com maxNumAlloc = Param.Unsigned(1, 12413626Sjairo.balart@metempsy.com "Max number of TAGE entries allocted on mispredict") 12513626Sjairo.balart@metempsy.com 12613626Sjairo.balart@metempsy.com # List of enabled TAGE tables. If empty, all are enabled 12713626Sjairo.balart@metempsy.com noSkip = VectorParam.Bool([], "Vector of enabled TAGE tables") 12813626Sjairo.balart@metempsy.com 12913626Sjairo.balart@metempsy.com speculativeHistUpdate = Param.Bool(True, 13013626Sjairo.balart@metempsy.com "Use speculative update for histories") 13113626Sjairo.balart@metempsy.com 13213626Sjairo.balart@metempsy.com# TAGE branch predictor as described in https://www.jilp.org/vol8/v8paper1.pdf 13313626Sjairo.balart@metempsy.com# The default sizes below are for the 8C-TAGE configuration (63.5 Kbits) 13413626Sjairo.balart@metempsy.comclass TAGE(BranchPredictor): 13513626Sjairo.balart@metempsy.com type = 'TAGE' 13613626Sjairo.balart@metempsy.com cxx_class = 'TAGE' 13713626Sjairo.balart@metempsy.com cxx_header = "cpu/pred/tage.hh" 13813626Sjairo.balart@metempsy.com tage = Param.TAGEBase(TAGEBase(), "Tage object") 13913626Sjairo.balart@metempsy.com 14013626Sjairo.balart@metempsy.comclass LTAGE_TAGE(TAGEBase): 14113626Sjairo.balart@metempsy.com nHistoryTables = 12 14213626Sjairo.balart@metempsy.com minHist = 4 14313626Sjairo.balart@metempsy.com maxHist = 640 14413626Sjairo.balart@metempsy.com tagTableTagWidths = [0, 7, 7, 8, 8, 9, 10, 11, 12, 12, 13, 14, 15] 14513626Sjairo.balart@metempsy.com logTagTableSizes = [14, 10, 10, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9] 14613626Sjairo.balart@metempsy.com logUResetPeriod = 19 14713454Spau.cabre@metempsy.com 14813627Sjavier.bueno@metempsy.comclass LoopPredictor(SimObject): 14913627Sjavier.bueno@metempsy.com type = 'LoopPredictor' 15013627Sjavier.bueno@metempsy.com cxx_class = 'LoopPredictor' 15113627Sjavier.bueno@metempsy.com cxx_header = 'cpu/pred/loop_predictor.hh' 15213454Spau.cabre@metempsy.com 15311784Sarthur.perais@inria.fr logSizeLoopPred = Param.Unsigned(8, "Log size of the loop predictor") 15413444Spau.cabre@metempsy.com withLoopBits = Param.Unsigned(7, "Size of the WITHLOOP counter") 15513442Spau.cabre@metempsy.com loopTableAgeBits = Param.Unsigned(8, "Number of age bits per loop entry") 15613442Spau.cabre@metempsy.com loopTableConfidenceBits = Param.Unsigned(2, 15713442Spau.cabre@metempsy.com "Number of confidence bits per loop entry") 15813442Spau.cabre@metempsy.com loopTableTagBits = Param.Unsigned(14, "Number of tag bits per loop entry") 15913442Spau.cabre@metempsy.com loopTableIterBits = Param.Unsigned(14, "Nuber of iteration bits per loop") 16013444Spau.cabre@metempsy.com logLoopTableAssoc = Param.Unsigned(2, "Log loop predictor associativity") 16113442Spau.cabre@metempsy.com 16213493Spau.cabre@metempsy.com # Parameters for enabling modifications to the loop predictor 16313627Sjavier.bueno@metempsy.com # They have been copied from TAGE-GSC-IMLI 16413627Sjavier.bueno@metempsy.com # (http://www.irisa.fr/alf/downloads/seznec/TAGE-GSC-IMLI.tar) 16513493Spau.cabre@metempsy.com # 16613493Spau.cabre@metempsy.com # All of them should be disabled to match the original LTAGE implementation 16713493Spau.cabre@metempsy.com # (http://hpca23.cse.tamu.edu/taco/camino/cbp2/cbp-src/realistic-seznec.h) 16813493Spau.cabre@metempsy.com 16913493Spau.cabre@metempsy.com # Add speculation 17013493Spau.cabre@metempsy.com useSpeculation = Param.Bool(False, "Use speculation") 17113493Spau.cabre@metempsy.com 17213493Spau.cabre@metempsy.com # Add hashing for calculating the loop table index 17313493Spau.cabre@metempsy.com useHashing = Param.Bool(False, "Use hashing") 17413493Spau.cabre@metempsy.com 17513493Spau.cabre@metempsy.com # Add a direction bit to the loop table entries 17613493Spau.cabre@metempsy.com useDirectionBit = Param.Bool(False, "Use direction info") 17713493Spau.cabre@metempsy.com 17813627Sjavier.bueno@metempsy.com # If true, use random to decide whether to allocate or not, and only try 17913627Sjavier.bueno@metempsy.com # with one entry 18013627Sjavier.bueno@metempsy.com restrictAllocation = Param.Bool(False, 18113627Sjavier.bueno@metempsy.com "Restrict the allocation conditions") 18213627Sjavier.bueno@metempsy.com 18313627Sjavier.bueno@metempsy.com initialLoopIter = Param.Unsigned(1, "Initial iteration number") 18413627Sjavier.bueno@metempsy.com initialLoopAge = Param.Unsigned(255, "Initial age value") 18513627Sjavier.bueno@metempsy.com optionalAgeReset = Param.Bool(True, 18613627Sjavier.bueno@metempsy.com "Reset age bits optionally in some cases") 18713627Sjavier.bueno@metempsy.com 18813627Sjavier.bueno@metempsy.com 18913627Sjavier.bueno@metempsy.com# LTAGE branch predictor as described in 19013627Sjavier.bueno@metempsy.com# https://www.irisa.fr/caps/people/seznec/L-TAGE.pdf 19113627Sjavier.bueno@metempsy.com# It is basically a TAGE predictor plus a loop predictor 19213627Sjavier.bueno@metempsy.com# The differnt TAGE sizes are updated according to the paper values (256 Kbits) 19313627Sjavier.bueno@metempsy.comclass LTAGE(TAGE): 19413627Sjavier.bueno@metempsy.com type = 'LTAGE' 19513627Sjavier.bueno@metempsy.com cxx_class = 'LTAGE' 19613627Sjavier.bueno@metempsy.com cxx_header = "cpu/pred/ltage.hh" 19713627Sjavier.bueno@metempsy.com 19813627Sjavier.bueno@metempsy.com tage = LTAGE_TAGE() 19913627Sjavier.bueno@metempsy.com loop_predictor = Param.LoopPredictor(LoopPredictor(), "Loop predictor") 200