gem5 v24.0.0.0
Loading...
Searching...
No Matches
chunk_generator.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __BASE_CHUNK_GENERATOR_HH__
30#define __BASE_CHUNK_GENERATOR_HH__
31
37#include <algorithm>
38#include <cassert>
39
40#include "base/intmath.hh"
41#include "base/types.hh"
42
43namespace gem5
44{
45
60{
61 private:
76
77 public:
87 ChunkGenerator(Addr _startAddr, Addr totalSize, Addr _chunkSize) :
88 startAddr(_startAddr), chunkSize(_chunkSize)
89 {
90 // chunkSize must be a power of two
91 assert(chunkSize == 0 || isPowerOf2(chunkSize));
92
93 // set up initial chunk.
95
96 if (chunkSize == 0) { // Special Case, if we see 0, assume no chunking.
97 nextAddr = startAddr + totalSize;
98 } else {
99 // nextAddr should be *next* chunk start.
101 if (curAddr == nextAddr) {
102 // ... even if startAddr is already chunk-aligned
104 }
105 nextAddr = std::min(nextAddr, startAddr + totalSize);
106 }
107
108 // How many bytes are left between curAddr and the end of this chunk?
110 sizeLeft = totalSize - curSize;
111 nextSize = std::min(sizeLeft, chunkSize);
112 }
113
119 Addr addr() const { return curAddr; }
125 Addr size() const { return curSize; }
126
132 Addr complete() const { return curAddr - startAddr; }
133
141 bool done() const { return curSize == 0; }
142
149 bool last() const { return sizeLeft == 0; }
150
157 void
159 {
160 assert(next >= nextAddr);
161
162 const Addr skipping = std::min(next - nextAddr, sizeLeft);
163
164 sizeLeft -= skipping;
165 curSize += skipping;
166 nextAddr = next;
167
168 assert(chunkSize);
169
170 // nextSize will be enough to get to an alignment boundary,
172 // or if it's already aligned, to the following boundary or the end.
173 if (!nextSize)
174 nextSize = std::min(sizeLeft, chunkSize);
175 }
176
184 bool
186 {
187 if (last()) {
188 curSize = 0;
189 return false;
190 }
191
194 sizeLeft -= curSize;
195 nextAddr += curSize;
196 nextSize = std::min(sizeLeft, chunkSize);
197 return true;
198 }
199};
200
201} // namespace gem5
202
203#endif // __BASE_CHUNK_GENERATOR_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
This class takes an arbitrary memory region (address/length pair) and generates a series of appropria...
const Addr chunkSize
The maximum chunk size, e.g., the cache block size or page size.
Addr curSize
The size of the current chunk (in bytes).
Addr nextSize
The size of the next chunk (in bytes).
Addr sizeLeft
The number of bytes remaining in the region after the current chunk.
Addr curAddr
The starting address of the current chunk.
Addr nextAddr
The starting address of the next chunk (after the current one).
const Addr startAddr
The start address so we can calculate offset in writing block.
static constexpr bool isPowerOf2(const T &n)
Definition intmath.hh:98
static constexpr T roundUp(const T &val, const U &align)
This function is used to align addresses in memory.
Definition intmath.hh:260
bool last() const
Is this the last chunk?
Addr addr() const
Return starting address of current chunk.
Addr complete() const
Number of bytes we have already chunked up.
ChunkGenerator(Addr _startAddr, Addr totalSize, Addr _chunkSize)
Constructor.
void setNext(Addr next)
Grow this chunk to cover additional bytes which are already handled.
bool done() const
Are we done? That is, did the last call to next() advance past the end of the region?
Addr size() const
Return size in bytes of current chunk.
bool next()
Advance generator to next chunk.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147

Generated on Tue Jun 18 2024 16:24:00 for gem5 by doxygen 1.11.0