tage.cc (13654:dc3878f03a0c) tage.cc (13685:bb3377c81303)
1/*
2 * Copyright (c) 2014 The University of Wisconsin
3 *
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)
7 *
8 * All rights reserved.
9 *
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.
20 *
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.
32 *
33 * Authors: Vignyan Reddy, Dibakar Gope and Arthur Perais,
34 * from André Seznec's code.
35 */
36
37/* @file
38 * Implementation of a TAGE branch predictor
39 */
40
41#include "cpu/pred/tage.hh"
42
43#include "base/intmath.hh"
44#include "base/logging.hh"
45#include "base/random.hh"
46#include "base/trace.hh"
47#include "debug/Fetch.hh"
48#include "debug/Tage.hh"
49
50TAGE::TAGE(const TAGEParams *params) : BPredUnit(params), tage(params->tage)
51{
52}
53
54// PREDICTOR UPDATE
55void
56TAGE::update(ThreadID tid, Addr branch_pc, bool taken, void* bp_history,
57 bool squashed, const StaticInstPtr & inst, Addr corrTarget)
58{
59 assert(bp_history);
60
61 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
1/*
2 * Copyright (c) 2014 The University of Wisconsin
3 *
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)
7 *
8 * All rights reserved.
9 *
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.
20 *
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.
32 *
33 * Authors: Vignyan Reddy, Dibakar Gope and Arthur Perais,
34 * from André Seznec's code.
35 */
36
37/* @file
38 * Implementation of a TAGE branch predictor
39 */
40
41#include "cpu/pred/tage.hh"
42
43#include "base/intmath.hh"
44#include "base/logging.hh"
45#include "base/random.hh"
46#include "base/trace.hh"
47#include "debug/Fetch.hh"
48#include "debug/Tage.hh"
49
50TAGE::TAGE(const TAGEParams *params) : BPredUnit(params), tage(params->tage)
51{
52}
53
54// PREDICTOR UPDATE
55void
56TAGE::update(ThreadID tid, Addr branch_pc, bool taken, void* bp_history,
57 bool squashed, const StaticInstPtr & inst, Addr corrTarget)
58{
59 assert(bp_history);
60
61 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
62 TAGEBase::BranchInfo *tage_bi = bi->tageBranchInfo;
62
63 assert(corrTarget != MaxAddr);
64
65 if (squashed) {
66 // This restores the global history, then update it
67 // and recomputes the folded histories.
63
64 assert(corrTarget != MaxAddr);
65
66 if (squashed) {
67 // This restores the global history, then update it
68 // and recomputes the folded histories.
68 tage->squash(tid, taken, bi->tageBranchInfo, corrTarget);
69 tage->squash(tid, taken, tage_bi, corrTarget);
69 return;
70 }
71
70 return;
71 }
72
72 int nrand = TAGEBase::getRandom() & 3;
73 int nrand = random_mt.random<int>() & 3;
73 if (bi->tageBranchInfo->condBranch) {
74 DPRINTF(Tage, "Updating tables for branch:%lx; taken?:%d\n",
75 branch_pc, taken);
76 tage->updateStats(taken, bi->tageBranchInfo);
74 if (bi->tageBranchInfo->condBranch) {
75 DPRINTF(Tage, "Updating tables for branch:%lx; taken?:%d\n",
76 branch_pc, taken);
77 tage->updateStats(taken, bi->tageBranchInfo);
77 tage->condBranchUpdate(tid, branch_pc, taken, bi->tageBranchInfo,
78 nrand, corrTarget);
78 tage->condBranchUpdate(tid, branch_pc, taken, tage_bi, nrand,
79 corrTarget, bi->tageBranchInfo->tagePred);
79 }
80
80 }
81
81 tage->updateHistories(tid, branch_pc, taken, bi->tageBranchInfo, false,
82 inst, corrTarget);
83
82 // optional non speculative update of the histories
83 tage->updateHistories(tid, branch_pc, taken, tage_bi, false, inst,
84 corrTarget);
84 delete bi;
85}
86
87void
88TAGE::squash(ThreadID tid, void *bp_history)
89{
90 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
91 DPRINTF(Tage, "Deleting branch info: %lx\n", bi->tageBranchInfo->branchPC);
92 delete bi;
93}
94
95bool
96TAGE::predict(ThreadID tid, Addr branch_pc, bool cond_branch, void* &b)
97{
85 delete bi;
86}
87
88void
89TAGE::squash(ThreadID tid, void *bp_history)
90{
91 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
92 DPRINTF(Tage, "Deleting branch info: %lx\n", bi->tageBranchInfo->branchPC);
93 delete bi;
94}
95
96bool
97TAGE::predict(ThreadID tid, Addr branch_pc, bool cond_branch, void* &b)
98{
98 TageBranchInfo *bi = new TageBranchInfo(*tage);
99 TageBranchInfo *bi = new TageBranchInfo(*tage);//nHistoryTables+1);
99 b = (void*)(bi);
100 return tage->tagePredict(tid, branch_pc, cond_branch, bi->tageBranchInfo);
101}
102
103bool
104TAGE::lookup(ThreadID tid, Addr branch_pc, void* &bp_history)
105{
106 bool retval = predict(tid, branch_pc, true, bp_history);
107
108 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
109
110 DPRINTF(Tage, "Lookup branch: %lx; predict:%d\n", branch_pc, retval);
111
112 tage->updateHistories(tid, branch_pc, retval, bi->tageBranchInfo, true);
113
114 return retval;
115}
116
117void
118TAGE::btbUpdate(ThreadID tid, Addr branch_pc, void* &bp_history)
119{
120 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
121 tage->btbUpdate(tid, branch_pc, bi->tageBranchInfo);
122}
123
124void
125TAGE::uncondBranch(ThreadID tid, Addr br_pc, void* &bp_history)
126{
127 DPRINTF(Tage, "UnConditionalBranch: %lx\n", br_pc);
128 predict(tid, br_pc, false, bp_history);
129 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
130 tage->updateHistories(tid, br_pc, true, bi->tageBranchInfo, true);
131}
132
133TAGE*
134TAGEParams::create()
135{
136 return new TAGE(this);
137}
100 b = (void*)(bi);
101 return tage->tagePredict(tid, branch_pc, cond_branch, bi->tageBranchInfo);
102}
103
104bool
105TAGE::lookup(ThreadID tid, Addr branch_pc, void* &bp_history)
106{
107 bool retval = predict(tid, branch_pc, true, bp_history);
108
109 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
110
111 DPRINTF(Tage, "Lookup branch: %lx; predict:%d\n", branch_pc, retval);
112
113 tage->updateHistories(tid, branch_pc, retval, bi->tageBranchInfo, true);
114
115 return retval;
116}
117
118void
119TAGE::btbUpdate(ThreadID tid, Addr branch_pc, void* &bp_history)
120{
121 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
122 tage->btbUpdate(tid, branch_pc, bi->tageBranchInfo);
123}
124
125void
126TAGE::uncondBranch(ThreadID tid, Addr br_pc, void* &bp_history)
127{
128 DPRINTF(Tage, "UnConditionalBranch: %lx\n", br_pc);
129 predict(tid, br_pc, false, bp_history);
130 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
131 tage->updateHistories(tid, br_pc, true, bi->tageBranchInfo, true);
132}
133
134TAGE*
135TAGEParams::create()
136{
137 return new TAGE(this);
138}