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

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

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

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

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

--- 14 unchanged lines hidden ---