gem5  v21.1.0.2
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 namespace gem5
54 {
55 
56 namespace ruby
57 {
58 
59 class WriteMask
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  {
84  mMask = std::vector<bool>(mSize, false);
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  void
226  performAtomic(uint8_t * p) const
227  {
228  for (int i = 0; i < mAtomicOp.size(); i++) {
229  int offset = mAtomicOp[i].first;
230  AtomicOpFunctor *fnctr = mAtomicOp[i].second;
231  (*fnctr)(&p[offset]);
232  }
233  }
234 
235  void
237  {
238  for (int i = 0; i < mAtomicOp.size(); i++) {
239  int offset = mAtomicOp[i].first;
240  uint8_t *p = blk.getDataMod(offset);
241  AtomicOpFunctor *fnctr = mAtomicOp[i].second;
242  (*fnctr)(p);
243  }
244  }
245 
246  const AtomicOpVector&
247  getAtomicOps() const
248  {
249  return mAtomicOp;
250  }
251 
252  void
253  setAtomicOps(const AtomicOpVector& atomicOps)
254  {
255  mAtomic = true;
256  mAtomicOp = std::move(atomicOps);
257  }
258 
259  private:
260  int mSize;
262  bool mAtomic;
264 };
265 
266 inline std::ostream&
267 operator<<(std::ostream& out, const WriteMask& obj)
268 {
269  obj.print(out);
270  out << std::flush;
271  return out;
272 }
273 
274 } // namespace ruby
275 } // namespace gem5
276 
277 #endif // __MEM_RUBY_COMMON_WRITEMASK_HH__
gem5::ruby::WriteMask::setAtomicOps
void setAtomicOps(const AtomicOpVector &atomicOps)
Definition: WriteMask.hh:253
gem5::ArmISA::len
Bitfield< 18, 16 > len
Definition: misc_types.hh:444
gem5::ruby::WriteMask
Definition: WriteMask.hh:59
gem5::ruby::WriteMask::performAtomic
void performAtomic(uint8_t *p) const
Definition: WriteMask.hh:226
gem5::AtomicOpFunctor
Definition: amo.hh:43
amo.hh
gem5::ruby::operator<<
std::ostream & operator<<(std::ostream &os, const BoolVec &myvector)
Definition: BoolVec.cc:49
gem5::ruby::WriteMask::mMask
std::vector< bool > mMask
Definition: WriteMask.hh:261
gem5::ruby::WriteMask::performAtomic
void performAtomic(DataBlock &blk) const
Definition: WriteMask.hh:236
gem5::ruby::WriteMask::setInvertedMask
void setInvertedMask(const WriteMask &writeMask)
Definition: WriteMask.hh:197
gem5::ruby::WriteMask::WriteMask
WriteMask()
Definition: WriteMask.cc:41
gem5::ruby::WriteMask::getMask
bool getMask(int offset, int len) const
Definition: WriteMask.hh:111
gem5::X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:775
gem5::ruby::WriteMask::getAtomicOps
const AtomicOpVector & getAtomicOps() const
Definition: WriteMask.hh:247
std::vector
STL vector class.
Definition: stl.hh:37
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::mask
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
gem5::ruby::WriteMask::print
void print(std::ostream &out) const
Definition: WriteMask.cc:47
gem5::ruby::WriteMask::test
bool test(int offset) const
Definition: WriteMask.hh:88
gem5::ruby::WriteMask::isFull
bool isFull() const
Definition: WriteMask.hh:158
gem5::ruby::WriteMask::setMask
void setMask(int offset, int len, bool val=true)
Definition: WriteMask.hh:95
DataBlock.hh
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
TypeDefines.hh
gem5::ruby::WriteMask::clear
void clear()
Definition: WriteMask.hh:82
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::ruby::WriteMask::mAtomicOp
AtomicOpVector mAtomicOp
Definition: WriteMask.hh:263
gem5::ruby::WriteMask::fillMask
void fillMask()
Definition: WriteMask.hh:103
gem5::ruby::WriteMask::WriteMask
WriteMask(int size, std::vector< bool > &mask, AtomicOpVector atomicOp)
Definition: WriteMask.hh:74
gem5::ruby::WriteMask::WriteMask
WriteMask(int size, std::vector< bool > &mask)
Definition: WriteMask.hh:70
gem5::ruby::WriteMask::firstBitSet
int firstBitSet(bool val, int offset=0) const
Definition: WriteMask.hh:206
gem5::ruby::WriteMask::~WriteMask
~WriteMask()
Definition: WriteMask.hh:78
gem5::ruby::WriteMask::mSize
int mSize
Definition: WriteMask.hh:260
gem5::ruby::WriteMask::andMask
void andMask(const WriteMask &writeMask)
Definition: WriteMask.hh:169
gem5::ruby::WriteMask::isEmpty
bool isEmpty() const
Definition: WriteMask.hh:147
gem5::ruby::WriteMask::AtomicOpVector
std::vector< std::pair< int, AtomicOpFunctor * > > AtomicOpVector
Definition: WriteMask.hh:62
gem5::ruby::WriteMask::isOverlap
bool isOverlap(const WriteMask &readMask) const
Definition: WriteMask.hh:122
gem5::ruby::WriteMask::mAtomic
bool mAtomic
Definition: WriteMask.hh:262
gem5::ruby::WriteMask::orMask
void orMask(const WriteMask &writeMask)
Definition: WriteMask.hh:183
gem5::ruby::WriteMask::containsMask
bool containsMask(const WriteMask &readMask) const
Definition: WriteMask.hh:135
gem5::ruby::DataBlock::getDataMod
uint8_t * getDataMod(int offset)
Definition: DataBlock.cc:118
gem5::ruby::DataBlock
Definition: DataBlock.hh:60
gem5::ruby::WriteMask::count
int count(int offset=0) const
Definition: WriteMask.hh:215
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::ruby::WriteMask::WriteMask
WriteMask(int size)
Definition: WriteMask.hh:66

Generated on Tue Sep 21 2021 12:25:40 for gem5 by doxygen 1.8.17