OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
FUState Class Reference

#include <FUState.hh>

Inheritance diagram for FUState:
Inheritance graph
Collaboration diagram for FUState:
Collaboration graph

Public Member Functions

 FUState ()
 
 FUState (const TCEString &name)
 
virtual ~FUState ()
 
void setTriggered ()
 
void setOperation (Operation &operation)
 
void setOperation (Operation &operation, OperationExecutor &executor)
 
bool isIdle ()
 
virtual void endClock ()
 
virtual void advanceClock ()
 
virtual void addInputPortState (PortState &port)
 
virtual void addOutputPortState (PortState &port)
 
virtual void addOperationExecutor (OperationExecutor &opExec, Operation &op)
 
virtual void setOperationSimulator (DetailedOperationSimulator &sim)
 
virtual void replaceOperationExecutor (Operation &op, OperationExecutor *newExecutor)
 
virtual OperationExecutorexecutor (Operation &op)
 
virtual OperationContextcontext ()
 
virtual void reset ()
 this is called at (re)initialization of the simulation
 
- Public Member Functions inherited from ClockedState
 ClockedState ()
 
virtual ~ClockedState ()
 

Protected Attributes

bool idle_
 The idle status of the FU. The derived classes should alway set this to true when possible to avoid unnecessary advanceClock() and endClock() calls.
 

Private Types

typedef std::map< Operation *, OperationExecutor * > ExecutorContainer
 Maps operations to executors.
 
typedef std::vector< OperationExecutor * > ExecutorList
 Contains all the different instances of executors.
 

Private Member Functions

 FUState (const FUState &)
 Copying not allowed.
 
FUStateoperator= (const FUState &)
 Assignment not allowed.
 
void clearPorts ()
 
bool sameBindings (OperationExecutor &exec1, OperationExecutor &exec2, Operation &op)
 
virtual void setOperationSimulator (Operation &op, DetailedOperationSimulator &sim)
 

Private Attributes

bool trigger_
 True if operation is triggered in current clock cycle.
 
OperationnextOperation_
 Operation to be triggered next.
 
OperationExecutornextExecutor_
 OperationExecutor to be used for the next operation (an optimization).
 
OperationContext operationContext_
 The operation context for this FU.
 
ExecutorContainer executors_
 All operation executors.
 
ExecutorList execList_
 All the different instances of OperationExecutors.
 
std::vector< PortState * > inputPorts_
 Input ports of the function unit.
 
std::vector< PortState * > outputPorts_
 Output ports of the function unit.
 
std::size_t activeExecutors_
 Count of active executors (to allow returning instantly from advanceClock())
 
DetailedOperationSimulatordetailedModel_
 Optional detailed operation simulation model. Assume there's one such model per FU or none at all for now (could be possible to be one model per Operation).
 

Detailed Description

Models the state of the function unit of a TTA processor.

Definition at line 58 of file FUState.hh.

Member Typedef Documentation

◆ ExecutorContainer

Maps operations to executors.

Definition at line 114 of file FUState.hh.

◆ ExecutorList

typedef std::vector<OperationExecutor*> FUState::ExecutorList
private

Contains all the different instances of executors.

Definition at line 116 of file FUState.hh.

Constructor & Destructor Documentation

◆ FUState() [1/3]

FUState::FUState ( )

Constructor (no explicitly given FU name).

Parameters
lockGlobal lock signal.

Definition at line 67 of file FUState.cc.

67 :
68 ClockedState(), idle_(false), trigger_(false),
69 nextOperation_(NULL), nextExecutor_(NULL),
72}
#define DEFAULT_FU_NAME
bool trigger_
True if operation is triggered in current clock cycle.
Definition FUState.hh:119
OperationContext operationContext_
The operation context for this FU.
Definition FUState.hh:125
std::size_t activeExecutors_
Count of active executors (to allow returning instantly from advanceClock())
Definition FUState.hh:136
bool idle_
The idle status of the FU. The derived classes should alway set this to true when possible to avoid u...
Definition FUState.hh:95
Operation * nextOperation_
Operation to be triggered next.
Definition FUState.hh:121
OperationExecutor * nextExecutor_
OperationExecutor to be used for the next operation (an optimization).
Definition FUState.hh:123
DetailedOperationSimulator * detailedModel_
Optional detailed operation simulation model. Assume there's one such model per FU or none at all for...
Definition FUState.hh:140

