X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fbase%2Fchunk_generator.hh;h=bc71a0569c0b574e63ef79170f6dd74f69492043;hb=498ea0bdab4d092a9c7dad648f80d1132fd7e145;hp=e8238464be94b129636ac7b3ff831a6476c2cd29;hpb=d0d0d7b636c20ad0fafec885c246711ec4218fff;p=gem5.git diff --git a/src/base/chunk_generator.hh b/src/base/chunk_generator.hh index e8238464b..bc71a0569 100644 --- a/src/base/chunk_generator.hh +++ b/src/base/chunk_generator.hh @@ -37,8 +37,9 @@ */ #include + #include "base/intmath.hh" -#include "arch/isa_traits.hh" // for Addr +#include "base/types.hh" /** * This class takes an arbitrary memory region (address/length pair) @@ -61,13 +62,13 @@ class ChunkGenerator /** The starting address of the next chunk (after the current one). */ Addr nextAddr; /** The size of the current chunk (in bytes). */ - int curSize; + unsigned curSize; /** The number of bytes remaining in the region after the current chunk. */ - int sizeLeft; + unsigned sizeLeft; /** The start address so we can calculate offset in writing block. */ const Addr startAddr; /** The maximum chunk size, e.g., the cache block size or page size. */ - const int chunkSize; + const unsigned chunkSize; public: /** @@ -77,11 +78,12 @@ class ChunkGenerator * @param _chunkSize The size/alignment of chunks into which * the region should be decomposed. */ - ChunkGenerator(Addr _startAddr, int totalSize, int _chunkSize) + ChunkGenerator(Addr _startAddr, unsigned totalSize, unsigned _chunkSize) : startAddr(_startAddr), chunkSize(_chunkSize) { // chunkSize must be a power of two assert(chunkSize == 0 || isPowerOf2(chunkSize)); + assert(totalSize >= 0); // set up initial chunk. curAddr = startAddr; @@ -101,31 +103,33 @@ class ChunkGenerator } // how many bytes are left between curAddr and the end of this chunk? - int left_in_chunk = nextAddr - curAddr; + unsigned left_in_chunk = nextAddr - curAddr; curSize = std::min(totalSize, left_in_chunk); sizeLeft = totalSize - curSize; } /** Return starting address of current chunk. */ - Addr addr() { return curAddr; } + Addr addr() const { return curAddr; } /** Return size in bytes of current chunk. */ - int size() { return curSize; } + unsigned size() const { return curSize; } /** Number of bytes we have already chunked up. */ - int complete() { return curAddr - startAddr; } + unsigned complete() const { return curAddr - startAddr; } + /** * Are we done? That is, did the last call to next() advance * past the end of the region? * @return True if yes, false if more to go. */ - bool done() { return (curSize == 0); } + bool done() const { return (curSize == 0); } /** * Advance generator to next chunk. * @return True if successful, false if unsuccessful * (because we were at the last chunk). */ - bool next() + bool + next() { if (sizeLeft == 0) { curSize = 0;