NetDest.hh revision 6762:a22a47e60c21
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
30/*
31 * Set.hh
32 *
33 * Description:
34 *
35 * $Id$
36 *
37 */
38
39// NetDest specifies the network destination of a NetworkMessage
40// This is backward compatible with the Set class that was previously
41// used to specify network destinations.
42// NetDest supports both node networks and component networks
43
44#ifndef NETDEST_H
45#define NETDEST_H
46
47#include "mem/ruby/common/Global.hh"
48#include "mem/gems_common/Vector.hh"
49#include "mem/ruby/system/NodeID.hh"
50#include "mem/ruby/system/MachineID.hh"
51#include "mem/ruby/common/Set.hh"
52#include "mem/protocol/MachineType.hh"
53
54class Set;
55
56class NetDest {
57public:
58  // Constructors
59  // creates and empty set
60  NetDest();
61  explicit NetDest(int bit_size);
62
63  NetDest& operator=(const Set& obj);
64
65  // Destructor
66  ~NetDest() { DEBUG_MSG(MEMORY_COMP, LowPrio, "NetDest Destructor"); }
67
68  // Public Methods
69  void add(MachineID newElement);
70  void addNetDest(const NetDest& netDest);
71  void addRandom();
72  void setNetDest(MachineType machine, const Set& set);
73  void remove(MachineID oldElement);
74  void removeNetDest(const NetDest& netDest);
75  void clear();
76  void broadcast();
77  void broadcast(MachineType machine);
78  int count() const;
79  bool isEqual(const NetDest& netDest);
80
81  NetDest OR(const NetDest& orNetDest) const;  // return the logical OR of this netDest and orNetDest
82  NetDest AND(const NetDest& andNetDest) const;  // return the logical AND of this netDest and andNetDest
83
84  // Returns true if the intersection of the two netDests is non-empty
85  bool intersectionIsNotEmpty(const NetDest& other_netDest) const;
86
87  // Returns true if the intersection of the two netDests is empty
88  bool intersectionIsEmpty(const NetDest& other_netDest) const;
89
90  bool isSuperset(const NetDest& test) const;
91  bool isSubset(const NetDest& test) const { return test.isSuperset(*this); }
92  bool isElement(MachineID element) const;
93  bool isBroadcast() const;
94  bool isEmpty() const;
95
96  //For Princeton Network
97  Vector<NodeID> getAllDest();
98
99  NodeID smallestElement() const;
100  MachineID smallestElement(MachineType machine) const;
101
102  void setSize();
103  int getSize() const { return m_bits.size(); }
104
105  // get element for a index
106  NodeID elementAt(MachineID index);
107
108  void print(ostream& out) const;
109
110private:
111
112  // Private Methods
113  // returns a value >= MachineType_base_level("this machine") and < MachineType_base_level("next highest machine")
114  int vecIndex(MachineID m) const {
115    int vec_index = MachineType_base_level(m.type);
116    assert(vec_index < m_bits.size());
117    return vec_index;
118  }
119
120  NodeID bitIndex(NodeID index) const {
121    return index;
122  }
123
124  // Data Members (m_ prefix)
125  Vector < Set > m_bits;  // a Vector of bit vectors - i.e. Sets
126
127};
128
129// Output operator declaration
130ostream& operator<<(ostream& out, const NetDest& obj);
131
132// ******************* Definitions *******************
133
134// Output operator definition
135extern inline
136ostream& operator<<(ostream& out, const NetDest& obj)
137{
138  obj.print(out);
139  out << flush;
140  return out;
141}
142
143#endif //NETDEST_H
144
145