31 #ifndef __BASE__CHUNK_GENERATOR_HH__ 32 #define __BASE__CHUNK_GENERATOR_HH__ 82 : startAddr(_startAddr), chunkSize(_chunkSize)
85 assert(chunkSize == 0 ||
isPowerOf2(chunkSize));
92 nextAddr = startAddr + totalSize;
97 nextAddr =
roundUp(startAddr, chunkSize);
98 if (curAddr == nextAddr) {
105 unsigned left_in_chunk = nextAddr -
curAddr;
106 curSize = std::min(totalSize, left_in_chunk);
107 sizeLeft = totalSize -
curSize;
123 bool done()
const {
return (curSize == 0); }
129 bool last()
const {
return (sizeLeft == 0); }
145 curSize = std::min(sizeLeft, chunkSize);
152 #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.