◆ FUState() [2/3]

FUState::FUState ( const TCEString name)

Constructor (with explicitly given FU name).

Parameters
lockGlobal lock signal.

Definition at line 79 of file FUState.cc.

79 :
80 ClockedState(), idle_(false), trigger_(false),
83}

◆ ~FUState()

FUState::~FUState ( )
virtual

Destructor.

Definition at line 88 of file FUState.cc.

88 {
89 clearPorts();
91}
ExecutorList execList_
All the different instances of OperationExecutors.
Definition FUState.hh:129
void clearPorts()
Definition FUState.cc:97
static void deleteAllItems(SequenceType &aSequence)

References clearPorts(), SequenceTools::deleteAllItems(), and execList_.

Here is the call graph for this function:

◆ FUState() [3/3]

FUState::FUState ( const FUState )
private

Copying not allowed.

Member Function Documentation

◆ addInputPortState()

void FUState::addInputPortState ( PortState port)
virtual

Adds new input port state.

Parameters
portNew input port state.

Reimplemented in NullFUState.

Definition at line 211 of file FUState.cc.

211 {
212 inputPorts_.push_back(&port);
213}
std::vector< PortState * > inputPorts_
Input ports of the function unit.
Definition FUState.hh:131

References inputPorts_.

Referenced by MachineStateBuilder::addPortToFU(), and MachineStateBuilder::addVirtualOpcodeSettingPortsToFU().

◆ addOperationExecutor()

void FUState::addOperationExecutor ( OperationExecutor opExec,
Operation op 
)
virtual

Adds operation executor for a given operation.

Parameters
opExecOperation executor to be added.
opOperation which executor is added.

Reimplemented in NullFUState.

Definition at line 232 of file FUState.cc.

232 {
233
234 op.createState(context());
235
236 // do not use same operation executor even if the latency and operand
237 // bindings are equal between the operations, because the executor
238 // properties can be different (especially, one of the executors can
239 // have conflict detection)
240 OperationExecutor* newExecutor = opExec.copy();
241 execList_.push_back(newExecutor);
242 newExecutor->setContext(context());
243 executors_[&op] = newExecutor;
244}
virtual OperationContext & context()
Definition FUState.cc:376
ExecutorContainer executors_
All operation executors.
Definition FUState.hh:127
virtual void setContext(OperationContext &context)=0
virtual OperationExecutor * copy()=0
virtual void createState(OperationContext &context) const
Definition Operation.cc:590

References context(), OperationExecutor::copy(), Operation::createState(), execList_, executors_, and OperationExecutor::setContext().

Referenced by MachineStateBuilder::addVirtualOpcodeSettingPortsToFU().

Here is the call graph for this function:

◆ addOutputPortState()

void FUState::addOutputPortState ( PortState port)
virtual

Adds new output port state.

Parameters
portNew output port state.

Reimplemented in NullFUState.

Definition at line 221 of file FUState.cc.

221 {
222 outputPorts_.push_back(&port);
223}
std::vector< PortState * > outputPorts_
Output ports of the function unit.
Definition FUState.hh:133

References outputPorts_.

Referenced by MachineStateBuilder::addPortToFU().

◆ advanceClock()

void FUState::advanceClock ( )
virtual

Handles actions that take place while clock cycle changes.

advanceClock() of all active operation executors are called.

Todo:
detect if there are clocked state objects
Todo:
detect if there are clocked state objects

Implements ClockedState.

Reimplemented in NullFUState, and GCUState.

Definition at line 152 of file FUState.cc.

