gem5 v24.0.0.0
Loading...
Searching...
No Matches
WriteMask.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020,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) 2012-15 Advanced Micro Devices, Inc.
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
41#ifndef __MEM_RUBY_COMMON_WRITEMASK_HH__
42#define __MEM_RUBY_COMMON_WRITEMASK_HH__
43
44#include <cassert>
45#include <iomanip>
46#include <iostream>
47#include <vector>
48
49#include "base/amo.hh"
52
53namespace gem5
54{
55
56namespace ruby
57{
58
60{
61 public:
63
64 WriteMask();
65
66 WriteMask(int size)
67 : mSize(size), mMask(size, false), mAtomic(false)
68 {}
69
71 : mSize(size), mMask(mask), mAtomic(false)
72 {}
73
75 : mSize(size), mMask(mask), mAtomic(true), mAtomicOp(atomicOp)
76 {}
77
79 {}
80
81 void
83 {
85 }
86
87 bool
88 test(int offset) const
89 {
90 assert(offset < mSize);
91 return mMask[offset];
92 }
93
94 void
95 setMask(int offset, int len, bool val = true)
96 {
97 assert(mSize >= (offset + len));
98 for (int i = 0; i < len; i++) {
99 mMask[offset + i] = val;
100 }
101 }
102 void
104 {
105 for (int i = 0; i < mSize; i++) {
106 mMask[i] = true;
107 }
108 }
109
110 bool
111 getMask(int offset, int len) const
112 {
113 bool tmp = true;
114 assert(mSize >= (offset + len));
115 for (int i = 0; i < len; i++) {
116 tmp = tmp & mMask.at(offset + i);
117 }
118 return tmp;
119 }
120
121 bool
122 isOverlap(const WriteMask &readMask) const
123 {
124 bool tmp = false;
125 assert(mSize == readMask.mSize);
126 for (int i = 0; i < mSize; i++) {
127 if (readMask.mMask.at(i)) {
128 tmp = tmp | mMask.at(i);
129 }
130 }
131 return tmp;
132 }
133
134 bool
135 containsMask(const WriteMask &readMask) const
136 {
137 bool tmp = true;
138 assert(mSize == readMask.mSize);
139 for (int i = 0; i < mSize; i++) {
140 if (readMask.mMask.at(i)) {
141 tmp = tmp & mMask.at(i);
142 }
143 }
144 return tmp;
145 }
146
147 bool isEmpty() const
148 {
149 for (int i = 0; i < mSize; i++) {
150 if (mMask.at(i)) {
151 return false;
152 }
153 }
154 return true;
155 }
156
157 bool
158 isFull() const
159 {
160 for (int i = 0; i < mSize; i++) {
161 if (!mMask.at(i)) {
162 return false;
163 }
164 }
165 return true;
166 }
167
168 void
169 andMask(const WriteMask & writeMask)
170 {
171 assert(mSize == writeMask.mSize);
172 for (int i = 0; i < mSize; i++) {
173 mMask[i] = (mMask.at(i)) && (writeMask.mMask.at(i));
174 }
175
176 if (writeMask.mAtomic) {
177 mAtomic = true;
178 mAtomicOp = writeMask.mAtomicOp;
179 }
180 }
181
182 void
183 orMask(const WriteMask & writeMask)
184 {
185 assert(mSize == writeMask.mSize);
186 for (int i = 0; i < mSize; i++) {
187 mMask[i] = (mMask.at(i)) || (writeMask.mMask.at(i));
188 }
189
190 if (writeMask.mAtomic) {
191 mAtomic = true;
192 mAtomicOp = writeMask.mAtomicOp;
193 }
194 }
195
196 void
197 setInvertedMask(const WriteMask & writeMask)
198 {
199 assert(mSize == writeMask.mSize);
200 for (int i = 0; i < mSize; i++) {
201 mMask[i] = !writeMask.mMask.at(i);
202 }
203 }
204
205 int
206 firstBitSet(bool val, int offset = 0) const
207 {
208 for (int i = offset; i < mSize; ++i)
209 if (mMask[i] == val)
210 return i;
211 return mSize;
212 }
213
214 int
215 count(int offset = 0) const
216 {
217 int count = 0;
218 for (int i = offset; i < mSize; ++i)
219 count += mMask[i];
220 return count;
221 }
222
223 void print(std::ostream& out) const;
224
225 /*
226 * Performs atomic operations on the data block pointed to by p. The
227 * atomic operations to perform are in the vector mAtomicOp. The
228 * effect of each atomic operation is pushed to the atomicChangeLog
229 * so that each individual atomic requestor may see the results of their
230 * specific atomic operation.
231 */
232 void performAtomic(uint8_t * p,
233 std::deque<uint8_t*>& atomicChangeLog,
234 bool isAtomicNoReturn=true) const;
235
236 const AtomicOpVector&
238 {
239 return mAtomicOp;
240 }
241
242 void
243 setAtomicOps(const AtomicOpVector& atomicOps)
244 {
245 mAtomic = true;
246 mAtomicOp = std::move(atomicOps);
247 }
248
249 private:
250 int mSize;
254};
255
256inline std::ostream&
257operator<<(std::ostream& out, const WriteMask& obj)
258{
259 obj.print(out);
260 out << std::flush;
261 return out;
262}
263
264} // namespace ruby
265} // namespace gem5
266
267#endif // __MEM_RUBY_COMMON_WRITEMASK_HH__
bool isFull() const
Definition WriteMask.hh:158
bool isEmpty() const
Definition WriteMask.hh:147
void performAtomic(uint8_t *p, std::deque< uint8_t * > &atomicChangeLog, bool isAtomicNoReturn=true) const
Definition WriteMask.cc:59
bool getMask(int offset, int len) const
Definition WriteMask.hh:111
bool isOverlap(const WriteMask &readMask) const
Definition WriteMask.hh:122
AtomicOpVector mAtomicOp
Definition WriteMask.hh:253
std::vector< std::pair< int, AtomicOpFunctor * > > AtomicOpVector
Definition WriteMask.hh:62
bool containsMask(const WriteMask &readMask) const
Definition WriteMask.hh:135
int count(int offset=0) const
Definition WriteMask.hh:215
void setMask(int offset, int len, bool val=true)
Definition WriteMask.hh:95
std::vector< bool > mMask
Definition WriteMask.hh:251
WriteMask(int size, std::vector< bool > &mask, AtomicOpVector atomicOp)
Definition WriteMask.hh:74
void setInvertedMask(const WriteMask &writeMask)
Definition WriteMask.hh:197
bool test(int offset) const
Definition WriteMask.hh:88
void orMask(const WriteMask &writeMask)
Definition WriteMask.hh:183
const AtomicOpVector & getAtomicOps() const
Definition WriteMask.hh:237
WriteMask(int size, std::vector< bool > &mask)
Definition WriteMask.hh:70
void print(std::ostream &out) const
Definition WriteMask.cc:47
void andMask(const WriteMask &writeMask)
Definition WriteMask.hh:169
void setAtomicOps(const AtomicOpVector &atomicOps)
Definition WriteMask.hh:243
int firstBitSet(bool val, int offset=0) const
Definition WriteMask.hh:206
STL deque class.
Definition stl.hh:44
STL vector class.
Definition stl.hh:37
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
Bitfield< 0 > p
Bitfield< 63 > val
Definition misc.hh:804
std::ostream & operator<<(std::ostream &os, const BoolVec &myvector)
Definition BoolVec.cc:49
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