OpenASIP  2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
DirectAccessMemory Class Reference

#include <DirectAccessMemory.hh>

Inheritance diagram for DirectAccessMemory:
Inheritance graph
Collaboration diagram for DirectAccessMemory:
Collaboration graph

Public Member Functions

 DirectAccessMemory (ULongWord start, ULongWord end, Word MAUSize, bool littleEndian)
 
virtual ~DirectAccessMemory ()
 
void write (ULongWord address, Memory::MAU data) override
 
void fastWriteMAU (ULongWord address, ULongWord data)
 
void fastWrite2MAUsBE (ULongWord address, ULongWord data)
 
void fastWrite4MAUsBE (ULongWord address, ULongWord data)
 
void fastWrite2MAUsLE (ULongWord address, ULongWord data)
 
void fastWrite4MAUsLE (ULongWord address, ULongWord data)
 
Memory::MAU read (ULongWord address) override
 
void fastReadMAU (ULongWord address, ULongWord &data)
 
void fastRead2MAUsBE (ULongWord address, ULongWord &data)
 
void fastRead4MAUsBE (ULongWord address, ULongWord &data)
 
void fastRead2MAUsLE (ULongWord address, ULongWord &data)
 
void fastRead4MAUsLE (ULongWord address, ULongWord &data)
 
virtual void advanceClock ()
 
virtual void reset ()
 
virtual void fillWithZeros ()
 
void writeBE (ULongWord address, int count, ULongWord data) override
 
virtual void write (ULongWord address, MAU data)=0
 
void write (ULongWord address, int size, ULongWord data)
 
void write (ULongWord address, FloatWord data)
 
void write (ULongWord address, DoubleWord data)
 
virtual Memory::MAU read (ULongWord address)=0
 
void read (ULongWord address, int size, ULongWord &data)
 
void read (ULongWord address, DoubleWord &data)
 
void read (ULongWord address, FloatWord &data)
 
- Public Member Functions inherited from Memory
 Memory (ULongWord start, ULongWord end, ULongWord MAUSize, bool littleEndian_)
 
virtual ~Memory ()
 
virtual void writeLE (ULongWord address, int size, ULongWord data)
 
void write (ULongWord address, int size, ULongWord data)
 
virtual void writeDirectlyBE (ULongWord address, int size, ULongWord data)
 
virtual void writeDirectlyLE (ULongWord address, int size, ULongWord data)
 
void write (ULongWord address, FloatWord data)
 
void write (ULongWord address, DoubleWord data)
 
void read (ULongWord address, int size, ULongWord &data)
 
void read (ULongWord address, DoubleWord &data)
 
void read (ULongWord address, FloatWord &data)
 
virtual void writeBE (ULongWord address, FloatWord data)
 
virtual void writeBE (ULongWord address, DoubleWord data)
 
virtual void writeLE (ULongWord address, FloatWord data)
 
virtual void writeLE (ULongWord address, DoubleWord data)
 
virtual void readBE (ULongWord address, int size, ULongWord &data)
 
virtual void readLE (ULongWord address, int size, ULongWord &data)
 
virtual void readBE (ULongWord address, FloatWord &data)
 
virtual void readBE (ULongWord address, DoubleWord &data)
 
virtual void readLE (ULongWord address, FloatWord &data)
 
virtual void readLE (ULongWord address, DoubleWord &data)
 
virtual ULongWord start ()
 
virtual ULongWord end ()
 
virtual ULongWord MAUSize ()
 
bool isLittleEndian ()
 

Private Member Functions

 DirectAccessMemory (const DirectAccessMemory &)
 Copying not allowed. More...
 
DirectAccessMemoryoperator= (const DirectAccessMemory &)
 Assignment not allowed. More...
 

Private Attributes

Word start_
 Starting point of the address space. More...
 
Word end_
 End point of the address space. More...
 
Word MAUSize_
 Size of the minimum adressable unit. More...
 
Word MAUSize3_
 precalculated MAUSize_ * 3 More...
 
Word MAUSize2_
 precalculated MAUSize_ * 2 More...
 
Word wordSize_
 Size of the natural word as MAUs. More...
 
Word mask_
 Mask bit pattern for unpacking IntWord to MAUs. More...
 
MemoryContentsdata_
 Contains MAUs of the memory model, that is, the actual data of the memory. More...
 

Additional Inherited Members

