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 TAGE branch predictor
38 #include "cpu/pred/tage.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/Tage.hh"
47 TAGE::TAGE(const TAGEParams
*params
) : BPredUnit(params
), tage(params
->tage
)
53 TAGE::update(ThreadID tid
, Addr branch_pc
, bool taken
, void* bp_history
,
54 bool squashed
, const StaticInstPtr
& inst
, Addr corrTarget
)
58 TageBranchInfo
*bi
= static_cast<TageBranchInfo
*>(bp_history
);
59 TAGEBase::BranchInfo
*tage_bi
= bi
->tageBranchInfo
;
62 // This restores the global history, then update it
63 // and recomputes the folded histories.
64 tage
->squash(tid
, taken
, tage_bi
, corrTarget
);
68 int nrand
= random_mt
.random
<int>() & 3;
69 if (bi
->tageBranchInfo
->condBranch
) {
70 DPRINTF(Tage
, "Updating tables for branch:%lx; taken?:%d\n",
72 tage
->updateStats(taken
, bi
->tageBranchInfo
);
73 tage
->condBranchUpdate(tid
, branch_pc
, taken
, tage_bi
, nrand
,
74 corrTarget
, bi
->tageBranchInfo
->tagePred
);
77 // optional non speculative update of the histories
78 tage
->updateHistories(tid
, branch_pc
, taken
, tage_bi
, false, inst
,
84 TAGE::squash(ThreadID tid
, void *bp_history
)
86 TageBranchInfo
*bi
= static_cast<TageBranchInfo
*>(bp_history
);
87 DPRINTF(Tage
, "Deleting branch info: %lx\n", bi
->tageBranchInfo
->branchPC
);
92 TAGE::predict(ThreadID tid
, Addr branch_pc
, bool cond_branch
, void* &b
)
94 TageBranchInfo
*bi
= new TageBranchInfo(*tage
);//nHistoryTables+1);
96 return tage
->tagePredict(tid
, branch_pc
, cond_branch
, bi
->tageBranchInfo
);
100 TAGE::lookup(ThreadID tid
, Addr branch_pc
, void* &bp_history
)
102 bool retval
= predict(tid
, branch_pc
, true, bp_history
);
104 TageBranchInfo
*bi
= static_cast<TageBranchInfo
*>(bp_history
);
106 DPRINTF(Tage
, "Lookup branch: %lx; predict:%d\n", branch_pc
, retval
);
108 tage
->updateHistories(tid
, branch_pc
, retval
, bi
->tageBranchInfo
, true);
114 TAGE::btbUpdate(ThreadID tid
, Addr branch_pc
, void* &bp_history
)
116 TageBranchInfo
*bi
= static_cast<TageBranchInfo
*>(bp_history
);
117 tage
->btbUpdate(tid
, branch_pc
, bi
->tageBranchInfo
);
121 TAGE::uncondBranch(ThreadID tid
, Addr br_pc
, void* &bp_history
)
123 DPRINTF(Tage
, "UnConditionalBranch: %lx\n", br_pc
);
124 predict(tid
, br_pc
, false, bp_history
);
125 TageBranchInfo
*bi
= static_cast<TageBranchInfo
*>(bp_history
);
126 tage
->updateHistories(tid
, br_pc
, true, bi
->tageBranchInfo
, true);
132 return new TAGE(this);