Deleted Added
sdiff udiff text old ( 13494:ed4ed5351b16 ) new ( 13626:d6a6358aa6db )
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.

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

163 if (bi->loopPredValid) {
164 if (taken != bi->loopPred) {
165 // free the entry
166 ltable[idx].numIter = 0;
167 ltable[idx].age = 0;
168 ltable[idx].confidence = 0;
169 ltable[idx].currentIter = 0;
170 return;
171 } else if (bi->loopPred != bi->tagePred) {
172 DPRINTF(LTage, "Loop Prediction success:%lx\n",pc);
173 unsignedCtrUpdate(ltable[idx].age, true, loopTableAgeBits);
174 }
175 }
176
177 ltable[idx].currentIter =
178 (ltable[idx].currentIter + 1) & loopNumIterMask;
179 if (ltable[idx].currentIter > ltable[idx].numIter) {
180 ltable[idx].confidence = 0;
181 if (ltable[idx].numIter != 0) {
182 // free the entry
183 ltable[idx].numIter = 0;
184 ltable[idx].age = 0;
185 ltable[idx].confidence = 0;
186 }
187 }
188
189 if (taken != (useDirectionBit ? ltable[idx].dir : true)) {
190 if (ltable[idx].currentIter == ltable[idx].numIter) {
191 DPRINTF(LTage, "Loop End predicted successfully:%lx\n", pc);
192
193 unsignedCtrUpdate(ltable[idx].confidence, true,
194 loopTableConfidenceBits);
195 //just do not predict when the loop count is 1 or 2
196 if (ltable[idx].numIter < 3) {
197 // free the entry
198 ltable[idx].dir = taken; // ignored if no useDirectionBit
199 ltable[idx].numIter = 0;
200 ltable[idx].age = 0;
201 ltable[idx].confidence = 0;

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

213 ltable[idx].age = 0;
214 ltable[idx].confidence = 0;
215 }
216 }
217 ltable[idx].currentIter = 0;
218 }
219
220 } else if (useDirectionBit ?
221 ((bi->loopPredValid ? bi->loopPred : bi->tagePred) != taken) :
222 taken) {
223 //try to allocate an entry on taken branch
224 int nrand = random_mt.random<int>();
225 for (int i = 0; i < (1 << logLoopTableAssoc); i++) {
226 int loop_hit = (nrand + i) & ((1 << logLoopTableAssoc) - 1);
227 idx = bi->loopIndex + loop_hit;
228 if (ltable[idx].age == 0) {
229 DPRINTF(LTage, "Allocating loop pred entry for branch %lx\n",
230 pc);
231 ltable[idx].dir = !taken; // ignored if no useDirectionBit
232 ltable[idx].tag = bi->loopTag;

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

243 }
244
245}
246
247//prediction
248bool
249LTAGE::predict(ThreadID tid, Addr branch_pc, bool cond_branch, void* &b)
250{
251 LTageBranchInfo *bi = new LTageBranchInfo(nHistoryTables+1);
252 b = (void*)(bi);
253
254 bool pred_taken = tagePredict(tid, branch_pc, cond_branch, bi);
255
256 if (cond_branch) {
257 // loop prediction
258 bi->loopPred = getLoop(branch_pc, bi, useSpeculation);
259
260 if ((loopUseCounter >= 0) && bi->loopPredValid) {
261 pred_taken = bi->loopPred;
262 bi->provider = LOOP;
263 }
264 DPRINTF(LTage, "Predict for %lx: taken?:%d, loopTaken?:%d, "
265 "loopValid?:%d, loopUseCounter:%d, tagePred:%d, altPred:%d\n",
266 branch_pc, pred_taken, bi->loopPred, bi->loopPredValid,
267 loopUseCounter, bi->tagePred, bi->altTaken);
268
269 if (useSpeculation) {
270 specLoopUpdate(pred_taken, bi);
271 }
272 }
273
274 return pred_taken;
275}
276
277void
278LTAGE::condBranchUpdate(Addr branch_pc, bool taken,
279 TageBranchInfo* tage_bi, int nrand)
280{
281 LTageBranchInfo* bi = static_cast<LTageBranchInfo*>(tage_bi);
282
283 if (useSpeculation) {
284 // recalculate loop prediction without speculation
285 // It is ok to overwrite the loop prediction fields in bi
286 // as the stats have already been updated with the previous
287 // values
288 bi->loopPred = getLoop(branch_pc, bi, false);
289 }
290
291 if (bi->loopPredValid) {
292 if (bi->tagePred != bi->loopPred) {
293 ctrUpdate(loopUseCounter,
294 (bi->loopPred == taken),
295 withLoopBits);
296 }
297 }
298
299 loopUpdate(branch_pc, taken, bi);
300
301 TAGE::condBranchUpdate(branch_pc, taken, bi, nrand);
302}
303
304void
305LTAGE::squash(ThreadID tid, bool taken, void *bp_history)
306{
307 TAGE::squash(tid, taken, bp_history);
308
309 LTageBranchInfo* bi = (LTageBranchInfo*)(bp_history);
310
311 if (bi->condBranch) {
312 if (bi->loopHit >= 0) {
313 int idx = finallindex(bi->loopIndex,
314 bi->loopLowPcBits,
315 bi->loopHit);
316 ltable[idx].currentIterSpec = bi->currentIter;
317 }
318 }
319}
320
321void
322LTAGE::squash(ThreadID tid, void *bp_history)
323{
324 LTageBranchInfo* bi = (LTageBranchInfo*)(bp_history);
325 if (bi->condBranch) {
326 if (bi->loopHit >= 0) {
327 int idx = finallindex(bi->loopIndex,
328 bi->loopLowPcBits,
329 bi->loopHit);
330 ltable[idx].currentIterSpec = bi->currentIter;
331 }
332 }
333
334 TAGE::squash(tid, bp_history);
335}
336
337
338void
339LTAGE::updateStats(bool taken, TageBranchInfo* bi)
340{
341 TAGE::updateStats(taken, bi);
342
343 LTageBranchInfo * ltage_bi = static_cast<LTageBranchInfo *>(bi);
344
345 if (ltage_bi->provider == LOOP) {
346 if (taken == ltage_bi->loopPred) {
347 loopPredictorCorrect++;
348 } else {
349 loopPredictorWrong++;
350 }
351 }
352}
353
354
355
356void
357LTAGE::regStats()
358{
359 TAGE::regStats();
360
361 loopPredictorCorrect
362 .name(name() + ".loopPredictorCorrect")
363 .desc("Number of times the loop predictor is the provider and "
364 "the prediction is correct");

--- 14 unchanged lines hidden ---