152 {
153
154 if (detailedModel_ != NULL)
156
157 // in case there are no active operations and there are no states
158 // which need clock advancing, the FU is in idle state
159 if (activeExecutors_ == 0 && context().isEmpty()) {
160 idle_ = true;
161 return;
162 } else if (activeExecutors_ == 1 && nextExecutor_ != NULL &&
164 // a special case for sequential simulation:
165 // if there's only one active executor, and it's the one
166 // triggered previously in endClock(), we can use
167 // nextExecutor_ and avoid traversing the whole list of executors
171 idle_ = false;
172 } else {
174 idle_ = true;
175 }
176 // advance clock of all operations with state
177 /// @todo detect if there are *clocked* state objects
178 if (!context().isEmpty()) {
180 }
181 return;
182 }
183
185 size_t execListSize = execList_.size();
186 for (size_t i = 0; i < execListSize; ++i) {
187 OperationExecutor* opexec = execList_[i];
188 if (opexec->hasPendingOperations()) {
189 opexec->advanceClock();
190 // check if it's still active
191 if (opexec->hasPendingOperations()) {
193 }
194 }
195 }
196 // advance clock of all operations with state
197 /// @todo detect if there are *clocked* state objects
198 if (!context().isEmpty()) {
200 }
201
202 idle_ = (activeExecutors_ == 0 && context().isEmpty());
203}
bool hasPendingOperations() const
virtual void advanceClock()=0

References activeExecutors_, OperationContext::advanceClock(), OperationExecutor::advanceClock(), context(), detailedModel_, execList_, OperationExecutor::hasPendingOperations(), idle_, OperationContext::isEmpty(), nextExecutor_, and DetailedOperationSimulator::simulateCycleStart().

Referenced by FUTestbenchGenerator::createStimulus().

Here is the call graph for this function:

◆ clearPorts()

void FUState::clearPorts ( )
private

Clears input and output ports.

Definition at line 97 of file FUState.cc.

97 {
98 inputPorts_.clear();
99 outputPorts_.clear();
100}

References inputPorts_, and outputPorts_.

Referenced by ~FUState().

◆ context()

OperationContext & FUState::context ( )
virtual

Returns the operation context.

This is a "template method" to allow differently initialized OperationContext-classes in FUState subclasses.

Returns
The operation context for the FU.

Reimplemented in GCUState, and MemoryAccessingFUState.

Definition at line 376 of file FUState.cc.

376 {
377 return operationContext_;
378}

References operationContext_.

Referenced by addOperationExecutor(), advanceClock(), replaceOperationExecutor(), reset(), SimulationController::SimulationController(), and TransportPipeline::TransportPipeline().

◆ endClock()

void FUState::endClock ( )
virtual

Handles actions that take place in the end of the clock cycle.

If operation is triggered, startOperation() of the executor of the operation is called.

Implements ClockedState.

Reimplemented in NullFUState.

Definition at line 122 of file FUState.cc.

122 {
123 if (trigger_) {
124 if (nextOperation_ == NULL) {
125 throw Exception(
126 __FILE__, __LINE__, __func__,
127 "Tried to trigger FU without operation code.");
128 }
129 if (nextExecutor_ == NULL) {
130 ExecutorContainer::iterator iter = executors_.find(nextOperation_);
131 assert(iter != executors_.end());
132 nextExecutor_ = (*iter).second;
133 }
134 // set this flag to false before actually handling the trigger
135 // condition because startOperation() can cause a runtime error
136 // exception
137 trigger_ = false;
141 idle_ = false;
142 }
143 }
144}
#define __func__
#define assert(condition)
virtual void startOperation(Operation &op)=0

References __func__, activeExecutors_, assert, executors_, OperationExecutor::hasPendingOperations(), idle_, nextExecutor_, nextOperation_, OperationExecutor::startOperation(), and trigger_.

Referenced by OTASimulationController::advanceMachineCycle(), FUTestbenchGenerator::createStimulus(), and SimulationController::simulateCycle().

Here is the call graph for this function:

◆ executor()

OperationExecutor * FUState::executor ( Operation op)
virtual

Returns OperationExecutor for the given operation.

Parameters
opThe operation of the wanted OperationExecutor.

Reimplemented in NullFUState.

Definition at line 358 of file FUState.cc.

358 {
359 ExecutorContainer::iterator iter = executors_.find(&op);
360 if (iter == executors_.end()) {
361 return NULL;
362 } else {
363 return (*iter).second;
364 }
365}

References executors_.

Referenced by MachineStateBuilder::addVirtualOpcodeSettingPortsToFU(), and setOperationSimulator().

