pipe_data.cc revision 10259
1/*
2 * Copyright (c) 2013-2014 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 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * Authors: Andrew Bardsley
38 */
39
40#include "cpu/minor/pipe_data.hh"
41
42namespace Minor
43{
44
45std::ostream &
46operator <<(std::ostream &os, BranchData::Reason reason)
47{
48    switch (reason)
49    {
50      case BranchData::NoBranch:
51        os << "NoBranch";
52        break;
53      case BranchData::UnpredictedBranch:
54        os << "UnpredictedBranch";
55        break;
56      case BranchData::BranchPrediction:
57        os << "BranchPrediction";
58        break;
59      case BranchData::CorrectlyPredictedBranch:
60        os << "CorrectlyPredictedBranch";
61        break;
62      case BranchData::BadlyPredictedBranch:
63        os << "BadlyPredictedBranch";
64        break;
65      case BranchData::BadlyPredictedBranchTarget:
66        os << "BadlyPredictedBranchTarget";
67        break;
68      case BranchData::Interrupt:
69        os << "Interrupt";
70        break;
71      case BranchData::SuspendThread:
72        os << "SuspendThread";
73        break;
74      case BranchData::WakeupFetch:
75        os << "WakeupFetch";
76        break;
77      case BranchData::HaltFetch:
78        os << "HaltFetch";
79        break;
80    }
81
82    return os;
83}
84
85bool
86BranchData::isStreamChange(const BranchData::Reason reason)
87{
88    bool ret = false;
89
90    switch (reason)
91    {
92        /* No change of stream (see the enum comment in pipe_data.hh) */
93      case NoBranch:
94      case CorrectlyPredictedBranch:
95        ret = false;
96        break;
97
98        /* Change of stream (Fetch1 should act on) */
99      case UnpredictedBranch:
100      case BranchPrediction:
101      case BadlyPredictedBranchTarget:
102      case BadlyPredictedBranch:
103      case SuspendThread:
104      case Interrupt:
105      case WakeupFetch:
106      case HaltFetch:
107        ret = true;
108        break;
109    }
110
111    return ret;
112}
113
114bool
115BranchData::isBranch(const BranchData::Reason reason)
116{
117    bool ret = false;
118
119    switch (reason)
120    {
121        /* No change of stream (see the enum comment in pipe_data.hh) */
122      case NoBranch:
123      case CorrectlyPredictedBranch:
124      case SuspendThread:
125      case Interrupt:
126      case WakeupFetch:
127      case HaltFetch:
128        ret = false;
129        break;
130
131        /* Change of stream (Fetch1 should act on) */
132      case UnpredictedBranch:
133      case BranchPrediction:
134      case BadlyPredictedBranchTarget:
135      case BadlyPredictedBranch:
136        ret = true;
137        break;
138    }
139
140    return ret;
141}
142
143void
144BranchData::reportData(std::ostream &os) const
145{
146    if (isBubble()) {
147        os << '-';
148    } else {
149        os << reason
150            << ';' << newStreamSeqNum << '.' << newPredictionSeqNum
151            << ";0x" << std::hex << target.instAddr() << std::dec
152            << ';';
153        inst->reportData(os);
154    }
155}
156
157std::ostream &
158operator <<(std::ostream &os, const BranchData &branch)
159{
160    os << branch.reason << " target: 0x"
161        << std::hex << branch.target.instAddr() << std::dec
162        << ' ' << *branch.inst
163        << ' ' << branch.newStreamSeqNum << "(stream)."
164        << branch.newPredictionSeqNum << "(pred)";
165
166    return os;
167}
168
169void
170ForwardLineData::setFault(Fault fault_)
171{
172    fault = fault_;
173    if (isFault())
174        bubbleFlag = false;
175}
176
177void
178ForwardLineData::allocateLine(unsigned int width_)
179{
180    lineWidth = width_;
181    bubbleFlag = false;
182
183    assert(!isFault());
184    assert(!line);
185
186    line = new uint8_t[width_];
187}
188
189void
190ForwardLineData::adoptPacketData(Packet *packet)
191{
192    this->packet = packet;
193    lineWidth = packet->req->getSize();
194    bubbleFlag = false;
195
196    assert(!isFault());
197    assert(!line);
198
199    line = packet->getPtr<uint8_t>();
200}
201
202void
203ForwardLineData::freeLine()
204{
205    /* Only free lines in non-faulting, non-bubble lines */
206    if (!isFault() && !isBubble()) {
207        assert(line);
208        /* If packet is not NULL then the line must belong to the packet so
209         *  we don't need to separately deallocate the line */
210        if (packet) {
211            delete packet;
212        } else {
213            delete [] line;
214        }
215        line = NULL;
216        bubbleFlag = true;
217    }
218}
219
220void
221ForwardLineData::reportData(std::ostream &os) const
222{
223    if (isBubble())
224        os << '-';
225    else if (fault != NoFault)
226        os << "F;" << id;
227    else
228        os << id;
229}
230
231ForwardInstData::ForwardInstData(unsigned int width) :
232    numInsts(width)
233{
234    bubbleFill();
235}
236
237ForwardInstData::ForwardInstData(const ForwardInstData &src)
238{
239    *this = src;
240}
241
242ForwardInstData &
243ForwardInstData::operator =(const ForwardInstData &src)
244{
245    numInsts = src.numInsts;
246
247    for (unsigned int i = 0; i < src.numInsts; i++)
248        insts[i] = src.insts[i];
249
250    return *this;
251}
252
253bool
254ForwardInstData::isBubble() const
255{
256    return numInsts == 0 || insts[0]->isBubble();
257}
258
259void
260ForwardInstData::bubbleFill()
261{
262    for (unsigned int i = 0; i < numInsts; i++)
263        insts[i] = MinorDynInst::bubble();
264}
265
266void
267ForwardInstData::resize(unsigned int width)
268{
269    assert(width < MAX_FORWARD_INSTS);
270    numInsts = width;
271
272    bubbleFill();
273}
274
275void
276ForwardInstData::reportData(std::ostream &os) const
277{
278    if (isBubble()) {
279        os << '-';
280    } else {
281        unsigned int i = 0;
282
283        os << '(';
284        while (i != numInsts) {
285            insts[i]->reportData(os);
286            i++;
287            if (i != numInsts)
288                os << ',';
289        }
290        os << ')';
291    }
292}
293
294}
295