gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ltage.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 The University of Wisconsin
3  *
4  * Copyright (c) 2006 INRIA (Institut National de Recherche en
5  * Informatique et en Automatique / French National Research Institute
6  * for Computer Science and Applied Mathematics)
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are
12  * met: redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer;
14  * redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution;
17  * neither the name of the copyright holders nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Authors: Vignyan Reddy, Dibakar Gope and Arthur Perais,
34  * from AndrĂ© Seznec's code.
35  */
36 
37 /* @file
38  * Implementation of a L-TAGE branch predictor. TAGE is a global-history based
39  * branch predictor. It features a PC-indexed bimodal predictor and N
40  * partially tagged tables, indexed with a hash of the PC and the global
41  * branch history. The different lengths of global branch history used to
42  * index the partially tagged tables grow geometrically. A small path history
43  * is also used in the hash. L-TAGE also features a loop predictor that records
44  * iteration count of loops and predicts accordingly.
45  *
46  * All TAGE tables are accessed in parallel, and the one using the longest
47  * history that matches provides the prediction (some exceptions apply).
48  * Entries are allocated in components using a longer history than the
49  * one that predicted when the prediction is incorrect.
50  */
51 
52 #ifndef __CPU_PRED_LTAGE
53 #define __CPU_PRED_LTAGE
54 
55 #include <vector>
56 
57 #include "base/types.hh"
58 #include "cpu/pred/bpred_unit.hh"
59 #include "params/LTAGE.hh"
60 
61 class LTAGE: public BPredUnit
62 {
63  public:
64  LTAGE(const LTAGEParams *params);
65 
66  // Base class methods.
67  void uncondBranch(ThreadID tid, Addr br_pc, void* &bp_history) override;
68  bool lookup(ThreadID tid, Addr branch_addr, void* &bp_history) override;
69  void btbUpdate(ThreadID tid, Addr branch_addr, void* &bp_history) override;
70  void update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history,
71  bool squashed) override;
72  void squash(ThreadID tid, void *bp_history) override;
73  unsigned getGHR(ThreadID tid, void *bp_history) const override;
74 
75  private:
76  // Prediction Structures
77  // Loop Predictor Entry
78  struct LoopEntry
79  {
80  uint16_t numIter;
81  uint16_t currentIter;
82  uint16_t currentIterSpec;
83  uint8_t confidence;
84  uint16_t tag;
85  uint8_t age;
86  bool dir;
87 
89  confidence(0), tag(0), age(0), dir(0) { }
90  };
91 
92  // Bimodal Predictor Entry
93  struct BimodalEntry
94  {
95  uint8_t pred;
96  uint8_t hyst;
97 
98  BimodalEntry() : pred(0), hyst(1) { }
99  };
100 
101  // Tage Entry
102  struct TageEntry
103  {
104  int8_t ctr;
105  uint16_t tag;
106  int8_t u;
107  TageEntry() : ctr(0), tag(0), u(0) { }
108  };
109 
110  // Folded History Table - compressed history
111  // to mix with instruction PC to index partially
112  // tagged tables.
114  {
115  unsigned comp;
118  int outpoint;
119 
120  void init(int original_length, int compressed_length)
121  {
122  comp = 0;
123  origLength = original_length;
124  compLength = compressed_length;
125  outpoint = original_length % compressed_length;
126  }
127 
128  void update(uint8_t * h)
129  {
130  comp = (comp << 1) | h[0];
131  comp ^= h[origLength] << outpoint;
132  comp ^= (comp >> compLength);
133  comp &= (ULL(1) << compLength) - 1;
134  }
135  };
136 
137  // Primary branch history entry
138  struct BranchInfo
139  {
140  int pathHist;
141  int ptGhist;
142  int hitBank;
144  int altBank;
147  int loopTag;
148  uint16_t currentIter;
149 
150  bool tagePred;
151  bool altTaken;
152  bool loopPred;
155  int loopHit;
160 
161  // Pointer to dynamically allocated storage
162  // to save table indices and folded histories.
163  // To do one call to new instead of five.
164  int *storage;
165 
166  // Pointers to actual saved array within the dynamically
167  // allocated storage.
169  int *tableTags;
170  int *ci;
171  int *ct0;
172  int *ct1;
173 
174  BranchInfo(int sz)
175  : pathHist(0), ptGhist(0),
176  hitBank(0), hitBankIndex(0),
177  altBank(0), altBankIndex(0),
178  bimodalIndex(0), loopTag(0), currentIter(0),
179  tagePred(false), altTaken(false), loopPred(false),
180  loopPredValid(false), loopIndex(0), loopHit(0),
181  condBranch(false), longestMatchPred(false),
182  pseudoNewAlloc(false), branchPC(0)
183  {
184  storage = new int [sz * 5];
186  tableTags = storage + sz;
187  ci = tableTags + sz;
188  ct0 = ci + sz;
189  ct1 = ct0 + sz;
190  }
191 
193  {
194  delete[] storage;
195  }
196  };
197 
203  int bindex(Addr pc_in) const;
204 
210  int lindex(Addr pc_in) const;
211 
220  inline int gindex(ThreadID tid, Addr pc, int bank) const;
221 
229  int F(int phist, int size, int bank) const;
230 
238  inline uint16_t gtag(ThreadID tid, Addr pc, int bank) const;
239 
247  void ctrUpdate(int8_t & ctr, bool taken, int nbits);
248 
256  bool getBimodePred(Addr pc, BranchInfo* bi) const;
257 
265  void baseUpdate(Addr pc, bool taken, BranchInfo* bi);
266 
274  bool getLoop(Addr pc, BranchInfo* bi) const;
275 
283  void loopUpdate(Addr pc, bool Taken, BranchInfo* bi);
284 
293  void updateGHist(uint8_t * &h, bool dir, uint8_t * tab, int &PT);
294 
305  bool predict(ThreadID tid, Addr branch_pc, bool cond_branch, void* &b);
306 
317  void update(ThreadID tid, Addr branch_pc, bool taken, BranchInfo* bi);
318 
331  void updateHistories(ThreadID tid, Addr branch_pc, bool taken, void* b);
332 
345  void squash(ThreadID tid, bool taken, void *bp_history);
346 
355  void specLoopUpdate(Addr pc, bool taken, BranchInfo* bi);
356 
357  const unsigned logSizeBiMP;
358  const unsigned logSizeTagTables;
359  const unsigned logSizeLoopPred;
360  const unsigned nHistoryTables;
361  const unsigned tagTableCounterBits;
362  const unsigned histBufferSize;
363  const unsigned minHist;
364  const unsigned maxHist;
365  const unsigned minTagWidth;
366 
370 
371  // Keep per-thread histories to
372  // support SMT.
373  struct ThreadHistory {
374  // Speculative path history
375  // (LSB of branch address)
376  int pathHist;
377 
378  // Speculative branch direction
379  // history (circular buffer)
380  // @TODO Convert to std::vector<bool>
381  uint8_t *globalHistory;
382 
383  // Pointer to most recent branch outcome
384  uint8_t* gHist;
385 
386  // Index to most recent branch outcome
387  int ptGhist;
388 
389  // Speculative folded histories.
392  };
393 
395 
396  int tagWidths[15];
397  int tagTableSizes[15];
400  int *tableTags;
401 
404  int tCounter;
405  int logTick;
406 };
407 
408 #endif // __CPU_PRED_LTAGE
void updateHistories(ThreadID tid, Addr branch_pc, bool taken, void *b)
(Speculatively) updates global histories (path and direction).
Definition: ltage.cc:628
uint8_t confidence
Definition: ltage.hh:83
LTAGE(const LTAGEParams *params)
Definition: ltage.cc:50
const unsigned minHist
Definition: ltage.hh:363
void init(int original_length, int compressed_length)
Definition: ltage.hh:120
TageEntry ** gtable
Definition: ltage.hh:368
const unsigned maxHist
Definition: ltage.hh:364
Definition: ltage.hh:61
const unsigned nHistoryTables
Definition: ltage.hh:360
int lindex(Addr pc_in) const
Computes the index used to access the loop predictor.
Definition: ltage.cc:145
void baseUpdate(Addr pc, bool taken, BranchInfo *bi)
Updates the bimodal predictor.
Definition: ltage.cc:218
int * histLengths
Definition: ltage.hh:398
int * tableIndices
Definition: ltage.hh:168
const unsigned minTagWidth
Definition: ltage.hh:365
const Params * params() const
Definition: sim_object.hh:111
uint8_t * gHist
Definition: ltage.hh:384
BimodalEntry * btable
Definition: ltage.hh:367
void btbUpdate(ThreadID tid, Addr branch_addr, void *&bp_history) override
If a branch is not taken, because the BTB address is invalid or missing, this function sets the appro...
Definition: ltage.cc:715
unsigned getGHR(ThreadID tid, void *bp_history) const override
Definition: ltage.cc:386
int8_t ctr
Definition: ltage.hh:104
Bitfield< 20, 16 > bi
Definition: types.hh:65
int8_t useAltPredForNewlyAllocated
Definition: ltage.hh:403
STL vector class.
Definition: stl.hh:40
int * tableTags
Definition: ltage.hh:169
uint16_t tag
Definition: ltage.hh:105
void update(uint8_t *h)
Definition: ltage.hh:128
uint8_t hyst
Definition: ltage.hh:96
Bitfield< 7 > b
Definition: miscregs.hh:1564
void uncondBranch(ThreadID tid, Addr br_pc, void *&bp_history) override
Definition: ltage.cc:733
std::vector< ThreadHistory > threadHistory
Definition: ltage.hh:394
uint16_t currentIter
Definition: ltage.hh:148
const unsigned logSizeLoopPred
Definition: ltage.hh:359
void squash(ThreadID tid, void *bp_history) override
Definition: ltage.cc:687
uint16_t currentIterSpec
Definition: ltage.hh:82
int gindex(ThreadID tid, Addr pc, int bank) const
Computes the index used to access a partially tagged table.
Definition: ltage.cc:169
int * tableTags
Definition: ltage.hh:400
uint16_t currentIter
Definition: ltage.hh:81
void loopUpdate(Addr pc, bool Taken, BranchInfo *bi)
Updates the loop predictor.
Definition: ltage.cc:274
int tCounter
Definition: ltage.hh:404
uint16_t numIter
Definition: ltage.hh:80
int tagTableSizes[15]
Definition: ltage.hh:397
int logTick
Definition: ltage.hh:405
int8_t loopUseCounter
Definition: ltage.hh:402
int bindex(Addr pc_in) const
Computes the index used to access the bimodal table.
Definition: ltage.cc:139
bool getBimodePred(Addr pc, BranchInfo *bi) const
Get a branch prediction from the bimodal predictor.
Definition: ltage.cc:209
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
#define ULL(N)
uint64_t constant
Definition: types.hh:50
int * tableIndices
Definition: ltage.hh:399
uint8_t * globalHistory
Definition: ltage.hh:381
FoldedHistory * computeIndices
Definition: ltage.hh:390
const unsigned tagTableCounterBits
Definition: ltage.hh:361
FoldedHistory * computeTags[2]
Definition: ltage.hh:391
Basically a wrapper class to hold both the branch predictor and the BTB.
Definition: bpred_unit.hh:67
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:171
const unsigned logSizeBiMP
Definition: ltage.hh:357
BranchInfo(int sz)
Definition: ltage.hh:174
int size()
Definition: pagetable.hh:146
bool longestMatchPred
Definition: ltage.hh:157
bool predict(ThreadID tid, Addr branch_pc, bool cond_branch, void *&b)
Get a branch prediction from L-TAGE.
Definition: ltage.cc:403
const unsigned histBufferSize
Definition: ltage.hh:362
int F(int phist, int size, int bank) const
Utility function to shuffle the path history depending on which tagged table we are accessing...
Definition: ltage.cc:151
uint8_t pred
Definition: ltage.hh:95
uint8_t age
Definition: ltage.hh:85
const unsigned logSizeTagTables
Definition: ltage.hh:358
bool loopPredValid
Definition: ltage.hh:153
uint16_t gtag(ThreadID tid, Addr pc, int bank) const
Computes the partial tag of a tagged table.
Definition: ltage.cc:184
IntReg pc
Definition: remote_gdb.hh:91
bool getLoop(Addr pc, BranchInfo *bi) const
Get a branch prediction from the loop predictor.
Definition: ltage.cc:237
void updateGHist(uint8_t *&h, bool dir, uint8_t *tab, int &PT)
(Speculatively) updates the global branch history.
Definition: ltage.cc:365
uint16_t tag
Definition: ltage.hh:84
void specLoopUpdate(Addr pc, bool taken, BranchInfo *bi)
Speculatively updates the loop predictor iteration count.
Definition: ltage.cc:261
bool lookup(ThreadID tid, Addr branch_addr, void *&bp_history) override
Looks up a given PC in the BP to see if it is taken or not taken.
Definition: ltage.cc:702
void ctrUpdate(int8_t &ctr, bool taken, int nbits)
Updates a direction counter based on the actual branch outcome.
Definition: ltage.cc:195
int tagWidths[15]
Definition: ltage.hh:396
LoopEntry * ltable
Definition: ltage.hh:369
void update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history, bool squashed) override
Updates the BP with taken/not taken information.
Definition: ltage.cc:489
bool pseudoNewAlloc
Definition: ltage.hh:158

Generated on Fri Jun 9 2017 13:03:44 for gem5 by doxygen 1.8.6