- Public Types inherited from Memory
typedef MinimumAddressableUnit MAU
 
typedef MAUMAUTable
 
- Protected Member Functions inherited from Memory
void packBE (const Memory::MAUTable data, int size, ULongWord &value)
 
void unpackBE (const ULongWord &value, int size, Memory::MAUTable data)
 
void packLE (const Memory::MAUTable data, int size, ULongWord &value)
 
void unpackLE (const ULongWord &value, int size, Memory::MAUTable data)
 
- Protected Attributes inherited from Memory
bool littleEndian_
 

Detailed Description

Class that models an "ideal" memory to which updates are visible immediately.

This model is used in compiled simulation. It does not require an advance clock call: all writes to it are visible immediately. Thus, one has to make sure that all reads in the same cycle are executed before writes in order for the reads to read the old values.

Note that all range checking is disabled for fastest possible simulation model. In case you are unsure of your simulated input correctness, use the old simulation engine for verification.

Definition at line 55 of file DirectAccessMemory.hh.

Constructor & Destructor Documentation

◆ DirectAccessMemory() [1/2]

DirectAccessMemory::DirectAccessMemory ( ULongWord  start,
ULongWord  end,
Word  MAUSize,
bool  littleEndian 
)

Constructor. Create a model for a given memory.

The created memory model is empty. No data is allocated for its contents.

Parameters
startFirst address of the memory.
endLast address of the memory.
MAUSizeBit width of the minimum addressable unit of the memory.
Note
In C++, when shifting more bits than there are in integer, the result is undefined. Thus, we just set the mask to ~0 in this case. We should probably give user a warning if MAUSize is larger than the integer size!

Definition at line 55 of file DirectAccessMemory.cc.

56  :
57  Memory(start, end, MAUSize, littleEndian),
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 }

References data_, end_, mask_, MAUSize_, and start_.

◆ ~DirectAccessMemory()

DirectAccessMemory::~DirectAccessMemory ( )
virtual

Destructor.

Definition at line 78 of file DirectAccessMemory.cc.

78  {
79  delete data_;
80  data_ = NULL;
81 }

References data_.

◆ DirectAccessMemory() [2/2]

DirectAccessMemory::DirectAccessMemory ( const DirectAccessMemory )
private

Copying not allowed.

Member Function Documentation

◆ advanceClock()

virtual void DirectAccessMemory::advanceClock ( )
inlinevirtual

Advances clock for one cycle.

Commits all pending write requests to the memory. Cannot throw an exception, request legality is checked when request is initiated.

Reimplemented from Memory.

Definition at line 108 of file DirectAccessMemory.hh.

108 {}

◆ fastRead2MAUsBE()

void DirectAccessMemory::fastRead2MAUsBE ( ULongWord  address,
ULongWord data 
)

Reads 2 MAUs from the memory as fast as possible in BE

Parameters
addressaddress to read
datareference to the read data
Note
No bounds checking is made so the address is assumed to be in range.
On a cycle with read and write, make sure the read is done first !

Definition at line 236 of file DirectAccessMemory.cc.

236  {
237  const Word index = address - start_;
238  data = data_->readData(index) << MAUSize_;
239  data |= data_->readData(index + 1);
240 }

References data_, MAUSize_, PagedArray< ValueType, PageSize, DefaultValue >::readData(), and start_.

Here is the call graph for this function:

◆ fastRead2MAUsLE()

void DirectAccessMemory::fastRead2MAUsLE ( ULongWord  address,
ULongWord data 
)

Reads 2 MAUs from the memory as fast as possible in LE

Parameters
addressaddress to read
datareference to the read data
Note
No bounds checking is made so the address is assumed to be in range.
On a cycle with read and write, make sure the read is done first !

Definition at line 251 of file DirectAccessMemory.cc.

251  {
252  const Word index = address - start_;
253  data = data_->readData(index +1) << MAUSize_;
254  data |= data_->readData(index);
255 }

References data_, MAUSize_, PagedArray< ValueType, PageSize, DefaultValue >::readData(), and start_.

Here is the call graph for this function:

◆ fastRead4MAUsBE()

void DirectAccessMemory::fastRead4MAUsBE ( ULongWord  address,
ULongWord data 
)

Reads 4 MAUs from the memory as fast as possible in BE

Parameters
addressaddress to read
datareference to the read data
Note
No bounds checking is made so the address is assumed to be in range.
On a cycle with read and write, make sure the read is done first !

