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