gem5  v20.1.0.0
WriteMask.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-15 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef __MEM_RUBY_COMMON_WRITEMASK_HH__
30 #define __MEM_RUBY_COMMON_WRITEMASK_HH__
31 
32 #include <cassert>
33 #include <iomanip>
34 #include <iostream>
35 #include <vector>
36 
39 
40 class WriteMask
41 {
42  public:
44 
46  : mSize(RubySystem::getBlockSizeBytes()), mMask(mSize, false),
47  mAtomic(false)
48  {}
49 
50  WriteMask(int size)
51  : mSize(size), mMask(size, false), mAtomic(false)
52  {}
53 
55  : mSize(size), mMask(mask), mAtomic(false)
56  {}
57 
59  : mSize(size), mMask(mask), mAtomic(true), mAtomicOp(atomicOp)
60  {}
61 
63  {}
64 
65  void
67  {
68  mMask = std::vector<bool>(mSize, false);
69  }
70 
71  bool
72  test(int offset)
73  {
74  assert(offset < mSize);
75  return mMask[offset];
76  }
77 
78  void
79  setMask(int offset, int len)
80  {
81  assert(mSize >= (offset + len));
82  for (int i = 0; i < len; i++) {
83  mMask[offset + i] = true;
84  }
85  }
86  void
88  {
89  for (int i = 0; i < mSize; i++) {
90  mMask[i] = true;
91  }
92  }
93 
94  bool
95  getMask(int offset, int len) const
96  {
97  bool tmp = true;
98  assert(mSize >= (offset + len));
99  for (int i = 0; i < len; i++) {
100  tmp = tmp & mMask.at(offset + i);
101  }
102  return tmp;
103  }
104 
105  bool
106  isOverlap(const WriteMask &readMask) const
107  {
108  bool tmp = false;
109  assert(mSize == readMask.mSize);
110  for (int i = 0; i < mSize; i++) {
111  if (readMask.mMask.at(i)) {
112  tmp = tmp | mMask.at(i);
113  }
114  }
115  return tmp;
116  }
117 
118  bool
119  cmpMask(const WriteMask &readMask) const
120  {
121  bool tmp = true;
122  assert(mSize == readMask.mSize);
123  for (int i = 0; i < mSize; i++) {
124  if (readMask.mMask.at(i)) {
125  tmp = tmp & mMask.at(i);
126  }
127  }
128  return tmp;
129  }
130 
131  bool isEmpty() const
132  {
133  for (int i = 0; i < mSize; i++) {
134  if (mMask.at(i)) {
135  return false;
136  }
137  }
138  return true;
139  }
140 
141  bool
142  isFull() const
143  {
144  for (int i = 0; i < mSize; i++) {
145  if (!mMask.at(i)) {
146  return false;
147  }
148  }
149  return true;
150  }
151 
152  void
153  orMask(const WriteMask & writeMask)
154  {
155  assert(mSize == writeMask.mSize);
156  for (int i = 0; i < mSize; i++) {
157  mMask[i] = (mMask.at(i)) | (writeMask.mMask.at(i));
158  }
159 
160  if (writeMask.mAtomic) {
161  mAtomic = true;
162  mAtomicOp = writeMask.mAtomicOp;
163  }
164  }
165 
166  void print(std::ostream& out) const;
167 
168  void
169  performAtomic(uint8_t * p) const
170  {
171  for (int i = 0; i < mAtomicOp.size(); i++) {
172  int offset = mAtomicOp[i].first;
173  AtomicOpFunctor *fnctr = mAtomicOp[i].second;
174  (*fnctr)(&p[offset]);
175  }
176  }
177 
178  void
180  {
181  for (int i = 0; i < mAtomicOp.size(); i++) {
182  int offset = mAtomicOp[i].first;
183  uint8_t *p = blk.getDataMod(offset);
184  AtomicOpFunctor *fnctr = mAtomicOp[i].second;
185  (*fnctr)(p);
186  }
187  }
188 
189  const AtomicOpVector&
190  getAtomicOps() const
191  {
192  return mAtomicOp;
193  }
194 
195  void
196  setAtomicOps(const AtomicOpVector& atomicOps)
197  {
198  mAtomic = true;
199  mAtomicOp = std::move(atomicOps);
200  }
201 
202  private:
203  int mSize;
205  bool mAtomic;
207 };
208 
209 inline std::ostream&
210 operator<<(std::ostream& out, const WriteMask& obj)
211 {
212  obj.print(out);
213  out << std::flush;
214  return out;
215 }
216 
217 #endif // __MEM_RUBY_COMMON_WRITEMASK_HH__
WriteMask::WriteMask
WriteMask(int size, std::vector< bool > &mask, AtomicOpVector atomicOp)
Definition: WriteMask.hh:58
WriteMask::cmpMask
bool cmpMask(const WriteMask &readMask) const
Definition: WriteMask.hh:119
WriteMask::clear
void clear()
Definition: WriteMask.hh:66
WriteMask::mMask
std::vector< bool > mMask
Definition: WriteMask.hh:204
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
operator<<
std::ostream & operator<<(std::ostream &out, const WriteMask &obj)
Definition: WriteMask.hh:210
WriteMask::setAtomicOps
void setAtomicOps(const AtomicOpVector &atomicOps)
Definition: WriteMask.hh:196
std::vector
STL vector class.
Definition: stl.hh:37
WriteMask::~WriteMask
~WriteMask()
Definition: WriteMask.hh:62
DataBlock
Definition: DataBlock.hh:40
WriteMask::test
bool test(int offset)
Definition: WriteMask.hh:72
AtomicOpFunctor
Definition: amo.hh:40
WriteMask::isFull
bool isFull() const
Definition: WriteMask.hh:142
WriteMask::getMask
bool getMask(int offset, int len) const
Definition: WriteMask.hh:95
WriteMask::WriteMask
WriteMask(int size, std::vector< bool > &mask)
Definition: WriteMask.hh:54
WriteMask::isOverlap
bool isOverlap(const WriteMask &readMask) const
Definition: WriteMask.hh:106
RubySystem
Definition: RubySystem.hh:52
TypeDefines.hh
WriteMask::performAtomic
void performAtomic(DataBlock &blk) const
Definition: WriteMask.hh:179
WriteMask::isEmpty
bool isEmpty() const
Definition: WriteMask.hh:131
WriteMask::WriteMask
WriteMask(int size)
Definition: WriteMask.hh:50
RubySystem.hh
WriteMask::print
void print(std::ostream &out) const
Definition: WriteMask.cc:36
WriteMask::WriteMask
WriteMask()
Definition: WriteMask.hh:45
WriteMask::getAtomicOps
const AtomicOpVector & getAtomicOps() const
Definition: WriteMask.hh:190
WriteMask::mSize
int mSize
Definition: WriteMask.hh:203
ArmISA::len
Bitfield< 18, 16 > len
Definition: miscregs_types.hh:439
DataBlock::getDataMod
uint8_t * getDataMod(int offset)
Definition: DataBlock.cc:102
WriteMask::mAtomic
bool mAtomic
Definition: WriteMask.hh:205
WriteMask::setMask
void setMask(int offset, int len)
Definition: WriteMask.hh:79
WriteMask::performAtomic
void performAtomic(uint8_t *p) const
Definition: WriteMask.hh:169
WriteMask::orMask
void orMask(const WriteMask &writeMask)
Definition: WriteMask.hh:153
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
WriteMask::AtomicOpVector
std::vector< std::pair< int, AtomicOpFunctor * > > AtomicOpVector
Definition: WriteMask.hh:43
WriteMask::mAtomicOp
AtomicOpVector mAtomicOp
Definition: WriteMask.hh:206
WriteMask
Definition: WriteMask.hh:40
WriteMask::fillMask
void fillMask()
Definition: WriteMask.hh:87
ArmISA::mask
Bitfield< 28, 24 > mask
Definition: miscregs_types.hh:711
ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:153

Generated on Wed Sep 30 2020 14:02:13 for gem5 by doxygen 1.8.17