gem5  v22.1.0.0
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__
uint8_t * getDataMod(int offset)
Definition: DataBlock.cc:118
bool isFull() const
Definition: WriteMask.hh:158
bool isEmpty() const
Definition: WriteMask.hh:147
void performAtomic(DataBlock &blk) const
Definition: WriteMask.hh:236
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:263
std::vector< std::pair< int, AtomicOpFunctor * > > AtomicOpVector
Definition: WriteMask.hh:62
bool containsMask(const WriteMask &readMask) const
Definition: WriteMask.hh:135
void performAtomic(uint8_t *p) const
Definition: WriteMask.hh:226
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:261
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
const AtomicOpVector & getAtomicOps() const
Definition: WriteMask.hh:247
void orMask(const WriteMask &writeMask)
Definition: WriteMask.hh:183
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:253
int firstBitSet(bool val, int offset=0) const
Definition: WriteMask.hh:206
STL vector class.
Definition: stl.hh:37
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
uint16_t len
Definition: helpers.cc:62
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 23, 0 > offset
Definition: types.hh:144
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 63 > val
Definition: misc.hh:776
std::ostream & operator<<(std::ostream &os, const BoolVec &myvector)
Definition: BoolVec.cc:49
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....

Generated on Wed Dec 21 2022 10:22:38 for gem5 by doxygen 1.9.1