29 #ifndef __BASE__CHUNK_GENERATOR_HH__ 30 #define __BASE__CHUNK_GENERATOR_HH__ 80 : startAddr(_startAddr), chunkSize(_chunkSize)
83 assert(chunkSize == 0 ||
isPowerOf2(chunkSize));
90 nextAddr = startAddr + totalSize;
95 nextAddr =
roundUp(startAddr, chunkSize);
96 if (curAddr == nextAddr) {
103 unsigned left_in_chunk = nextAddr -
curAddr;
104 curSize = std::min(totalSize, left_in_chunk);
105 sizeLeft = totalSize -
curSize;
121 bool done()
const {
return (curSize == 0); }
127 bool last()
const {
return (sizeLeft == 0); }
143 curSize = std::min(sizeLeft, chunkSize);
150 #endif // __BASE__CHUNK_GENERATOR_HH__
bool next()
Advance generator to next chunk.
Addr curAddr
The starting address of the current chunk.
bool last() const
Is this the last chunk?
T roundUp(const T &val, const U &align)
This function is used to align addresses in memory.
unsigned curSize
The size of the current chunk (in bytes).
unsigned sizeLeft
The number of bytes remaining in the region after the current chunk.
unsigned size() const
Return size in bytes of current chunk.
This class takes an arbitrary memory region (address/length pair) and generates a series of appropria...
ChunkGenerator(Addr _startAddr, unsigned totalSize, unsigned _chunkSize)
Constructor.
const Addr startAddr
The start address so we can calculate offset in writing block.
bool isPowerOf2(const T &n)
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
bool done() const
Are we done? That is, did the last call to next() advance past the end of the region?
Addr nextAddr
The starting address of the next chunk (after the current one).
unsigned complete() const
Number of bytes we have already chunked up.
const unsigned chunkSize
The maximum chunk size, e.g., the cache block size or page size.
Addr addr() const
Return starting address of current chunk.