X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fbase%2Fchunk_generator.hh;h=bc71a0569c0b574e63ef79170f6dd74f69492043;hb=498ea0bdab4d092a9c7dad648f80d1132fd7e145;hp=4f708bd4bedc584444274c18a5d647c63218a780;hpb=ba2eae5d528487900d1510fc0a160e660f2c394c;p=gem5.git diff --git a/src/base/chunk_generator.hh b/src/base/chunk_generator.hh index 4f708bd4b..bc71a0569 100644 --- a/src/base/chunk_generator.hh +++ b/src/base/chunk_generator.hh @@ -24,6 +24,8 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Steve Reinhardt */ #ifndef __BASE__CHUNK_GENERATOR_HH__ @@ -35,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) @@ -59,27 +62,28 @@ 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: /** * Constructor. - * @param startAddr The starting address of the region. + * @param _startAddr The starting address of the region. * @param totalSize The total size of the region. * @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; @@ -99,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;