tournament.cc (13654:dc3878f03a0c) | tournament.cc (13959:ea907b02c800) |
---|---|
1/* 2 * Copyright (c) 2011, 2014 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software --- 35 unchanged lines hidden (view full) --- 44 45#include "base/bitfield.hh" 46#include "base/intmath.hh" 47 48TournamentBP::TournamentBP(const TournamentBPParams *params) 49 : BPredUnit(params), 50 localPredictorSize(params->localPredictorSize), 51 localCtrBits(params->localCtrBits), | 1/* 2 * Copyright (c) 2011, 2014 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software --- 35 unchanged lines hidden (view full) --- 44 45#include "base/bitfield.hh" 46#include "base/intmath.hh" 47 48TournamentBP::TournamentBP(const TournamentBPParams *params) 49 : BPredUnit(params), 50 localPredictorSize(params->localPredictorSize), 51 localCtrBits(params->localCtrBits), |
52 localCtrs(localPredictorSize, SatCounter(localCtrBits)), |
|
52 localHistoryTableSize(params->localHistoryTableSize), 53 localHistoryBits(ceilLog2(params->localPredictorSize)), 54 globalPredictorSize(params->globalPredictorSize), 55 globalCtrBits(params->globalCtrBits), | 53 localHistoryTableSize(params->localHistoryTableSize), 54 localHistoryBits(ceilLog2(params->localPredictorSize)), 55 globalPredictorSize(params->globalPredictorSize), 56 globalCtrBits(params->globalCtrBits), |
57 globalCtrs(globalPredictorSize, SatCounter(globalCtrBits)), |
|
56 globalHistory(params->numThreads, 0), 57 globalHistoryBits( 58 ceilLog2(params->globalPredictorSize) > 59 ceilLog2(params->choicePredictorSize) ? 60 ceilLog2(params->globalPredictorSize) : 61 ceilLog2(params->choicePredictorSize)), 62 choicePredictorSize(params->choicePredictorSize), | 58 globalHistory(params->numThreads, 0), 59 globalHistoryBits( 60 ceilLog2(params->globalPredictorSize) > 61 ceilLog2(params->choicePredictorSize) ? 62 ceilLog2(params->globalPredictorSize) : 63 ceilLog2(params->choicePredictorSize)), 64 choicePredictorSize(params->choicePredictorSize), |
63 choiceCtrBits(params->choiceCtrBits) | 65 choiceCtrBits(params->choiceCtrBits), 66 choiceCtrs(choicePredictorSize, SatCounter(choiceCtrBits)) |
64{ 65 if (!isPowerOf2(localPredictorSize)) { 66 fatal("Invalid local predictor size!\n"); 67 } 68 69 if (!isPowerOf2(globalPredictorSize)) { 70 fatal("Invalid global predictor size!\n"); 71 } 72 | 67{ 68 if (!isPowerOf2(localPredictorSize)) { 69 fatal("Invalid local predictor size!\n"); 70 } 71 72 if (!isPowerOf2(globalPredictorSize)) { 73 fatal("Invalid global predictor size!\n"); 74 } 75 |
73 //Set up the array of counters for the local predictor 74 localCtrs.resize(localPredictorSize); 75 76 for (int i = 0; i < localPredictorSize; ++i) 77 localCtrs[i].setBits(localCtrBits); 78 | |
79 localPredictorMask = mask(localHistoryBits); 80 81 if (!isPowerOf2(localHistoryTableSize)) { 82 fatal("Invalid local history table size!\n"); 83 } 84 85 //Setup the history table for the local table 86 localHistoryTable.resize(localHistoryTableSize); 87 88 for (int i = 0; i < localHistoryTableSize; ++i) 89 localHistoryTable[i] = 0; 90 | 76 localPredictorMask = mask(localHistoryBits); 77 78 if (!isPowerOf2(localHistoryTableSize)) { 79 fatal("Invalid local history table size!\n"); 80 } 81 82 //Setup the history table for the local table 83 localHistoryTable.resize(localHistoryTableSize); 84 85 for (int i = 0; i < localHistoryTableSize; ++i) 86 localHistoryTable[i] = 0; 87 |
91 //Setup the array of counters for the global predictor 92 globalCtrs.resize(globalPredictorSize); 93 94 for (int i = 0; i < globalPredictorSize; ++i) 95 globalCtrs[i].setBits(globalCtrBits); 96 | |
97 // Set up the global history mask 98 // this is equivalent to mask(log2(globalPredictorSize) 99 globalHistoryMask = globalPredictorSize - 1; 100 101 if (!isPowerOf2(choicePredictorSize)) { 102 fatal("Invalid choice predictor size!\n"); 103 } 104 105 // Set up choiceHistoryMask 106 // this is equivalent to mask(log2(choicePredictorSize) 107 choiceHistoryMask = choicePredictorSize - 1; 108 | 88 // Set up the global history mask 89 // this is equivalent to mask(log2(globalPredictorSize) 90 globalHistoryMask = globalPredictorSize - 1; 91 92 if (!isPowerOf2(choicePredictorSize)) { 93 fatal("Invalid choice predictor size!\n"); 94 } 95 96 // Set up choiceHistoryMask 97 // this is equivalent to mask(log2(choicePredictorSize) 98 choiceHistoryMask = choicePredictorSize - 1; 99 |
109 //Setup the array of counters for the choice predictor 110 choiceCtrs.resize(choicePredictorSize); 111 112 for (int i = 0; i < choicePredictorSize; ++i) 113 choiceCtrs[i].setBits(choiceCtrBits); 114 | |
115 //Set up historyRegisterMask 116 historyRegisterMask = mask(globalHistoryBits); 117 118 //Check that predictors don't use more bits than they have available 119 if (globalHistoryMask > historyRegisterMask) { 120 fatal("Global predictor too large for global history bits!\n"); 121 } 122 if (choiceHistoryMask > historyRegisterMask) { --- 73 unchanged lines hidden (view full) --- 196 197 bool global_prediction; 198 bool choice_prediction; 199 200 //Lookup in the local predictor to get its branch prediction 201 local_history_idx = calcLocHistIdx(branch_addr); 202 local_predictor_idx = localHistoryTable[local_history_idx] 203 & localPredictorMask; | 100 //Set up historyRegisterMask 101 historyRegisterMask = mask(globalHistoryBits); 102 103 //Check that predictors don't use more bits than they have available 104 if (globalHistoryMask > historyRegisterMask) { 105 fatal("Global predictor too large for global history bits!\n"); 106 } 107 if (choiceHistoryMask > historyRegisterMask) { --- 73 unchanged lines hidden (view full) --- 181 182 bool global_prediction; 183 bool choice_prediction; 184 185 //Lookup in the local predictor to get its branch prediction 186 local_history_idx = calcLocHistIdx(branch_addr); 187 local_predictor_idx = localHistoryTable[local_history_idx] 188 & localPredictorMask; |
204 local_prediction = localCtrs[local_predictor_idx].read() > localThreshold; | 189 local_prediction = localCtrs[local_predictor_idx] > localThreshold; |
205 206 //Lookup in the global predictor to get its branch prediction 207 global_prediction = globalThreshold < | 190 191 //Lookup in the global predictor to get its branch prediction 192 global_prediction = globalThreshold < |
208 globalCtrs[globalHistory[tid] & globalHistoryMask].read(); | 193 globalCtrs[globalHistory[tid] & globalHistoryMask]; |
209 210 //Lookup in the choice predictor to see which one to use 211 choice_prediction = choiceThreshold < | 194 195 //Lookup in the choice predictor to see which one to use 196 choice_prediction = choiceThreshold < |
212 choiceCtrs[globalHistory[tid] & choiceHistoryMask].read(); | 197 choiceCtrs[globalHistory[tid] & choiceHistoryMask]; |
213 214 // Create BPHistory and pass it back to be recorded. 215 BPHistory *history = new BPHistory; 216 history->globalHistory = globalHistory[tid]; 217 history->localPredTaken = local_prediction; 218 history->globalPredTaken = global_prediction; 219 history->globalUsed = choice_prediction; 220 history->localHistoryIdx = local_history_idx; --- 82 unchanged lines hidden (view full) --- 303 304 assert(old_local_pred_index < localPredictorSize); 305 306 // Update the choice predictor to tell it which one was correct if 307 // there was a prediction. 308 if (history->localPredTaken != history->globalPredTaken && 309 old_local_pred_valid) 310 { | 198 199 // Create BPHistory and pass it back to be recorded. 200 BPHistory *history = new BPHistory; 201 history->globalHistory = globalHistory[tid]; 202 history->localPredTaken = local_prediction; 203 history->globalPredTaken = global_prediction; 204 history->globalUsed = choice_prediction; 205 history->localHistoryIdx = local_history_idx; --- 82 unchanged lines hidden (view full) --- 288 289 assert(old_local_pred_index < localPredictorSize); 290 291 // Update the choice predictor to tell it which one was correct if 292 // there was a prediction. 293 if (history->localPredTaken != history->globalPredTaken && 294 old_local_pred_valid) 295 { |
311 // If the local prediction matches the actual outcome, 312 // decrement the counter. Otherwise increment the 313 // counter. 314 unsigned choice_predictor_idx = 315 history->globalHistory & choiceHistoryMask; 316 if (history->localPredTaken == taken) { 317 choiceCtrs[choice_predictor_idx].decrement(); 318 } else if (history->globalPredTaken == taken) { 319 choiceCtrs[choice_predictor_idx].increment(); 320 } | 296 // If the local prediction matches the actual outcome, 297 // decrement the counter. Otherwise increment the 298 // counter. 299 unsigned choice_predictor_idx = 300 history->globalHistory & choiceHistoryMask; 301 if (history->localPredTaken == taken) { 302 choiceCtrs[choice_predictor_idx]--; 303 } else if (history->globalPredTaken == taken) { 304 choiceCtrs[choice_predictor_idx]++; 305 } |
321 } 322 323 // Update the counters with the proper 324 // resolution of the branch. Histories are updated 325 // speculatively, restored upon squash() calls, and 326 // recomputed upon update(squash = true) calls, 327 // so they do not need to be updated. 328 unsigned global_predictor_idx = 329 history->globalHistory & globalHistoryMask; 330 if (taken) { | 306 } 307 308 // Update the counters with the proper 309 // resolution of the branch. Histories are updated 310 // speculatively, restored upon squash() calls, and 311 // recomputed upon update(squash = true) calls, 312 // so they do not need to be updated. 313 unsigned global_predictor_idx = 314 history->globalHistory & globalHistoryMask; 315 if (taken) { |
331 globalCtrs[global_predictor_idx].increment(); 332 if (old_local_pred_valid) { 333 localCtrs[old_local_pred_index].increment(); 334 } | 316 globalCtrs[global_predictor_idx]++; 317 if (old_local_pred_valid) { 318 localCtrs[old_local_pred_index]++; 319 } |
335 } else { | 320 } else { |
336 globalCtrs[global_predictor_idx].decrement(); 337 if (old_local_pred_valid) { 338 localCtrs[old_local_pred_index].decrement(); 339 } | 321 globalCtrs[global_predictor_idx]--; 322 if (old_local_pred_valid) { 323 localCtrs[old_local_pred_index]--; 324 } |
340 } 341 342 // We're done with this history, now delete it. 343 delete history; 344} 345 346void 347TournamentBP::squash(ThreadID tid, void *bp_history) --- 25 unchanged lines hidden --- | 325 } 326 327 // We're done with this history, now delete it. 328 delete history; 329} 330 331void 332TournamentBP::squash(ThreadID tid, void *bp_history) --- 25 unchanged lines hidden --- |