OpenASIP 2.2
Loading...
Searching...
No Matches
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
41using std::string;
42
43namespace 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();
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();
255 }
256}
257
258/**
259 * The destructor.
260 */
263
264
265/**
266 * Tells whether the RF has parameterized width.
267 *
268 * @return True if the RF has parameterized width, otherwise false.
269 */
270bool
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 */
281bool
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 */
293void
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 */
309void
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 */
325int
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 */
342int
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 */
358void
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 */
371int
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 */
383void
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 */
396int
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 */
408void
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 */
421int
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 */
433void
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 */
446int
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 */
458void
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 */
471int
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 */
483void
485 if (latency < 1) {
486 throw OutOfRange(__FILE__, __LINE__, __func__);
487 }
489}
490
491/**
492 * Returns the latency of the register file.
493 *
494 * @return The latency of the register file.
495 */
496int
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 */
507void
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 */
518bool
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
529void
533
534/**
535 * Tells whether the RF has a zero register
536 *
537 * @return True if RF has a zero register
538 */
539
540bool
544
545/**
546 * Returns the guard latency.
547 *
548 * @return The guard latency.
549 */
550int
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 */
563bool
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}
#define __func__
void setGuardSupport(bool supported)
void setZeroRegister(bool zeroRegister)
bool hasGuardSupport() const
int bidirPorts_
Number of bidir ports.
bool hasParameterizedWidth() const
int maxWrites_
Maximum number of ports that can read a register in the same cycle in which another port writes the s...
void setWritePortCount(int portCount)
RFArchitecture(int readPorts, int writePorts, int bidirPorts, int maxReads, int maxWrites, int latency, bool guardSupport, int guardLatency=0, bool zeroRegister=false)
int writePorts_
Number of write ports.
bool operator==(const RFArchitecture &rightHand) const
void setBidirPortCount(int portCount)
void setSize(int size)
bool zeroRegister() const
int size_
Size of the register file.
int width_
Width of the register file.
void setReadPortCount(int portCount)
void setWidth(int width)
int guardLatency_
Guard latency.
void setMaxWrites(int maxWrites)
void setMaxReads(int maxReads)
bool guardSupport_
The guard support.
void setLatency(int latency)
bool hasParameterizedSize() const
int readPorts_
Number of read ports.
bool zeroRegister_
Zero register.
int maxReads_
Maximum number of simultaneous reads.
int latency_
The latency.
virtual int numberOfRegisters() const
virtual int width() const
virtual RFPort * port(const std::string &name) const
Guard * guard(int index) const
Definition Bus.cc:456
int guardCount() const
Definition Bus.cc:441
virtual Machine * machine() const
virtual bool isRegistered() const
ComponentType * item(int index) const
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
virtual Socket * outputSocket() const
Definition Port.cc:281
virtual Socket * inputSocket() const
Definition Port.cc:261
virtual int maxReads() const
virtual int guardLatency() const
virtual int maxWrites() const
const RegisterFile * registerFile() const
virtual int portCount() const
Definition Unit.cc:135