Definition at line 266 of file DirectAccessMemory.cc.

266  {
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 }

References data_, MAUSize2_, MAUSize3_, MAUSize_, PagedArray< ValueType, PageSize, DefaultValue >::readData(), and start_.

Here is the call graph for this function:

◆ fastRead4MAUsLE()

void DirectAccessMemory::fastRead4MAUsLE ( ULongWord  address,
ULongWord data 
)

Reads 4 MAUs from the memory as fast as possible in LE

Parameters
addressaddress to read
datareference to the read data
Note
No bounds checking is made so the address is assumed to be in range.
On a cycle with read and write, make sure the read is done first !

Definition at line 283 of file DirectAccessMemory.cc.

283  {
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 }

References data_, MAUSize2_, MAUSize3_, MAUSize_, PagedArray< ValueType, PageSize, DefaultValue >::readData(), and start_.

Here is the call graph for this function:

◆ fastReadMAU()

void DirectAccessMemory::fastReadMAU ( ULongWord  address,
ULongWord data 
)

Reads 1 MAU from the memory as fast as possible

Parameters
addressaddress to read
datareference to the read data
Note
No bounds checking is made so the address is assumed to be in range.
On a cycle with read and write, make sure the read is done first !

Definition at line 223 of file DirectAccessMemory.cc.

223  {
224  data = data_->readData(address - start_);
225 }

References data_, PagedArray< ValueType, PageSize, DefaultValue >::readData(), and start_.

Referenced by read().

Here is the call graph for this function:

◆ fastWrite2MAUsBE()

void DirectAccessMemory::fastWrite2MAUsBE ( ULongWord  address,
ULongWord  data 
)

Writes 2 MAUs to the memory as fast as possible

Parameters
addressaddress to write
datadata to be written
Note
No bounds checking is made so the address is assumed to be in range.
On a cycle with read and write, make sure the read is done first !

Definition at line 159 of file DirectAccessMemory.cc.

159  {
160  const Word index = address - start_;
161  data_->writeData(index, (int)((data >> MAUSize_) & mask_));
162  data_->writeData(index + 1, (int)(data & mask_));
163 }

References data_, mask_, MAUSize_, start_, and PagedArray< ValueType, PageSize, DefaultValue >::writeData().

Here is the call graph for this function:

◆ fastWrite2MAUsLE()

void DirectAccessMemory::fastWrite2MAUsLE ( ULongWord  address,
ULongWord  data 
)

Writes 2 MAUs to the memory as fast as possible in little Endian

Parameters
addressaddress to write
datadata to be written
Note
No bounds checking is made so the address is assumed to be in range.
On a cycle with read and write, make sure the read is done first !

Definition at line 174 of file DirectAccessMemory.cc.

174  {
175  const Word index = address - start_;
176  data_->writeData(index + 1, (int)((data >> MAUSize_) & mask_));
177  data_->writeData(index, (int)(data & mask_));
178 }

References data_, mask_, MAUSize_, start_, and PagedArray< ValueType, PageSize, DefaultValue >::writeData().

Here is the call graph for this function:

◆ fastWrite4MAUsBE()

void DirectAccessMemory::fastWrite4MAUsBE ( ULongWord  address,
ULongWord  data 
)

Writes 4 MAUs to the memory as fast as possible in BE.

Parameters
addressaddress to write
datadata to be written
Note
No bounds checking is made so the address is assumed to be in range.
On a cycle with read and write, make sure the read is done first !

Definition at line 189 of file DirectAccessMemory.cc.

189  {
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 }

References data_, mask_, MAUSize2_, MAUSize3_, MAUSize_, start_, and PagedArray< ValueType, PageSize, DefaultValue >::writeData().

Here is the call graph for this function:

◆ fastWrite4MAUsLE()

void DirectAccessMemory::fastWrite4MAUsLE ( ULongWord  address,
ULongWord  data 
)

Writes 4 MAUs to the memory as fast as possible in LE

Parameters
addressaddress to write
datadata to be written
Note
No bounds checking is made so the address is assumed to be in range.
On a cycle with read and write, make sure the read is done first !

Definition at line 206 of file DirectAccessMemory.cc.

206  {
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 }

References data_, mask_, MAUSize2_, MAUSize3_, MAUSize_, start_, and PagedArray< ValueType, PageSize, DefaultValue >::writeData().

