NetDest.hh revision 10086
12817Sksewell@umich.edu/*
22817Sksewell@umich.edu * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
32817Sksewell@umich.edu * All rights reserved.
42817Sksewell@umich.edu *
52817Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without
62817Sksewell@umich.edu * modification, are permitted provided that the following conditions are
72817Sksewell@umich.edu * met: redistributions of source code must retain the above copyright
82817Sksewell@umich.edu * notice, this list of conditions and the following disclaimer;
92817Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright
102817Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the
112817Sksewell@umich.edu * documentation and/or other materials provided with the distribution;
122817Sksewell@umich.edu * neither the name of the copyright holders nor the names of its
132817Sksewell@umich.edu * contributors may be used to endorse or promote products derived from
142817Sksewell@umich.edu * this software without specific prior written permission.
152817Sksewell@umich.edu *
162817Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172817Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182817Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192817Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202817Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212817Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222817Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232817Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242817Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252817Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262817Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272817Sksewell@umich.edu */
282817Sksewell@umich.edu
294202Sbinkertn@umich.edu// NetDest specifies the network destination of a NetworkMessage
302817Sksewell@umich.edu// This is backward compatible with the Set class that was previously
312817Sksewell@umich.edu// used to specify network destinations.
322817Sksewell@umich.edu// NetDest supports both node networks and component networks
334202Sbinkertn@umich.edu
342817Sksewell@umich.edu#ifndef __MEM_RUBY_COMMON_NETDEST_HH__
355192Ssaidi@eecs.umich.edu#define __MEM_RUBY_COMMON_NETDEST_HH__
365192Ssaidi@eecs.umich.edu
375192Ssaidi@eecs.umich.edu#include <iostream>
385192Ssaidi@eecs.umich.edu#include <vector>
395192Ssaidi@eecs.umich.edu
405192Ssaidi@eecs.umich.edu#include "mem/ruby/common/Set.hh"
415192Ssaidi@eecs.umich.edu#include "mem/ruby/system/MachineID.hh"
425192Ssaidi@eecs.umich.edu
435192Ssaidi@eecs.umich.educlass NetDest
445192Ssaidi@eecs.umich.edu{
454202Sbinkertn@umich.edu  public:
464486Sbinkertn@umich.edu    // Constructors
474486Sbinkertn@umich.edu    // creates and empty set
484486Sbinkertn@umich.edu    NetDest();
494486Sbinkertn@umich.edu    explicit NetDest(int bit_size);
504202Sbinkertn@umich.edu
514202Sbinkertn@umich.edu    NetDest& operator=(const Set& obj);
524202Sbinkertn@umich.edu
534202Sbinkertn@umich.edu    ~NetDest()
545597Sgblack@eecs.umich.edu    { }
554202Sbinkertn@umich.edu
565597Sgblack@eecs.umich.edu    void add(MachineID newElement);
574202Sbinkertn@umich.edu    void addNetDest(const NetDest& netDest);
584202Sbinkertn@umich.edu    void addRandom();
594202Sbinkertn@umich.edu    void setNetDest(MachineType machine, const Set& set);
604202Sbinkertn@umich.edu    void remove(MachineID oldElement);
614202Sbinkertn@umich.edu    void removeNetDest(const NetDest& netDest);
624202Sbinkertn@umich.edu    void clear();
634202Sbinkertn@umich.edu    void broadcast();
644202Sbinkertn@umich.edu    void broadcast(MachineType machine);
654202Sbinkertn@umich.edu    int count() const;
664202Sbinkertn@umich.edu    bool isEqual(const NetDest& netDest) const;
674202Sbinkertn@umich.edu
684202Sbinkertn@umich.edu    // return the logical OR of this netDest and orNetDest
694202Sbinkertn@umich.edu    NetDest OR(const NetDest& orNetDest) const;
705597Sgblack@eecs.umich.edu
712817Sksewell@umich.edu    // return the logical AND of this netDest and andNetDest
725192Ssaidi@eecs.umich.edu    NetDest AND(const NetDest& andNetDest) const;
735192Ssaidi@eecs.umich.edu
745192Ssaidi@eecs.umich.edu    // Returns true if the intersection of the two netDests is non-empty
755192Ssaidi@eecs.umich.edu    bool intersectionIsNotEmpty(const NetDest& other_netDest) const;
765192Ssaidi@eecs.umich.edu
775192Ssaidi@eecs.umich.edu    // Returns true if the intersection of the two netDests is empty
785192Ssaidi@eecs.umich.edu    bool intersectionIsEmpty(const NetDest& other_netDest) const;
795192Ssaidi@eecs.umich.edu
805192Ssaidi@eecs.umich.edu    bool isSuperset(const NetDest& test) const;
815192Ssaidi@eecs.umich.edu    bool isSubset(const NetDest& test) const { return test.isSuperset(*this); }
825192Ssaidi@eecs.umich.edu    bool isElement(MachineID element) const;
835192Ssaidi@eecs.umich.edu    bool isBroadcast() const;
845192Ssaidi@eecs.umich.edu    bool isEmpty() const;
855192Ssaidi@eecs.umich.edu
865192Ssaidi@eecs.umich.edu    // For Princeton Network
874202Sbinkertn@umich.edu    std::vector<NodeID> getAllDest();
884497Sbinkertn@umich.edu
894202Sbinkertn@umich.edu    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__
125