OpenASIP 2.2
Loading...
Searching...
No Matches
LongImmediateUnitState.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 LongImmediateUnitState
26 *
27 * Definition of LongImmediateUnitState class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
31 * @note rating: red
32 */
33
34#include <string>
35
38#include "SequenceTools.hh"
39#include "Application.hh"
40#include "Exception.hh"
41
42using std::string;
43
44//////////////////////////////////////////////////////////////////////////////
45// LongImmediateUnitState
46//////////////////////////////////////////////////////////////////////////////
47
48/**
49 * Constructor.
50 *
51 * @param size Size of the unit.
52 * @param latency Latency of the unit.
53 * @param name Name of the unit.
54 * @param width The bit width of the registers in the unit.
55 * @param signExtend Whether the values written to the registers should be sign
56 * extended.
57 */
59 int size,
60 int latency,
61 const std::string& name,
62 int width,
63 bool signExtend) :
64 ClockedState(), latency_(latency), name_(name) {
65
66 for (int i = 0; i < size; i++) {
67 registers_.push_back(
68 new LongImmediateRegisterState(this, i, width, signExtend));
69 }
70 SimValue val(width);
71 values_.resize(size, val);
72}
73
74/**
75 * Destructor.
76 */
80
81/**
82 * Clears the containers.
83 */
84void
89
90/**
91 * Returns the register value of the given index.
92 *
93 * @param index Index of the register.
94 * @return Register value of the given index.
95 * @exception OutOfRange If index is out of range.
96 */
99 if (index < 0 || index > static_cast<int>(values_.size()) - 1) {
100 string msg = "Index out of range.";
101 throw OutOfRange(__FILE__, __LINE__, __func__, msg);
102 }
103 return values_[index];
104}
105
106/**
107 * Sets the register value.
108 *
109 * @param index Index of the register.
110 * @param value Value to be set.
111 * @exception OutOfRange If index is out of range.
112 */
113void
115 if (index < 0 || index > static_cast<int>(values_.size()) - 1) {
116 string msg = "Index out of range.";
117 throw OutOfRange(__FILE__, __LINE__, __func__, msg);
118 }
119
120 if (latency_ == 0) {
121 values_[index] = value;
122 } else {
123 queue_.emplace(value, index, timer_ + latency_);
124 }
125}
126
127/**
128 * End of clock cycle.
129 *
130 * Nothing is done.
131 */
132void
135
136/**
137 * Advances clock by one cycle.
138 *
139 * Register values are updated. This method is used to simulate the latency of
140 * the immediate unit state: register values are not updated immediately in
141 * case the latency is greater than zero.
142 */
143void
145 timer_++;
146 while (!queue_.empty() && queue_.front().arrival_ == timer_) {
147 values_[queue_.front().index_] = queue_.front().value_;
148 queue_.pop();
149 }
150}
151
152/**
153 * Returns the register of the given index.
154 *
155 * @param index Index of the register.
156 * @return Register of the given index.
157 * @exception OutOfRange If index is out of range.
158 */
161 if (i < 0 || i > static_cast<int>(registers_.size()) - 1) {
162 string msg = "Index out of range.";
163 throw OutOfRange(__FILE__, __LINE__, __func__, msg);
164 }
165 return *registers_[i];
166}
167
168/**
169 * Returns the count of the registers in the unit.
170 *
171 * @return The count of the immediate registers.
172 */
173int
177
178
179//////////////////////////////////////////////////////////////////////////////
180// NullLongImmediateUnitState
181//////////////////////////////////////////////////////////////////////////////
182
184
185/**
186 * Returns NullLongImmediateUnitState instance.
187 *
188 * @return NullLongImmediateUnitState instance.
189 */
192 if (instance_ == NULL) {
194 }
195 return *instance_;
196}
197
198/**
199 * Constructor.
200 */
204
205/**
206 * Destructor.
207 */
210
211/**
212 * Aborts the program with error message.
213 *
214 * @return Never returns.
215 * @exception OutOfRange Never throws.
216 */
219 Application::abortWithError("registerValue()");
220 return NullSimValue::instance();
221}
222
223/**
224 * Aborts the program with error message.
225 *
226 * @exception OutOfRange Never throws.
227 */
228void
230 Application::abortWithError("setRegisterValue()");
231}
232
233/**
234 * Aborts the program with error message.
235 */
236void
238 Application::abortWithError("endClock()");
239}
240
241/**
242 * Aborts the program with error message.
243 */
244void
246 Application::abortWithError("advanceClock()");
247}
248
249/**
250 * Aborts the program with error message.
251 *
252 * @return Never returns.
253 */
256 Application::abortWithError("immediateRegister()");
257 return *(new LongImmediateRegisterState(NULL, 0, 0, false));
258}
259
260/**
261 * Aborts the program with error message.
262 *
263 * @return Never returns.
264 */
265int
267 Application::abortWithError("immediateRegisterCount()");
268 return 0;
269}
#define __func__
find Finds info of the inner loops in the false
virtual LongImmediateRegisterState & immediateRegister(int i)
LongImmediateUnitState(int size, int latency, const std::string &name, int width, bool signExtend)
virtual int immediateRegisterCount() const
ItemQueue queue_
Queue of register value update requests.
unsigned timer_
Counter to time arrival of immediate values. Note: value is expected to wrap.
ValueContainer values_
Contains all values of the registers.
virtual void setRegisterValue(int index, const SimValue &value)
virtual SimValue & registerValue(int index)
int latency_
Latency of LongImmediateUnit.
RegisterContainer registers_
Contains all long immediate registers of the unit.
virtual SimValue & registerValue(int index)
virtual int immediateRegisterCount() const
static NullLongImmediateUnitState * instance_
Unique instance of NullLongImmediateUnitState.
static NullLongImmediateUnitState & instance()
virtual void setRegisterValue(int index, const SimValue &value)
virtual LongImmediateRegisterState & immediateRegister(int i)
static SimValue & instance()
Definition SimValue.cc:1642
static void deleteAllItems(SequenceType &aSequence)