2 * Copyright (c) 2012-15 Advanced Micro Devices, Inc.
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.
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.
29 #ifndef __MEM_RUBY_COMMON_WRITEMASK_HH__
30 #define __MEM_RUBY_COMMON_WRITEMASK_HH__
37 #include "mem/ruby/common/TypeDefines.hh"
38 #include "mem/ruby/system/RubySystem.hh"
44 : mSize(RubySystem::getBlockSizeBytes()), mMask(mSize, false),
49 : mSize(size), mMask(size, false), mAtomic(false)
52 WriteMask(int size, std::vector<bool> & mask)
53 : mSize(size), mMask(mask), mAtomic(false)
56 WriteMask(int size, std::vector<bool> &mask,
57 std::vector<std::pair<int, AtomicOpFunctor*> > atomicOp)
58 : mSize(size), mMask(mask), mAtomic(true), mAtomicOp(atomicOp)
67 mMask = std::vector<bool>(mSize, false);
73 assert(offset < mSize);
74 return mMask[offset] == true;
78 setMask(int offset, int len)
80 assert(mSize >= (offset + len));
81 for (int i = 0; i < len; i++) {
82 mMask[offset + i] = true;
88 for (int i = 0; i < mSize; i++) {
94 getMask(int offset, int len) const
97 assert(mSize >= (offset + len));
98 for (int i = 0; i < len; i++) {
99 tmp = tmp & mMask.at(offset + i);
105 isOverlap(const WriteMask &readMask) const
108 assert(mSize == readMask.mSize);
109 for (int i = 0; i < mSize; i++) {
110 if (readMask.mMask.at(i)) {
111 tmp = tmp | mMask.at(i);
118 cmpMask(const WriteMask &readMask) const
121 assert(mSize == readMask.mSize);
122 for (int i = 0; i < mSize; i++) {
123 if (readMask.mMask.at(i)) {
124 tmp = tmp & mMask.at(i);
132 for (int i = 0; i < mSize; i++) {
143 for (int i = 0; i < mSize; i++) {
152 orMask(const WriteMask & writeMask)
154 assert(mSize == writeMask.mSize);
155 for (int i = 0; i < mSize; i++) {
156 mMask[i] = (mMask.at(i)) | (writeMask.mMask.at(i));
159 if (writeMask.mAtomic) {
161 mAtomicOp = writeMask.mAtomicOp;
165 void print(std::ostream& out) const;
168 performAtomic(uint8_t * p) const
170 for (int i = 0; i < mAtomicOp.size(); i++) {
171 int offset = mAtomicOp[i].first;
172 AtomicOpFunctor *fnctr = mAtomicOp[i].second;
173 (*fnctr)(&p[offset]);
178 performAtomic(DataBlock & blk) const
180 for (int i = 0; i < mAtomicOp.size(); i++) {
181 int offset = mAtomicOp[i].first;
182 uint8_t *p = blk.getDataMod(offset);
183 AtomicOpFunctor *fnctr = mAtomicOp[i].second;
189 std::vector<bool> mMask;
191 std::vector<std::pair<int, AtomicOpFunctor*> > mAtomicOp;
195 operator<<(std::ostream& out, const WriteMask& obj)
202 #endif // __MEM_RUBY_COMMON_WRITEMASK_HH__