OpenASIP  2.0
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 
42 using 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  */
78  clear();
79 }
80 
81 /**
82  * Clears the containers.
83  */
84 void
87  values_.clear();
88 }
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  */
97 SimValue&
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  */
113 void
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  */
132 void
134 }
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  */
143 void
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  */
173 int
175  return registers_.size();
176 }
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  */
202  LongImmediateUnitState(0, 0, "<NULL>", 0, false) {
203 }
204 
205 /**
206  * Destructor.
207  */
209 }
210 
211 /**
212  * Aborts the program with error message.
213  *
214  * @return Never returns.
215  * @exception OutOfRange Never throws.
216  */
217 SimValue&
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  */
228 void
230  Application::abortWithError("setRegisterValue()");
231 }
232 
233 /**
234  * Aborts the program with error message.
235  */
236 void
238  Application::abortWithError("endClock()");
239 }
240 
241 /**
242  * Aborts the program with error message.
243  */
244 void
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  */
265 int
267  Application::abortWithError("immediateRegisterCount()");
268  return 0;
269 }
LongImmediateUnitState::LongImmediateUnitState
LongImmediateUnitState(int size, int latency, const std::string &name, int width, bool signExtend)
Definition: LongImmediateUnitState.cc:58
LongImmediateUnitState::immediateRegister
virtual LongImmediateRegisterState & immediateRegister(int i)
Definition: LongImmediateUnitState.cc:160
NullLongImmediateUnitState::registerValue
virtual SimValue & registerValue(int index)
Definition: LongImmediateUnitState.cc:218
NullLongImmediateUnitState::instance
static NullLongImmediateUnitState & instance()
Definition: LongImmediateUnitState.cc:191
ClockedState
Definition: ClockedState.hh:40
Exception.hh
LongImmediateUnitState::values_
ValueContainer values_
Contains all values of the registers.
Definition: LongImmediateUnitState.hh:114
OutOfRange
Definition: Exception.hh:320
LongImmediateUnitState::immediateRegisterCount
virtual int immediateRegisterCount() const
Definition: LongImmediateUnitState.cc:174
SequenceTools.hh
LongImmediateUnitState::advanceClock
virtual void advanceClock()
Definition: LongImmediateUnitState.cc:144
NullSimValue::instance
static SimValue & instance()
Definition: SimValue.cc:1642
LongImmediateUnitState::queue_
ItemQueue queue_
Queue of register value update requests.
Definition: LongImmediateUnitState.hh:110
LongImmediateUnitState::setRegisterValue
virtual void setRegisterValue(int index, const SimValue &value)
Definition: LongImmediateUnitState.cc:114
SimValue
Definition: SimValue.hh:96
LongImmediateUnitState.hh
NullLongImmediateUnitState::immediateRegisterCount
virtual int immediateRegisterCount() const
Definition: LongImmediateUnitState.cc:266
NullLongImmediateUnitState::NullLongImmediateUnitState
NullLongImmediateUnitState()
Definition: LongImmediateUnitState.cc:201
NullLongImmediateUnitState::endClock
virtual void endClock()
Definition: LongImmediateUnitState.cc:237
LongImmediateRegisterState
Definition: LongImmediateRegisterState.hh:47
SequenceTools::deleteAllItems
static void deleteAllItems(SequenceType &aSequence)
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
LongImmediateRegisterState.hh
Application.hh
LongImmediateUnitState::clear
void clear()
Definition: LongImmediateUnitState.cc:85
__func__
#define __func__
Definition: Application.hh:67
NullLongImmediateUnitState
Definition: LongImmediateUnitState.hh:128
NullLongImmediateUnitState::setRegisterValue
virtual void setRegisterValue(int index, const SimValue &value)
Definition: LongImmediateUnitState.cc:229
NullLongImmediateUnitState::advanceClock
virtual void advanceClock()
Definition: LongImmediateUnitState.cc:245
LongImmediateUnitState::~LongImmediateUnitState
virtual ~LongImmediateUnitState()
Definition: LongImmediateUnitState.cc:77
LongImmediateUnitState::registers_
RegisterContainer registers_
Contains all long immediate registers of the unit.
Definition: LongImmediateUnitState.hh:112
NullLongImmediateUnitState::immediateRegister
virtual LongImmediateRegisterState & immediateRegister(int i)
Definition: LongImmediateUnitState.cc:255
NullLongImmediateUnitState::~NullLongImmediateUnitState
virtual ~NullLongImmediateUnitState()
Definition: LongImmediateUnitState.cc:208
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
NullLongImmediateUnitState::instance_
static NullLongImmediateUnitState * instance_
Unique instance of NullLongImmediateUnitState.
Definition: LongImmediateUnitState.hh:151
LongImmediateUnitState::registerValue
virtual SimValue & registerValue(int index)
Definition: LongImmediateUnitState.cc:98
LongImmediateUnitState::endClock
virtual void endClock()
Definition: LongImmediateUnitState.cc:133
LongImmediateUnitState
Definition: LongImmediateUnitState.hh:55
LongImmediateUnitState::timer_
unsigned timer_
Counter to time arrival of immediate values. Note: value is expected to wrap.
Definition: LongImmediateUnitState.hh:117
LongImmediateUnitState::latency_
int latency_
Latency of LongImmediateUnit.
Definition: LongImmediateUnitState.hh:106