Here is the call graph for this function:

◆ fastWriteMAU()

void DirectAccessMemory::fastWriteMAU ( ULongWord  address,
ULongWord  data 
)

Writes 1 MAU to the memory as fast as possible

Parameters
addressaddress to write
datadata to be written
Note
No bounds checking is made so the address is assumed to be in range.
On a cycle with read and write, make sure the read is done first !

Definition at line 146 of file DirectAccessMemory.cc.

146  {
147  data_->writeData(address - start_, (int)(data & mask_));
148 }

References data_, mask_, start_, and PagedArray< ValueType, PageSize, DefaultValue >::writeData().

Referenced by write().

Here is the call graph for this function:

◆ fillWithZeros()

void DirectAccessMemory::fillWithZeros ( )
virtual

Fills the whole memory with zeros.

This is needed due to some buggy simulated programs which expect uninitialized data to be zero.

Reimplemented from Memory.

Definition at line 90 of file DirectAccessMemory.cc.

90  {
91  data_->clear();
92 }

References PagedArray< ValueType, PageSize, DefaultValue >::clear(), and data_.

Here is the call graph for this function:

◆ operator=()

DirectAccessMemory& DirectAccessMemory::operator= ( const DirectAccessMemory )
private

Assignment not allowed.

◆ read() [1/5]

Memory::MAU DirectAccessMemory::read ( ULongWord  address)
overridevirtual

Reads a single MAU using the fastest possible method.

Parameters
addressThe address.
Returns
Data.

Implements Memory.

Definition at line 131 of file DirectAccessMemory.cc.

131  {
132  ULongWord data = 0;
133  fastReadMAU(address, data);
134  return data;
135 }

References fastReadMAU().

Here is the call graph for this function:

◆ read() [2/5]

Memory::MAU Memory::read

Reads a single memory location.

Must be implemented in the derived class. No range checking. The fastest way to read the memory.

Parameters
addressThe address to read.
Returns
The data read.

Definition at line 160 of file Memory.cc.

160  {
161  return 0;
162 }

◆ read() [3/5]

void Memory::read

A convenience method for reading data from the memory and interpreting it as a DoubleWord in order set by endian bit of memory.

Note
Currently works only if MAU == 8 bits. asserts otherwise.
Parameters
addressThe address to read.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 513 of file Memory.cc.

513  {
514  if (littleEndian_) {
515  readLE(address, data);
516  } else {
517  readBE(address, data);
518  }
519 }

◆ read() [4/5]

void Memory::read

A convenience method for reading data from the memory and interpreting it as a FloatWord in order set by the memory.

Note
Currently works only if MAU == 8 bits. asserts otherwise.
Parameters
addressThe address to read.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 329 of file Memory.cc.

329  {
330  if (littleEndian_) {
331  readLE(address, data);
332  } else {
333  readBE(address, data);
334  }
335 }

◆ read() [5/5]

void Memory::read

A convenience method for reading units of data from the memory.

The data is written to an UIntWord.

Parameters
addressThe address to read.
countNumber of MAUs to read.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 663 of file Memory.cc.

663  {
664  if (littleEndian_) {
665  readLE(address, size, data);
666  } else {
667  readBE(address, size, data);
668  }
669 }

◆ reset()

virtual void DirectAccessMemory::reset ( )
inlinevirtual

Resets the memory.

Clears any pending write requests.

Reimplemented from Memory.

Definition at line 109 of file DirectAccessMemory.hh.

109 {}

◆ write() [1/5]

void Memory::write

A convenience method for writing a DoubleWord to the memory.

Note
Currently works only if MAU == 8 bits. asserts otherwise.
Parameters
addressThe address to write.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 531 of file Memory.cc.

531  {
532  if (littleEndian_) {
533  writeLE(address, data);
534  } else {
535  writeBE(address, data);
536  }
537 }

◆ write() [2/5]

void Memory::write

◆ write() [3/5]

void Memory::write

A convenience method for writing units of data to the memory.

The data is stored in an UIntWord.

Parameters
addressThe address to write.
countNumber of MAUs to write.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 175 of file Memory.cc.

175  {
176  if (littleEndian_) {
177  writeLE(address, count, data);
178  } else {
179  writeBE(address, count, data);
180  }
181 }

◆ write() [4/5]

void Memory::write

Writes a single memory location.

