3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
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.
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.
33 * Description: See NetDest.h
39 #include "mem/ruby/common/NetDest.hh"
40 #include "mem/ruby/config/RubyConfig.hh"
41 #include "mem/protocol/Protocol.hh"
48 void NetDest::add(MachineID newElement
)
50 m_bits
[vecIndex(newElement
)].add(bitIndex(newElement
.num
));
53 void NetDest::addNetDest(const NetDest
& netDest
)
55 assert(m_bits
.size() == netDest
.getSize());
56 for (int i
= 0; i
< m_bits
.size(); i
++) {
57 m_bits
[i
].addSet(netDest
.m_bits
[i
]);
61 void NetDest::addRandom()
63 int i
= random()%m_bits
.size();
64 m_bits
[i
].addRandom();
67 void NetDest::setNetDest(MachineType machine
, const Set
& set
)
69 // assure that there is only one set of destinations for this machine
70 assert(MachineType_base_level((MachineType
)(machine
+1)) - MachineType_base_level(machine
) == 1);
71 m_bits
[MachineType_base_level(machine
)] = set
;
74 void NetDest::remove(MachineID oldElement
)
76 m_bits
[vecIndex(oldElement
)].remove(bitIndex(oldElement
.num
));
79 void NetDest::removeNetDest(const NetDest
& netDest
)
81 assert(m_bits
.size() == netDest
.getSize());
82 for (int i
= 0; i
< m_bits
.size(); i
++) {
83 m_bits
[i
].removeSet(netDest
.m_bits
[i
]);
90 for (int i
= 0; i
< m_bits
.size(); i
++) {
95 void NetDest::broadcast()
97 for (MachineType machine
= MachineType_FIRST
; machine
< MachineType_NUM
; ++machine
) {
102 void NetDest::broadcast(MachineType machineType
) {
104 for (int i
= 0; i
< MachineType_base_count(machineType
); i
++) {
105 MachineID mach
= {machineType
, i
};
110 //For Princeton Network
111 Vector
<NodeID
> NetDest::getAllDest() {
114 for (int i
=0; i
<m_bits
.size(); i
++) {
115 for (int j
=0; j
<m_bits
[i
].getSize(); j
++) {
116 if (m_bits
[i
].isElement(j
)) {
117 dest
.insertAtBottom((NodeID
) (MachineType_base_number((MachineType
) i
) + j
));
124 int NetDest::count() const
127 for (int i
=0; i
<m_bits
.size(); i
++) {
128 counter
+= m_bits
[i
].count();
133 NodeID
NetDest::elementAt(MachineID index
) {
134 return m_bits
[vecIndex(index
)].elementAt(bitIndex(index
.num
));
137 NodeID
NetDest::smallestElement() const
140 for (int i
=0; i
<m_bits
.size(); i
++) {
141 for (int j
=0; j
<m_bits
[i
].getSize(); j
++) {
142 if (m_bits
[i
].isElement(j
)) {
147 ERROR_MSG("No smallest element of an empty set.");
150 MachineID
NetDest::smallestElement(MachineType machine
) const
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
};
159 ERROR_MSG("No smallest element of given MachineType.");
163 // Returns true iff all bits are set
164 bool NetDest::isBroadcast() const
166 for (int i
=0; i
<m_bits
.size(); i
++) {
167 if (!m_bits
[i
].isBroadcast()) {
174 // Returns true iff no bits are set
175 bool NetDest::isEmpty() const
177 for (int i
=0; i
<m_bits
.size(); i
++) {
178 if (!m_bits
[i
].isEmpty()) {
185 // returns the logical OR of "this" set and orNetDest
186 NetDest
NetDest::OR(const NetDest
& orNetDest
) const
188 assert(m_bits
.size() == orNetDest
.getSize());
190 for (int i
=0; i
<m_bits
.size(); i
++) {
191 result
.m_bits
[i
] = m_bits
[i
].OR(orNetDest
.m_bits
[i
]);
197 // returns the logical AND of "this" set and andNetDest
198 NetDest
NetDest::AND(const NetDest
& andNetDest
) const
200 assert(m_bits
.size() == andNetDest
.getSize());
202 for (int i
=0; i
<m_bits
.size(); i
++) {
203 result
.m_bits
[i
] = m_bits
[i
].AND(andNetDest
.m_bits
[i
]);
208 // Returns true if the intersection of the two sets is non-empty
209 bool NetDest::intersectionIsNotEmpty(const NetDest
& other_netDest
) const
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
])) {
220 bool NetDest::isSuperset(const NetDest
& test
) const
222 assert(m_bits
.size() == test
.getSize());
224 for (int i
=0; i
<m_bits
.size(); i
++) {
225 if (!m_bits
[i
].isSuperset(test
.m_bits
[i
])) {
232 bool NetDest::isElement(MachineID element
) const
234 return ((m_bits
[vecIndex(element
)])).isElement(bitIndex(element
.num
));
237 void NetDest::setSize()
239 m_bits
.setSize(MachineType_base_level(MachineType_NUM
));
240 assert(m_bits
.size() == MachineType_NUM
);
242 for (int i
= 0; i
< m_bits
.size(); i
++) {
243 m_bits
[i
].setSize(MachineType_base_count((MachineType
)i
));
247 void NetDest::print(ostream
& out
) const
249 out
<< "[NetDest (" << m_bits
.size() << ") ";
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
) << " ";