NetDest.hh revision 6284:a63d1dc4c820
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/config/RubyConfig.hh"
52#include "mem/ruby/common/Set.hh"
53#include "mem/protocol/MachineType.hh"
54
55class Set;
56
57class NetDest {
58public:
59  // Constructors
60  // creates and empty set
61  NetDest();
62  explicit NetDest(int bit_size);
63
64  NetDest& operator=(const Set& obj);
65
66  // Destructor
67  // ~NetDest();
68
69  // Public Methods
70  void add(MachineID newElement);
71  void addNetDest(const NetDest& netDest);
72  void addRandom();
73  void setNetDest(MachineType machine, const Set& set);
74  void remove(MachineID oldElement);
75  void removeNetDest(const NetDest& netDest);
76  void clear();
77  void broadcast();
78  void broadcast(MachineType machine);
79  int count() const;
80  bool isEqual(const NetDest& netDest);
81
82  NetDest OR(const NetDest& orNetDest) const;  // return the logical OR of this netDest and orNetDest
83  NetDest AND(const NetDest& andNetDest) const;  // return the logical AND of this netDest and andNetDest
84
85  // Returns true if the intersection of the two netDests is non-empty
86  bool intersectionIsNotEmpty(const NetDest& other_netDest) const;
87
88  // Returns true if the intersection of the two netDests is empty
89  bool intersectionIsEmpty(const NetDest& other_netDest) const;
90
91  bool isSuperset(const NetDest& test) const;
92  bool isSubset(const NetDest& test) const { return test.isSuperset(*this); }
93  bool isElement(MachineID element) const;
94  bool isBroadcast() const;
95  bool isEmpty() const;
96
97  //For Princeton Network
98  Vector<NodeID> getAllDest();
99
100  NodeID smallestElement() const;
101  MachineID smallestElement(MachineType machine) const;
102
103  void setSize();
104  int getSize() const { return m_bits.size(); }
105
106  // get element for a index
107  NodeID elementAt(MachineID index);
108
109  void print(ostream& out) const;
110
111private:
112
113  // Private Methods
114  // returns a value >= MachineType_base_level("this machine") and < MachineType_base_level("next highest machine")
115  int vecIndex(MachineID m) const {
116    int vec_index = MachineType_base_level(m.type);
117    assert(vec_index < m_bits.size());
118    return vec_index;
119  }
120
121  NodeID bitIndex(NodeID index) const {
122    return index;
123  }
124
125  // Data Members (m_ prefix)
126  Vector < Set > m_bits;  // a Vector of bit vectors - i.e. Sets
127
128};
129
130// Output operator declaration
131ostream& operator<<(ostream& out, const NetDest& obj);
132
133// ******************* Definitions *******************
134
135// Output operator definition
136extern inline
137ostream& operator<<(ostream& out, const NetDest& obj)
138{
139  obj.print(out);
140  out << flush;
141  return out;
142}
143
144#endif //NETDEST_H
145
146