gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
53 class WriteMask
54 {
55  public:
57 
58  WriteMask();
59 
60  WriteMask(int size)
61  : mSize(size), mMask(size, false), mAtomic(false)
62  {}
63 
65  : mSize(size), mMask(mask), mAtomic(false)
66  {}
67 
69  : mSize(size), mMask(mask), mAtomic(true), mAtomicOp(atomicOp)
70  {}
71 
73  {}
74 
75  void
77  {
78  mMask = std::vector<bool>(mSize, false);
79  }
80 
81  bool
82  test(int offset) const
83  {
84  assert(offset < mSize);
85  return mMask[offset];
86  }
87 
88  void
89  setMask(int offset, int len, bool val = true)
90  {
91  assert(mSize >= (offset + len));
92  for (int i = 0; i < len; i++) {
93  mMask[offset + i] = val;
94  }
95  }
96  void
98  {
99  for (int i = 0; i < mSize; i++) {
100  mMask[i] = true;
101  }
102  }
103 
104  bool
105  getMask(int offset, int len) const
106  {
107  bool tmp = true;
108  assert(mSize >= (offset + len));
109  for (int i = 0; i < len; i++) {
110  tmp = tmp & mMask.at(offset + i);
111  }
112  return tmp;
113  }
114 
115  bool
116  isOverlap(const WriteMask &readMask) const
117  {
118  bool tmp = false;
119  assert(mSize == readMask.mSize);
120  for (int i = 0; i < mSize; i++) {
121  if (readMask.mMask.at(i)) {
122  tmp = tmp | mMask.at(i);
123  }
124  }
125  return tmp;
126  }
127 
128  bool
129  cmpMask(const WriteMask &readMask) const
130  {
131  bool tmp = true;
132  assert(mSize == readMask.mSize);
133  for (int i = 0; i < mSize; i++) {
134  if (readMask.mMask.at(i)) {
135  tmp = tmp & mMask.at(i);
136  }
137  }
138  return tmp;
139  }
140 
141  bool isEmpty() const
142  {
143  for (int i = 0; i < mSize; i++) {
144  if (mMask.at(i)) {
145  return false;
146  }
147  }
148  return true;
149  }
150 
151  bool
152  isFull() const
153  {
154  for (int i = 0; i < mSize; i++) {
155  if (!mMask.at(i)) {
156  return false;
157  }
158  }
159  return true;
160  }
161 
162  void
163  andMask(const WriteMask & writeMask)
164  {
165  assert(mSize == writeMask.mSize);
166  for (int i = 0; i < mSize; i++) {
167  mMask[i] = (mMask.at(i)) & (writeMask.mMask.at(i));
168  }
169 
170  if (writeMask.mAtomic) {
171  mAtomic = true;
172  mAtomicOp = writeMask.mAtomicOp;
173  }
174  }
175 
176  void
177  orMask(const WriteMask & writeMask)
178  {
179  assert(mSize == writeMask.mSize);
180  for (int i = 0; i < mSize; i++) {
181  mMask[i] = (mMask.at(i)) | (writeMask.mMask.at(i));
182  }
183 
184  if (writeMask.mAtomic) {
185  mAtomic = true;
186  mAtomicOp = writeMask.mAtomicOp;
187  }
188  }
189 
190  void
191  setInvertedMask(const WriteMask & writeMask)
192  {
193  assert(mSize == writeMask.mSize);
194  for (int i = 0; i < mSize; i++) {
195  mMask[i] = !writeMask.mMask.at(i);
196  }
197  }
198 
199  int
200  firstBitSet(bool val, int offset = 0) const
201  {
202  for (int i = offset; i < mSize; ++i)
203  if (mMask[i] == val)
204  return i;
205  return mSize;
206  }
207 
208  int
209  count(int offset = 0) const
210  {
211  int count = 0;
212  for (int i = offset; i < mSize; ++i)
213  count += mMask[i];
214  return count;
215  }
216 
217  void print(std::ostream& out) const;
218 
219  void
220  performAtomic(uint8_t * p) const
221  {
222  for (int i = 0; i < mAtomicOp.size(); i++) {
223  int offset = mAtomicOp[i].first;
224  AtomicOpFunctor *fnctr = mAtomicOp[i].second;
225  (*fnctr)(&p[offset]);
226  }
227  }
228 
229  void
231  {
232  for (int i = 0; i < mAtomicOp.size(); i++) {
233  int offset = mAtomicOp[i].first;
234  uint8_t *p = blk.getDataMod(offset);
235  AtomicOpFunctor *fnctr = mAtomicOp[i].second;
236  (*fnctr)(p);
237  }
238  }
239 
240  const AtomicOpVector&
241  getAtomicOps() const
242  {
243  return mAtomicOp;
244  }
245 
246  void
247  setAtomicOps(const AtomicOpVector& atomicOps)
248  {
249  mAtomic = true;
250  mAtomicOp = std::move(atomicOps);
251  }
252 
253  private:
254  int mSize;
256  bool mAtomic;
258 };
259 
260 inline std::ostream&
261 operator<<(std::ostream& out, const WriteMask& obj)
262 {
263  obj.print(out);
264  out << std::flush;
265  return out;
266 }
267 
268 #endif // __MEM_RUBY_COMMON_WRITEMASK_HH__
WriteMask::WriteMask
WriteMask(int size, std::vector< bool > &mask, AtomicOpVector atomicOp)
Definition: WriteMask.hh:68
WriteMask::cmpMask
bool cmpMask(const WriteMask &readMask) const
Definition: WriteMask.hh:129
WriteMask::test
bool test(int offset) const
Definition: WriteMask.hh:82
amo.hh
WriteMask::firstBitSet
int firstBitSet(bool val, int offset=0) const
Definition: WriteMask.hh:200
WriteMask::clear
void clear()
Definition: WriteMask.hh:76
WriteMask::mMask
std::vector< bool > mMask
Definition: WriteMask.hh:255
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
operator<<
std::ostream & operator<<(std::ostream &out, const WriteMask &obj)
Definition: WriteMask.hh:261
WriteMask::setAtomicOps
void setAtomicOps(const AtomicOpVector &atomicOps)
Definition: WriteMask.hh:247
WriteMask::andMask
void andMask(const WriteMask &writeMask)
Definition: WriteMask.hh:163
std::vector
STL vector class.
Definition: stl.hh:37
WriteMask::setMask
void setMask(int offset, int len, bool val=true)
Definition: WriteMask.hh:89
WriteMask::~WriteMask
~WriteMask()
Definition: WriteMask.hh:72
DataBlock
Definition: DataBlock.hh:54
AtomicOpFunctor
Definition: amo.hh:40
WriteMask::isFull
bool isFull() const
Definition: WriteMask.hh:152
WriteMask::getMask
bool getMask(int offset, int len) const
Definition: WriteMask.hh:105
WriteMask::WriteMask
WriteMask(int size, std::vector< bool > &mask)
Definition: WriteMask.hh:64
WriteMask::isOverlap
bool isOverlap(const WriteMask &readMask) const
Definition: WriteMask.hh:116
DataBlock.hh
TypeDefines.hh
WriteMask::performAtomic
void performAtomic(DataBlock &blk) const
Definition: WriteMask.hh:230
WriteMask::isEmpty
bool isEmpty() const
Definition: WriteMask.hh:141
WriteMask::WriteMask
WriteMask(int size)
Definition: WriteMask.hh:60
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
WriteMask::count
int count(int offset=0) const
Definition: WriteMask.hh:209
WriteMask::print
void print(std::ostream &out) const
Definition: WriteMask.cc:41
WriteMask::WriteMask
WriteMask()
Definition: WriteMask.cc:35
WriteMask::setInvertedMask
void setInvertedMask(const WriteMask &writeMask)
Definition: WriteMask.hh:191
WriteMask::getAtomicOps
const AtomicOpVector & getAtomicOps() const
Definition: WriteMask.hh:241
WriteMask::mSize
int mSize
Definition: WriteMask.hh:254
ArmISA::len
Bitfield< 18, 16 > len
Definition: miscregs_types.hh:439
DataBlock::getDataMod
uint8_t * getDataMod(int offset)
Definition: DataBlock.cc:112
WriteMask::mAtomic
bool mAtomic
Definition: WriteMask.hh:256
WriteMask::performAtomic
void performAtomic(uint8_t *p) const
Definition: WriteMask.hh:220
WriteMask::orMask
void orMask(const WriteMask &writeMask)
Definition: WriteMask.hh:177
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
WriteMask::AtomicOpVector
std::vector< std::pair< int, AtomicOpFunctor * > > AtomicOpVector
Definition: WriteMask.hh:56
WriteMask::mAtomicOp
AtomicOpVector mAtomicOp
Definition: WriteMask.hh:257
WriteMask
Definition: WriteMask.hh:53
WriteMask::fillMask
void fillMask()
Definition: WriteMask.hh:97
ArmISA::mask
Bitfield< 28, 24 > mask
Definition: miscregs_types.hh:711
ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:153

Generated on Tue Mar 23 2021 19:41:28 for gem5 by doxygen 1.8.17