2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
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.
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.
31 #include "mem/ruby/common/NetDest.hh"
39 NetDest::add(MachineID newElement
)
41 assert(bitIndex(newElement
.num
) < m_bits
[vecIndex(newElement
)].getSize());
42 m_bits
[vecIndex(newElement
)].add(bitIndex(newElement
.num
));
46 NetDest::addNetDest(const NetDest
& netDest
)
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
]);
55 NetDest::setNetDest(MachineType machine
, const Set
& set
)
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
;
64 NetDest::remove(MachineID oldElement
)
66 m_bits
[vecIndex(oldElement
)].remove(bitIndex(oldElement
.num
));
70 NetDest::removeNetDest(const NetDest
& netDest
)
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
]);
81 for (int i
= 0; i
< m_bits
.size(); i
++) {
89 for (MachineType machine
= MachineType_FIRST
;
90 machine
< MachineType_NUM
; ++machine
) {
96 NetDest::broadcast(MachineType machineType
)
98 for (NodeID i
= 0; i
< MachineType_base_count(machineType
); i
++) {
99 MachineID mach
= {machineType
, i
};
104 //For Princeton Network
106 NetDest::getAllDest()
108 std::vector
<NodeID
> dest
;
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
);
122 NetDest::count() const
125 for (int i
= 0; i
< m_bits
.size(); i
++) {
126 counter
+= m_bits
[i
].count();
132 NetDest::elementAt(MachineID index
)
134 return m_bits
[vecIndex(index
)].elementAt(bitIndex(index
.num
));
138 NetDest::smallestElement() const
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
};
149 panic("No smallest element of an empty set.");
153 NetDest::smallestElement(MachineType machine
) const
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
};
163 panic("No smallest element of given MachineType.");
166 // Returns true iff all bits are set
168 NetDest::isBroadcast() const
170 for (int i
= 0; i
< m_bits
.size(); i
++) {
171 if (!m_bits
[i
].isBroadcast()) {
178 // Returns true iff no bits are set
180 NetDest::isEmpty() const
182 for (int i
= 0; i
< m_bits
.size(); i
++) {
183 if (!m_bits
[i
].isEmpty()) {
190 // returns the logical OR of "this" set and orNetDest
192 NetDest::OR(const NetDest
& orNetDest
) const
194 assert(m_bits
.size() == orNetDest
.getSize());
196 for (int i
= 0; i
< m_bits
.size(); i
++) {
197 result
.m_bits
[i
] = m_bits
[i
].OR(orNetDest
.m_bits
[i
]);
202 // returns the logical AND of "this" set and andNetDest
204 NetDest::AND(const NetDest
& andNetDest
) const
206 assert(m_bits
.size() == andNetDest
.getSize());
208 for (int i
= 0; i
< m_bits
.size(); i
++) {
209 result
.m_bits
[i
] = m_bits
[i
].AND(andNetDest
.m_bits
[i
]);
214 // Returns true if the intersection of the two sets is non-empty
216 NetDest::intersectionIsNotEmpty(const NetDest
& other_netDest
) const
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
])) {
228 NetDest::isSuperset(const NetDest
& test
) const
230 assert(m_bits
.size() == test
.getSize());
232 for (int i
= 0; i
< m_bits
.size(); i
++) {
233 if (!m_bits
[i
].isSuperset(test
.m_bits
[i
])) {
241 NetDest::isElement(MachineID element
) const
243 return ((m_bits
[vecIndex(element
)])).isElement(bitIndex(element
.num
));
249 m_bits
.resize(MachineType_base_level(MachineType_NUM
));
250 assert(m_bits
.size() == MachineType_NUM
);
252 for (int i
= 0; i
< m_bits
.size(); i
++) {
253 m_bits
[i
].setSize(MachineType_base_count((MachineType
)i
));
258 NetDest::print(std::ostream
& out
) const
260 out
<< "[NetDest (" << m_bits
.size() << ") ";
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
) << " ";
272 NetDest::isEqual(const NetDest
& n
) const
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
]))