tournament.cc (8487:c7982323e834) tournament.cc (8842:a02932e2e73d)
1/*
1/*
2 * Copyright (c) 2011 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
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
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;
9 * redistributions in binary form must reproduce the above copyright

--- 131 unchanged lines hidden (view full) ---

141inline
142void
143TournamentBP::updateLocalHistNotTaken(unsigned local_history_idx)
144{
145 localHistoryTable[local_history_idx] =
146 (localHistoryTable[local_history_idx] << 1);
147}
148
14 * Copyright (c) 2004-2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright

--- 131 unchanged lines hidden (view full) ---

153inline
154void
155TournamentBP::updateLocalHistNotTaken(unsigned local_history_idx)
156{
157 localHistoryTable[local_history_idx] =
158 (localHistoryTable[local_history_idx] << 1);
159}
160
161
162void
163TournamentBP::BTBUpdate(Addr &branch_addr, void * &bp_history)
164{
165 unsigned local_history_idx = calcLocHistIdx(branch_addr);
166 //Update Global History to Not Taken
167 globalHistory = globalHistory & (globalHistoryMask - 1);
168 //Update Local History to Not Taken
169 localHistoryTable[local_history_idx] =
170 localHistoryTable[local_history_idx] & (localPredictorMask - 1);
171}
172
149bool
150TournamentBP::lookup(Addr &branch_addr, void * &bp_history)
151{
152 bool local_prediction;
153 unsigned local_history_idx;
154 unsigned local_predictor_idx;
155
156 bool global_prediction;

--- 12 unchanged lines hidden (view full) ---

169 choice_prediction = choiceCtrs[globalHistory].read() > threshold;
170
171 // Create BPHistory and pass it back to be recorded.
172 BPHistory *history = new BPHistory;
173 history->globalHistory = globalHistory;
174 history->localPredTaken = local_prediction;
175 history->globalPredTaken = global_prediction;
176 history->globalUsed = choice_prediction;
173bool
174TournamentBP::lookup(Addr &branch_addr, void * &bp_history)
175{
176 bool local_prediction;
177 unsigned local_history_idx;
178 unsigned local_predictor_idx;
179
180 bool global_prediction;

--- 12 unchanged lines hidden (view full) ---

193 choice_prediction = choiceCtrs[globalHistory].read() > threshold;
194
195 // Create BPHistory and pass it back to be recorded.
196 BPHistory *history = new BPHistory;
197 history->globalHistory = globalHistory;
198 history->localPredTaken = local_prediction;
199 history->globalPredTaken = global_prediction;
200 history->globalUsed = choice_prediction;
201 history->localHistory = local_predictor_idx;
177 bp_history = (void *)history;
178
179 assert(globalHistory < globalPredictorSize &&
180 local_history_idx < localHistoryTableSize &&
181 local_predictor_idx < localPredictorSize);
182
183 // Commented code is for doing speculative update of counters and
184 // all histories.
185 if (choice_prediction) {
186 if (global_prediction) {
202 bp_history = (void *)history;
203
204 assert(globalHistory < globalPredictorSize &&
205 local_history_idx < localHistoryTableSize &&
206 local_predictor_idx < localPredictorSize);
207
208 // Commented code is for doing speculative update of counters and
209 // all histories.
210 if (choice_prediction) {
211 if (global_prediction) {
187// updateHistoriesTaken(local_history_idx);
188// globalCtrs[globalHistory].increment();
189// localCtrs[local_history_idx].increment();
190 updateGlobalHistTaken();
212 updateGlobalHistTaken();
213 updateLocalHistTaken(local_history_idx);
191 return true;
192 } else {
214 return true;
215 } else {
193// updateHistoriesNotTaken(local_history_idx);
194// globalCtrs[globalHistory].decrement();
195// localCtrs[local_history_idx].decrement();
196 updateGlobalHistNotTaken();
216 updateGlobalHistNotTaken();
217 updateLocalHistNotTaken(local_history_idx);
197 return false;
198 }
199 } else {
200 if (local_prediction) {
218 return false;
219 }
220 } else {
221 if (local_prediction) {
201// updateHistoriesTaken(local_history_idx);
202// globalCtrs[globalHistory].increment();
203// localCtrs[local_history_idx].increment();
204 updateGlobalHistTaken();
222 updateGlobalHistTaken();
223 updateLocalHistTaken(local_history_idx);
205 return true;
206 } else {
224 return true;
225 } else {
207// updateHistoriesNotTaken(local_history_idx);
208// globalCtrs[globalHistory].decrement();
209// localCtrs[local_history_idx].decrement();
210 updateGlobalHistNotTaken();
226 updateGlobalHistNotTaken();
227 updateLocalHistNotTaken(local_history_idx);
211 return false;
212 }
213 }
214}
215
216void
217TournamentBP::uncondBr(void * &bp_history)
218{
219 // Create BPHistory and pass it back to be recorded.
220 BPHistory *history = new BPHistory;
221 history->globalHistory = globalHistory;
222 history->localPredTaken = true;
223 history->globalPredTaken = true;
224 history->globalUsed = true;
228 return false;
229 }
230 }
231}
232
233void
234TournamentBP::uncondBr(void * &bp_history)
235{
236 // Create BPHistory and pass it back to be recorded.
237 BPHistory *history = new BPHistory;
238 history->globalHistory = globalHistory;
239 history->localPredTaken = true;
240 history->globalPredTaken = true;
241 history->globalUsed = true;
242 history->localHistory = invalidPredictorIndex;
225 bp_history = static_cast<void *>(history);
226
227 updateGlobalHistTaken();
228}
229
230void
243 bp_history = static_cast<void *>(history);
244
245 updateGlobalHistTaken();
246}
247
248void
231TournamentBP::update(Addr &branch_addr, bool taken, void *bp_history)
249TournamentBP::update(Addr &branch_addr, bool taken, void *bp_history,
250 bool squashed)
232{
233 unsigned local_history_idx;
251{
252 unsigned local_history_idx;
234 unsigned local_predictor_idx;
253 unsigned local_predictor_idx M5_VAR_USED;
235 unsigned local_predictor_hist;
236
237 // Get the local predictor's current prediction
238 local_history_idx = calcLocHistIdx(branch_addr);
239 local_predictor_hist = localHistoryTable[local_history_idx];
240 local_predictor_idx = local_predictor_hist & localPredictorMask;
241
242 // Update the choice predictor to tell it which one was correct if

--- 11 unchanged lines hidden (view full) ---

254 }
255
256 }
257
258 // Update the counters and local history with the proper
259 // resolution of the branch. Global history is updated
260 // speculatively and restored upon squash() calls, so it does not
261 // need to be updated.
254 unsigned local_predictor_hist;
255
256 // Get the local predictor's current prediction
257 local_history_idx = calcLocHistIdx(branch_addr);
258 local_predictor_hist = localHistoryTable[local_history_idx];
259 local_predictor_idx = local_predictor_hist & localPredictorMask;
260
261 // Update the choice predictor to tell it which one was correct if

--- 11 unchanged lines hidden (view full) ---

273 }
274
275 }
276
277 // Update the counters and local history with the proper
278 // resolution of the branch. Global history is updated
279 // speculatively and restored upon squash() calls, so it does not
280 // need to be updated.
281 unsigned old_local_pred_index = history->localHistory
282 & localPredictorMask;
262 if (taken) {
283 if (taken) {
263 localCtrs[local_predictor_idx].increment();
264 globalCtrs[history->globalHistory].increment();
284 globalCtrs[history->globalHistory].increment();
265
266 updateLocalHistTaken(local_history_idx);
285 if (old_local_pred_index != invalidPredictorIndex) {
286 localCtrs[old_local_pred_index].increment();
287 }
267 } else {
288 } else {
268 localCtrs[local_predictor_idx].decrement();
269 globalCtrs[history->globalHistory].decrement();
289 globalCtrs[history->globalHistory].decrement();
270
271 updateLocalHistNotTaken(local_history_idx);
290 if (old_local_pred_index != invalidPredictorIndex) {
291 localCtrs[old_local_pred_index].decrement();
292 }
272 }
273
293 }
294
274 bool mispredict = false;
275
276 //global predictor used and mispredicted
277 if (history->globalUsed && history->globalPredTaken != taken)
278 mispredict = true;
279 //local predictor used and mispredicted
280 else if (!history->globalUsed && history->localPredTaken != taken)
281 mispredict = true;
282
283 if (mispredict) {
295 if (squashed) {
284 if (taken) {
296 if (taken) {
285 globalHistory = globalHistory | 1;
297 globalHistory = (history->globalHistory << 1) | 1;
298 globalHistory = globalHistory & globalHistoryMask;
299 if (history->localHistory != invalidPredictorIndex)
300 localHistoryTable[local_history_idx] =
301 (history->localHistory << 1) | 1;
286 } else {
302 } else {
287 unsigned mask = globalHistoryMask - 1;
288 globalHistory = globalHistory & mask;
303 globalHistory = (history->globalHistory << 1);
304 globalHistory = globalHistory & globalHistoryMask;
305 if (history->localHistory != invalidPredictorIndex) {
306 localHistoryTable[local_history_idx] =
307 history->localHistory << 1;
308 }
289 }
290
291 }
292 // We're done with this history, now delete it.
293 delete history;
294 }
295
296 assert(globalHistory < globalPredictorSize &&

--- 22 unchanged lines hidden ---
309 }
310
311 }
312 // We're done with this history, now delete it.
313 delete history;
314 }
315
316 assert(globalHistory < globalPredictorSize &&

--- 22 unchanged lines hidden ---