◆ isIdle()

bool FUState::isIdle ( )

◆ operator=()

FUState & FUState::operator= ( const FUState )
private

Assignment not allowed.

◆ replaceOperationExecutor()

void FUState::replaceOperationExecutor ( Operation op,
OperationExecutor newExecutor 
)
virtual

Replaces the operation executor model for an operation.

Does not copy the operation executor but uses the given instance. The method copies the I/O bindings and sets the parent FUState from the old model.

Parameters
opOperation of which executor is added.
newExecutorOperation executor to be set.

Definition at line 257 of file FUState.cc.

259 {
260
261 op.createState(context());
262 newExecutor->setContext(context());
263
264 OperationExecutor* oldExecutor = executors_[&op];
265 newExecutor->setParent(oldExecutor->parent());
266
267 /* Copy the operand-port bindings. */
268 for (int ioId = 1;
269 ioId <= op.numberOfInputs() + op.numberOfOutputs(); ++ioId) {
270 newExecutor->addBinding(ioId, oldExecutor->binding(ioId));
271 }
272 assert(sameBindings(*oldExecutor, *newExecutor, op));
273
274 /* Replace the executor in the execution list. */
275 for (std::size_t i = 0; i < execList_.size(); ++i) {
276 if (execList_.at(i) == oldExecutor) {
277 execList_[i] = newExecutor;
278 break;
279 }
280 }
281 executors_[&op] = newExecutor;
282 delete oldExecutor;
283}
bool sameBindings(OperationExecutor &exec1, OperationExecutor &exec2, Operation &op)
Definition FUState.cc:324
void addBinding(int io, PortState &port)
PortState & binding(int io) const
void setParent(FUState &parent)
FUState & parent() const
virtual int numberOfInputs() const
Definition Operation.cc:192
virtual int numberOfOutputs() const
Definition Operation.cc:202

References OperationExecutor::addBinding(), assert, OperationExecutor::binding(), context(), Operation::createState(), execList_, executors_, Operation::numberOfInputs(), Operation::numberOfOutputs(), OperationExecutor::parent(), sameBindings(), OperationExecutor::setContext(), and OperationExecutor::setParent().

Here is the call graph for this function:

◆ reset()

void FUState::reset ( )
virtual

this is called at (re)initialization of the simulation

Reimplemented from ClockedState.

Reimplemented in GCUState.

Definition at line 103 of file FUState.cc.

103 {
104 for (ExecutorContainer::iterator i = executors_.begin();
105 i != executors_.end(); ++i) {
106 Operation* op = (*i).first;
107 // Ensure the init state is called again.
108 op->deleteState(context());
109 op->createState(context());
110 // Reset the internal state of executor
111 (*i).second->reset();
112 }
113}
virtual void deleteState(OperationContext &context) const
Definition Operation.cc:601

References context(), Operation::createState(), Operation::deleteState(), and executors_.

Here is the call graph for this function:

◆ sameBindings()

bool FUState::sameBindings ( OperationExecutor exec1,
OperationExecutor exec2,
Operation op 
)
private

Returns true if the two OperationExecutors have the same bindings.

Parameters
exec1First OperationExecutor.
exec2Second OperationExecutor.
opOperation to be executed with executors.
Returns
True if the two executors have same bindings.

Definition at line 324 of file FUState.cc.

327 {
328
329 for (int i = 1; i <= op.numberOfInputs() + op.numberOfOutputs(); i++) {
330
331 PortState* port1 = NULL;
332 try {
333 port1 = &exec1.binding(i);
334 } catch (const OutOfRange& o) {
335 return false;
336 }
337
338 PortState* port2 = NULL;
339 try {
340 port2 = &exec2.binding(i);
341 } catch (const OutOfRange& o) {
342 return false;
343 }
344
345 if (port1 != port2) {
346 return false;
347 }
348 }
349 return true;
350}

References OperationExecutor::binding(), Operation::numberOfInputs(), and Operation::numberOfOutputs().

Referenced by replaceOperationExecutor().

Here is the call graph for this function:

◆ setOperation() [1/2]

void FUState::setOperation ( Operation operation)

