gem5  v20.1.0.0
NetDest.cc
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 
30 
31 #include <algorithm>
32 
34 {
35  resize();
36 }
37 
38 void
40 {
41  assert(bitIndex(newElement.num) < m_bits[vecIndex(newElement)].getSize());
42  m_bits[vecIndex(newElement)].add(bitIndex(newElement.num));
43 }
44 
45 void
47 {
48  assert(m_bits.size() == netDest.getSize());
49  for (int i = 0; i < m_bits.size(); i++) {
50  m_bits[i].addSet(netDest.m_bits[i]);
51  }
52 }
53 
54 void
55 NetDest::setNetDest(MachineType machine, const Set& set)
56 {
57  // assure that there is only one set of destinations for this machine
58  assert(MachineType_base_level((MachineType)(machine + 1)) -
59  MachineType_base_level(machine) == 1);
60  m_bits[MachineType_base_level(machine)] = set;
61 }
62 
63 void
65 {
66  m_bits[vecIndex(oldElement)].remove(bitIndex(oldElement.num));
67 }
68 
69 void
71 {
72  assert(m_bits.size() == netDest.getSize());
73  for (int i = 0; i < m_bits.size(); i++) {
74  m_bits[i].removeSet(netDest.m_bits[i]);
75  }
76 }
77 
78 void
80 {
81  for (int i = 0; i < m_bits.size(); i++) {
82  m_bits[i].clear();
83  }
84 }
85 
86 void
88 {
89  for (MachineType machine = MachineType_FIRST;
90  machine < MachineType_NUM; ++machine) {
91  broadcast(machine);
92  }
93 }
94 
95 void
96 NetDest::broadcast(MachineType machineType)
97 {
98  for (NodeID i = 0; i < MachineType_base_count(machineType); i++) {
99  MachineID mach = {machineType, i};
100  add(mach);
101  }
102 }
103 
104 //For Princeton Network
107 {
108  std::vector<NodeID> dest;
109  dest.clear();
110  for (int i = 0; i < m_bits.size(); i++) {
111  for (int j = 0; j < m_bits[i].getSize(); j++) {
112  if (m_bits[i].isElement(j)) {
113  int id = MachineType_base_number((MachineType)i) + j;
114  dest.push_back((NodeID)id);
115  }
116  }
117  }
118  return dest;
119 }
120 
121 int
123 {
124  int counter = 0;
125  for (int i = 0; i < m_bits.size(); i++) {
126  counter += m_bits[i].count();
127  }
128  return counter;
129 }
130 
131 NodeID
133 {
134  return m_bits[vecIndex(index)].elementAt(bitIndex(index.num));
135 }
136 
137 MachineID
139 {
140  assert(count() > 0);
141  for (int i = 0; i < m_bits.size(); i++) {
142  for (NodeID j = 0; j < m_bits[i].getSize(); j++) {
143  if (m_bits[i].isElement(j)) {
144  MachineID mach = {MachineType_from_base_level(i), j};
145  return mach;
146  }
147  }
148  }
149  panic("No smallest element of an empty set.");
150 }
151 
152 MachineID
153 NetDest::smallestElement(MachineType machine) const
154 {
155  int size = m_bits[MachineType_base_level(machine)].getSize();
156  for (NodeID j = 0; j < size; j++) {
157  if (m_bits[MachineType_base_level(machine)].isElement(j)) {
158  MachineID mach = {machine, j};
159  return mach;
160  }
161  }
162 
163  panic("No smallest element of given MachineType.");
164 }
165 
166 // Returns true iff all bits are set
167 bool
169 {
170  for (int i = 0; i < m_bits.size(); i++) {
171  if (!m_bits[i].isBroadcast()) {
172  return false;
173  }
174  }
175  return true;
176 }
177 
178 // Returns true iff no bits are set
179 bool
181 {
182  for (int i = 0; i < m_bits.size(); i++) {
183  if (!m_bits[i].isEmpty()) {
184  return false;
185  }
186  }
187  return true;
188 }
189 
190 // returns the logical OR of "this" set and orNetDest
191 NetDest
192 NetDest::OR(const NetDest& orNetDest) const
193 {
194  assert(m_bits.size() == orNetDest.getSize());
195  NetDest result;
196  for (int i = 0; i < m_bits.size(); i++) {
197  result.m_bits[i] = m_bits[i].OR(orNetDest.m_bits[i]);
198  }
199  return result;
200 }
201 
202 // returns the logical AND of "this" set and andNetDest
203 NetDest
204 NetDest::AND(const NetDest& andNetDest) const
205 {
206  assert(m_bits.size() == andNetDest.getSize());
207  NetDest result;
208  for (int i = 0; i < m_bits.size(); i++) {
209  result.m_bits[i] = m_bits[i].AND(andNetDest.m_bits[i]);
210  }
211  return result;
212 }
213 
214 // Returns true if the intersection of the two sets is non-empty
215 bool
216 NetDest::intersectionIsNotEmpty(const NetDest& other_netDest) const
217 {
218  assert(m_bits.size() == other_netDest.getSize());
219  for (int i = 0; i < m_bits.size(); i++) {
220  if (!m_bits[i].intersectionIsEmpty(other_netDest.m_bits[i])) {
221  return true;
222  }
223  }
224  return false;
225 }
226 
227 bool
229 {
230  assert(m_bits.size() == test.getSize());
231 
232  for (int i = 0; i < m_bits.size(); i++) {
233  if (!m_bits[i].isSuperset(test.m_bits[i])) {
234  return false;
235  }
236  }
237  return true;
238 }
239 
240 bool
242 {
243  return ((m_bits[vecIndex(element)])).isElement(bitIndex(element.num));
244 }
245 
246 void
248 {
249  m_bits.resize(MachineType_base_level(MachineType_NUM));
250  assert(m_bits.size() == MachineType_NUM);
251 
252  for (int i = 0; i < m_bits.size(); i++) {
253  m_bits[i].setSize(MachineType_base_count((MachineType)i));
254  }
255 }
256 
257 void
258 NetDest::print(std::ostream& out) const
259 {
260  out << "[NetDest (" << m_bits.size() << ") ";
261 
262  for (int i = 0; i < m_bits.size(); i++) {
263  for (int j = 0; j < m_bits[i].getSize(); j++) {
264  out << (bool) m_bits[i].isElement(j) << " ";
265  }
266  out << " - ";
267  }
268  out << "]";
269 }
270 
271 bool
273 {
274  assert(m_bits.size() == n.m_bits.size());
275  for (unsigned int i = 0; i < m_bits.size(); ++i) {
276  if (!m_bits[i].isEqual(n.m_bits[i]))
277  return false;
278  }
279  return true;
280 }
NetDest::add
void add(MachineID newElement)
Definition: NetDest.cc:39
Set
Definition: Set.hh:42
MipsISA::index
Bitfield< 30, 0 > index
Definition: pra_constants.hh:44
NetDest::count
int count() const
Definition: NetDest.cc:122
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
test
Definition: test.h:38
NetDest::remove
void remove(MachineID oldElement)
Definition: NetDest.cc:64
NetDest::getSize
int getSize() const
Definition: NetDest.hh:88
NetDest::elementAt
NodeID elementAt(MachineID index)
Definition: NetDest.cc:132
NetDest::intersectionIsEmpty
bool intersectionIsEmpty(const NetDest &other_netDest) const
std::vector
STL vector class.
Definition: stl.hh:37
MachineID
Definition: MachineID.hh:38
NetDest::isElement
bool isElement(MachineID element) const
Definition: NetDest.cc:241
NetDest::resize
void resize()
Definition: NetDest.cc:247
ArmISA::n
Bitfield< 31 > n
Definition: miscregs_types.hh:450
NetDest::print
void print(std::ostream &out) const
Definition: NetDest.cc:258
NetDest::NetDest
NetDest()
Definition: NetDest.cc:33
ArmISA::j
Bitfield< 24 > j
Definition: miscregs_types.hh:54
NetDest::setNetDest
void setNetDest(MachineType machine, const Set &set)
Definition: NetDest.cc:55
NetDest::m_bits
std::vector< Set > m_bits
Definition: NetDest.hh:108
NetDest::smallestElement
MachineID smallestElement() const
Definition: NetDest.cc:138
NetDest::OR
NetDest OR(const NetDest &orNetDest) const
Definition: NetDest.cc:192
NetDest::bitIndex
NodeID bitIndex(NodeID index) const
Definition: NetDest.hh:106
NetDest::clear
void clear()
Definition: NetDest.cc:79
NetDest::broadcast
void broadcast()
Definition: NetDest.cc:87
NetDest::isSuperset
bool isSuperset(const NetDest &test) const
Definition: NetDest.cc:228
NetDest::vecIndex
int vecIndex(MachineID m) const
Definition: NetDest.hh:99
MachineID::num
NodeID num
range: 0 ... number of this machine's components in system - 1
Definition: MachineID.hh:46
NetDest::addNetDest
void addNetDest(const NetDest &netDest)
Definition: NetDest.cc:46
NodeID
unsigned int NodeID
Definition: TypeDefines.hh:34
NetDest::intersectionIsNotEmpty
bool intersectionIsNotEmpty(const NetDest &other_netDest) const
Definition: NetDest.cc:216
NetDest::isEmpty
bool isEmpty() const
Definition: NetDest.cc:180
NetDest::isBroadcast
bool isBroadcast() const
Definition: NetDest.cc:168
NetDest::AND
NetDest AND(const NetDest &andNetDest) const
Definition: NetDest.cc:204
NetDest::isEqual
bool isEqual(const NetDest &netDest) const
Definition: NetDest.cc:272
NetDest::getAllDest
std::vector< NodeID > getAllDest()
Definition: NetDest.cc:106
NetDest
Definition: NetDest.hh:39
NetDest.hh
NetDest::removeNetDest
void removeNetDest(const NetDest &netDest)
Definition: NetDest.cc:70
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171

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