Deleted Added
sdiff udiff text old ( 13443:a111cb197897 ) new ( 13444:26f81be73cb7 )
full compact
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.

--- 35 unchanged lines hidden (view full) ---

44#include "base/logging.hh"
45#include "base/random.hh"
46#include "base/trace.hh"
47#include "debug/Fetch.hh"
48#include "debug/LTage.hh"
49
50LTAGE::LTAGE(const LTAGEParams *params)
51 : BPredUnit(params),
52 logSizeBiMP(params->logSizeBiMP),
53 logRatioBiModalHystEntries(params->logRatioBiModalHystEntries),
54 logSizeTagTables(params->logSizeTagTables),
55 logSizeLoopPred(params->logSizeLoopPred),
56 nHistoryTables(params->nHistoryTables),
57 tagTableCounterBits(params->tagTableCounterBits),
58 tagTableUBits(params->tagTableUBits),
59 histBufferSize(params->histBufferSize),
60 minHist(params->minHist),
61 maxHist(params->maxHist),
62 minTagWidth(params->minTagWidth),
63 loopTableAgeBits(params->loopTableAgeBits),
64 loopTableConfidenceBits(params->loopTableConfidenceBits),
65 loopTableTagBits(params->loopTableTagBits),
66 loopTableIterBits(params->loopTableIterBits),
67 confidenceThreshold((1 << loopTableConfidenceBits) - 1),
68 loopTagMask((1 << loopTableTagBits) - 1),
69 loopNumIterMask((1 << loopTableIterBits) - 1),
70 threadHistory(params->numThreads)
71{
72 // Current method for periodically resetting the u counter bits only
73 // works for 1 or 2 bits
74 // Also make sure that it is not 0
75 assert(tagTableUBits <= 2 && (tagTableUBits > 0));
76
77 // we use uint16_t type for these vales, so they cannot be more than
78 // 16 bits
79 assert(loopTableTagBits <= 16);
80 assert(loopTableIterBits <= 16);
81
82 assert(params->histBufferSize > params->maxHist * 2);
83 useAltPredForNewlyAllocated = 0;
84 logTick = 19;
85 tCounter = ULL(1) << (logTick - 1);
86
87 for (auto& history : threadHistory) {
88 history.pathHist = 0;
89 history.globalHistory = new uint8_t[histBufferSize];
90 history.gHist = history.globalHistory;
91 memset(history.gHist, 0, histBufferSize);
92 history.ptGhist = 0;
93 }

--- 4 unchanged lines hidden (view full) ---

98
99 for (int i = 2; i <= nHistoryTables; i++) {
100 histLengths[i] = (int) (((double) minHist *
101 pow ((double) (maxHist) / (double) minHist,
102 (double) (i - 1) / (double) ((nHistoryTables- 1))))
103 + 0.5);
104 }
105
106 tagWidths[1] = minTagWidth;
107 tagWidths[2] = minTagWidth;
108 tagWidths[3] = minTagWidth + 1;
109 tagWidths[4] = minTagWidth + 1;
110 tagWidths[5] = minTagWidth + 2;
111 tagWidths[6] = minTagWidth + 3;
112 tagWidths[7] = minTagWidth + 4;
113 tagWidths[8] = minTagWidth + 5;
114 tagWidths[9] = minTagWidth + 5;
115 tagWidths[10] = minTagWidth + 6;
116 tagWidths[11] = minTagWidth + 7;
117 tagWidths[12] = minTagWidth + 8;
118
119 for (int i = 1; i <= 2; i++)
120 tagTableSizes[i] = logSizeTagTables - 1;
121 for (int i = 3; i <= 6; i++)
122 tagTableSizes[i] = logSizeTagTables;
123 for (int i = 7; i <= 10; i++)
124 tagTableSizes[i] = logSizeTagTables - 1;
125 for (int i = 11; i <= 12; i++)
126 tagTableSizes[i] = logSizeTagTables - 2;
127
128 for (auto& history : threadHistory) {
129 history.computeIndices = new FoldedHistory[nHistoryTables+1];
130 history.computeTags[0] = new FoldedHistory[nHistoryTables+1];
131 history.computeTags[1] = new FoldedHistory[nHistoryTables+1];
132
133 for (int i = 1; i <= nHistoryTables; i++) {
134 history.computeIndices[i].init(histLengths[i], (tagTableSizes[i]));
135 history.computeTags[0][i].init(
136 history.computeIndices[i].origLength, tagWidths[i]);
137 history.computeTags[1][i].init(
138 history.computeIndices[i].origLength, tagWidths[i] - 1);
139 DPRINTF(LTage, "HistLength:%d, TTSize:%d, TTTWidth:%d\n",
140 histLengths[i], tagTableSizes[i], tagWidths[i]);
141 }
142 }
143
144 const uint64_t bimodalTableSize = ULL(1) << logSizeBiMP;
145 btablePrediction.resize(bimodalTableSize, false);
146 btableHysteresis.resize(bimodalTableSize >> logRatioBiModalHystEntries,
147 true);
148
149 ltable = new LoopEntry[ULL(1) << logSizeLoopPred];
150 gtable = new TageEntry*[nHistoryTables + 1];
151 for (int i = 1; i <= nHistoryTables; i++) {
152 gtable[i] = new TageEntry[1<<(tagTableSizes[i])];
153 }
154
155 tableIndices = new int [nHistoryTables+1];
156 tableTags = new int [nHistoryTables+1];
157
158 loopUseCounter = 0;
159}
160
161int
162LTAGE::bindex(Addr pc_in) const
163{
164 return ((pc_in >> instShiftAmt) & ((ULL(1) << (logSizeBiMP)) - 1));
165}
166
167int
168LTAGE::lindex(Addr pc_in) const
169{
170 return (((pc_in >> instShiftAmt) &
171 ((ULL(1) << (logSizeLoopPred - 2)) - 1)) << 2);
172}
173
174int
175LTAGE::F(int A, int size, int bank) const
176{
177 int A1, A2;
178
179 A = A & ((ULL(1) << size) - 1);
180 A1 = (A & ((ULL(1) << tagTableSizes[bank]) - 1));
181 A2 = (A >> tagTableSizes[bank]);
182 A2 = ((A2 << bank) & ((ULL(1) << tagTableSizes[bank]) - 1))
183 + (A2 >> (tagTableSizes[bank] - bank));
184 A = A1 ^ A2;
185 A = ((A << bank) & ((ULL(1) << tagTableSizes[bank]) - 1))
186 + (A >> (tagTableSizes[bank] - bank));
187 return (A);
188}
189
190
191// gindex computes a full hash of pc, ghist and pathHist
192int
193LTAGE::gindex(ThreadID tid, Addr pc, int bank) const
194{
195 int index;
196 int hlen = (histLengths[bank] > 16) ? 16 : histLengths[bank];
197 index =
198 (pc >> instShiftAmt) ^
199 ((pc >> instShiftAmt) >> ((int) abs(tagTableSizes[bank] - bank) + 1)) ^
200 threadHistory[tid].computeIndices[bank].comp ^
201 F(threadHistory[tid].pathHist, hlen, bank);
202
203 return (index & ((ULL(1) << (tagTableSizes[bank])) - 1));
204}
205
206
207// Tag computation
208uint16_t
209LTAGE::gtag(ThreadID tid, Addr pc, int bank) const
210{
211 int tag = (pc >> instShiftAmt) ^
212 threadHistory[tid].computeTags[0][bank].comp ^
213 (threadHistory[tid].computeTags[1][bank].comp << 1);
214
215 return (tag & ((ULL(1) << tagWidths[bank]) - 1));
216}
217
218
219// Up-down saturating counter
220void
221LTAGE::ctrUpdate(int8_t & ctr, bool taken, int nbits)
222{
223 assert(nbits <= sizeof(int8_t) << 3);

--- 51 unchanged lines hidden (view full) ---

275
276//loop prediction: only used if high confidence
277bool
278LTAGE::getLoop(Addr pc, BranchInfo* bi) const
279{
280 bi->loopHit = -1;
281 bi->loopPredValid = false;
282 bi->loopIndex = lindex(pc);
283 bi->loopTag = ((pc) >> (instShiftAmt + logSizeLoopPred - 2)) & loopTagMask;
284
285 for (int i = 0; i < 4; i++) {
286 if (ltable[bi->loopIndex + i].tag == bi->loopTag) {
287 bi->loopHit = i;
288 bi->loopPredValid =
289 ltable[bi->loopIndex + i].confidence == confidenceThreshold;
290 bi->currentIter = ltable[bi->loopIndex + i].currentIterSpec;
291 if (ltable[bi->loopIndex + i].currentIterSpec + 1 ==
292 ltable[bi->loopIndex + i].numIter) {
293 return !(ltable[bi->loopIndex + i].dir);

--- 80 unchanged lines hidden (view full) ---

374 }
375 }
376 ltable[idx].currentIter = 0;
377 }
378
379 } else if (taken) {
380 //try to allocate an entry on taken branch
381 int nrand = random_mt.random<int>();
382 for (int i = 0; i < 4; i++) {
383 int loop_hit = (nrand + i) & 3;
384 idx = bi->loopIndex + loop_hit;
385 if (ltable[idx].age == 0) {
386 DPRINTF(LTage, "Allocating loop pred entry for branch %lx\n",
387 pc);
388 ltable[idx].dir = !taken;
389 ltable[idx].tag = bi->loopTag;
390 ltable[idx].numIter = 0;
391 ltable[idx].age = (1 << loopTableAgeBits) - 1;

--- 155 unchanged lines hidden (view full) ---

547 if (bi->condBranch) {
548 DPRINTF(LTage, "Updating tables for branch:%lx; taken?:%d\n",
549 branch_pc, taken);
550 // first update the loop predictor
551 loopUpdate(pc, taken, bi);
552
553 if (bi->loopPredValid) {
554 if (bi->tagePred != bi->loopPred) {
555 ctrUpdate(loopUseCounter, (bi->loopPred== taken), 7);
556 }
557 }
558
559 // TAGE UPDATE
560 // try to allocate a new entries only if prediction was wrong
561 bool longest_match_pred = false;
562 bool alloc = (bi->tagePred != taken) && (bi->hitBank < nHistoryTables);
563 if (bi->hitBank > 0) {

--- 6 unchanged lines hidden (view full) ---

570 if (PseudoNewAlloc) {
571 if (longest_match_pred == taken) {
572 alloc = false;
573 }
574 // if it was delivering the correct prediction, no need to
575 // allocate new entry even if the overall prediction was false
576 if (longest_match_pred != bi->altTaken) {
577 ctrUpdate(useAltPredForNewlyAllocated,
578 bi->altTaken == taken, 4);
579 }
580 }
581 }
582
583 if (alloc) {
584 // is there some "unuseful" entry to allocate
585 uint8_t min = 1;
586 for (int i = nHistoryTables; i > bi->hitBank; i--) {

--- 25 unchanged lines hidden (view full) ---

612 gtable[i][bi->tableIndices[i]].tag = bi->tableTags[i];
613 gtable[i][bi->tableIndices[i]].ctr = (taken) ? 0 : -1;
614 break;
615 }
616 }
617 }
618 //periodic reset of u: reset is not complete but bit by bit
619 tCounter++;
620 if ((tCounter & ((ULL(1) << logTick) - 1)) == 0) {
621 // reset least significant bit
622 // most significant bit becomes least significant bit
623 for (int i = 1; i <= nHistoryTables; i++) {
624 for (int j = 0; j < (ULL(1) << tagTableSizes[i]); j++) {
625 gtable[i][j].u = gtable[i][j].u >> 1;
626 }
627 }
628 }
629
630 if (bi->hitBank > 0) {
631 DPRINTF(LTage, "Updating tag table entry (%d,%d) for branch %lx\n",
632 bi->hitBank, bi->hitBankIndex, branch_pc);

--- 36 unchanged lines hidden (view full) ---

669 BranchInfo* bi = (BranchInfo*)(b);
670 ThreadHistory& tHist = threadHistory[tid];
671 // UPDATE HISTORIES
672 bool pathbit = ((branch_pc >> instShiftAmt) & 1);
673 //on a squash, return pointers to this and recompute indices.
674 //update user history
675 updateGHist(tHist.gHist, taken, tHist.globalHistory, tHist.ptGhist);
676 tHist.pathHist = (tHist.pathHist << 1) + pathbit;
677 tHist.pathHist = (tHist.pathHist & ((ULL(1) << 16) - 1));
678
679 bi->ptGhist = tHist.ptGhist;
680 bi->pathHist = tHist.pathHist;
681 //prepare next index and tag computations for user branchs
682 for (int i = 1; i <= nHistoryTables; i++)
683 {
684 bi->ci[i] = tHist.computeIndices[i].comp;
685 bi->ct0[i] = tHist.computeTags[0][i].comp;

--- 100 unchanged lines hidden ---