OpenASIP 2.2
Loading...
Searching...
No Matches
ImmediateUnit.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 ImmediateUnit.cc
26 *
27 * Implementation of ImmediateUnit class.
28 *
29 * @author Lasse Laasonen 2003 (lasse.laasonen-no.spam-tut.fi)
30 * @author Esa Määttä 2007 (esa.maatta-no.spam-tut.fi)
31 */
32
33#include "ImmediateUnit.hh"
34#include "Port.hh"
35#include "ObjectState.hh"
36
37using std::string;
38
39// constant latency value for immediate unit
40const int LATENCY = 1;
41
42// constant max writes value for immediate unit
43const int MAX_WRITES = 1;
44
45// initialization of static data members
47 "immediate-unit";
48const string TTAMachine::ImmediateUnit::OSKEY_EXTENSION = "extension";
49const string TTAMachine::ImmediateUnit::OSVALUE_SIGN = "sign";
50const string TTAMachine::ImmediateUnit::OSVALUE_ZERO = "zero";
51const string TTAMachine::ImmediateUnit::OSKEY_LATENCY = "latency";
52
53namespace TTAMachine {
54
55/**
56 * Constructor.
57 *
58 * @param name Name of the immediate unit.
59 * @param size Number of immediate registers in the immediate unit.
60 * @param width Bit width of the long immediate registers in the immediate
61 * unit.
62 * @param extension Extension mode applied to the long immediate when it is
63 * narrower than the immediate register,
64 * see Machine::Extension.
65 * @param latency Number of cycles needed between the encoding of a long
66 * immediate and its earliest transport on a data bus.
67 * The value "0" indicates that the long immediate can be
68 * read onto a bus in the same cycle in which the instruction
69 * that encodes it is executed.
70 * @exception OutOfRange If the given size or width is invalid.
71 * @exception InvalidName If the given name is not a valid name for a
72 component.
73 */
75 const string& name, unsigned int size, unsigned int width,
76 unsigned int maxReads, unsigned int guardLatency,
77 Machine::Extension extension)
79 name, size, width, maxReads, MAX_WRITES, guardLatency,
81 extension_(extension),
82 latency_(LATENCY) {
85}
86
87/**
88 * Constructor.
89 *
90 * Loads the state of the immediate unit from the given ObjectState instance.
91 * Does not load references to other components.
92 *
93 * @param state The ObjectState instance.
94 * @exception ObjectStateLoadingException If the given ObjectState instance
95 * is invalid or if connections to
96 * other machine parts cannot be made.
97 */
101
102/**
103 * Destructor.
104 */
108
109
110/**
111 * Sets the name of the immediate unit.
112 *
113 * @param name Name of the immediate unit.
114 * @exception ComponentAlreadyExists If an immediate unit with the given
115 * name is already in the same machine.
116 * @exception InvalidName If the given name is not a valid name for a
117 * component.
118 */
119void
120ImmediateUnit::setName(const string& name) {
121 if (name == this->name()) {
122 return;
123 }
124
125 if (machine() != NULL) {
126 if (machine()->immediateUnitNavigator().hasItem(name)) {
127 string procName = "ImmediateUnit::setName";
128 throw ComponentAlreadyExists(__FILE__, __LINE__, procName);
129 } else {
131 }
132 } else {
134 }
135}
136
137/**
138 * Returns the extension mode of the immediate unit.
139 *
140 * @return The extension mode of the immediate unit.
141 */
144 return extension_;
145}
146
147
148/**
149 * Returns the minimum number of cycles needed between the encoding of a long
150 * immediate and its earliest transport on a data bus.
151 *
152 * @return Latency of the immediate unit.
153 */
154int
156 return latency_;
157}
158
159
160/**
161 * Sets the maximum number of ports that can write a register all in the same
162 * cycle.
163 *
164 * For immediate unit the value is fixed to 1.
165 *
166 * @param writes Maximum number of ports.
167 * @exception OutOfRange If the given number of maximum writes is out of
168 * range.
169 */
170void
172 if (maxWrites != MAX_WRITES) {
173 std::string procName = "ImmediateUnit::setMaxWrites";
174 throw OutOfRange(__FILE__, __LINE__, procName);
175 }
177}
178
179/**
180 * Sets the extension mode for the immediate unit.
181 *
182 * @param mode The new extension mode.
183 */
184void
188
189
190/**
191 * Sets the latency of the immediate unit.
192 *
193 * @param latency The new latency.
194 * @exception OutOfRange If the given latency is less than zero.
195 */
196void
198 if (latency != LATENCY) {
199 string procName = "ImmediateUnit::setLatency";
200 throw OutOfRange(__FILE__, __LINE__, procName);
201 }
203}
204
205/**
206 * Removes the immediate unit from machine.
207 */
208void
210 Machine* mach = machine();
211 if (mach == NULL) {
212 return;
213 }
214
217 Machine::BusNavigator busNav = mach->busNavigator();
218 for (int itIndex = 0; itIndex < itNav.count(); itIndex++) {
219 InstructionTemplate* it = itNav.item(itIndex);
220 it->removeSlots(*this);
221 }
223 mach->removeImmediateUnit(*this);
224}
225
226
227/**
228 * Saves the contents to an ObjectState tree.
229 *
230 * @return The newly created ObjectState tree.
231 */
234
237
238 // set extension mode
239 if (extension_ == Machine::SIGN) {
241 } else {
243 }
244
246
247 return iUnit;
248}
249
250
251/**
252 * Loads its state from the given ObjectState instance.
253 *
254 * @param state The ObjectState instance.
255 * @exception ObjectStateLoadingException If the given ObjectState instance
256 * is invalid or if the connections
257 * to other machine parts cannot be
258 * made.
259 */
260void
265
266/**
267 * Loads the state of the immediate unit without references to other
268 * components.
269 *
270 * @param state The ObjectState instance from which the state is loaded.
271 * @exception ObjectStateLoadingException If an error occurs while loading
272 * the state.
273 */
274void
276 const string procName = "ImmediateUnit::loadStateWithoutReferences";
277
278 if (state->name() != OSNAME_IMMEDIATE_UNIT) {
279 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
280 }
281
282 try {
283 string extension = state->stringAttribute(OSKEY_EXTENSION);
284 if (extension == OSVALUE_SIGN) {
286 } else if (extension == OSVALUE_ZERO) {
288 } else {
289 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
290 }
291
293 assert(latency_ >= 0);
294
295 } catch (const Exception& e) {
297 __FILE__, __LINE__, procName, e.errorMessage());
298 }
299}
300}
#define assert(condition)
TTAMachine::Machine * machine
the architecture definition of the estimated processor
const int LATENCY
const int MAX_WRITES
std::string errorMessage() const
Definition Exception.cc:123
void setName(const std::string &name)
void setAttribute(const std::string &name, const std::string &value)
std::string stringAttribute(const std::string &name) const
int intAttribute(const std::string &name) const
std::string name() const
virtual int size() const
virtual int width() const
virtual void setWidth(int width)
virtual void setName(const std::string &name)
virtual void unsetMachine()=0
virtual TCEString name() const
static const std::string OSVALUE_SIGN
ObjectState attribute value for sign extension.
virtual void setLatency(int latency)
void loadStateWithoutReferences(const ObjectState *state)
virtual void loadState(const ObjectState *state)
ImmediateUnit(const std::string &name, unsigned int size, unsigned int width, unsigned int maxReads, unsigned int guardLatency, Machine::Extension extension)
Machine::Extension extension_
static const std::string OSKEY_LATENCY
ObjectState attribute key for latency.
virtual void setMaxWrites(int maxWrites)
virtual void setExtensionMode(Machine::Extension mode)
virtual int latency() const
static const std::string OSNAME_IMMEDIATE_UNIT
ObjectState name for ImmediateUnit.
virtual ObjectState * saveState() const
virtual Machine::Extension extensionMode() const
static const std::string OSVALUE_ZERO
ObjectState attribute value for zero extension.
virtual void setName(const std::string &name)
static const std::string OSKEY_EXTENSION
ObjectState attribute key for the extension mode.
virtual void removeSlots(const ImmediateUnit &dstUnit)
ComponentType * item(int index) const
virtual InstructionTemplateNavigator instructionTemplateNavigator() const
Definition Machine.cc:428
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
@ SIGN
Sign extension.
Definition Machine.hh:82
@ ZERO
Zero extension.
Definition Machine.hh:81
virtual void removeImmediateUnit(ImmediateUnit &unit)
Definition Machine.cc:542
virtual void loadState(const ObjectState *state)
virtual ObjectState * saveState() const
virtual void setMaxWrites(int maxWrites)
virtual void setNumberOfRegisters(int registers)
virtual int maxWrites() const
mode
Definition tceopgen.cc:45
@ NORMAL
Definition tceopgen.cc:45