BranchPredictor.py revision 13494:ed4ed5351b16
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
90# TAGE branch predictor as described in https://www.jilp.org/vol8/v8paper1.pdf
91# The default sizes below are for the 8C-TAGE configuration (63.5 Kbits)
92class TAGE(BranchPredictor):
93    type = 'TAGE'
94    cxx_class = 'TAGE'
95    cxx_header = "cpu/pred/tage.hh"
96
97    nHistoryTables = Param.Unsigned(7, "Number of history tables")
98    minHist = Param.Unsigned(5, "Minimum history size of TAGE")
99    maxHist = Param.Unsigned(130, "Maximum history size of TAGE")
100
101    tagTableTagWidths = VectorParam.Unsigned(
102        [0, 9, 9, 10, 10, 11, 11, 12], "Tag size in TAGE tag tables")
103    logTagTableSizes = VectorParam.Int(
104        [13, 9, 9, 9, 9, 9, 9, 9], "Log2 of TAGE table sizes")
105    logRatioBiModalHystEntries = Param.Unsigned(2,
106        "Log num of prediction entries for a shared hysteresis bit " \
107        "for the Bimodal")
108
109    tagTableCounterBits = Param.Unsigned(3, "Number of tag table counter bits")
110    tagTableUBits = Param.Unsigned(2, "Number of tag table u bits")
111
112    histBufferSize = Param.Unsigned(2097152,
113            "A large number to track all branch histories(2MEntries default)")
114
115    pathHistBits = Param.Unsigned(16, "Path history size")
116    logUResetPeriod = Param.Unsigned(18,
117        "Log period in number of branches to reset TAGE useful counters")
118    useAltOnNaBits = Param.Unsigned(4, "Size of the USE_ALT_ON_NA counter")
119
120
121# LTAGE branch predictor as described in
122# https://www.irisa.fr/caps/people/seznec/L-TAGE.pdf
123# It is basically a TAGE predictor plus a loop predictor
124# The differnt TAGE sizes are updated according to the paper values (256 Kbits)
125class LTAGE(TAGE):
126    type = 'LTAGE'
127    cxx_class = 'LTAGE'
128    cxx_header = "cpu/pred/ltage.hh"
129
130    nHistoryTables = 12
131    minHist = 4
132    maxHist = 640
133    tagTableTagWidths = [0, 7, 7, 8, 8, 9, 10, 11, 12, 12, 13, 14, 15]
134    logTagTableSizes = [14, 10, 10, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9]
135    logUResetPeriod = 19
136
137    logSizeLoopPred = Param.Unsigned(8, "Log size of the loop predictor")
138    withLoopBits = Param.Unsigned(7, "Size of the WITHLOOP counter")
139    loopTableAgeBits = Param.Unsigned(8, "Number of age bits per loop entry")
140    loopTableConfidenceBits = Param.Unsigned(2,
141            "Number of confidence bits per loop entry")
142    loopTableTagBits = Param.Unsigned(14, "Number of tag bits per loop entry")
143    loopTableIterBits = Param.Unsigned(14, "Nuber of iteration bits per loop")
144    logLoopTableAssoc = Param.Unsigned(2, "Log loop predictor associativity")
145
146    # Parameters for enabling modifications to the loop predictor
147    # They have been copied from ISL-TAGE
148    # (https://www.jilp.org/jwac-2/program/03_seznec.tgz)
149    #
150    # All of them should be disabled to match the original LTAGE implementation
151    # (http://hpca23.cse.tamu.edu/taco/camino/cbp2/cbp-src/realistic-seznec.h)
152
153    # Add speculation
154    useSpeculation = Param.Bool(False, "Use speculation")
155
156    # Add hashing for calculating the loop table index
157    useHashing = Param.Bool(False, "Use hashing")
158
159    # Add a direction bit to the loop table entries
160    useDirectionBit = Param.Bool(False, "Use direction info")
161
162