2 * Copyright (c) 2014 The University of Wisconsin
4 * Copyright (c) 2006 INRIA (Institut National de Recherche en
5 * Informatique et en Automatique / French National Research Institute
6 * for Computer Science and Applied Mathematics)
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are
12 * met: redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer;
14 * redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution;
17 * neither the name of the copyright holders nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * Implementation of a L-TAGE branch predictor
38 #include "cpu/pred/ltage.hh"
40 #include "base/intmath.hh"
41 #include "base/logging.hh"
42 #include "base/random.hh"
43 #include "base/trace.hh"
44 #include "debug/Fetch.hh"
45 #include "debug/LTage.hh"
47 LTAGE::LTAGE(const LTAGEParams
*params
)
48 : TAGE(params
), loopPredictor(params
->loop_predictor
)
60 LTAGE::predict(ThreadID tid
, Addr branch_pc
, bool cond_branch
, void* &b
)
62 LTageBranchInfo
*bi
= new LTageBranchInfo(*tage
, *loopPredictor
);
65 bool pred_taken
= tage
->tagePredict(tid
, branch_pc
, cond_branch
,
68 pred_taken
= loopPredictor
->loopPredict(tid
, branch_pc
, cond_branch
,
69 bi
->lpBranchInfo
, pred_taken
,
72 if (bi
->lpBranchInfo
->loopPredUsed
) {
73 bi
->tageBranchInfo
->provider
= LOOP
;
75 DPRINTF(LTage
, "Predict for %lx: taken?:%d, loopTaken?:%d, "
76 "loopValid?:%d, loopUseCounter:%d, tagePred:%d, altPred:%d\n",
77 branch_pc
, pred_taken
, bi
->lpBranchInfo
->loopPred
,
78 bi
->lpBranchInfo
->loopPredValid
,
79 loopPredictor
->getLoopUseCounter(),
80 bi
->tageBranchInfo
->tagePred
, bi
->tageBranchInfo
->altTaken
);
83 // record final prediction
84 bi
->lpBranchInfo
->predTaken
= pred_taken
;
91 LTAGE::update(ThreadID tid
, Addr branch_pc
, bool taken
, void* bp_history
,
92 bool squashed
, const StaticInstPtr
& inst
, Addr corrTarget
)
96 LTageBranchInfo
* bi
= static_cast<LTageBranchInfo
*>(bp_history
);
99 if (tage
->isSpeculativeUpdateEnabled()) {
100 // This restores the global history, then update it
101 // and recomputes the folded histories.
102 tage
->squash(tid
, taken
, bi
->tageBranchInfo
, corrTarget
);
104 if (bi
->tageBranchInfo
->condBranch
) {
105 loopPredictor
->squashLoop(bi
->lpBranchInfo
);
111 int nrand
= random_mt
.random
<int>() & 3;
112 if (bi
->tageBranchInfo
->condBranch
) {
113 DPRINTF(LTage
, "Updating tables for branch:%lx; taken?:%d\n",
115 tage
->updateStats(taken
, bi
->tageBranchInfo
);
117 loopPredictor
->updateStats(taken
, bi
->lpBranchInfo
);
119 loopPredictor
->condBranchUpdate(tid
, branch_pc
, taken
,
120 bi
->tageBranchInfo
->tagePred
, bi
->lpBranchInfo
, instShiftAmt
);
122 tage
->condBranchUpdate(tid
, branch_pc
, taken
, bi
->tageBranchInfo
,
123 nrand
, corrTarget
, bi
->lpBranchInfo
->predTaken
);
126 tage
->updateHistories(tid
, branch_pc
, taken
, bi
->tageBranchInfo
, false,
133 LTAGE::squash(ThreadID tid
, void *bp_history
)
135 LTageBranchInfo
* bi
= (LTageBranchInfo
*)(bp_history
);
137 if (bi
->tageBranchInfo
->condBranch
) {
138 loopPredictor
->squash(tid
, bi
->lpBranchInfo
);
141 TAGE::squash(tid
, bp_history
);
151 LTAGEParams::create()
153 return new LTAGE(this);