gem5  v21.1.0.2
Set.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
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 // modified by Dan Gibson on 05/20/05 to accomidate FASTER
30 // >32 set lengths, using an array of ints w/ 32 bits/int
31 
32 #ifndef __MEM_RUBY_COMMON_SET_HH__
33 #define __MEM_RUBY_COMMON_SET_HH__
34 
35 #include <bitset>
36 #include <cassert>
37 #include <iostream>
38 
39 #include "base/logging.hh"
41 
42 namespace gem5
43 {
44 
45 namespace ruby
46 {
47 
48 class Set
49 {
50  private:
51  // Number of bits in use in this set.
52  // can be defined in build_opts file (default=64).
53  int m_nSize;
54  std::bitset<NUMBER_BITS_PER_SET> bits;
55 
56  public:
57  Set() : m_nSize(0) {}
58 
59  Set(int size) : m_nSize(size)
60  {
61  if (size > NUMBER_BITS_PER_SET)
62  fatal("Number of bits(%d) < size specified(%d). "
63  "Increase the number of bits and recompile.\n",
64  NUMBER_BITS_PER_SET, size);
65  }
66 
67  Set(const Set& obj) : m_nSize(obj.m_nSize), bits(obj.bits) {}
68  ~Set() {}
69 
70  Set& operator=(const Set& obj)
71  {
72  m_nSize = obj.m_nSize;
73  bits = obj.bits;
74  return *this;
75  }
76 
77  void
79  {
80  bits.set(index);
81  }
82 
83  /*
84  * This function should set all the bits in the current set that are
85  * already set in the parameter set
86  */
87  void
88  addSet(const Set& obj)
89  {
90  assert(m_nSize == obj.m_nSize);
91  bits |= obj.bits;
92  }
93 
94  /*
95  * This function clears bits that are =1 in the parameter set
96  */
97  void
99  {
100  bits.reset(index);
101  }
102 
103  /*
104  * This function clears bits that are =1 in the parameter set
105  */
106  void
107  removeSet(const Set& obj)
108  {
109  assert(m_nSize == obj.m_nSize);
110  bits &= (~obj.bits);
111  }
112 
113  void clear() { bits.reset(); }
114 
115  /*
116  * this function sets all bits in the set
117  */
118  void broadcast()
119  {
120  bits.set();
121  for (int j = m_nSize; j < NUMBER_BITS_PER_SET; ++j) {
122  bits.reset(j);
123  }
124  }
125 
126  /*
127  * This function returns the population count of 1's in the set
128  */
129  int count() const { return bits.count(); }
130 
131  /*
132  * This function checks for set equality
133  */
134  bool
135  isEqual(const Set& obj) const
136  {
137  assert(m_nSize == obj.m_nSize);
138  return bits == obj.bits;
139  }
140 
141  // return the logical OR of this set and orSet
142  Set
143  OR(const Set& obj) const
144  {
145  assert(m_nSize == obj.m_nSize);
146  Set r(m_nSize);
147  r.bits = bits | obj.bits;
148  return r;
149  };
150 
151  // return the logical AND of this set and andSet
152  Set
153  AND(const Set& obj) const
154  {
155  assert(m_nSize == obj.m_nSize);
156  Set r(m_nSize);
157  r.bits = bits & obj.bits;
158  return r;
159  }
160 
161  // Returns true if the intersection of the two sets is empty
162  bool
163  intersectionIsEmpty(const Set& obj) const
164  {
165  std::bitset<NUMBER_BITS_PER_SET> r = bits & obj.bits;
166  return r.none();
167  }
168 
169  /*
170  * Returns false if a bit is set in the parameter set that is NOT set
171  * in this set
172  */
173  bool
174  isSuperset(const Set& test) const
175  {
176  assert(m_nSize == test.m_nSize);
177  std::bitset<NUMBER_BITS_PER_SET> r = bits | test.bits;
178  return (r == bits);
179  }
180 
181  bool isSubset(const Set& test) const { return test.isSuperset(*this); }
182 
183  bool isElement(NodeID element) const { return bits.test(element); }
184 
185  /*
186  * this function returns true iff all bits in use are set
187  */
188  bool
189  isBroadcast() const
190  {
191  return (bits.count() == m_nSize);
192  }
193 
194  bool isEmpty() const { return bits.none(); }
195 
197  {
198  for (int i = 0; i < m_nSize; ++i) {
199  if (bits.test(i)) {
200  return i;
201  }
202  }
203  panic("No smallest element of an empty set.");
204  }
205 
206  bool elementAt(int index) const { return bits[index]; }
207 
208  int getSize() const { return m_nSize; }
209 
210  void
211  setSize(int size)
212  {
213  if (size > NUMBER_BITS_PER_SET)
214  fatal("Number of bits(%d) < size specified(%d). "
215  "Increase the number of bits and recompile.\n",
216  NUMBER_BITS_PER_SET, size);
217  m_nSize = size;
218  bits.reset();
219  }
220 
221  void print(std::ostream& out) const
222  {
223  out << "[Set (" << m_nSize << "): " << bits << "]";
224  }
225 };
226 
227 inline std::ostream&
228 operator<<(std::ostream& out, const Set& obj)
229 {
230  obj.print(out);
231  out << std::flush;
232  return out;
233 }
234 
235 } // namespace ruby
236 } // namespace gem5
237 
238 #endif // __MEM_RUBY_COMMON_SET_HH__
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:189
gem5::ruby::Set::broadcast
void broadcast()
Definition: Set.hh:118
gem5::ruby::Set::isElement
bool isElement(NodeID element) const
Definition: Set.hh:183
gem5::ruby::Set::~Set
~Set()
Definition: Set.hh:68
gem5::ruby::Set::isBroadcast
bool isBroadcast() const
Definition: Set.hh:189
gem5::ruby::Set
Definition: Set.hh:48
gem5::ruby::Set::elementAt
bool elementAt(int index) const
Definition: Set.hh:206
gem5::ruby::Set::Set
Set(const Set &obj)
Definition: Set.hh:67
gem5::MipsISA::index
Bitfield< 30, 0 > index
Definition: pra_constants.hh:47
test
Definition: test.h:38
gem5::ruby::Set::setSize
void setSize(int size)
Definition: Set.hh:211
gem5::ruby::operator<<
std::ostream & operator<<(std::ostream &os, const BoolVec &myvector)
Definition: BoolVec.cc:49
gem5::ruby::Set::bits
std::bitset< NUMBER_BITS_PER_SET > bits
Definition: Set.hh:54
gem5::ruby::Set::m_nSize
int m_nSize
Definition: Set.hh:53
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::ruby::Set::isEmpty
bool isEmpty() const
Definition: Set.hh:194
gem5::ruby::Set::AND
Set AND(const Set &obj) const
Definition: Set.hh:153
gem5::ruby::Set::addSet
void addSet(const Set &obj)
Definition: Set.hh:88
gem5::ruby::Set::isSuperset
bool isSuperset(const Set &test) const
Definition: Set.hh:174
gem5::ArmISA::j
Bitfield< 24 > j
Definition: misc_types.hh:57
gem5::ruby::Set::isEqual
bool isEqual(const Set &obj) const
Definition: Set.hh:135
gem5::ruby::Set::clear
void clear()
Definition: Set.hh:113
gem5::ruby::Set::operator=
Set & operator=(const Set &obj)
Definition: Set.hh:70
TypeDefines.hh
gem5::ruby::Set::print
void print(std::ostream &out) const
Definition: Set.hh:221
gem5::ruby::Set::getSize
int getSize() const
Definition: Set.hh:208
gem5::ruby::Set::smallestElement
NodeID smallestElement() const
Definition: Set.hh:196
gem5::ruby::Set::OR
Set OR(const Set &obj) const
Definition: Set.hh:143
gem5::ruby::Set::count
int count() const
Definition: Set.hh:129
logging.hh
gem5::ruby::Set::intersectionIsEmpty
bool intersectionIsEmpty(const Set &obj) const
Definition: Set.hh:163
gem5::ruby::Set::removeSet
void removeSet(const Set &obj)
Definition: Set.hh:107
gem5::ruby::NodeID
unsigned int NodeID
Definition: TypeDefines.hh:40
gem5::MipsISA::r
r
Definition: pra_constants.hh:98
gem5::ruby::Set::Set
Set(int size)
Definition: Set.hh:59
gem5::ruby::Set::Set
Set()
Definition: Set.hh:57
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::ruby::Set::add
void add(NodeID index)
Definition: Set.hh:78
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177
gem5::ruby::Set::isSubset
bool isSubset(const Set &test) const
Definition: Set.hh:181
gem5::ruby::Set::remove
void remove(NodeID index)
Definition: Set.hh:98

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