gem5  v21.1.0.2
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 
43 namespace gem5
44 {
45 
60 {
61  private:
73  const Addr startAddr;
75  const Addr chunkSize;
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
103  nextAddr += chunkSize;
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 
192  curAddr = nextAddr;
193  curSize = nextSize;
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__
gem5::ChunkGenerator::chunkSize
const Addr chunkSize
The maximum chunk size, e.g., the cache block size or page size.
Definition: chunk_generator.hh:75
gem5::ChunkGenerator::nextAddr
Addr nextAddr
The starting address of the next chunk (after the current one).
Definition: chunk_generator.hh:65
gem5::ChunkGenerator::curAddr
Addr curAddr
The starting address of the current chunk.
Definition: chunk_generator.hh:63
gem5::ChunkGenerator::next
bool next()
Advance generator to next chunk.
Definition: chunk_generator.hh:185
gem5::ChunkGenerator::complete
Addr complete() const
Number of bytes we have already chunked up.
Definition: chunk_generator.hh:132
gem5::ChunkGenerator::nextSize
Addr nextSize
The size of the next chunk (in bytes).
Definition: chunk_generator.hh:69
gem5::ChunkGenerator::sizeLeft
Addr sizeLeft
The number of bytes remaining in the region after the current chunk.
Definition: chunk_generator.hh:71
gem5::isPowerOf2
static constexpr bool isPowerOf2(const T &n)
Definition: intmath.hh:98
gem5::ChunkGenerator::last
bool last() const
Is this the last chunk?
Definition: chunk_generator.hh:149
gem5::ChunkGenerator::size
Addr size() const
Return size in bytes of current chunk.
Definition: chunk_generator.hh:125
gem5::ChunkGenerator
This class takes an arbitrary memory region (address/length pair) and generates a series of appropria...
Definition: chunk_generator.hh:59
gem5::ChunkGenerator::curSize
Addr curSize
The size of the current chunk (in bytes).
Definition: chunk_generator.hh:67
gem5::ChunkGenerator::done
bool done() const
Are we done? That is, did the last call to next() advance past the end of the region?
Definition: chunk_generator.hh:141
gem5::ChunkGenerator::startAddr
const Addr startAddr
The start address so we can calculate offset in writing block.
Definition: chunk_generator.hh:73
gem5::ChunkGenerator::ChunkGenerator
ChunkGenerator(Addr _startAddr, Addr totalSize, Addr _chunkSize)
Constructor.
Definition: chunk_generator.hh:87
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
types.hh
gem5::ChunkGenerator::setNext
void setNext(Addr next)
Grow this chunk to cover additional bytes which are already handled.
Definition: chunk_generator.hh:158
gem5::ChunkGenerator::addr
Addr addr() const
Return starting address of current chunk.
Definition: chunk_generator.hh:119
gem5::roundUp
static constexpr T roundUp(const T &val, const U &align)
This function is used to align addresses in memory.
Definition: intmath.hh:260
intmath.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40

Generated on Tue Sep 21 2021 12:24:54 for gem5 by doxygen 1.8.17