gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DataBlock.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 ARM Limited
3 * All rights reserved.
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
42
45
46namespace gem5
47{
48
49namespace ruby
50{
51
53{
54 assert(cp.isAlloc());
55 assert(cp.getBlockSize() > 0);
56 assert(!m_alloc);
57
58 uint8_t *block_update;
60 m_data = new uint8_t[m_block_size];
61 memcpy(m_data, cp.m_data, m_block_size);
62 m_alloc = true;
63 // If this data block is involved in an atomic operation, the effect
64 // of applying the atomic operations on the data block are recorded in
65 // m_atomicLog. If so, we must copy over every entry in the change log
66 for (size_t i = 0; i < cp.m_atomicLog.size(); i++) {
67 block_update = new uint8_t[m_block_size];
68 memcpy(block_update, cp.m_atomicLog[i], m_block_size);
69 m_atomicLog.push_back(block_update);
70 }
71}
72
73void
75{
76 assert(!m_alloc);
77
78 if (!m_block_size) {
79 return;
80 }
81
82 m_data = new uint8_t[m_block_size];
83 m_alloc = true;
84 clear();
85}
86
87void
88DataBlock::realloc(int blk_size)
89{
90 m_block_size = blk_size;
91 assert(m_block_size > 0);
92
93 if (m_alloc) {
94 delete [] m_data;
95 m_alloc = false;
96 }
97 alloc();
98}
99
100void
102{
103 assert(m_alloc);
104 assert(m_block_size > 0);
105 memset(m_data, 0, m_block_size);
106}
107
108bool
110{
111 assert(m_alloc);
112 assert(m_block_size > 0);
113 size_t block_bytes = m_block_size;
114 // Check that the block contents match
115 if (memcmp(m_data, obj.m_data, block_bytes)) {
116 return false;
117 }
118 if (m_atomicLog.size() != obj.m_atomicLog.size()) {
119 return false;
120 }
121 for (size_t i = 0; i < m_atomicLog.size(); i++) {
122 if (memcmp(m_atomicLog[i], obj.m_atomicLog[i], block_bytes)) {
123 return false;
124 }
125 }
126 return true;
127}
128
129void
131{
132 assert(m_alloc);
133 assert(m_block_size > 0);
134 for (int i = 0; i < m_block_size; i++) {
135 if (mask.getMask(i, 1)) {
136 m_data[i] = dblk.m_data[i];
137 }
138 }
139}
140
141void
143 bool isAtomicNoReturn)
144{
145 assert(m_alloc);
146 assert(m_block_size > 0);
147 for (int i = 0; i < m_block_size; i++) {
148 m_data[i] = dblk.m_data[i];
149 }
150 mask.performAtomic(m_data, m_atomicLog, isAtomicNoReturn);
151}
152
153void
154DataBlock::print(std::ostream& out) const
155{
156 assert(m_alloc);
157 assert(m_block_size > 0);
158 int size = m_block_size;
159 out << "[ ";
160 for (int i = 0; i < size; i++) {
161 out << std::setw(2) << std::setfill('0') << std::hex
162 << "0x" << (int)m_data[i] << " " << std::setfill(' ');
163 }
164 out << std::dec << "]" << std::flush;
165}
166
167int
169{
170 return m_atomicLog.size();
171}
172uint8_t*
174{
175 assert(m_atomicLog.size() > 0);
176 auto ret = m_atomicLog.front();
177 m_atomicLog.pop_front();
178 return ret;
179}
180void
182{
183 assert(m_alloc);
184 for (auto log : m_atomicLog) {
185 delete [] log;
186 }
187 m_atomicLog.clear();
188}
189
190const uint8_t*
192{
193 assert(m_alloc);
194 assert(m_block_size > 0);
195 assert(offset + len <= m_block_size);
196 return &m_data[offset];
197}
198
199uint8_t*
201{
202 assert(m_alloc);
203 return &m_data[offset];
204}
205
206void
207DataBlock::setData(const uint8_t *data, int offset, int len)
208{
209 assert(m_alloc);
210 memcpy(&m_data[offset], data, len);
211}
212
213void
215{
216 assert(m_alloc);
217 assert(m_block_size > 0);
219 assert(offset + pkt->getSize() <= m_block_size);
220 pkt->writeData(&m_data[offset]);
221}
222
223DataBlock &
225{
226 // Reallocate if needed
227 if (m_alloc && m_block_size != obj.getBlockSize()) {
228 delete [] m_data;
230 alloc();
231 } else if (!m_alloc) {
233 alloc();
234
235 // Assume this will be realloc'd later if zero.
236 if (m_block_size == 0) {
237 return *this;
238 }
239 } else {
240 assert(m_alloc && m_block_size == obj.getBlockSize());
241 }
242 assert(m_block_size > 0);
243
244 uint8_t *block_update;
245 size_t block_bytes = m_block_size;
246 // Copy entire block contents from obj to current block
247 memcpy(m_data, obj.m_data, block_bytes);
248 // If this data block is involved in an atomic operation, the effect
249 // of applying the atomic operations on the data block are recorded in
250 // m_atomicLog. If so, we must copy over every entry in the change log
251 for (size_t i = 0; i < obj.m_atomicLog.size(); i++) {
252 block_update = new uint8_t[block_bytes];
253 memcpy(block_update, obj.m_atomicLog[i], block_bytes);
254 m_atomicLog.push_back(block_update);
255 }
256 return *this;
257}
258
259} // namespace ruby
260} // namespace gem5
const char data[]
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Addr getAddr() const
Definition packet.hh:807
unsigned getSize() const
Definition packet.hh:817
void writeData(uint8_t *p) const
Copy data from the packet to the memory at the provided pointer.
Definition packet.hh:1322
void atomicPartial(const DataBlock &dblk, const WriteMask &mask, bool isAtomicNoReturn=true)
Definition DataBlock.cc:142
const uint8_t * getData(int offset, int len) const
Definition DataBlock.cc:191
uint8_t * popAtomicLogEntryFront()
Definition DataBlock.cc:173
void copyPartial(const DataBlock &dblk, int offset, int len)
Definition DataBlock.hh:151
uint8_t * getDataMod(int offset)
Definition DataBlock.cc:200
bool isAlloc() const
Definition DataBlock.hh:112
int numAtomicLogEntries() const
Definition DataBlock.cc:168
DataBlock & operator=(const DataBlock &obj)
Definition DataBlock.cc:224
bool equal(const DataBlock &obj) const
Definition DataBlock.cc:109
void realloc(int blk_size)
Definition DataBlock.cc:88
int getBlockSize() const
Definition DataBlock.hh:110
std::deque< uint8_t * > m_atomicLog
Definition DataBlock.hh:122
void print(std::ostream &out) const
Definition DataBlock.cc:154
void setData(const uint8_t *data, int offset, int len)
Definition DataBlock.cc:207
static constexpr std::enable_if_t< std::is_integral_v< T >, int > floorLog2(T x)
Definition intmath.hh:59
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
Bitfield< 18, 16 > len
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 23, 0 > offset
Definition types.hh:144
Addr getOffset(Addr addr, int cacheLineBits)
Definition Address.cc:54
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36

Generated on Mon Jan 13 2025 04:28:40 for gem5 by doxygen 1.9.8