1/* 2 * Copyright (c) 2004-2006 The Regents of The University of Michigan 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; --- 22 unchanged lines hidden (view full) --- 31#include "base/intmath.hh" 32#include "cpu/pred/tournament.hh" 33 34TournamentBP::TournamentBP(unsigned _localPredictorSize, 35 unsigned _localCtrBits, 36 unsigned _localHistoryTableSize, 37 unsigned _localHistoryBits, 38 unsigned _globalPredictorSize, |
39 unsigned _globalHistoryBits, |
40 unsigned _globalCtrBits, |
41 unsigned _choicePredictorSize, 42 unsigned _choiceCtrBits, 43 unsigned _instShiftAmt) 44 : localPredictorSize(_localPredictorSize), 45 localCtrBits(_localCtrBits), 46 localHistoryTableSize(_localHistoryTableSize), 47 localHistoryBits(_localHistoryBits), 48 globalPredictorSize(_globalPredictorSize), --- 193 unchanged lines hidden (view full) --- 242 // there was a prediction. 243 if (bp_history) { 244 BPHistory *history = static_cast<BPHistory *>(bp_history); 245 if (history->localPredTaken != history->globalPredTaken) { 246 // If the local prediction matches the actual outcome, 247 // decerement the counter. Otherwise increment the 248 // counter. 249 if (history->localPredTaken == taken) { |
250 choiceCtrs[history->globalHistory].decrement(); |
251 } else if (history->globalPredTaken == taken){ |
252 choiceCtrs[history->globalHistory].increment(); |
253 } |
254 |
255 } 256 |
257 // Update the counters and local history with the proper 258 // resolution of the branch. Global history is updated 259 // speculatively and restored upon squash() calls, so it does not 260 // need to be updated. 261 if (taken) { 262 localCtrs[local_predictor_idx].increment(); 263 globalCtrs[history->globalHistory].increment(); 264 265 updateLocalHistTaken(local_history_idx); 266 } else { 267 localCtrs[local_predictor_idx].decrement(); 268 globalCtrs[history->globalHistory].decrement(); 269 270 updateLocalHistNotTaken(local_history_idx); 271 } 272 273 bool mispredict = false; 274 275 //global predictor used and mispredicted 276 if (history->globalUsed && history->globalPredTaken != taken) 277 mispredict = true; 278 //local predictor used and mispredicted 279 else if (!history->globalUsed && history->localPredTaken != taken) 280 mispredict = true; 281 282 if (mispredict) { 283 if (taken) { 284 globalHistory = globalHistory | 1; 285 } else { 286 unsigned mask = globalHistoryMask - 1; 287 globalHistory = globalHistory & mask; 288 } 289 290 } |
291 // We're done with this history, now delete it. 292 delete history; 293 } 294 295 assert(globalHistory < globalPredictorSize && 296 local_history_idx < localHistoryTableSize && 297 local_predictor_idx < localPredictorSize); 298 |
299 |
300} 301 302void 303TournamentBP::squash(void *bp_history) 304{ 305 BPHistory *history = static_cast<BPHistory *>(bp_history); 306 307 // Restore global history to state prior to this branch. 308 globalHistory = history->globalHistory; 309 310 // Delete this BPHistory now that we're done with it. 311 delete history; 312} 313 314#ifdef DEBUG 315int 316TournamentBP::BPHistory::newCount = 0; 317#endif |