From fd4ae25626b2119795fae8f4b5a5b076611033ef Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tiago=20M=C3=BCck?= Date: Thu, 28 May 2020 12:31:36 -0500 Subject: [PATCH] mem-ruby: additional WriteMask methods MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: Ib5d5f892075b38f46d1d802c043853f56e19ea12 Signed-off-by: Tiago Mück Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/31257 Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- src/mem/ruby/common/WriteMask.hh | 45 ++++++++++++++++++++-- src/mem/ruby/protocol/RubySlicc_Exports.sm | 9 +++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/mem/ruby/common/WriteMask.hh b/src/mem/ruby/common/WriteMask.hh index 6a0a041e7..6e3ea2982 100644 --- a/src/mem/ruby/common/WriteMask.hh +++ b/src/mem/ruby/common/WriteMask.hh @@ -1,4 +1,16 @@ /* + * Copyright (c) 2020 ARM Limited + * All rights reserved. + * + * The license below extends only to copyright in the software and shall + * not be construed as granting a license to any other intellectual + * property including but not limited to intellectual property relating + * to a hardware implementation of the functionality of the software + * licensed hereunder. You may use the software subject to the license + * terms below provided that you ensure that this notice is replicated + * unmodified and in its entirety in all distributions of the software, + * modified or unmodified, in source code or in binary form. + * * Copyright (c) 2012-15 Advanced Micro Devices, Inc. * All rights reserved. * @@ -69,18 +81,18 @@ class WriteMask } bool - test(int offset) + test(int offset) const { assert(offset < mSize); return mMask[offset]; } void - setMask(int offset, int len) + setMask(int offset, int len, bool val = true) { assert(mSize >= (offset + len)); for (int i = 0; i < len; i++) { - mMask[offset + i] = true; + mMask[offset + i] = val; } } void @@ -163,6 +175,33 @@ class WriteMask } } + void + setInvertedMask(const WriteMask & writeMask) + { + assert(mSize == writeMask.mSize); + for (int i = 0; i < mSize; i++) { + mMask[i] = !writeMask.mMask.at(i); + } + } + + int + firstBitSet(bool val, int offset = 0) const + { + for (int i = offset; i < mSize; ++i) + if (mMask[i] == val) + return i; + return mSize; + } + + int + count(int offset = 0) const + { + int count = 0; + for (int i = offset; i < mSize; ++i) + count += mMask[i]; + return count; + } + void print(std::ostream& out) const; void diff --git a/src/mem/ruby/protocol/RubySlicc_Exports.sm b/src/mem/ruby/protocol/RubySlicc_Exports.sm index ea61350ff..1b67dc603 100644 --- a/src/mem/ruby/protocol/RubySlicc_Exports.sm +++ b/src/mem/ruby/protocol/RubySlicc_Exports.sm @@ -58,7 +58,16 @@ structure(WriteMask, external="yes", desc="...") { bool isFull(); bool isOverlap(WriteMask); void orMask(WriteMask); + void setInvertedMask(WriteMask); void fillMask(); + void setMask(int,int); + bool getMask(int,int); + void setMask(int,int,bool); + int firstBitSet(bool); + int firstBitSet(bool,int); + int count(); + int count(int); + bool test(int); } structure(DataBlock, external = "yes", desc="..."){ -- 2.30.2