OpenASIP  2.0
RFArchitecture.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 RFArchitecture.cc
26  *
27  * Implementation of RFArchitecture class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <string>
34 #include "RFArchitecture.hh"
35 #include "BaseRegisterFile.hh"
36 #include "RegisterFile.hh"
37 #include "ImmediateUnit.hh"
38 #include "Socket.hh"
39 #include "Guard.hh"
40 
41 using std::string;
42 
43 namespace HDB {
44 
45 /**
46  * The constructor.
47  *
48  * Creates an architecture that has parameterized width and size. To set
49  * fixed size or width, use setWidth or setSize method.
50  *
51  * @param readPorts The number of read ports.
52  * @param writePorts The number of write ports.
53  * @param bidirPorts The number of bidirectional ports.
54  * @param maxReads The maximum number of simultaneous reads.
55  * @param maxWrites The maximum number of simultaneous writes.
56  * @param latency Latency of the register file.
57  * @param guardSupport Tells whether the RF architecture supports guards.
58  * @param guardLatency Latency between writing a register and updating the
59  * value of guard port.
60  * @param zeroRegister Tells whether RF architecture has a zero register.
61  * @exception OutOfRange If some of the arguments is out of range.
62  */
64  int readPorts, int writePorts, int bidirPorts, int maxReads,
65  int maxWrites, int latency, bool guardSupport, int guardLatency,
66  bool zeroRegister)
67  : readPorts_(readPorts),
68  writePorts_(writePorts),
69  bidirPorts_(bidirPorts),
70  maxReads_(maxReads),
71  maxWrites_(maxWrites),
72  latency_(latency),
73  guardSupport_(guardSupport),
74  width_(0),
75  size_(0),
76  guardLatency_(guardLatency),
77  zeroRegister_(zeroRegister) {
78  if (readPorts < 0 || writePorts < 0 || bidirPorts < 0 || maxReads < 0 ||
79  maxWrites < 0 || latency < 0 || guardLatency < 0) {
80  const string procName = "RFArchitecture::RFArchitecture";
81  throw OutOfRange(__FILE__, __LINE__, procName);
82  }
83 }
84 
85 /**
86  * Builds RFArchitecture from RegisterFile*.
87  *
88  * @param rf RegisterFile*.
89  */
91 
92  int readPorts = 0;
93  int writePorts = 0;
94  int bidirPorts = 0;
95  for (int i = 0; i < rf->portCount(); i++) {
96  TTAMachine::Socket* input = rf->port(i)->inputSocket();
97  TTAMachine::Socket* output = rf->port(i)->outputSocket();
98  if (input != NULL && output != NULL) {
99  bidirPorts++;
100  } else if (input != NULL) {
101  readPorts++;
102  } else if (output != NULL) {
103  writePorts++;
104  }
105  }
106 
107  bool guardSupport = false;
108  if (rf->isRegistered()) {
110  rf->machine()->busNavigator();
111  for (int i = 0; i < navigator.count(); i++) {
112  TTAMachine::Bus* bus = navigator.item(i);
113  for (int n = 0; n < bus->guardCount(); n++) {
114  TTAMachine::Guard* guard = bus->guard(n);
115  TTAMachine::RegisterGuard* registerGuard =
116  dynamic_cast<TTAMachine::RegisterGuard*>(guard);
117  if (registerGuard != NULL) {
118  if (registerGuard->registerFile() == rf) {
119  guardSupport = true;
120  }
121  }
122  }
123  }
124  }
125  readPorts_ = readPorts;
126  writePorts_ = writePorts;
127  bidirPorts_ = bidirPorts;
128  maxReads_ = rf->maxReads();
129  maxWrites_ = rf->maxWrites();
130  latency_ = 1;
131  guardSupport_ = guardSupport;
132  width_ = rf->width();
133  size_ = rf->numberOfRegisters();
134  guardLatency_ = rf->guardLatency();
135 }
136 
137 /**
138  * Builds RFArchitecture from ImmediateUnit*.
139  *
140  * @param imm ImmediateUnit*.
141  */
143 
144  int readPorts = 0;
145  int writePorts = 0;
146  int bidirPorts = 0;
147  for (int i = 0; i < imm->portCount(); i++) {
148  TTAMachine::Socket* input = imm->port(i)->inputSocket();
149  TTAMachine::Socket* output = imm->port(i)->outputSocket();
150  if (input != NULL && output != NULL) {
151  bidirPorts++;
152  } else if (input != NULL) {
153  readPorts++;
154  } else if (output != NULL) {
155  writePorts++;
156  }
157  }
158 
159  // immediate unit has no MaxReadWrite, no MaxReads and no guard support
160  readPorts_ = readPorts;
161  writePorts_ = writePorts;
162  bidirPorts_ = bidirPorts;
163  maxReads_ = 0;
164  maxWrites_ = 0;
165  latency_ = 1;
166  guardSupport_ = false;
167  width_ = imm->width();
168  size_ = imm->numberOfRegisters();
169  guardLatency_ = 0;
170 }
171 
172 /**
173  * Builds RFArchitecture from BaseRegisterFile*.
174  *
175  * @param baseRF BaseRegisterfile*.
176  */
178 
179  const TTAMachine::ImmediateUnit* imm =
180  dynamic_cast<const TTAMachine::ImmediateUnit*>(baseRF);
181  const TTAMachine::RegisterFile* rf =
182  dynamic_cast<const TTAMachine::RegisterFile*>(baseRF);
183  if (imm != NULL) {
184  int readPorts = 0;
185  int writePorts = 0;
186  int bidirPorts = 0;
187  for (int i = 0; i < imm->portCount(); i++) {
188  TTAMachine::Socket* input = imm->port(i)->inputSocket();
189  TTAMachine::Socket* output = imm->port(i)->outputSocket();
190  if (input != NULL && output != NULL) {
191  bidirPorts++;
192  } else if (input != NULL) {
193  readPorts++;
194  } else if (output != NULL) {
195  writePorts++;
196  }
197  }
198 
199  // immediate unit has no MaxReadWrite, no MaxReads and no guard support
200  readPorts_ = readPorts;
201  writePorts_ = writePorts;
202  bidirPorts_ = bidirPorts;
203  maxReads_ = 0;
204  maxWrites_ = 0;
205  latency_ = 1;
206  guardSupport_ = false;
207  width_ = imm->width();
208  size_ = imm->numberOfRegisters();
209  guardLatency_ = 0;
210  }
211  if (rf != NULL) {
212  int readPorts = 0;
213  int writePorts = 0;
214  int bidirPorts = 0;
215  for (int i = 0; i < rf->portCount(); i++) {
216  TTAMachine::Socket* input = rf->port(i)->inputSocket();
217  TTAMachine::Socket* output = rf->port(i)->outputSocket();
218  if (input != NULL && output != NULL) {
219  bidirPorts++;
220  } else if (input != NULL) {
221  readPorts++;
222  } else if (output != NULL) {
223  writePorts++;
224  }
225  }
226 
227  bool guardSupport = false;
228  if (rf->isRegistered()) {
230  rf->machine()->busNavigator();
231  for (int i = 0; i < navigator.count(); i++) {
232  TTAMachine::Bus* bus = navigator.item(i);
233  for (int n = 0; n < bus->guardCount(); n++) {
234  TTAMachine::Guard* guard = bus->guard(n);
235  TTAMachine::RegisterGuard* registerGuard =
236  dynamic_cast<TTAMachine::RegisterGuard*>(guard);
237  if (registerGuard != NULL) {
238  if (registerGuard->registerFile() == rf) {
239  guardSupport = true;
240  }
241  }
242  }
243  }
244  }
245  readPorts_ = readPorts;
246  writePorts_ = writePorts;
247  bidirPorts_ = bidirPorts;
248  maxReads_ = rf->maxReads();
249  maxWrites_ = rf->maxWrites();
250  latency_ = 1;
251  guardSupport_ = guardSupport;
252  width_ = rf->width();
253  size_ = rf->numberOfRegisters();
254  guardLatency_ = rf->guardLatency();
255  }
256 }
257 
258 /**
259  * The destructor.
260  */
262 }
263 
264 
265 /**
266  * Tells whether the RF has parameterized width.
267  *
268  * @return True if the RF has parameterized width, otherwise false.
269  */
270 bool
272  return width_ == 0;
273 }
274 
275 
276 /**
277  * Tells whether the RF has parameterized size.
278  *
279  * @return True if the RF has parameterized size, otherwise false.
280  */
281 bool
283  return size_ == 0;
284 }
285 
286 
287 /**
288  * Sets the width of the register file.
289  *
290  * @param width The new width.
291  * @exception OutOfRange If the width is less than 1.
292  */
293 void
295  if (width < 1) {
296  const string procName = "RFArchitecture::setWidth";
297  throw OutOfRange(__FILE__, __LINE__, procName);
298  } else {
299  width_ = width;
300  }
301 }
302 
303 /**
304  * Sets the size of the register file.
305  *
306  * @param size The new size.
307  * @exception OutOfRange If the size is less than 1.
308  */
309 void
311  if (size < 1) {
312  const string procName = "RFArchitecture::setSize";
313  throw OutOfRange(__FILE__, __LINE__, procName);
314  } else {
315  size_ = size;
316  }
317 }
318 
319 /**
320  * Returns the size of the register file.
321  *
322  * @return The size of the register file.
323  * @exception NotAvailable If the size is parameterized.
324  */
325 int
327  if (hasParameterizedSize()) {
328  const string procName = "RFArchitecture::size";
329  throw NotAvailable(__FILE__, __LINE__, procName);
330  } else {
331  return size_;
332  }
333 }
334 
335 /**
336  * Returns the width of the register file.
337  *
338  * @return The width of the register file.
339  * @exception NotAvailable If the width of the register file is
340  * parameterized.
341  */
342 int
344  if (hasParameterizedWidth()) {
345  const string procName = "RFArchitecture::width";
346  throw NotAvailable(__FILE__, __LINE__, procName);
347  } else {
348  return width_;
349  }
350 }
351 
352 /**
353  * Sets the number of read ports.
354  *
355  * @param portCount The number of read ports.
356  * @exception OutOfRange If the given port count is negative.
357  */
358 void
360  if (portCount < 0) {
361  throw OutOfRange(__FILE__, __LINE__, __func__);
362  }
363  readPorts_ = portCount;
364 }
365 
366 /**
367  * Returns the number of read ports.
368  *
369  * @return The number of read ports.
370  */
371 int
373  return readPorts_;
374 }
375 
376 
377 /**
378  * Sets the number of write ports.
379  *
380  * @param portCount The number of write ports.
381  * @exception OutOfRange If the given port count is smaller than 1.
382  */
383 void
385  if (portCount < 0) {
386  throw OutOfRange(__FILE__, __LINE__, __func__);
387  }
388  writePorts_ = portCount;
389 }
390 
391 /**
392  * Returns the number of write ports.
393  *
394  * @return The number of write ports.
395  */
396 int
398  return writePorts_;
399 }
400 
401 
402 /**
403  * Sets the number of bidirectional ports.
404  *
405  * @param portCount The number of bidirectional ports.
406  * @exception OutOfRange If the given port count is negative.
407  */
408 void
410  if (portCount < 0) {
411  throw OutOfRange(__FILE__, __LINE__, __func__);
412  }
413  bidirPorts_ = portCount;
414 }
415 
416 /**
417  * Returns the number of bidirectional ports.
418  *
419  * @return The number of bidirectional ports.
420  */
421 int
423  return bidirPorts_;
424 }
425 
426 
427 /**
428  * Sets the maximum number of simultaneous reads.
429  *
430  * @param maxReads The new value.
431  * @exception OutOfRange If the given value is negative.
432  */
433 void
435  if (maxReads < 0) {
436  throw OutOfRange(__FILE__, __LINE__, __func__);
437  }
439 }
440 
441 /**
442  * Returns the maximum number of simultaneous reads.
443  *
444  * @return The maximum number of simultaneous reads.
445  */
446 int
448  return maxReads_;
449 }
450 
451 
452 /**
453  * Sets the maximum number of simultaneous writes.
454  *
455  * @param maxWrites The new value.
456  * @exception OutOfRange If the given value is negative.
457  */
458 void
460  if (maxWrites < 0) {
461  throw OutOfRange(__FILE__, __LINE__, __func__);
462  }
464 }
465 
466 /**
467  * Returns the maximum number of simultaneous writes.
468  *
469  * @return The maximum number of simultaneous writes.
470  */
471 int
473  return maxWrites_;
474 }
475 
476 
477 /**
478  * Sets the latency of the register file.
479  *
480  * @param latency The new latency.
481  * @exception OutOfRange If the given latency is smaller than 1.
482  */
483 void
485  if (latency < 1) {
486  throw OutOfRange(__FILE__, __LINE__, __func__);
487  }
488  latency_ = latency;
489 }
490 
491 /**
492  * Returns the latency of the register file.
493  *
494  * @return The latency of the register file.
495  */
496 int
498  return latency_;
499 }
500 
501 
502 /**
503  * Sets the guard support of the register file.
504  *
505  * @param supported True if supported, otherwise false.
506  */
507 void
509  guardSupport_ = supported;
510 }
511 
512 
513 /**
514  * Tells whether the RF supports guards.
515  *
516  * @return True if the RF supports guards, otherwise false.
517  */
518 bool
520  return guardSupport_;
521 }
522 
523 /**
524  * Sets the zero register flag of the register file
525  *
526  * @param zeroRegister True if has a zero register, otherwise false
527  */
528 
529 void
532 }
533 
534 /**
535  * Tells whether the RF has a zero register
536  *
537  * @return True if RF has a zero register
538  */
539 
540 bool
542  return zeroRegister_;
543 }
544 
545 /**
546  * Returns the guard latency.
547  *
548  * @return The guard latency.
549  */
550 int
552  return guardLatency_;
553 }
554 
555 
556 /**
557  * Checks whether the given RF has a mathing architecture with the given RF
558  * architecture instance.
559  *
560  * @param rightHand Right hand operand.
561  * @return True if the architectures match, otherwise false.
562  */
563 bool
565 
566  if (rightHand.readPortCount() != readPortCount()) {
567  return false;
568  }
569  if (rightHand.writePortCount() != writePortCount()) {
570  return false;
571  }
572  if (rightHand.bidirPortCount() != bidirPortCount()) {
573  return false;
574  }
575  if (rightHand.maxReads() != maxReads()) {
576  return false;
577  }
578  if (rightHand.maxWrites() != maxWrites()) {
579  return false;
580  }
581  if (rightHand.latency() != latency()) {
582  return false;
583  }
584  if (rightHand.hasGuardSupport() != hasGuardSupport()) {
585  return false;
586  }
587  if (rightHand.guardLatency() != guardLatency()) {
588  return false;
589  }
590  if (rightHand.hasParameterizedSize() != hasParameterizedSize()) {
591  return false;
592  }
593  if (!hasParameterizedSize()) {
594  if (rightHand.size() != size()) {
595  return false;
596  }
597  }
598  if (rightHand.hasParameterizedWidth() != hasParameterizedWidth()) {
599  return false;
600  }
601  if (!hasParameterizedWidth()) {
602  if (rightHand.width() != width()) {
603  return false;
604  }
605  }
606  return true;
607 }
608 }
TTAMachine::Guard
Definition: Guard.hh:55
BaseRegisterFile.hh
HDB::RFArchitecture::bidirPorts_
int bidirPorts_
Number of bidir ports.
Definition: RFArchitecture.hh:104
HDB::RFArchitecture::setReadPortCount
void setReadPortCount(int portCount)
Definition: RFArchitecture.cc:359
HDB::RFArchitecture::maxReads
int maxReads() const
Definition: RFArchitecture.cc:447
TTAMachine::Port::inputSocket
virtual Socket * inputSocket() const
Definition: Port.cc:261
HDB::RFArchitecture::RFArchitecture
RFArchitecture(int readPorts, int writePorts, int bidirPorts, int maxReads, int maxWrites, int latency, bool guardSupport, int guardLatency=0, bool zeroRegister=false)
Definition: RFArchitecture.cc:63
HDB
Definition: CostDatabase.hh:49
TTAMachine::Component::isRegistered
virtual bool isRegistered() const
Definition: MachinePart.cc:177
HDB::RFArchitecture::setLatency
void setLatency(int latency)
Definition: RFArchitecture.cc:484
HDB::RFArchitecture::latency
int latency() const
Definition: RFArchitecture.cc:497
HDB::RFArchitecture::readPorts_
int readPorts_
Number of read ports.
Definition: RFArchitecture.hh:100
HDB::RFArchitecture::~RFArchitecture
virtual ~RFArchitecture()
Definition: RFArchitecture.cc:261
OutOfRange
Definition: Exception.hh:320
HDB::RFArchitecture::size_
int size_
Size of the register file.
Definition: RFArchitecture.hh:117
HDB::RFArchitecture::zeroRegister
bool zeroRegister() const
Definition: RFArchitecture.cc:541
TTAMachine::Bus
Definition: Bus.hh:53
HDB::RFArchitecture::setMaxWrites
void setMaxWrites(int maxWrites)
Definition: RFArchitecture.cc:459
ImmediateUnit.hh
HDB::RFArchitecture::setZeroRegister
void setZeroRegister(bool zeroRegister)
Definition: RFArchitecture.cc:530
HDB::RFArchitecture::hasParameterizedSize
bool hasParameterizedSize() const
Definition: RFArchitecture.cc:282
TTAMachine::Machine::Navigator::count
int count() const
HDB::RFArchitecture::setBidirPortCount
void setBidirPortCount(int portCount)
Definition: RFArchitecture.cc:409
HDB::RFArchitecture::width_
int width_
Width of the register file.
Definition: RFArchitecture.hh:115
HDB::RFArchitecture::guardSupport_
bool guardSupport_
The guard support.
Definition: RFArchitecture.hh:113
TTAMachine::RegisterFile::maxWrites
virtual int maxWrites() const
Definition: RegisterFile.cc:135
Socket.hh
NotAvailable
Definition: Exception.hh:728
HDB::RFArchitecture::width
int width() const
Definition: RFArchitecture.cc:343
TTAMachine::BaseRegisterFile::numberOfRegisters
virtual int numberOfRegisters() const
TTAMachine::BaseRegisterFile
Definition: BaseRegisterFile.hh:48
HDB::RFArchitecture::writePorts_
int writePorts_
Number of write ports.
Definition: RFArchitecture.hh:102
TTAMachine::RegisterFile::maxReads
virtual int maxReads() const
Definition: RegisterFile.cc:123
HDB::RFArchitecture::maxWrites
int maxWrites() const
Definition: RFArchitecture.cc:472
TTAMachine::RegisterGuard
Definition: Guard.hh:137
__func__
#define __func__
Definition: Application.hh:67
TTAMachine::Socket
Definition: Socket.hh:53
Guard.hh
RFArchitecture.hh
HDB::RFArchitecture::hasParameterizedWidth
bool hasParameterizedWidth() const
Definition: RFArchitecture.cc:271
HDB::RFArchitecture::maxWrites_
int maxWrites_
Maximum number of ports that can read a register in the same cycle in which another port writes the s...
Definition: RFArchitecture.hh:109
HDB::RFArchitecture::setWidth
void setWidth(int width)
Definition: RFArchitecture.cc:294
HDB::RFArchitecture::guardLatency
int guardLatency() const
Definition: RFArchitecture.cc:551
HDB::RFArchitecture::guardLatency_
int guardLatency_
Guard latency.
Definition: RFArchitecture.hh:119
TTAMachine::Bus::guardCount
int guardCount() const
Definition: Bus.cc:441
TTAMachine::Bus::guard
Guard * guard(int index) const
Definition: Bus.cc:456
TTAMachine::Unit::portCount
virtual int portCount() const
Definition: Unit.cc:135
HDB::RFArchitecture::hasGuardSupport
bool hasGuardSupport() const
Definition: RFArchitecture.cc:519
HDB::RFArchitecture
Definition: RFArchitecture.hh:50
TTAMachine::BaseRegisterFile::port
virtual RFPort * port(const std::string &name) const
Definition: BaseRegisterFile.cc:129
HDB::RFArchitecture::maxReads_
int maxReads_
Maximum number of simultaneous reads.
Definition: RFArchitecture.hh:106
TTAMachine::Component::machine
virtual Machine * machine() const
RegisterFile.hh
HDB::RFArchitecture::latency_
int latency_
The latency.
Definition: RFArchitecture.hh:111
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
HDB::RFArchitecture::readPortCount
int readPortCount() const
Definition: RFArchitecture.cc:372
TTAMachine::Port::outputSocket
virtual Socket * outputSocket() const
Definition: Port.cc:281
HDB::RFArchitecture::zeroRegister_
bool zeroRegister_
Zero register.
Definition: RFArchitecture.hh:121
HDB::RFArchitecture::size
int size() const
Definition: RFArchitecture.cc:326
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
TTAMachine::RegisterFile::guardLatency
virtual int guardLatency() const
Definition: RegisterFile.cc:333
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
HDB::RFArchitecture::operator==
bool operator==(const RFArchitecture &rightHand) const
Definition: RFArchitecture.cc:564
HDB::RFArchitecture::bidirPortCount
int bidirPortCount() const
Definition: RFArchitecture.cc:422
TTAMachine::BaseRegisterFile::width
virtual int width() const
HDB::RFArchitecture::setMaxReads
void setMaxReads(int maxReads)
Definition: RFArchitecture.cc:434
TTAMachine::RegisterGuard::registerFile
const RegisterFile * registerFile() const
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
HDB::RFArchitecture::setSize
void setSize(int size)
Definition: RFArchitecture.cc:310
HDB::RFArchitecture::writePortCount
int writePortCount() const
Definition: RFArchitecture.cc:397
HDB::RFArchitecture::setGuardSupport
void setGuardSupport(bool supported)
Definition: RFArchitecture.cc:508
HDB::RFArchitecture::setWritePortCount
void setWritePortCount(int portCount)
Definition: RFArchitecture.cc:384
TTAMachine::ImmediateUnit
Definition: ImmediateUnit.hh:50