bi_mode.cc (13654:dc3878f03a0c) | bi_mode.cc (13959:ea907b02c800) |
---|---|
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; --- 30 unchanged lines hidden (view full) --- 39 40BiModeBP::BiModeBP(const BiModeBPParams *params) 41 : BPredUnit(params), 42 globalHistoryReg(params->numThreads, 0), 43 globalHistoryBits(ceilLog2(params->globalPredictorSize)), 44 choicePredictorSize(params->choicePredictorSize), 45 choiceCtrBits(params->choiceCtrBits), 46 globalPredictorSize(params->globalPredictorSize), | 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; --- 30 unchanged lines hidden (view full) --- 39 40BiModeBP::BiModeBP(const BiModeBPParams *params) 41 : BPredUnit(params), 42 globalHistoryReg(params->numThreads, 0), 43 globalHistoryBits(ceilLog2(params->globalPredictorSize)), 44 choicePredictorSize(params->choicePredictorSize), 45 choiceCtrBits(params->choiceCtrBits), 46 globalPredictorSize(params->globalPredictorSize), |
47 globalCtrBits(params->globalCtrBits) | 47 globalCtrBits(params->globalCtrBits), 48 choiceCounters(choicePredictorSize, SatCounter(choiceCtrBits)), 49 takenCounters(globalPredictorSize, SatCounter(globalCtrBits)), 50 notTakenCounters(globalPredictorSize, SatCounter(globalCtrBits)) |
48{ 49 if (!isPowerOf2(choicePredictorSize)) 50 fatal("Invalid choice predictor size.\n"); 51 if (!isPowerOf2(globalPredictorSize)) 52 fatal("Invalid global history predictor size.\n"); 53 | 51{ 52 if (!isPowerOf2(choicePredictorSize)) 53 fatal("Invalid choice predictor size.\n"); 54 if (!isPowerOf2(globalPredictorSize)) 55 fatal("Invalid global history predictor size.\n"); 56 |
54 choiceCounters.resize(choicePredictorSize); 55 takenCounters.resize(globalPredictorSize); 56 notTakenCounters.resize(globalPredictorSize); 57 58 for (int i = 0; i < choicePredictorSize; ++i) { 59 choiceCounters[i].setBits(choiceCtrBits); 60 } 61 for (int i = 0; i < globalPredictorSize; ++i) { 62 takenCounters[i].setBits(globalCtrBits); 63 notTakenCounters[i].setBits(globalCtrBits); 64 } 65 | |
66 historyRegisterMask = mask(globalHistoryBits); 67 choiceHistoryMask = choicePredictorSize - 1; 68 globalHistoryMask = globalPredictorSize - 1; 69 70 choiceThreshold = (ULL(1) << (choiceCtrBits - 1)) - 1; 71 takenThreshold = (ULL(1) << (globalCtrBits - 1)) - 1; 72 notTakenThreshold = (ULL(1) << (globalCtrBits - 1)) - 1; 73} --- 41 unchanged lines hidden (view full) --- 115 & choiceHistoryMask); 116 unsigned globalHistoryIdx = (((branchAddr >> instShiftAmt) 117 ^ globalHistoryReg[tid]) 118 & globalHistoryMask); 119 120 assert(choiceHistoryIdx < choicePredictorSize); 121 assert(globalHistoryIdx < globalPredictorSize); 122 | 57 historyRegisterMask = mask(globalHistoryBits); 58 choiceHistoryMask = choicePredictorSize - 1; 59 globalHistoryMask = globalPredictorSize - 1; 60 61 choiceThreshold = (ULL(1) << (choiceCtrBits - 1)) - 1; 62 takenThreshold = (ULL(1) << (globalCtrBits - 1)) - 1; 63 notTakenThreshold = (ULL(1) << (globalCtrBits - 1)) - 1; 64} --- 41 unchanged lines hidden (view full) --- 106 & choiceHistoryMask); 107 unsigned globalHistoryIdx = (((branchAddr >> instShiftAmt) 108 ^ globalHistoryReg[tid]) 109 & globalHistoryMask); 110 111 assert(choiceHistoryIdx < choicePredictorSize); 112 assert(globalHistoryIdx < globalPredictorSize); 113 |
123 bool choicePrediction = choiceCounters[choiceHistoryIdx].read() | 114 bool choicePrediction = choiceCounters[choiceHistoryIdx] |
124 > choiceThreshold; | 115 > choiceThreshold; |
125 bool takenGHBPrediction = takenCounters[globalHistoryIdx].read() | 116 bool takenGHBPrediction = takenCounters[globalHistoryIdx] |
126 > takenThreshold; | 117 > takenThreshold; |
127 bool notTakenGHBPrediction = notTakenCounters[globalHistoryIdx].read() | 118 bool notTakenGHBPrediction = notTakenCounters[globalHistoryIdx] |
128 > notTakenThreshold; 129 bool finalPrediction; 130 131 BPHistory *history = new BPHistory; 132 history->globalHistoryReg = globalHistoryReg[tid]; 133 history->takenUsed = choicePrediction; 134 history->takenPred = takenGHBPrediction; 135 history->notTakenPred = notTakenGHBPrediction; --- 45 unchanged lines hidden (view full) --- 181 & globalHistoryMask); 182 183 assert(choiceHistoryIdx < choicePredictorSize); 184 assert(globalHistoryIdx < globalPredictorSize); 185 186 if (history->takenUsed) { 187 // if the taken array's prediction was used, update it 188 if (taken) { | 119 > notTakenThreshold; 120 bool finalPrediction; 121 122 BPHistory *history = new BPHistory; 123 history->globalHistoryReg = globalHistoryReg[tid]; 124 history->takenUsed = choicePrediction; 125 history->takenPred = takenGHBPrediction; 126 history->notTakenPred = notTakenGHBPrediction; --- 45 unchanged lines hidden (view full) --- 172 & globalHistoryMask); 173 174 assert(choiceHistoryIdx < choicePredictorSize); 175 assert(globalHistoryIdx < globalPredictorSize); 176 177 if (history->takenUsed) { 178 // if the taken array's prediction was used, update it 179 if (taken) { |
189 takenCounters[globalHistoryIdx].increment(); | 180 takenCounters[globalHistoryIdx]++; |
190 } else { | 181 } else { |
191 takenCounters[globalHistoryIdx].decrement(); | 182 takenCounters[globalHistoryIdx]--; |
192 } 193 } else { 194 // if the not-taken array's prediction was used, update it 195 if (taken) { | 183 } 184 } else { 185 // if the not-taken array's prediction was used, update it 186 if (taken) { |
196 notTakenCounters[globalHistoryIdx].increment(); | 187 notTakenCounters[globalHistoryIdx]++; |
197 } else { | 188 } else { |
198 notTakenCounters[globalHistoryIdx].decrement(); | 189 notTakenCounters[globalHistoryIdx]--; |
199 } 200 } 201 202 if (history->finalPred == taken) { 203 /* If the final prediction matches the actual branch's 204 * outcome and the choice predictor matches the final 205 * outcome, we update the choice predictor, otherwise it 206 * is not updated. While the designers of the bi-mode 207 * predictor don't explicity say why this is done, one 208 * can infer that it is to preserve the choice predictor's 209 * bias with respect to the branch being predicted; afterall, 210 * the whole point of the bi-mode predictor is to identify the 211 * atypical case when a branch deviates from its bias. 212 */ 213 if (history->finalPred == history->takenUsed) { 214 if (taken) { | 190 } 191 } 192 193 if (history->finalPred == taken) { 194 /* If the final prediction matches the actual branch's 195 * outcome and the choice predictor matches the final 196 * outcome, we update the choice predictor, otherwise it 197 * is not updated. While the designers of the bi-mode 198 * predictor don't explicity say why this is done, one 199 * can infer that it is to preserve the choice predictor's 200 * bias with respect to the branch being predicted; afterall, 201 * the whole point of the bi-mode predictor is to identify the 202 * atypical case when a branch deviates from its bias. 203 */ 204 if (history->finalPred == history->takenUsed) { 205 if (taken) { |
215 choiceCounters[choiceHistoryIdx].increment(); | 206 choiceCounters[choiceHistoryIdx]++; |
216 } else { | 207 } else { |
217 choiceCounters[choiceHistoryIdx].decrement(); | 208 choiceCounters[choiceHistoryIdx]--; |
218 } 219 } 220 } else { 221 // always update the choice predictor on an incorrect prediction 222 if (taken) { | 209 } 210 } 211 } else { 212 // always update the choice predictor on an incorrect prediction 213 if (taken) { |
223 choiceCounters[choiceHistoryIdx].increment(); | 214 choiceCounters[choiceHistoryIdx]++; |
224 } else { | 215 } else { |
225 choiceCounters[choiceHistoryIdx].decrement(); | 216 choiceCounters[choiceHistoryIdx]--; |
226 } 227 } 228 229 delete history; 230} 231 232void 233BiModeBP::updateGlobalHistReg(ThreadID tid, bool taken) 234{ 235 globalHistoryReg[tid] = taken ? (globalHistoryReg[tid] << 1) | 1 : 236 (globalHistoryReg[tid] << 1); 237 globalHistoryReg[tid] &= historyRegisterMask; 238} 239 240BiModeBP* 241BiModeBPParams::create() 242{ 243 return new BiModeBP(this); 244} | 217 } 218 } 219 220 delete history; 221} 222 223void 224BiModeBP::updateGlobalHistReg(ThreadID tid, bool taken) 225{ 226 globalHistoryReg[tid] = taken ? (globalHistoryReg[tid] << 1) | 1 : 227 (globalHistoryReg[tid] << 1); 228 globalHistoryReg[tid] &= historyRegisterMask; 229} 230 231BiModeBP* 232BiModeBPParams::create() 233{ 234 return new BiModeBP(this); 235} |