1
| |
2/* 3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29
| 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 * NetDest.C 32 * 33 * Description: See NetDest.hh 34 * 35 * $Id$ 36 * 37 */ 38
| |
39#include "mem/ruby/common/NetDest.hh" 40#include "mem/protocol/Protocol.hh" 41 42NetDest::NetDest() 43{ 44 setSize(); 45} 46
| 29#include "mem/ruby/common/NetDest.hh" 30#include "mem/protocol/Protocol.hh" 31 32NetDest::NetDest() 33{ 34 setSize(); 35} 36
|
47void NetDest::add(MachineID newElement)
| 37void 38NetDest::add(MachineID newElement)
|
48{
| 39{
|
49 m_bits[vecIndex(newElement)].add(bitIndex(newElement.num));
| 40 m_bits[vecIndex(newElement)].add(bitIndex(newElement.num));
|
50} 51
| 41} 42
|
52void NetDest::addNetDest(const NetDest& netDest)
| 43void 44NetDest::addNetDest(const NetDest& netDest)
|
53{
| 45{
|
54 assert(m_bits.size() == netDest.getSize()); 55 for (int i = 0; i < m_bits.size(); i++) { 56 m_bits[i].addSet(netDest.m_bits[i]); 57 }
| 46 assert(m_bits.size() == netDest.getSize()); 47 for (int i = 0; i < m_bits.size(); i++) { 48 m_bits[i].addSet(netDest.m_bits[i]); 49 }
|
58} 59
| 50} 51
|
60void NetDest::addRandom()
| 52void 53NetDest::addRandom()
|
61{
| 54{
|
62 int i = random()%m_bits.size(); 63 m_bits[i].addRandom();
| 55 int i = random()%m_bits.size(); 56 m_bits[i].addRandom();
|
64} 65
| 57} 58
|
66void NetDest::setNetDest(MachineType machine, const Set& set)
| 59void 60NetDest::setNetDest(MachineType machine, const Set& set)
|
67{
| 61{
|
68 // assure that there is only one set of destinations for this machine 69 assert(MachineType_base_level((MachineType)(machine+1)) - MachineType_base_level(machine) == 1); 70 m_bits[MachineType_base_level(machine)] = set;
| 62 // assure that there is only one set of destinations for this machine 63 assert(MachineType_base_level((MachineType)(machine + 1)) - 64 MachineType_base_level(machine) == 1); 65 m_bits[MachineType_base_level(machine)] = set;
|
71} 72
| 66} 67
|
73void NetDest::remove(MachineID oldElement)
| 68void 69NetDest::remove(MachineID oldElement)
|
74{
| 70{
|
75 m_bits[vecIndex(oldElement)].remove(bitIndex(oldElement.num));
| 71 m_bits[vecIndex(oldElement)].remove(bitIndex(oldElement.num));
|
76} 77
| 72} 73
|
78void NetDest::removeNetDest(const NetDest& netDest)
| 74void 75NetDest::removeNetDest(const NetDest& netDest)
|
79{
| 76{
|
80 assert(m_bits.size() == netDest.getSize()); 81 for (int i = 0; i < m_bits.size(); i++) { 82 m_bits[i].removeSet(netDest.m_bits[i]); 83 84 }
| 77 assert(m_bits.size() == netDest.getSize()); 78 for (int i = 0; i < m_bits.size(); i++) { 79 m_bits[i].removeSet(netDest.m_bits[i]); 80 }
|
85} 86
| 81} 82
|
87void NetDest::clear()
| 83void 84NetDest::clear()
|
88{
| 85{
|
89 for (int i = 0; i < m_bits.size(); i++) { 90 m_bits[i].clear(); 91 }
| 86 for (int i = 0; i < m_bits.size(); i++) { 87 m_bits[i].clear(); 88 }
|
92} 93
| 89} 90
|
94void NetDest::broadcast()
| 91void 92NetDest::broadcast()
|
95{
| 93{
|
96 for (MachineType machine = MachineType_FIRST; machine < MachineType_NUM; ++machine) { 97 broadcast(machine); 98 }
| 94 for (MachineType machine = MachineType_FIRST; 95 machine < MachineType_NUM; ++machine) { 96 broadcast(machine); 97 }
|
99} 100
| 98} 99
|
101void NetDest::broadcast(MachineType machineType) { 102 103 for (int i = 0; i < MachineType_base_count(machineType); i++) { 104 MachineID mach = {machineType, i}; 105 add(mach); 106 }
| 100void 101NetDest::broadcast(MachineType machineType) 102{ 103 for (int i = 0; i < MachineType_base_count(machineType); i++) { 104 MachineID mach = {machineType, i}; 105 add(mach); 106 }
|
107} 108 109//For Princeton Network
| 107} 108 109//For Princeton Network
|
110Vector<NodeID> NetDest::getAllDest() { 111 Vector<NodeID> dest; 112 dest.clear(); 113 for (int i=0; i<m_bits.size(); i++) { 114 for (int j=0; j<m_bits[i].getSize(); j++) { 115 if (m_bits[i].isElement(j)) { 116 dest.insertAtBottom((NodeID) (MachineType_base_number((MachineType) i) + j)); 117 } 118 }
| 110Vector 111NetDest::getAllDest() 112{ 113 Vector<NodeID> dest; 114 dest.clear(); 115 for (int i = 0; i < m_bits.size(); i++) { 116 for (int j = 0; j < m_bits[i].getSize(); j++) { 117 if (m_bits[i].isElement(j)) { 118 int id = MachineType_base_number((MachineType)i) + j; 119 dest.insertAtBottom((NodeID)id); 120 }
|
119 }
| 121 }
|
120 return dest;
| 122 } 123 return dest;
|
121} 122
| 124} 125
|
123int NetDest::count() const
| 126int 127NetDest::count() const
|
124{
| 128{
|
125 int counter = 0; 126 for (int i=0; i<m_bits.size(); i++) { 127 counter += m_bits[i].count(); 128 } 129 return counter;
| 129 int counter = 0; 130 for (int i = 0; i < m_bits.size(); i++) { 131 counter += m_bits[i].count(); 132 } 133 return counter;
|
130} 131
| 134} 135
|
132NodeID NetDest::elementAt(MachineID index) { 133 return m_bits[vecIndex(index)].elementAt(bitIndex(index.num));
| 136NodeID 137NetDest::elementAt(MachineID index) 138{ 139 return m_bits[vecIndex(index)].elementAt(bitIndex(index.num));
|
134} 135
| 140} 141
|
136MachineID NetDest::smallestElement() const
| 142MachineID 143NetDest::smallestElement() const
|
137{
| 144{
|
138 assert(count() > 0); 139 for (int i=0; i<m_bits.size(); i++) { 140 for (int j=0; j<m_bits[i].getSize(); j++) { 141 if (m_bits[i].isElement(j)) { 142 MachineID mach = {MachineType_from_base_level(i), j}; 143 return mach; 144 }
| 145 assert(count() > 0); 146 for (int i = 0; i < m_bits.size(); i++) { 147 for (int j = 0; j < m_bits[i].getSize(); j++) { 148 if (m_bits[i].isElement(j)) { 149 MachineID mach = {MachineType_from_base_level(i), j}; 150 return mach; 151 } 152 }
|
145 }
| 153 }
|
146 } 147 ERROR_MSG("No smallest element of an empty set.");
| 154 ERROR_MSG("No smallest element of an empty set.");
|
148} 149
| 155} 156
|
150MachineID NetDest::smallestElement(MachineType machine) const
| 157MachineID 158NetDest::smallestElement(MachineType machine) const
|
151{
| 159{
|
152 for (int j = 0; j < m_bits[MachineType_base_level(machine)].getSize(); j++) { 153 if (m_bits[MachineType_base_level(machine)].isElement(j)) { 154 MachineID mach = {machine, j}; 155 return mach;
| 160 int size = m_bits[MachineType_base_level(machine)].getSize(); 161 for (int j = 0; j < size; j++) { 162 if (m_bits[MachineType_base_level(machine)].isElement(j)) { 163 MachineID mach = {machine, j}; 164 return mach; 165 }
|
156 }
| 166 }
|
157 }
| |
158
| 167
|
159 ERROR_MSG("No smallest element of given MachineType.");
| 168 ERROR_MSG("No smallest element of given MachineType.");
|
160} 161
| 169} 170
|
162
| |
163// Returns true iff all bits are set
| 171// Returns true iff all bits are set
|
164bool NetDest::isBroadcast() const
| 172bool 173NetDest::isBroadcast() const
|
165{
| 174{
|
166 for (int i=0; i<m_bits.size(); i++) { 167 if (!m_bits[i].isBroadcast()) { 168 return false;
| 175 for (int i = 0; i < m_bits.size(); i++) { 176 if (!m_bits[i].isBroadcast()) { 177 return false; 178 }
|
169 }
| 179 }
|
170 } 171 return true;
| 180 return true;
|
172} 173 174// Returns true iff no bits are set
| 181} 182 183// Returns true iff no bits are set
|
175bool NetDest::isEmpty() const
| 184bool 185NetDest::isEmpty() const
|
176{
| 186{
|
177 for (int i=0; i<m_bits.size(); i++) { 178 if (!m_bits[i].isEmpty()) { 179 return false;
| 187 for (int i = 0; i < m_bits.size(); i++) { 188 if (!m_bits[i].isEmpty()) { 189 return false; 190 }
|
180 }
| 191 }
|
181 } 182 return true;
| 192 return true;
|
183} 184 185// returns the logical OR of "this" set and orNetDest
| 193} 194 195// returns the logical OR of "this" set and orNetDest
|
186NetDest NetDest::OR(const NetDest& orNetDest) const
| 196NetDest 197NetDest::OR(const NetDest& orNetDest) const
|
187{
| 198{
|
188 assert(m_bits.size() == orNetDest.getSize()); 189 NetDest result; 190 for (int i=0; i<m_bits.size(); i++) { 191 result.m_bits[i] = m_bits[i].OR(orNetDest.m_bits[i]); 192 } 193 return result;
| 199 assert(m_bits.size() == orNetDest.getSize()); 200 NetDest result; 201 for (int i = 0; i < m_bits.size(); i++) { 202 result.m_bits[i] = m_bits[i].OR(orNetDest.m_bits[i]); 203 } 204 return result;
|
194} 195
| 205} 206
|
196
| |
197// returns the logical AND of "this" set and andNetDest
| 207// returns the logical AND of "this" set and andNetDest
|
198NetDest NetDest::AND(const NetDest& andNetDest) const
| 208NetDest 209NetDest::AND(const NetDest& andNetDest) const
|
199{
| 210{
|
200 assert(m_bits.size() == andNetDest.getSize()); 201 NetDest result; 202 for (int i=0; i<m_bits.size(); i++) { 203 result.m_bits[i] = m_bits[i].AND(andNetDest.m_bits[i]); 204 } 205 return result;
| 211 assert(m_bits.size() == andNetDest.getSize()); 212 NetDest result; 213 for (int i = 0; i < m_bits.size(); i++) { 214 result.m_bits[i] = m_bits[i].AND(andNetDest.m_bits[i]); 215 } 216 return result;
|
206} 207 208// Returns true if the intersection of the two sets is non-empty
| 217} 218 219// Returns true if the intersection of the two sets is non-empty
|
209bool NetDest::intersectionIsNotEmpty(const NetDest& other_netDest) const
| 220bool 221NetDest::intersectionIsNotEmpty(const NetDest& other_netDest) const
|
210{
| 222{
|
211 assert(m_bits.size() == other_netDest.getSize()); 212 for (int i=0; i<m_bits.size(); i++) { 213 if (m_bits[i].intersectionIsNotEmpty(other_netDest.m_bits[i])) { 214 return true;
| 223 assert(m_bits.size() == other_netDest.getSize()); 224 for (int i = 0; i < m_bits.size(); i++) { 225 if (m_bits[i].intersectionIsNotEmpty(other_netDest.m_bits[i])) { 226 return true; 227 }
|
215 }
| 228 }
|
216 } 217 return false;
| 229 return false;
|
218} 219
| 230} 231
|
220bool NetDest::isSuperset(const NetDest& test) const
| 232bool 233NetDest::isSuperset(const NetDest& test) const
|
221{
| 234{
|
222 assert(m_bits.size() == test.getSize());
| 235 assert(m_bits.size() == test.getSize());
|
223
| 236
|
224 for (int i=0; i<m_bits.size(); i++) { 225 if (!m_bits[i].isSuperset(test.m_bits[i])) { 226 return false;
| 237 for (int i = 0; i < m_bits.size(); i++) { 238 if (!m_bits[i].isSuperset(test.m_bits[i])) { 239 return false; 240 }
|
227 }
| 241 }
|
228 } 229 return true;
| 242 return true;
|
230} 231
| 243} 244
|
232bool NetDest::isElement(MachineID element) const
| 245bool 246NetDest::isElement(MachineID element) const
|
233{
| 247{
|
234 return ((m_bits[vecIndex(element)])).isElement(bitIndex(element.num));
| 248 return ((m_bits[vecIndex(element)])).isElement(bitIndex(element.num));
|
235} 236
| 249} 250
|
237void NetDest::setSize()
| 251void 252NetDest::setSize()
|
238{
| 253{
|
239 m_bits.setSize(MachineType_base_level(MachineType_NUM)); 240 assert(m_bits.size() == MachineType_NUM);
| 254 m_bits.setSize(MachineType_base_level(MachineType_NUM)); 255 assert(m_bits.size() == MachineType_NUM);
|
241
| 256
|
242 for (int i = 0; i < m_bits.size(); i++) { 243 m_bits[i].setSize(MachineType_base_count((MachineType)i)); 244 }
| 257 for (int i = 0; i < m_bits.size(); i++) { 258 m_bits[i].setSize(MachineType_base_count((MachineType)i)); 259 }
|
245} 246
| 260} 261
|
247void NetDest::print(ostream& out) const
| 262void 263NetDest::print(ostream& out) const
|
248{
| 264{
|
249 out << "[NetDest (" << m_bits.size() << ") ";
| 265 out << "[NetDest (" << m_bits.size() << ") ";
|
250
| 266
|
251 for (int i=0; i<m_bits.size(); i++) { 252 for (int j=0; j<m_bits[i].getSize(); j++) { 253 out << (bool) m_bits[i].isElement(j) << " ";
| 267 for (int i = 0; i < m_bits.size(); i++) { 268 for (int j = 0; j < m_bits[i].getSize(); j++) { 269 out << (bool) m_bits[i].isElement(j) << " "; 270 } 271 out << " - ";
|
254 }
| 272 }
|
255 out << " - "; 256 } 257 out << "]";
| 273 out << "]";
|
258} 259
| 274} 275
|