◆ setOperation() [2/2]

void FUState::setOperation ( Operation operation,
OperationExecutor executor 
)

◆ setOperationSimulator() [1/2]

void FUState::setOperationSimulator ( DetailedOperationSimulator sim)
virtual

Sets a detailed operation simulation model for all operations in the FU.

Definition at line 304 of file FUState.cc.

304 {
305
306 for (ExecutorContainer::iterator i = executors_.begin();
307 i != executors_.end(); ++i) {
308 Operation* op = (*i).first;
309 setOperationSimulator(*op, sim);
310 }
311 detailedModel_ = &sim;
312}
virtual void setOperationSimulator(DetailedOperationSimulator &sim)
Definition FUState.cc:304

References detailedModel_, executors_, and setOperationSimulator().

Referenced by setOperationSimulator().

Here is the call graph for this function:

◆ setOperationSimulator() [2/2]

void FUState::setOperationSimulator ( Operation op,
DetailedOperationSimulator sim 
)
privatevirtual

Sets a detailed operation simulation model for all operations in the FU.

Definition at line 290 of file FUState.cc.

292 {
293
295 dynamic_cast<MultiLatencyOperationExecutor*>(executor(op));
296 assert (oe != NULL && "Can only add details to a complex executor.");
297 oe->setOperationSimulator(sim);
298}
virtual OperationExecutor * executor(Operation &op)
Definition FUState.cc:358
virtual void setOperationSimulator(DetailedOperationSimulator &sim)

References assert, executor(), and MultiLatencyOperationExecutor::setOperationSimulator().

Here is the call graph for this function:

◆ setTriggered()

void FUState::setTriggered ( )

Member Data Documentation

◆ activeExecutors_

std::size_t FUState::activeExecutors_
private

Count of active executors (to allow returning instantly from advanceClock())

Definition at line 136 of file FUState.hh.

Referenced by advanceClock(), and endClock().

◆ detailedModel_

DetailedOperationSimulator* FUState::detailedModel_
private

Optional detailed operation simulation model. Assume there's one such model per FU or none at all for now (could be possible to be one model per Operation).

Definition at line 140 of file FUState.hh.

Referenced by advanceClock(), and setOperationSimulator().

◆ execList_

ExecutorList FUState::execList_
private

All the different instances of OperationExecutors.

Definition at line 129 of file FUState.hh.

Referenced by addOperationExecutor(), advanceClock(), replaceOperationExecutor(), and ~FUState().

◆ executors_

ExecutorContainer FUState::executors_
private

All operation executors.

Definition at line 127 of file FUState.hh.

Referenced by addOperationExecutor(), endClock(), executor(), replaceOperationExecutor(), reset(), and setOperationSimulator().

◆ idle_

bool FUState::idle_
protected

The idle status of the FU. The derived classes should alway set this to true when possible to avoid unnecessary advanceClock() and endClock() calls.

Definition at line 95 of file FUState.hh.

Referenced by advanceClock(), GCUState::advanceClock(), and endClock().

◆ inputPorts_

std::vector<PortState*> FUState::inputPorts_
private

Input ports of the function unit.

Definition at line 131 of file FUState.hh.

Referenced by addInputPortState(), and clearPorts().

◆ nextExecutor_

OperationExecutor* FUState::nextExecutor_
private

OperationExecutor to be used for the next operation (an optimization).

Definition at line 123 of file FUState.hh.

Referenced by advanceClock(), and endClock().

◆ nextOperation_

Operation* FUState::nextOperation_
private

Operation to be triggered next.

Definition at line 121 of file FUState.hh.

Referenced by endClock().

◆ operationContext_

OperationContext FUState::operationContext_
private

The operation context for this FU.

Definition at line 125 of file FUState.hh.

Referenced by context().

◆ outputPorts_

std::vector<PortState*> FUState::outputPorts_
private

Output ports of the function unit.

Definition at line 133 of file FUState.hh.

Referenced by addOutputPortState(), and clearPorts().

◆ trigger_

bool FUState::trigger_
private

True if operation is triggered in current clock cycle.

Definition at line 119 of file FUState.hh.

Referenced by endClock().


The documentation for this class was generated from the following files: