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

#include <BusResource.hh>

Inheritance diagram for BusResource:
Inheritance graph
Collaboration diagram for BusResource:
Collaboration graph

Public Member Functions

 BusResource (const std::string &name, int width, int limmSlotCount, int nopSlotCount, int guardCount, int immSize, int socketCount, unsigned int initiationInterval=0)
 
virtual ~BusResource ()
 
virtual bool isInUse (const int cycle) const override
 
virtual bool isAvailable (const int cycle) const override
 
virtual bool isAvailable (const int cycle, const SchedulingResource &inputPSocket, const SchedulingResource &outputPSocket) const
 
virtual bool canAssign (const int cycle, const MoveNode &node) const override
 
virtual void assign (const int cycle, MoveNode &node) override
 
virtual void unassign (const int cycle, MoveNode &node) override
 
virtual bool canAssign (const int cycle, const MoveNode &node, const SchedulingResource &inputPSocket, const SchedulingResource &outputPSocket) const
 
virtual bool isBusResource () const override
 
virtual bool operator< (const SchedulingResource &other) const override
 
int nopSlotCount ()
 
void clear () override
 
- Public Member Functions inherited from SchedulingResource
virtual ~SchedulingResource ()
 
 SchedulingResource (const std::string &name, const unsigned int ii=0)
 
virtual int relatedResourceGroupCount () const
 
virtual int dependentResourceGroupCount () const
 
int relatedResourceCount (const int group) const
 
int dependentResourceCount (const int group) const
 
virtual void addToRelatedGroup (const int group, SchedulingResource &resource)
 
virtual void addToDependentGroup (const int group, SchedulingResource &resource)
 
virtual SchedulingResourcerelatedResource (const int group, const int index) const
 
virtual SchedulingResourcedependentResource (const int group, const int index) const
 
virtual bool hasRelatedResource (const SchedulingResource &sResource) const
 
virtual bool hasDependentResource (const SchedulingResource &sResource) const
 
virtual const std::string & name () const
 
virtual int useCount () const
 
virtual void increaseUseCount ()
 
virtual void decreaseUseCount ()
 
virtual bool isInputPSocketResource () const
 
virtual bool isOutputPSocketResource () const
 
virtual bool isShortImmPSocketResource () const
 
virtual bool isInputFUResource () const
 
virtual bool isOutputFUResource () const
 
virtual bool isExecutionPipelineResource () const
 
virtual bool isSegmentResource () const
 
virtual bool isIUResource () const
 
virtual bool isITemplateResource () const
 
int instructionIndex (int cycle) const
 
void setInitiationInterval (unsigned int ii)
 
int initiationInterval () const
 
virtual void setMaxCycle (unsigned int)
 

Protected Member Functions

virtual bool validateDependentGroups () override
 
virtual bool validateRelatedGroups () override
 

Private Types

typedef std::map< int, int > ResourceRecordType
 

Private Member Functions

 BusResource (const BusResource &)
 
BusResourceoperator= (const BusResource &)
 

Private Attributes

int busWidth_
 
int limmSlotCount_
 
int nopSlotCount_
 
int guardCount_
 
int immSize_
 
int socketCount_
 
ResourceRecordType resourceRecord_
 

Additional Inherited Members

- Protected Attributes inherited from SchedulingResource
int initiationInterval_
 

Detailed Description

An interface for scheduling resources of Resource Model The derived class BusResource

Definition at line 46 of file BusResource.hh.

Member Typedef Documentation

◆ ResourceRecordType

typedef std::map<int, int> BusResource::ResourceRecordType
private

Definition at line 97 of file BusResource.hh.

Constructor & Destructor Documentation

◆ BusResource() [1/2]

BusResource::BusResource ( const std::string &  name,
int  width,
int  limmSlotCount,
int  nopSlotCount,
int  guardCount,
int  immSize,
int  socketCount,
unsigned int  initiationInterval = 0 
)

Constructor Creates new resource with defined name

Parameters
nameName of resource
widthshort immediate width of the bus
limmSlotCounthow many itemplates use this bus in limm field

Definition at line 54 of file BusResource.cc.

57 :
60 guardCount_(guardCount),
61 immSize_(immSize), socketCount_(socketCount) {
62}
int nopSlotCount()
virtual const std::string & name() const

◆ ~BusResource()

BusResource::~BusResource ( )
virtual

Empty destructor

Definition at line 67 of file BusResource.cc.

67{}

◆ BusResource() [2/2]

BusResource::BusResource ( const BusResource )
private

Member Function Documentation

◆ assign()

void BusResource::assign ( const int  cycle,
MoveNode node 
)
overridevirtual

Assign resource to given node for given cycle without testing Input or Output PSocket, assign ALL segments of bus.

Parameters
cycleCycle to assign
nodeMoveNode assigned
Exceptions
Incase assignment can not be done

Implements SchedulingResource.

Definition at line 124 of file BusResource.cc.

125{
126 if (canAssign(cycle, node)) {
129 return;
130 }
131}
virtual bool canAssign(const int cycle, const MoveNode &node) const override
ResourceRecordType resourceRecord_
virtual void increaseUseCount()
int instructionIndex(int cycle) const

References canAssign(), SchedulingResource::increaseUseCount(), SchedulingResource::instructionIndex(), and resourceRecord_.

Referenced by BusBroker::assign().

Here is the call graph for this function:

◆ canAssign() [1/2]

bool BusResource::canAssign ( const int  cycle,
const MoveNode node 
) const
overridevirtual

Return true if resource can be assigned for given node in given cycle

Parameters
cycleCycle to test
nodeMoveNode to test
Returns
true if node can be assigned to cycle

Implements SchedulingResource.

Definition at line 164 of file BusResource.cc.

164 {
165 return isAvailable(cycle);
166}
virtual bool isAvailable(const int cycle) const override

References isAvailable().

Referenced by BusBroker::allAvailableResources(), assign(), and BusBroker::isAvailable().

Here is the call graph for this function:

◆ canAssign() [2/2]

bool BusResource::canAssign ( const int  cycle,
const MoveNode node,
const SchedulingResource inputPSocket,
const SchedulingResource outputPSocket 
) const
virtual

Return true if resource can be assigned for given node in given cycle

Parameters
cycleCycle to test
nodeMoveNode to test
inputPSocketPSocket connected to source of move
outputPSocketPSocket connected to destination of move
Returns
true if node can be assigned to cycle

Definition at line 177 of file BusResource.cc.

181 {
182
183 if (!isAvailable(cycle, inputPSocket, outputPSocket)) {
184 return false;
185 }
186
187 int defBits = node.isSourceConstant()?
188 busWidth_ : node.move().source().port().width();
189 // TODO: Check if source is from an operation result that defines less bits.
190 int useBits = node.move().destination().port().width();
191 if (useBits > busWidth_ && node.destinationOperationCount()) {
192 // Writing undefined bits *1 to upper bits of the destination port.
193 // Check if none of the destinations use those bits.
194 // *1: DefaultICDecoderPlugin zero extends when writing to port from
195 // narrower bus, but this is not documented semantic?
196 int maxOpdWidth = 0;
197 for (size_t i = 0; i < node.destinationOperationCount(); i++) {
198 const auto& op = node.destinationOperation(i).operation();
199 int opdIdx = node.move().destination().operationIndex();
200 int opdWidth = op.operand(opdIdx).width();
201 maxOpdWidth = std::max(maxOpdWidth, opdWidth);
202 }
203 assert(maxOpdWidth > 0);
204 useBits = std::min(useBits, maxOpdWidth);
205 }
206 // Define bit width of the value transportation as in below statement to
207 // allow cases such as:
208 // - Move from ALU compare to boolean reg.
209 // - Move from boolean reg to LSU store.
210 int transportWidth = std::min(defBits, useBits);
211 if (transportWidth > busWidth_) {
212 return false;
213 }
214
215 if (!inputPSocket.isOutputPSocketResource() ||
216 !hasRelatedResource(inputPSocket)) {
217 return false;
218 }
219 if (!outputPSocket.isInputPSocketResource() ||
220 !hasRelatedResource(outputPSocket)) {
221 return false;
222 }
223
224 return true;
225}
#define assert(condition)
unsigned int destinationOperationCount() const
TTAProgram::Move & move()
bool isSourceConstant() const
Definition MoveNode.cc:238
ProgramOperation & destinationOperation(unsigned int index=0) const
const Operation & operation() const
virtual bool isInputPSocketResource() const
virtual bool hasRelatedResource(const SchedulingResource &sResource) const
virtual bool isOutputPSocketResource() const
virtual int width() const =0
Terminal & source() const
Definition Move.cc:302
Terminal & destination() const
Definition Move.cc:323
virtual int operationIndex() const
Definition Terminal.cc:364
virtual const TTAMachine::Port & port() const
Definition Terminal.cc:378

References assert, busWidth_, TTAProgram::Move::destination(), MoveNode::destinationOperation(), MoveNode::destinationOperationCount(), SchedulingResource::hasRelatedResource(), isAvailable(), SchedulingResource::isInputPSocketResource(), SchedulingResource::isOutputPSocketResource(), MoveNode::isSourceConstant(), MoveNode::move(), ProgramOperation::operation(), TTAProgram::Terminal::operationIndex(), TTAProgram::Terminal::port(), TTAProgram::Move::source(), and TTAMachine::Port::width().

Here is the call graph for this function:

◆ clear()

void BusResource::clear ( )
overridevirtual

Clears bookkeeping of the scheduling resource.

After this call the state of the resource should be identical to a newly-created and initialized resource.

Reimplemented from SchedulingResource.

Definition at line 334 of file BusResource.cc.

334 {
336 resourceRecord_.clear();
337}

References SchedulingResource::clear(), and resourceRecord_.

Here is the call graph for this function:

◆ isAvailable() [1/2]

bool BusResource::isAvailable ( const int  cycle) const
overridevirtual

Test if resource BusResource is available

Parameters
cycleCycle which to test
Returns
False if all the segments of bus are InUse

Implements SchedulingResource.

Definition at line 90 of file BusResource.cc.

90 {
91 return !isInUse(cycle);
92}
virtual bool isInUse(const int cycle) const override

References isInUse().

Referenced by canAssign(), canAssign(), and isAvailable().

Here is the call graph for this function:

◆ isAvailable() [2/2]

bool BusResource::isAvailable ( const int  cycle,
const SchedulingResource inputPSocket,
const SchedulingResource outputPSocket 
) const
virtual

Test if resource BusResource is available.

Parameters
cycleCycle which to test
Returns
False if all the segments of bus are InUse

Definition at line 101 of file BusResource.cc.

104 {
105
106 if (!(hasRelatedResource(inputPSocket) &&
107 hasRelatedResource(outputPSocket))) {
108 // BusBroker does not need to test if sockets
109 // are connected to the bus...
110 return false;
111 }
112
113 return isAvailable(cycle);
114}

References SchedulingResource::hasRelatedResource(), and isAvailable().

Here is the call graph for this function:

◆ isBusResource()

bool BusResource::isBusResource ( ) const
overridevirtual

Return allways true

Returns
true

Reimplemented from SchedulingResource.

Definition at line 232 of file BusResource.cc.

232 {
233 return true;
234}

◆ isInUse()

bool BusResource::isInUse ( const int  cycle) const
overridevirtual

Test if resource BusResource is used in given cycle

Parameters
cycleCycle which to test
Returns
True if any of segments of bus isInUse in given cycle

Implements SchedulingResource.

Definition at line 75 of file BusResource.cc.

75 {
76 ResourceRecordType::const_iterator i =
78 if (i != resourceRecord_.end() && i->second != 0) {
79 return true;
80 }
81 return false;
82}

References SchedulingResource::instructionIndex(), and resourceRecord_.

Referenced by isAvailable(), BusBroker::isInUse(), and unassign().

Here is the call graph for this function:

◆ nopSlotCount()

int BusResource::nopSlotCount ( )
inline

Definition at line 72 of file BusResource.hh.

72{ return nopSlotCount_; }

References nopSlotCount_.

◆ operator<()

bool BusResource::operator< ( const SchedulingResource other) const
overridevirtual

Comparison operator.

Favours busses which have less limm slots associated to then in instruction templates, ie. busses which do not get into way of limm writes.

Reimplemented from SchedulingResource.

Definition at line 274 of file BusResource.cc.

