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
]);
57 int i
= random()%m_bits
.size();
58 m_bits
[i
].addRandom();
62 NetDest::setNetDest(MachineType machine
, const Set
& set
)
64 // assure that there is only one set of destinations for this machine
65 assert(MachineType_base_level((MachineType
)(machine
+ 1)) -
66 MachineType_base_level(machine
) == 1);
67 m_bits
[MachineType_base_level(machine
)] = set
;
71 NetDest::remove(MachineID oldElement
)
73 m_bits
[vecIndex(oldElement
)].remove(bitIndex(oldElement
.num
));
77 NetDest::removeNetDest(const NetDest
& netDest
)
79 assert(m_bits
.size() == netDest
.getSize());
80 for (int i
= 0; i
< m_bits
.size(); i
++) {
81 m_bits
[i
].removeSet(netDest
.m_bits
[i
]);
88 for (int i
= 0; i
< m_bits
.size(); i
++) {
96 for (MachineType machine
= MachineType_FIRST
;
97 machine
< MachineType_NUM
; ++machine
) {
103 NetDest::broadcast(MachineType machineType
)
105 for (int i
= 0; i
< MachineType_base_count(machineType
); i
++) {
106 MachineID mach
= {machineType
, i
};
111 //For Princeton Network
113 NetDest::getAllDest()
115 std::vector
<NodeID
> dest
;
117 for (int i
= 0; i
< m_bits
.size(); i
++) {
118 for (int j
= 0; j
< m_bits
[i
].getSize(); j
++) {
119 if (m_bits
[i
].isElement(j
)) {
120 int id
= MachineType_base_number((MachineType
)i
) + j
;
121 dest
.push_back((NodeID
)id
);
129 NetDest::count() const
132 for (int i
= 0; i
< m_bits
.size(); i
++) {
133 counter
+= m_bits
[i
].count();
139 NetDest::elementAt(MachineID index
)
141 return m_bits
[vecIndex(index
)].elementAt(bitIndex(index
.num
));
145 NetDest::smallestElement() const
148 for (int i
= 0; i
< m_bits
.size(); i
++) {
149 for (int j
= 0; j
< m_bits
[i
].getSize(); j
++) {
150 if (m_bits
[i
].isElement(j
)) {
151 MachineID mach
= {MachineType_from_base_level(i
), j
};
156 panic("No smallest element of an empty set.");
160 NetDest::smallestElement(MachineType machine
) const
162 int size
= m_bits
[MachineType_base_level(machine
)].getSize();
163 for (int j
= 0; j
< size
; j
++) {
164 if (m_bits
[MachineType_base_level(machine
)].isElement(j
)) {
165 MachineID mach
= {machine
, j
};
170 panic("No smallest element of given MachineType.");
173 // Returns true iff all bits are set
175 NetDest::isBroadcast() const
177 for (int i
= 0; i
< m_bits
.size(); i
++) {
178 if (!m_bits
[i
].isBroadcast()) {
185 // Returns true iff no bits are set
187 NetDest::isEmpty() const
189 for (int i
= 0; i
< m_bits
.size(); i
++) {
190 if (!m_bits
[i
].isEmpty()) {
197 // returns the logical OR of "this" set and orNetDest
199 NetDest::OR(const NetDest
& orNetDest
) const
201 assert(m_bits
.size() == orNetDest
.getSize());
203 for (int i
= 0; i
< m_bits
.size(); i
++) {
204 result
.m_bits
[i
] = m_bits
[i
].OR(orNetDest
.m_bits
[i
]);
209 // returns the logical AND of "this" set and andNetDest
211 NetDest::AND(const NetDest
& andNetDest
) const
213 assert(m_bits
.size() == andNetDest
.getSize());
215 for (int i
= 0; i
< m_bits
.size(); i
++) {
216 result
.m_bits
[i
] = m_bits
[i
].AND(andNetDest
.m_bits
[i
]);
221 // Returns true if the intersection of the two sets is non-empty
223 NetDest::intersectionIsNotEmpty(const NetDest
& other_netDest
) const
225 assert(m_bits
.size() == other_netDest
.getSize());
226 for (int i
= 0; i
< m_bits
.size(); i
++) {
227 if (!m_bits
[i
].intersectionIsEmpty(other_netDest
.m_bits
[i
])) {
235 NetDest::isSuperset(const NetDest
& test
) const
237 assert(m_bits
.size() == test
.getSize());
239 for (int i
= 0; i
< m_bits
.size(); i
++) {
240 if (!m_bits
[i
].isSuperset(test
.m_bits
[i
])) {
248 NetDest::isElement(MachineID element
) const
250 return ((m_bits
[vecIndex(element
)])).isElement(bitIndex(element
.num
));
256 m_bits
.resize(MachineType_base_level(MachineType_NUM
));
257 assert(m_bits
.size() == MachineType_NUM
);
259 for (int i
= 0; i
< m_bits
.size(); i
++) {
260 m_bits
[i
].setSize(MachineType_base_count((MachineType
)i
));
265 NetDest::print(std::ostream
& out
) const
267 out
<< "[NetDest (" << m_bits
.size() << ") ";
269 for (int i
= 0; i
< m_bits
.size(); i
++) {
270 for (int j
= 0; j
< m_bits
[i
].getSize(); j
++) {
271 out
<< (bool) m_bits
[i
].isElement(j
) << " ";