Must be implemented in the derived class. No range checking. The fastest way to write to the memory.

Parameters
addressThe target address.
dataThe data to write.

Definition at line 95 of file Memory.cc.

95  {
96  abortWithError("Must be implemented in the derived class.");
97 }

◆ write() [5/5]

void DirectAccessMemory::write ( ULongWord  address,
Memory::MAU  data 
)
overridevirtual

Writes a single MAU using the fastest possible method.

Parameters
addressThe address.
dataThe data.

Implements Memory.

Definition at line 101 of file DirectAccessMemory.cc.

101  {
102  fastWriteMAU(address, data);
103 }

References fastWriteMAU().

Here is the call graph for this function:

◆ writeBE()

void DirectAccessMemory::writeBE ( ULongWord  address,
int  count,
ULongWord  data 
)
overridevirtual

A convenience method for writing units of data to the memory.

The data is stored in an UIntWord.

Parameters
addressThe address to write.
countNumber of MAUs to write.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Reimplemented from Memory.

Definition at line 116 of file DirectAccessMemory.cc.

116  {
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 }

References Memory::advanceClock(), and Memory::writeBE().

Here is the call graph for this function:

Member Data Documentation

◆ data_

MemoryContents* DirectAccessMemory::data_
private

◆ end_

Word DirectAccessMemory::end_
private

End point of the address space.

Definition at line 127 of file DirectAccessMemory.hh.

Referenced by DirectAccessMemory().

◆ mask_

Word DirectAccessMemory::mask_
private

Mask bit pattern for unpacking IntWord to MAUs.

Definition at line 137 of file DirectAccessMemory.hh.

Referenced by DirectAccessMemory(), fastWrite2MAUsBE(), fastWrite2MAUsLE(), fastWrite4MAUsBE(), fastWrite4MAUsLE(), and fastWriteMAU().

◆ MAUSize2_

Word DirectAccessMemory::MAUSize2_
private

precalculated MAUSize_ * 2

Definition at line 133 of file DirectAccessMemory.hh.

Referenced by fastRead4MAUsBE(), fastRead4MAUsLE(), fastWrite4MAUsBE(), and fastWrite4MAUsLE().

◆ MAUSize3_

Word DirectAccessMemory::MAUSize3_
private

precalculated MAUSize_ * 3

Definition at line 131 of file DirectAccessMemory.hh.

Referenced by fastRead4MAUsBE(), fastRead4MAUsLE(), fastWrite4MAUsBE(), and fastWrite4MAUsLE().

◆ MAUSize_

Word DirectAccessMemory::MAUSize_
private

◆ start_

Word DirectAccessMemory::start_
private

◆ wordSize_

Word DirectAccessMemory::wordSize_
private

Size of the natural word as MAUs.

Definition at line 135 of file DirectAccessMemory.hh.


The documentation for this class was generated from the following files:
DirectAccessMemory::MAUSize_
Word MAUSize_
Size of the minimum adressable unit.
Definition: DirectAccessMemory.hh:129
Memory::littleEndian_
bool littleEndian_
Definition: Memory.hh:128
DirectAccessMemory::fastReadMAU
void fastReadMAU(ULongWord address, ULongWord &data)
Definition: DirectAccessMemory.cc:223
Memory::MAUSize
virtual ULongWord MAUSize()
Definition: Memory.hh:118
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
Memory::readBE
virtual void readBE(ULongWord address, int size, ULongWord &data)
Definition: Memory.cc:640
PagedArray::clear
void clear()
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
Memory::readLE
virtual void readLE(ULongWord address, int size, ULongWord &data)
Definition: Memory.cc:682
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
Memory::end
virtual ULongWord end()
Definition: Memory.hh:117
PagedArray::writeData
void writeData(IndexType index, const ValueType &data)
Memory::writeBE
virtual void writeBE(ULongWord address, int size, ULongWord data)
Definition: Memory.cc:194
Memory::writeLE
virtual void writeLE(ULongWord address, int size, ULongWord data)
Definition: Memory.cc:221
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
Memory::Memory
Memory(ULongWord start, ULongWord end, ULongWord MAUSize, bool littleEndian_)
Definition: Memory.cc:56
DirectAccessMemory::MAUSize2_
Word MAUSize2_
precalculated MAUSize_ * 2
Definition: DirectAccessMemory.hh:133
Memory::start
virtual ULongWord start()
Definition: Memory.hh:116