275 {
276 const BusResource *busr = static_cast<const BusResource*>(&other);
277
278 // favour buses with less nop slots
279 if (nopSlotCount_ < busr->nopSlotCount_) {
280 return true;
281 }
282 if (nopSlotCount_ > busr->nopSlotCount_) {
283 return false;
284 }
285
286 if (busr == NULL) {
287 return false;
288 }
289
290 // then try to use busses without guards, if possible.
291 if (guardCount_ < busr->guardCount_) {
292 return true;
293 }
294 if (guardCount_ > busr->guardCount_) {
295 return false;
296 }
297
298 // then favour busses with less sockets.
299 if (socketCount_ < busr->socketCount_) {
300 return true;
301 }
302 if (socketCount_ > busr->socketCount_) {
303 return false;
304 }
305
306 // first priority are limm slots.
307 if (limmSlotCount_ < busr->limmSlotCount_) {
308 return true;
309 }
310 if (limmSlotCount_ > busr->limmSlotCount_) {
311 return false;
312 }
313
314 // then favour busses with smallest immediate.
315 if (immSize_ < busr->immSize_) {
316 return true;
317 }
318 if (immSize_ > busr->immSize_) {
319 return false;
320 }
321
322 // then use the default use count, name comparison,
323 // but in opposite direction, facouring already used
324 return other.SchedulingResource::operator<(*this);
325}

References guardCount_, immSize_, limmSlotCount_, nopSlotCount_, and socketCount_.

◆ operator=()

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

◆ unassign()

void BusResource::unassign ( const int  cycle,
MoveNode node 
)
overridevirtual

Unassign resource from given node for given cycle without testing Input or Output PSocket, unassign all segments of bus

Parameters
cycleCycle to remove assignment from
nodeMoveNode to remove assignment from
Exceptions
Incase bus was not assigned

Implements SchedulingResource.

Definition at line 142 of file BusResource.cc.

142 {
143
144 if (isInUse(cycle)) {
146 return;
147 } else{
148 std::string msg = "Bus ";
149 msg += name();
150 msg += " can not be unassigned in cycle ";
151 msg += Conversion::toString(cycle);
152 msg += ", it was not in use!";
153 throw ModuleRunTimeError(__FILE__, __LINE__,__func__, msg);
154 }
155}
#define __func__
static std::string toString(const T &source)

References __func__, SchedulingResource::instructionIndex(), isInUse(), SchedulingResource::name(), resourceRecord_, and Conversion::toString().

Referenced by BusBroker::unassign().

Here is the call graph for this function:

◆ validateDependentGroups()

bool BusResource::validateDependentGroups ( )
overrideprotectedvirtual

Tests if all referred resources in dependent groups are of proper types

Returns
true If all resources in dependent groups are Segment resources

Reimplemented from SchedulingResource.

Definition at line 243 of file BusResource.cc.

243 {
244 return true;
245}

◆ validateRelatedGroups()

bool BusResource::validateRelatedGroups ( )
overrideprotectedvirtual

Tests if all resources in related resource groups are of proper types

Returns
true If all resources in related resource groups are PSockets

Reimplemented from SchedulingResource.

Definition at line 254 of file BusResource.cc.

254 {
255 for (int i = 0; i < relatedResourceGroupCount(); i++) {
256 for (int j = 0, count = relatedResourceCount(i);
257 j < count;
258 j++) {
261 return false;
262 }
263 }
264 return true;
265}
virtual SchedulingResource & relatedResource(const int group, const int index) const
int relatedResourceCount(const int group) const
virtual int relatedResourceGroupCount() const

References SchedulingResource::isInputPSocketResource(), SchedulingResource::isOutputPSocketResource(), SchedulingResource::relatedResource(), SchedulingResource::relatedResourceCount(), and SchedulingResource::relatedResourceGroupCount().

Here is the call graph for this function:

Member Data Documentation

◆ busWidth_

int BusResource::busWidth_
private

Definition at line 84 of file BusResource.hh.

Referenced by canAssign().

◆ guardCount_

int BusResource::guardCount_
private

Definition at line 90 of file BusResource.hh.

Referenced by operator<().

◆ immSize_

int BusResource::immSize_
private

Definition at line 92 of file BusResource.hh.

Referenced by operator<().

◆ limmSlotCount_

int BusResource::limmSlotCount_
private

Definition at line 86 of file BusResource.hh.

Referenced by operator<().

◆ nopSlotCount_

int BusResource::nopSlotCount_
private

Definition at line 88 of file BusResource.hh.

Referenced by nopSlotCount(), and operator<().

◆ resourceRecord_

ResourceRecordType BusResource::resourceRecord_
private

Definition at line 98 of file BusResource.hh.

Referenced by assign(), clear(), isInUse(), and unassign().

◆ socketCount_

int BusResource::socketCount_
private

Definition at line 94 of file BusResource.hh.

Referenced by operator<().


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