bi_mode.cc (11427:fb512311295e) | bi_mode.cc (11429:cf5af0cc3be4) |
---|---|
1/* 2 * Copyright (c) 2014 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; --- 24 unchanged lines hidden (view full) --- 33 */ 34 35#include "base/bitfield.hh" 36#include "base/intmath.hh" 37#include "cpu/pred/bi_mode.hh" 38 39BiModeBP::BiModeBP(const BiModeBPParams *params) 40 : BPredUnit(params), | 1/* 2 * Copyright (c) 2014 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; --- 24 unchanged lines hidden (view full) --- 33 */ 34 35#include "base/bitfield.hh" 36#include "base/intmath.hh" 37#include "cpu/pred/bi_mode.hh" 38 39BiModeBP::BiModeBP(const BiModeBPParams *params) 40 : BPredUnit(params), |
41 globalHistoryReg(params->numThreads, 0), | 41 globalHistoryReg(0), |
42 globalHistoryBits(ceilLog2(params->globalPredictorSize)), 43 choicePredictorSize(params->choicePredictorSize), 44 choiceCtrBits(params->choiceCtrBits), 45 globalPredictorSize(params->globalPredictorSize), 46 globalCtrBits(params->globalCtrBits) 47{ 48 if (!isPowerOf2(choicePredictorSize)) 49 fatal("Invalid choice predictor size.\n"); --- 22 unchanged lines hidden (view full) --- 72} 73 74/* 75 * For an unconditional branch we set its history such that 76 * everything is set to taken. I.e., its choice predictor 77 * chooses the taken array and the taken array predicts taken. 78 */ 79void | 42 globalHistoryBits(ceilLog2(params->globalPredictorSize)), 43 choicePredictorSize(params->choicePredictorSize), 44 choiceCtrBits(params->choiceCtrBits), 45 globalPredictorSize(params->globalPredictorSize), 46 globalCtrBits(params->globalCtrBits) 47{ 48 if (!isPowerOf2(choicePredictorSize)) 49 fatal("Invalid choice predictor size.\n"); --- 22 unchanged lines hidden (view full) --- 72} 73 74/* 75 * For an unconditional branch we set its history such that 76 * everything is set to taken. I.e., its choice predictor 77 * chooses the taken array and the taken array predicts taken. 78 */ 79void |
80BiModeBP::uncondBranch(ThreadID tid, Addr pc, void * &bpHistory) | 80BiModeBP::uncondBranch(Addr pc, void * &bpHistory) |
81{ 82 BPHistory *history = new BPHistory; | 81{ 82 BPHistory *history = new BPHistory; |
83 history->globalHistoryReg = globalHistoryReg[tid]; | 83 history->globalHistoryReg = globalHistoryReg; |
84 history->takenUsed = true; 85 history->takenPred = true; 86 history->notTakenPred = true; 87 history->finalPred = true; 88 bpHistory = static_cast<void*>(history); | 84 history->takenUsed = true; 85 history->takenPred = true; 86 history->notTakenPred = true; 87 history->finalPred = true; 88 bpHistory = static_cast<void*>(history); |
89 updateGlobalHistReg(tid, true); | 89 updateGlobalHistReg(true); |
90} 91 92void | 90} 91 92void |
93BiModeBP::squash(ThreadID tid, void *bpHistory) | 93BiModeBP::squash(void *bpHistory) |
94{ 95 BPHistory *history = static_cast<BPHistory*>(bpHistory); | 94{ 95 BPHistory *history = static_cast<BPHistory*>(bpHistory); |
96 globalHistoryReg[tid] = history->globalHistoryReg; | 96 globalHistoryReg = history->globalHistoryReg; |
97 98 delete history; 99} 100 101/* 102 * Here we lookup the actual branch prediction. We use the PC to 103 * identify the bias of a particular branch, which is based on the 104 * prediction in the choice array. A hash of the global history 105 * register and a branch's PC is used to index into both the taken 106 * and not-taken predictors, which both present a prediction. The 107 * choice array's prediction is used to select between the two 108 * direction predictors for the final branch prediction. 109 */ 110bool | 97 98 delete history; 99} 100 101/* 102 * Here we lookup the actual branch prediction. We use the PC to 103 * identify the bias of a particular branch, which is based on the 104 * prediction in the choice array. A hash of the global history 105 * register and a branch's PC is used to index into both the taken 106 * and not-taken predictors, which both present a prediction. The 107 * choice array's prediction is used to select between the two 108 * direction predictors for the final branch prediction. 109 */ 110bool |
111BiModeBP::lookup(ThreadID tid, Addr branchAddr, void * &bpHistory) | 111BiModeBP::lookup(Addr branchAddr, void * &bpHistory) |
112{ 113 unsigned choiceHistoryIdx = ((branchAddr >> instShiftAmt) 114 & choiceHistoryMask); 115 unsigned globalHistoryIdx = (((branchAddr >> instShiftAmt) | 112{ 113 unsigned choiceHistoryIdx = ((branchAddr >> instShiftAmt) 114 & choiceHistoryMask); 115 unsigned globalHistoryIdx = (((branchAddr >> instShiftAmt) |
116 ^ globalHistoryReg[tid]) | 116 ^ globalHistoryReg) |
117 & globalHistoryMask); 118 119 assert(choiceHistoryIdx < choicePredictorSize); 120 assert(globalHistoryIdx < globalPredictorSize); 121 122 bool choicePrediction = choiceCounters[choiceHistoryIdx].read() 123 > choiceThreshold; 124 bool takenGHBPrediction = takenCounters[globalHistoryIdx].read() 125 > takenThreshold; 126 bool notTakenGHBPrediction = notTakenCounters[globalHistoryIdx].read() 127 > notTakenThreshold; 128 bool finalPrediction; 129 130 BPHistory *history = new BPHistory; | 117 & globalHistoryMask); 118 119 assert(choiceHistoryIdx < choicePredictorSize); 120 assert(globalHistoryIdx < globalPredictorSize); 121 122 bool choicePrediction = choiceCounters[choiceHistoryIdx].read() 123 > choiceThreshold; 124 bool takenGHBPrediction = takenCounters[globalHistoryIdx].read() 125 > takenThreshold; 126 bool notTakenGHBPrediction = notTakenCounters[globalHistoryIdx].read() 127 > notTakenThreshold; 128 bool finalPrediction; 129 130 BPHistory *history = new BPHistory; |
131 history->globalHistoryReg = globalHistoryReg[tid]; | 131 history->globalHistoryReg = globalHistoryReg; |
132 history->takenUsed = choicePrediction; 133 history->takenPred = takenGHBPrediction; 134 history->notTakenPred = notTakenGHBPrediction; 135 136 if (choicePrediction) { 137 finalPrediction = takenGHBPrediction; 138 } else { 139 finalPrediction = notTakenGHBPrediction; 140 } 141 142 history->finalPred = finalPrediction; 143 bpHistory = static_cast<void*>(history); | 132 history->takenUsed = choicePrediction; 133 history->takenPred = takenGHBPrediction; 134 history->notTakenPred = notTakenGHBPrediction; 135 136 if (choicePrediction) { 137 finalPrediction = takenGHBPrediction; 138 } else { 139 finalPrediction = notTakenGHBPrediction; 140 } 141 142 history->finalPred = finalPrediction; 143 bpHistory = static_cast<void*>(history); |
144 updateGlobalHistReg(tid, finalPrediction); | 144 updateGlobalHistReg(finalPrediction); |
145 146 return finalPrediction; 147} 148 149void | 145 146 return finalPrediction; 147} 148 149void |
150BiModeBP::btbUpdate(ThreadID tid, Addr branchAddr, void * &bpHistory) | 150BiModeBP::btbUpdate(Addr branchAddr, void * &bpHistory) |
151{ | 151{ |
152 globalHistoryReg[tid] &= (historyRegisterMask & ~ULL(1)); | 152 globalHistoryReg &= (historyRegisterMask & ~ULL(1)); |
153} 154 155/* Only the selected direction predictor will be updated with the final 156 * outcome; the status of the unselected one will not be altered. The choice 157 * predictor is always updated with the branch outcome, except when the 158 * choice is opposite to the branch outcome but the selected counter of 159 * the direction predictors makes a correct final prediction. 160 */ 161void | 153} 154 155/* Only the selected direction predictor will be updated with the final 156 * outcome; the status of the unselected one will not be altered. The choice 157 * predictor is always updated with the branch outcome, except when the 158 * choice is opposite to the branch outcome but the selected counter of 159 * the direction predictors makes a correct final prediction. 160 */ 161void |
162BiModeBP::update(ThreadID tid, Addr branchAddr, bool taken, void *bpHistory, 163 bool squashed) | 162BiModeBP::update(Addr branchAddr, bool taken, void *bpHistory, bool squashed) |
164{ 165 if (bpHistory) { 166 BPHistory *history = static_cast<BPHistory*>(bpHistory); 167 168 unsigned choiceHistoryIdx = ((branchAddr >> instShiftAmt) 169 & choiceHistoryMask); 170 unsigned globalHistoryIdx = (((branchAddr >> instShiftAmt) 171 ^ history->globalHistoryReg) --- 42 unchanged lines hidden (view full) --- 214 choiceCounters[choiceHistoryIdx].increment(); 215 } else { 216 choiceCounters[choiceHistoryIdx].decrement(); 217 } 218 } 219 220 if (squashed) { 221 if (taken) { | 163{ 164 if (bpHistory) { 165 BPHistory *history = static_cast<BPHistory*>(bpHistory); 166 167 unsigned choiceHistoryIdx = ((branchAddr >> instShiftAmt) 168 & choiceHistoryMask); 169 unsigned globalHistoryIdx = (((branchAddr >> instShiftAmt) 170 ^ history->globalHistoryReg) --- 42 unchanged lines hidden (view full) --- 213 choiceCounters[choiceHistoryIdx].increment(); 214 } else { 215 choiceCounters[choiceHistoryIdx].decrement(); 216 } 217 } 218 219 if (squashed) { 220 if (taken) { |
222 globalHistoryReg[tid] = (history->globalHistoryReg << 1) | 1; | 221 globalHistoryReg = (history->globalHistoryReg << 1) | 1; |
223 } else { | 222 } else { |
224 globalHistoryReg[tid] = (history->globalHistoryReg << 1); | 223 globalHistoryReg = (history->globalHistoryReg << 1); |
225 } | 224 } |
226 globalHistoryReg[tid] &= historyRegisterMask; | 225 globalHistoryReg &= historyRegisterMask; |
227 } else { 228 delete history; 229 } 230 } 231} 232 233void | 226 } else { 227 delete history; 228 } 229 } 230} 231 232void |
234BiModeBP::retireSquashed(ThreadID tid, void *bp_history) | 233BiModeBP::retireSquashed(void *bp_history) |
235{ 236 BPHistory *history = static_cast<BPHistory*>(bp_history); 237 delete history; 238} 239 | 234{ 235 BPHistory *history = static_cast<BPHistory*>(bp_history); 236 delete history; 237} 238 |
240unsigned 241BiModeBP::getGHR(ThreadID tid, void *bp_history) const 242{ 243 return static_cast<BPHistory*>(bp_history)->globalHistoryReg; 244} 245 | |
246void | 239void |
247BiModeBP::updateGlobalHistReg(ThreadID tid, bool taken) | 240BiModeBP::updateGlobalHistReg(bool taken) |
248{ | 241{ |
249 globalHistoryReg[tid] = taken ? (globalHistoryReg[tid] << 1) | 1 : 250 (globalHistoryReg[tid] << 1); 251 globalHistoryReg[tid] &= historyRegisterMask; | 242 globalHistoryReg = taken ? (globalHistoryReg << 1) | 1 : 243 (globalHistoryReg << 1); 244 globalHistoryReg &= historyRegisterMask; |
252} 253 254BiModeBP* 255BiModeBPParams::create() 256{ 257 return new BiModeBP(this); 258} | 245} 246 247BiModeBP* 248BiModeBPParams::create() 249{ 250 return new BiModeBP(this); 251} |