gem5 v24.0.0.0
Loading...
Searching...
No Matches
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 uint8_t *block_update;
55 size_t block_bytes = RubySystem::getBlockSizeBytes();
56 m_data = new uint8_t[block_bytes];
57 memcpy(m_data, cp.m_data, block_bytes);
58 m_alloc = true;
59 // If this data block is involved in an atomic operation, the effect
60 // of applying the atomic operations on the data block are recorded in
61 // m_atomicLog. If so, we must copy over every entry in the change log
62 for (size_t i = 0; i < cp.m_atomicLog.size(); i++) {
63 block_update = new uint8_t[block_bytes];
64 memcpy(block_update, cp.m_atomicLog[i], block_bytes);
65 m_atomicLog.push_back(block_update);
66 }
67}
68
69void
71{
73 m_alloc = true;
74 clear();
75}
76
77void
82
83bool
84DataBlock::equal(const DataBlock& obj) const
85{
86 size_t block_bytes = RubySystem::getBlockSizeBytes();
87 // Check that the block contents match
88 if (memcmp(m_data, obj.m_data, block_bytes)) {
89 return false;
90 }
91 if (m_atomicLog.size() != obj.m_atomicLog.size()) {
92 return false;
93 }
94 for (size_t i = 0; i < m_atomicLog.size(); i++) {
95 if (memcmp(m_atomicLog[i], obj.m_atomicLog[i], block_bytes)) {
96 return false;
97 }
98 }
99 return true;
100}
101
102void
104{
105 for (int i = 0; i < RubySystem::getBlockSizeBytes(); i++) {
106 if (mask.getMask(i, 1)) {
107 m_data[i] = dblk.m_data[i];
108 }
109 }
110}
111
112void
114 bool isAtomicNoReturn)
115{
116 for (int i = 0; i < RubySystem::getBlockSizeBytes(); i++) {
117 m_data[i] = dblk.m_data[i];
118 }
119 mask.performAtomic(m_data, m_atomicLog, isAtomicNoReturn);
120}
121
122void
123DataBlock::print(std::ostream& out) const
124{
126 out << "[ ";
127 for (int i = 0; i < size; i++) {
128 out << std::setw(2) << std::setfill('0') << std::hex
129 << "0x" << (int)m_data[i] << " " << std::setfill(' ');
130 }
131 out << std::dec << "]" << std::flush;
132}
133
134int
136{
137 return m_atomicLog.size();
138}
139uint8_t*
141{
142 assert(m_atomicLog.size() > 0);
143 auto ret = m_atomicLog.front();
144 m_atomicLog.pop_front();
145 return ret;
146}
147void
149{
150 for (auto log : m_atomicLog) {
151 delete [] log;
152 }
153 m_atomicLog.clear();
154}
155
156const uint8_t*
158{
160 return &m_data[offset];
161}
162
163uint8_t*
165{
166 return &m_data[offset];
167}
168
169void
170DataBlock::setData(const uint8_t *data, int offset, int len)
171{
172 memcpy(&m_data[offset], data, len);
173}
174
175void
177{
178 int offset = getOffset(pkt->getAddr());
179 assert(offset + pkt->getSize() <= RubySystem::getBlockSizeBytes());
180 pkt->writeData(&m_data[offset]);
181}
182
183DataBlock &
185{
186 uint8_t *block_update;
187 size_t block_bytes = RubySystem::getBlockSizeBytes();
188 // Copy entire block contents from obj to current block
189 memcpy(m_data, obj.m_data, block_bytes);
190 // If this data block is involved in an atomic operation, the effect
191 // of applying the atomic operations on the data block are recorded in
192 // m_atomicLog. If so, we must copy over every entry in the change log
193 for (size_t i = 0; i < obj.m_atomicLog.size(); i++) {
194 block_update = new uint8_t[block_bytes];
195 memcpy(block_update, obj.m_atomicLog[i], block_bytes);
196 m_atomicLog.push_back(block_update);
197 }
198 return *this;
199}
200
201} // namespace ruby
202} // 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:113
const uint8_t * getData(int offset, int len) const
Definition DataBlock.cc:157
uint8_t * popAtomicLogEntryFront()
Definition DataBlock.cc:140
void copyPartial(const DataBlock &dblk, int offset, int len)
Definition DataBlock.hh:137
uint8_t * getDataMod(int offset)
Definition DataBlock.cc:164
int numAtomicLogEntries() const
Definition DataBlock.cc:135
DataBlock & operator=(const DataBlock &obj)
Definition DataBlock.cc:184
bool equal(const DataBlock &obj) const
Definition DataBlock.cc:84
std::deque< uint8_t * > m_atomicLog
Definition DataBlock.hh:110
void print(std::ostream &out) const
Definition DataBlock.cc:123
void setData(const uint8_t *data, int offset, int len)
Definition DataBlock.cc:170
static uint32_t getBlockSizeBytes()
Definition RubySystem.hh:72
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)
Definition Address.cc:54
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36

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