OpenASIP  2.0
ExecutingOperation.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2010 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 ExecutingOperation.hh
26  *
27  * @author Pekka Jääskeläinen 2010 (pjaaskel-no.spam-cs.tut.fi)
28  */
29 
30 #ifndef TTA_EXECUTING_OPERATION_HH
31 #define TTA_EXECUTING_OPERATION_HH
32 
33 #include <climits>
34 #include <vector>
35 
36 class Operation;
37 class PortState;
38 class SimValue;
39 
40 /**
41  * Models an operation executing in the FU pipeline.
42  *
43  * This is a helper class used by MultiCycleOperationExecutor to produce
44  * a more detailed simulation of operations executing in the FUs. Notably,
45  * this model is used in the interface to override operation simulation
46  * models from SystemC simulations (see tce_systemc.hh).
47  */
49 public:
50  ExecutingOperation(Operation& op, unsigned stages) :
51  stage_(0), stages_(stages), free_(true), op_(&op) {}
52 
53  /**
54  * Returns the value bound to the input or output operand
55  * with the given ID.
56  *
57  * @note operand is the OSAL ID, thus 1 is the first input and
58  * the outputs follow sequentially.
59  */
60 
61  SimValue& io(int operand);
62 
63  const Operation& operation() const { return *op_; }
64 
65  unsigned stage() const { return stage_; }
66 
67  /**
68  * Returns true in case the currently simulated stage for the
69  * operation is the last before finishing the execution.
70  *
71  * The next advanceCycle call will push the operation out from
72  * the FU pipeline after which all results are assumed to have
73  * arrived.
74  */
75  bool isLastPipelineStage() const { return stage_ == stages_ - 1; }
76 
77  /**
78  * Methods that should not be called from SystemC models.
79  */
80  void start();
81  void stop();
82  void advanceCycle();
83 
84  /**
85  * Models the latency of an operation result.
86  *
87  * This is used to make results visible in the output ports of the FU at
88  * the correct time.
89  */
90  struct PendingResult {
91  PendingResult(SimValue& result, PortState& targetPort, int latency) :
92  result_(&result), target_(&targetPort), cyclesToGo_(latency),
93  resultLatency_(latency) {
94  }
95 
96  /**
97  * Signals a cycle advance.
98  *
99  * Makes the result visible to the output port in time.
100  */
101  void advanceCycle();
102  void reset();
103 
104  /// The value that will be written to the target after the
105  /// latency has passed.
107  /// The target port to which the result will be written after the
108  /// latency.
110  /// How many cycles to wait until the result will be written to
111  /// the target.
114  };
115 
116  void initIOVec() {
117  for (std::size_t i = 0; i < iostorage_.size(); ++i)
118  iovec_.push_back(&iostorage_.at(i));
119  }
120  /* The input and output values of operation, in their OSAL order.
121 
122  The execution model can freely modify them duing the operation
123  execution simulation.
124  */
125  std::vector<SimValue> iostorage_;
126  /// OSAL simulateTrigger() compatible I/O vector for fast execution
127  std::vector<SimValue*> iovec_;
128  /* Buffer for results that have latency cycles left. After cycles
129  have passed, the results are removed from the queue.
130  The outputs are made visible to the FU output registers
131  automatically after the ADF declared execution latency. */
132  std::vector<PendingResult> pendingResults_;
133  // the stage of execution the operation is in
134  int stage_;
135  // how many stage to simulate (the maximum of the result latencies or the
136  // last pipeline resource usage)
137  int stages_;
138  bool free_;
139  // the OSAL operation being executed
140  const Operation* op_;
141 };
142 
143 #endif
ExecutingOperation::PendingResult
Definition: ExecutingOperation.hh:90
ExecutingOperation::ExecutingOperation
ExecutingOperation(Operation &op, unsigned stages)
Definition: ExecutingOperation.hh:50
ExecutingOperation::stage_
int stage_
Definition: ExecutingOperation.hh:134
ExecutingOperation::operation
const Operation & operation() const
Definition: ExecutingOperation.hh:63
ExecutingOperation::iostorage_
std::vector< SimValue > iostorage_
Definition: ExecutingOperation.hh:125
ExecutingOperation::free_
bool free_
Definition: ExecutingOperation.hh:138
ExecutingOperation::initIOVec
void initIOVec()
Definition: ExecutingOperation.hh:116
ExecutingOperation::PendingResult::reset
void reset()
Definition: ExecutingOperation.cc:97
SimValue
Definition: SimValue.hh:96
ExecutingOperation::isLastPipelineStage
bool isLastPipelineStage() const
Definition: ExecutingOperation.hh:75
ExecutingOperation::PendingResult::PendingResult
PendingResult(SimValue &result, PortState &targetPort, int latency)
Definition: ExecutingOperation.hh:91
ExecutingOperation::PendingResult::resultLatency_
int resultLatency_
Definition: ExecutingOperation.hh:113
ExecutingOperation::PendingResult::advanceCycle
void advanceCycle()
Definition: ExecutingOperation.cc:89
PortState
Definition: PortState.hh:51
ExecutingOperation
Definition: ExecutingOperation.hh:48
Operation
Definition: Operation.hh:59
ExecutingOperation::stages_
int stages_
Definition: ExecutingOperation.hh:137
ExecutingOperation::PendingResult::cyclesToGo_
int cyclesToGo_
How many cycles to wait until the result will be written to the target.
Definition: ExecutingOperation.hh:112
ExecutingOperation::stage
unsigned stage() const
Definition: ExecutingOperation.hh:65
ExecutingOperation::io
SimValue & io(int operand)
Definition: ExecutingOperation.cc:41
ExecutingOperation::PendingResult::target_
PortState * target_
The target port to which the result will be written after the latency.
Definition: ExecutingOperation.hh:109
ExecutingOperation::stop
void stop()
Definition: ExecutingOperation.cc:65
ExecutingOperation::PendingResult::result_
SimValue * result_
The value that will be written to the target after the latency has passed.
Definition: ExecutingOperation.hh:106
ExecutingOperation::op_
const Operation * op_
Definition: ExecutingOperation.hh:140
ExecutingOperation::advanceCycle
void advanceCycle()
Definition: ExecutingOperation.cc:73
ExecutingOperation::pendingResults_
std::vector< PendingResult > pendingResults_
Definition: ExecutingOperation.hh:132
ExecutingOperation::start
void start()
Definition: ExecutingOperation.cc:51
ExecutingOperation::iovec_
std::vector< SimValue * > iovec_
OSAL simulateTrigger() compatible I/O vector for fast execution.
Definition: ExecutingOperation.hh:127