OpenASIP  2.0
TransportPipeline.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file TransportPipeline.cc
26  *
27  * Definition of TransportPipeline class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @author Pekka Jääskeläinen 2005,2009 (pjaaskel-no.spam-cs.tut.fi)
31  * @note rating: red
32  */
33 
34 #include <vector>
35 
36 #include "TransportPipeline.hh"
37 #include "SimValue.hh"
38 #include "FUState.hh"
39 #include "Operation.hh"
40 #include "Application.hh"
41 #include "OperationContext.hh"
42 #include "Operation.hh"
43 #include "GCUState.hh"
44 #include "SimulatorToolbox.hh"
45 #include "OperationPool.hh"
46 #include "StringTools.hh"
47 #include "TCEString.hh"
48 
49 using std::vector;
50 using std::string;
51 
52 /**
53  * Constructor.
54  *
55  * @param parent Parent of the pipeline.
56  */
58  OperationExecutor(parent), operation_(NULL),
59  context_(&parent.context()),
60  tempContext_(NULL, PC_, RA_, parent.context().branchDelayCycles()),
61  parent_(parent) {
62  // delete the own state registry to avoid mem leaks
63  delete &tempContext_.stateRegistry();
64  // share the state registry with the actual context
66 }
67 
68 /**
69  * Destructor.
70  */
73 }
74 
75 /**
76  * Returns the latency of the pipeline.
77  *
78  * @return The latency of the pipeline.
79  */
80 int
82  return 0;
83 }
84 
85 /**
86  * Start the execution of the operation.
87  *
88  * First inputs and outputs of the operation are collected in a vector.
89  * Then a new operation context is created. After triggering the operation
90  * the registers which values are changed are updated in parent GCU state.
91  *
92  * @param op Operation to be triggered.
93  * @todo This can be optimized a lot.
94  */
95 void
97 
98  operation_ = &op;
99  int operands = op.numberOfInputs() + op.numberOfOutputs();
100  SimValue* io[32];
101  assert(operands < 32);
102  for (int i = 0; i < operands; ++i)
103  io[i] = const_cast<SimValue*>(&(binding(i + 1).value()));
104 
105  // use a temporary context here as the original context points to the
106  // internal program counter variables of the simulator engine,
107  // which we do not want to modify in the middle of simulating
108  // a cycle
114 
115  // If the operation is a jump or a call operation, update the program
116  // counter after delay slot cycles. If a loop buffer setup op is called,
117  // do not update the program counter this way.
118  if (tempContext_.updateProgramCounter() && (op.isCall() || op.isBranch())) {
120  }
123  }
124 }
125 
126 /**
127  * Nothing is done when clock cycle changes.
128  */
129 void
131 }
132 
133 /**
134  * Copies OperationExecutor.
135  *
136  * @return The copied OperationExecutor.
137  */
140  return new TransportPipeline(*this);
141 }
142 
143 /**
144  * Sets the OperationContext of the pipeline.
145  *
146  * @param context The OperationContext.
147  */
148 void
150  context_ = &context;
151 }
152 
TransportPipeline::tempContext_
OperationContext tempContext_
Operation context seen by the operation.
Definition: TransportPipeline.hh:72
OperationContext::setSaveReturnAddress
void setSaveReturnAddress(bool value)
Definition: OperationContext.cc:183
TransportPipeline::parent_
GCUState & parent_
The owner GCUState.
Definition: TransportPipeline.hh:82
GCUState.hh
TransportPipeline::copy
virtual OperationExecutor * copy()
Definition: TransportPipeline.cc:139
GCUState
Definition: GCUState.hh:46
OperationContext
Definition: OperationContext.hh:56
TransportPipeline::TransportPipeline
TransportPipeline(GCUState &parent)
Definition: TransportPipeline.cc:57
Operation::numberOfInputs
virtual int numberOfInputs() const
Definition: Operation.cc:192
OperationContext::setStateRegistry
void setStateRegistry(StateRegistry &stateRegistry)
Definition: OperationContext.cc:313
FUState.hh
OperationContext::saveReturnAddress
bool saveReturnAddress()
Definition: OperationContext.cc:194
TransportPipeline::setContext
virtual void setContext(OperationContext &context)
Definition: TransportPipeline.cc:149
SimValue
Definition: SimValue.hh:96
TCEString.hh
StringTools.hh
assert
#define assert(condition)
Definition: Application.hh:86
TransportPipeline::context_
OperationContext * context_
Operation context used to fetch the values for PC and RA.
Definition: TransportPipeline.hh:70
SimulatorToolbox.hh
OperationContext::stateRegistry
StateRegistry & stateRegistry()
Definition: OperationContext.cc:323
Application.hh
Operation.hh
TransportPipeline::startOperation
virtual void startOperation(Operation &op)
Definition: TransportPipeline.cc:96
TransportPipeline::operation_
Operation * operation_
Operation to be triggered next.
Definition: TransportPipeline.hh:68
OperationExecutor
Definition: OperationExecutor.hh:49
Operation
Definition: Operation.hh:59
GCUState::setReturnAddress
void setReturnAddress(const InstructionAddress &value)
OperationExecutor::parent
FUState & parent() const
TransportPipeline::advanceClock
virtual void advanceClock()
Definition: TransportPipeline.cc:130
OperationContext::programCounter
InstructionAddress & programCounter()
Definition: OperationContext.cc:152
SimValue.hh
TransportPipeline::~TransportPipeline
virtual ~TransportPipeline()
Definition: TransportPipeline.cc:71
OperationContext::setUpdateProgramCounter
void setUpdateProgramCounter(bool value)
Definition: OperationContext.cc:162
Operation::simulateTrigger
virtual bool simulateTrigger(SimValue **, OperationContext &context) const
Definition: Operation.cc:555
OperationContext::unsetStateRegistry
void unsetStateRegistry()
Definition: OperationContext.cc:318
Operation::isCall
virtual bool isCall() const
Definition: Operation.cc:318
OperationContext::updateProgramCounter
bool updateProgramCounter() const
Definition: OperationContext.cc:169
TransportPipeline::latency
virtual int latency() const
Definition: TransportPipeline.cc:81
OperationPool.hh
Operation::numberOfOutputs
virtual int numberOfOutputs() const
Definition: Operation.cc:202
TransportPipeline.hh
OperationExecutor::binding
PortState & binding(int io) const
Operation::isBranch
virtual bool isBranch() const
Definition: Operation.cc:306
OperationContext::returnAddress
SimValue & returnAddress()
Definition: OperationContext.cc:207
OperationContext.hh
GCUState::setProgramCounter
void setProgramCounter(const InstructionAddress &value)
FUState::context
virtual OperationContext & context()
Definition: FUState.cc:376