Deleted Added
sdiff udiff text old ( 13654:dc3878f03a0c ) new ( 13959:ea907b02c800 )
full compact
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),
48 choiceCounters(choicePredictorSize, SatCounter(choiceCtrBits)),
49 takenCounters(globalPredictorSize, SatCounter(globalCtrBits)),
50 notTakenCounters(globalPredictorSize, SatCounter(globalCtrBits))
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
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
114 bool choicePrediction = choiceCounters[choiceHistoryIdx]
115 > choiceThreshold;
116 bool takenGHBPrediction = takenCounters[globalHistoryIdx]
117 > takenThreshold;
118 bool notTakenGHBPrediction = notTakenCounters[globalHistoryIdx]
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) {
180 takenCounters[globalHistoryIdx]++;
181 } else {
182 takenCounters[globalHistoryIdx]--;
183 }
184 } else {
185 // if the not-taken array's prediction was used, update it
186 if (taken) {
187 notTakenCounters[globalHistoryIdx]++;
188 } else {
189 notTakenCounters[globalHistoryIdx]--;
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) {
206 choiceCounters[choiceHistoryIdx]++;
207 } else {
208 choiceCounters[choiceHistoryIdx]--;
209 }
210 }
211 } else {
212 // always update the choice predictor on an incorrect prediction
213 if (taken) {
214 choiceCounters[choiceHistoryIdx]++;
215 } else {
216 choiceCounters[choiceHistoryIdx]--;
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}