NetDest.hh (10301:44839e8febbd) NetDest.hh (10348:c91b23c72d5e)
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
29// NetDest specifies the network destination of a NetworkMessage
30// This is backward compatible with the Set class that was previously
31// used to specify network destinations.
32// NetDest supports both node networks and component networks
33
34#ifndef __MEM_RUBY_COMMON_NETDEST_HH__
35#define __MEM_RUBY_COMMON_NETDEST_HH__
36
37#include <iostream>
38#include <vector>
39
40#include "mem/ruby/common/Set.hh"
41#include "mem/ruby/common/MachineID.hh"
42
43class NetDest
44{
45 public:
46 // Constructors
47 // creates and empty set
48 NetDest();
49 explicit NetDest(int bit_size);
50
51 NetDest& operator=(const Set& obj);
52
53 ~NetDest()
54 { }
55
56 void add(MachineID newElement);
57 void addNetDest(const NetDest& netDest);
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
29// NetDest specifies the network destination of a NetworkMessage
30// This is backward compatible with the Set class that was previously
31// used to specify network destinations.
32// NetDest supports both node networks and component networks
33
34#ifndef __MEM_RUBY_COMMON_NETDEST_HH__
35#define __MEM_RUBY_COMMON_NETDEST_HH__
36
37#include <iostream>
38#include <vector>
39
40#include "mem/ruby/common/Set.hh"
41#include "mem/ruby/common/MachineID.hh"
42
43class NetDest
44{
45 public:
46 // Constructors
47 // creates and empty set
48 NetDest();
49 explicit NetDest(int bit_size);
50
51 NetDest& operator=(const Set& obj);
52
53 ~NetDest()
54 { }
55
56 void add(MachineID newElement);
57 void addNetDest(const NetDest& netDest);
58 void addRandom();
59 void setNetDest(MachineType machine, const Set& set);
60 void remove(MachineID oldElement);
61 void removeNetDest(const NetDest& netDest);
62 void clear();
63 void broadcast();
64 void broadcast(MachineType machine);
65 int count() const;
66 bool isEqual(const NetDest& netDest) const;
67
68 // return the logical OR of this netDest and orNetDest
69 NetDest OR(const NetDest& orNetDest) const;
70
71 // return the logical AND of this netDest and andNetDest
72 NetDest AND(const NetDest& andNetDest) const;
73
74 // Returns true if the intersection of the two netDests is non-empty
75 bool intersectionIsNotEmpty(const NetDest& other_netDest) const;
76
77 // Returns true if the intersection of the two netDests is empty
78 bool intersectionIsEmpty(const NetDest& other_netDest) const;
79
80 bool isSuperset(const NetDest& test) const;
81 bool isSubset(const NetDest& test) const { return test.isSuperset(*this); }
82 bool isElement(MachineID element) const;
83 bool isBroadcast() const;
84 bool isEmpty() const;
85
86 // For Princeton Network
87 std::vector<NodeID> getAllDest();
88
89 MachineID smallestElement() const;
90 MachineID smallestElement(MachineType machine) const;
91
92 void resize();
93 int getSize() const { return m_bits.size(); }
94
95 // get element for a index
96 NodeID elementAt(MachineID index);
97
98 void print(std::ostream& out) const;
99
100 private:
101 // returns a value >= MachineType_base_level("this machine")
102 // and < MachineType_base_level("next highest machine")
103 int
104 vecIndex(MachineID m) const
105 {
106 int vec_index = MachineType_base_level(m.type);
107 assert(vec_index < m_bits.size());
108 return vec_index;
109 }
110
111 NodeID bitIndex(NodeID index) const { return index; }
112
113 std::vector<Set> m_bits; // a vector of bit vectors - i.e. Sets
114};
115
116inline std::ostream&
117operator<<(std::ostream& out, const NetDest& obj)
118{
119 obj.print(out);
120 out << std::flush;
121 return out;
122}
123
124#endif // __MEM_RUBY_COMMON_NETDEST_HH__
58 void setNetDest(MachineType machine, const Set& set);
59 void remove(MachineID oldElement);
60 void removeNetDest(const NetDest& netDest);
61 void clear();
62 void broadcast();
63 void broadcast(MachineType machine);
64 int count() const;
65 bool isEqual(const NetDest& netDest) const;
66
67 // return the logical OR of this netDest and orNetDest
68 NetDest OR(const NetDest& orNetDest) const;
69
70 // return the logical AND of this netDest and andNetDest
71 NetDest AND(const NetDest& andNetDest) const;
72
73 // Returns true if the intersection of the two netDests is non-empty
74 bool intersectionIsNotEmpty(const NetDest& other_netDest) const;
75
76 // Returns true if the intersection of the two netDests is empty
77 bool intersectionIsEmpty(const NetDest& other_netDest) const;
78
79 bool isSuperset(const NetDest& test) const;
80 bool isSubset(const NetDest& test) const { return test.isSuperset(*this); }
81 bool isElement(MachineID element) const;
82 bool isBroadcast() const;
83 bool isEmpty() const;
84
85 // For Princeton Network
86 std::vector<NodeID> getAllDest();
87
88 MachineID smallestElement() const;
89 MachineID smallestElement(MachineType machine) const;
90
91 void resize();
92 int getSize() const { return m_bits.size(); }
93
94 // get element for a index
95 NodeID elementAt(MachineID index);
96
97 void print(std::ostream& out) const;
98
99 private:
100 // returns a value >= MachineType_base_level("this machine")
101 // and < MachineType_base_level("next highest machine")
102 int
103 vecIndex(MachineID m) const
104 {
105 int vec_index = MachineType_base_level(m.type);
106 assert(vec_index < m_bits.size());
107 return vec_index;
108 }
109
110 NodeID bitIndex(NodeID index) const { return index; }
111
112 std::vector<Set> m_bits; // a vector of bit vectors - i.e. Sets
113};
114
115inline std::ostream&
116operator<<(std::ostream& out, const NetDest& obj)
117{
118 obj.print(out);
119 out << std::flush;
120 return out;
121}
122
123#endif // __MEM_RUBY_COMMON_NETDEST_HH__