OpenASIP  2.0
DirectAccessMemory.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 DirectAccessMemory.cc
26  *
27  * Definition of DirectAccessMemory class.
28  *
29  * @author Pekka Jääskeläinen 2007 (pjaaskel-no.spam-cs.tut.fi)
30  * @author Viljami Korhonen 2008 (viljami.korhonen-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #include <string>
35 #include <utility>
36 #include <limits>
37 
38 #include "DirectAccessMemory.hh"
39 #include "MemoryContents.hh"
40 #include "Conversion.hh"
41 #include "Application.hh"
42 
43 using std::string;
44 
45 
46 /**
47  * Constructor. Create a model for a given memory.
48  *
49  * The created memory model is empty. No data is allocated for its contents.
50  *
51  * @param start First address of the memory.
52  * @param end Last address of the memory.
53  * @param MAUSize Bit width of the minimum addressable unit of the memory.
54  */
56  ULongWord start, ULongWord end, Word MAUSize, bool littleEndian) :
57  Memory(start, end, MAUSize, littleEndian),
58  start_(start), end_(end), MAUSize_(MAUSize),
59  MAUSize3_(MAUSize_ * 3), MAUSize2_(MAUSize_ * 2) {
60 
61  /// @note In C++, when shifting more bits than there are in integer, the
62  /// result is undefined. Thus, we just set the mask to ~0 in this case.
63  /// We should probably give user a warning if MAUSize is larger than
64  /// the integer size!
65  if (MAUSize_ >= static_cast<Word>(std::numeric_limits<Word>::digits)) {
66  mask_ = ~0u;
67  } else {
68  mask_ = ~(~0u << MAUSize_);
69  }
70 
72 }
73 
74 
75 /**
76  * Destructor.
77  */
79  delete data_;
80  data_ = NULL;
81 }
82 
83 /**
84  * Fills the whole memory with zeros.
85  *
86  * This is needed due to some buggy simulated programs which expect
87  * uninitialized data to be zero.
88  */
89 void
91  data_->clear();
92 }
93 
94 /**
95  * Writes a single MAU using the fastest possible method.
96  *
97  * @param address The address.
98  * @param data The data.
99  */
100 void
102  fastWriteMAU(address, data);
103 }
104 
105 /**
106  * A convenience method for writing units of data to the memory.
107  *
108  * The data is stored in an UIntWord.
109  *
110  * @param address The address to write.
111  * @param count Number of MAUs to write.
112  * @param data The data to write.
113  * @exception OutOfRange in case the address is out of range of the memory.
114  */
115 void
117  Memory::writeBE(address, count, data);
118  // compiled simulator does not call advance clock of
119  // memories at every cycle for efficiency, so we have
120  // to "flush" the writes right away
122 }
123 
124 /**
125  * Reads a single MAU using the fastest possible method.
126  *
127  * @param address The address.
128  * @return Data.
129  */
132  ULongWord data = 0;
133  fastReadMAU(address, data);
134  return data;
135 }
136 
137 /**
138  * Writes 1 MAU to the memory as fast as possible
139  *
140  * @param address address to write
141  * @param data data to be written
142  * @note No bounds checking is made so the address is assumed to be in range.
143  * @note On a cycle with read and write, make sure the read is done *first* !
144  */
145 void
147  data_->writeData(address - start_, (int)(data & mask_));
148 }
149 
150 /**
151  * Writes 2 MAUs to the memory as fast as possible
152  *
153  * @param address address to write
154  * @param data data to be written
155  * @note No bounds checking is made so the address is assumed to be in range.
156  * @note On a cycle with read and write, make sure the read is done *first* !
157  */
158 void
160  const Word index = address - start_;
161  data_->writeData(index, (int)((data >> MAUSize_) & mask_));
162  data_->writeData(index + 1, (int)(data & mask_));
163 }
164 
165 /**
166  * Writes 2 MAUs to the memory as fast as possible in little Endian
167  *
168  * @param address address to write
169  * @param data data to be written
170  * @note No bounds checking is made so the address is assumed to be in range.
171  * @note On a cycle with read and write, make sure the read is done *first* !
172  */
173 void
175  const Word index = address - start_;
176  data_->writeData(index + 1, (int)((data >> MAUSize_) & mask_));
177  data_->writeData(index, (int)(data & mask_));
178 }
179 
180 /**
181  * Writes 4 MAUs to the memory as fast as possible in BE.
182  *
183  * @param address address to write
184  * @param data data to be written
185  * @note No bounds checking is made so the address is assumed to be in range.
186  * @note On a cycle with read and write, make sure the read is done *first* !
187  */
188 void
190  const Word index = address - start_;
191  data_->writeData(index, (int)((data >> MAUSize3_) & mask_));
192  data_->writeData(index + 1, (int)((data >> MAUSize2_) & mask_));
193  data_->writeData(index + 2, (int)((data >> MAUSize_) & mask_));
194  data_->writeData(index + 3, (int)(data & mask_));
195 }
196 
197 /**
198  * Writes 4 MAUs to the memory as fast as possible in LE
199  *
200  * @param address address to write
201  * @param data data to be written
202  * @note No bounds checking is made so the address is assumed to be in range.
203  * @note On a cycle with read and write, make sure the read is done *first* !
204  */
205 void
207  const Word index = address - start_;
208  data_->writeData(index + 3, (int)((data >> MAUSize3_) & mask_));
209  data_->writeData(index + 2, (int)((data >> MAUSize2_) & mask_));
210  data_->writeData(index + 1, (int)((data >> MAUSize_) & mask_));
211  data_->writeData(index, (int)(data & mask_));
212 }
213 
214 /**
215  * Reads 1 MAU from the memory as fast as possible
216  *
217  * @param address address to read
218  * @param data reference to the read data
219  * @note No bounds checking is made so the address is assumed to be in range.
220  * @note On a cycle with read and write, make sure the read is done *first* !
221  */
222 void
224  data = data_->readData(address - start_);
225 }
226 
227 /**
228  * Reads 2 MAUs from the memory as fast as possible in BE
229  *
230  * @param address address to read
231  * @param data reference to the read data
232  * @note No bounds checking is made so the address is assumed to be in range.
233  * @note On a cycle with read and write, make sure the read is done *first* !
234  */
235 void
237  const Word index = address - start_;
238  data = data_->readData(index) << MAUSize_;
239  data |= data_->readData(index + 1);
240 }
241 
242 /**
243  * Reads 2 MAUs from the memory as fast as possible in LE
244  *
245  * @param address address to read
246  * @param data reference to the read data
247  * @note No bounds checking is made so the address is assumed to be in range.
248  * @note On a cycle with read and write, make sure the read is done *first* !
249  */
250 void
252  const Word index = address - start_;
253  data = data_->readData(index +1) << MAUSize_;
254  data |= data_->readData(index);
255 }
256 
257 /**
258  * Reads 4 MAUs from the memory as fast as possible in BE
259  *
260  * @param address address to read
261  * @param data reference to the read data
262  * @note No bounds checking is made so the address is assumed to be in range.
263  * @note On a cycle with read and write, make sure the read is done *first* !
264  */
265 void
267  const Word index = address - start_;
268  data = data_->readData(index) << MAUSize3_;
269  data |= data_->readData(index + 1) << MAUSize2_;
270  data |= data_->readData(index + 2) << MAUSize_;
271  data |= data_->readData(index + 3);
272 }
273 
274 /**
275  * Reads 4 MAUs from the memory as fast as possible in LE
276  *
277  * @param address address to read
278  * @param data reference to the read data
279  * @note No bounds checking is made so the address is assumed to be in range.
280  * @note On a cycle with read and write, make sure the read is done *first* !
281  */
282 void
284  const Word index = address - start_;
285  data = data_->readData(index + 3) << MAUSize3_;
286  data |= data_->readData(index + 2) << MAUSize2_;
287  data |= data_->readData(index + 1) << MAUSize_;
288  data |= data_->readData(index);
289 }
DirectAccessMemory::fastWrite2MAUsBE
void fastWrite2MAUsBE(ULongWord address, ULongWord data)
Definition: DirectAccessMemory.cc:159
DirectAccessMemory::MAUSize_
Word MAUSize_
Size of the minimum adressable unit.
Definition: DirectAccessMemory.hh:129
DirectAccessMemory::fastRead4MAUsBE
void fastRead4MAUsBE(ULongWord address, ULongWord &data)
Definition: DirectAccessMemory.cc:266
DirectAccessMemory::fillWithZeros
virtual void fillWithZeros()
Definition: DirectAccessMemory.cc:90
DirectAccessMemory::fastWrite4MAUsLE
void fastWrite4MAUsLE(ULongWord address, ULongWord data)
Definition: DirectAccessMemory.cc:206
MemoryContents.hh
DirectAccessMemory::fastReadMAU
void fastReadMAU(ULongWord address, ULongWord &data)
Definition: DirectAccessMemory.cc:223
DirectAccessMemory::write
void write(ULongWord address, Memory::MAU data) override
Definition: DirectAccessMemory.cc:101
DirectAccessMemory::fastWrite4MAUsBE
void fastWrite4MAUsBE(ULongWord address, ULongWord data)
Definition: DirectAccessMemory.cc:189
DirectAccessMemory::start_
Word start_
Starting point of the address space.
Definition: DirectAccessMemory.hh:125
PagedArray::readData
ValueType readData(IndexType index)
MemoryContents
Definition: MemoryContents.hh:48
PagedArray::clear
void clear()
DirectAccessMemory::fastWrite2MAUsLE
void fastWrite2MAUsLE(ULongWord address, ULongWord data)
Definition: DirectAccessMemory.cc:174
DirectAccessMemory::fastRead4MAUsLE
void fastRead4MAUsLE(ULongWord address, ULongWord &data)
Definition: DirectAccessMemory.cc:283
DirectAccessMemory::read
Memory::MAU read(ULongWord address) override
Definition: DirectAccessMemory.cc:131
Conversion.hh
Application.hh
Memory::MAU
MinimumAddressableUnit MAU
Definition: Memory.hh:76
DirectAccessMemory::fastWriteMAU
void fastWriteMAU(ULongWord address, ULongWord data)
Definition: DirectAccessMemory.cc:146
Memory::advanceClock
virtual void advanceClock()
Definition: Memory.cc:819
DirectAccessMemory::end_
Word end_
End point of the address space.
Definition: DirectAccessMemory.hh:127
DirectAccessMemory::writeBE
void writeBE(ULongWord address, int count, ULongWord data) override
Definition: DirectAccessMemory.cc:116
DirectAccessMemory::data_
MemoryContents * data_
Contains MAUs of the memory model, that is, the actual data of the memory.
Definition: DirectAccessMemory.hh:140
DirectAccessMemory.hh
PagedArray::writeData
void writeData(IndexType index, const ValueType &data)
Memory::writeBE
virtual void writeBE(ULongWord address, int size, ULongWord data)
Definition: Memory.cc:194
DirectAccessMemory::mask_
Word mask_
Mask bit pattern for unpacking IntWord to MAUs.
Definition: DirectAccessMemory.hh:137
DirectAccessMemory::MAUSize3_
Word MAUSize3_
precalculated MAUSize_ * 3
Definition: DirectAccessMemory.hh:131
ULongWord
unsigned long ULongWord
Definition: BaseType.hh:51
DirectAccessMemory::fastRead2MAUsBE
void fastRead2MAUsBE(ULongWord address, ULongWord &data)
Definition: DirectAccessMemory.cc:236
DirectAccessMemory::~DirectAccessMemory
virtual ~DirectAccessMemory()
Definition: DirectAccessMemory.cc:78
DirectAccessMemory::DirectAccessMemory
DirectAccessMemory(ULongWord start, ULongWord end, Word MAUSize, bool littleEndian)
Definition: DirectAccessMemory.cc:55
DirectAccessMemory::fastRead2MAUsLE
void fastRead2MAUsLE(ULongWord address, ULongWord &data)
Definition: DirectAccessMemory.cc:251
DirectAccessMemory::MAUSize2_
Word MAUSize2_
precalculated MAUSize_ * 2
Definition: DirectAccessMemory.hh:133
Memory
Definition: Memory.hh:74