NetDest.hh revision 10086
16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
36145Snate@binkert.org * All rights reserved.
46145Snate@binkert.org *
56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66145Snate@binkert.org * modification, are permitted provided that the following conditions are
76145Snate@binkert.org * met: redistributions of source code must retain the above copyright
86145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116145Snate@binkert.org * documentation and/or other materials provided with the distribution;
126145Snate@binkert.org * neither the name of the copyright holders nor the names of its
136145Snate@binkert.org * contributors may be used to endorse or promote products derived from
146145Snate@binkert.org * this software without specific prior written permission.
156145Snate@binkert.org *
166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276145Snate@binkert.org */
286145Snate@binkert.org
297832Snate@binkert.org// NetDest specifies the network destination of a NetworkMessage
307832Snate@binkert.org// This is backward compatible with the Set class that was previously
318645Snilay@cs.wisc.edu// used to specify network destinations.
327054Snate@binkert.org// NetDest supports both node networks and component networks
338232Snate@binkert.org
348229Snate@binkert.org#ifndef __MEM_RUBY_COMMON_NETDEST_HH__
3510301Snilay@cs.wisc.edu#define __MEM_RUBY_COMMON_NETDEST_HH__
366154Snate@binkert.org
3710895Snilay@cs.wisc.edu#include <iostream>
386154Snate@binkert.org#include <vector>
396145Snate@binkert.org
407055Snate@binkert.org#include "mem/ruby/common/Set.hh"
417055Snate@binkert.org#include "mem/ruby/system/MachineID.hh"
426145Snate@binkert.org
436145Snate@binkert.orgclass NetDest
446145Snate@binkert.org{
456145Snate@binkert.org  public:
466145Snate@binkert.org    // Constructors
4710895Snilay@cs.wisc.edu    // creates and empty set
486145Snate@binkert.org    NetDest();
4910918Sbrandon.potter@amd.com    explicit NetDest(int bit_size);
509230Snilay@cs.wisc.edu
519465Snilay@cs.wisc.edu    NetDest& operator=(const Set& obj);
5210918Sbrandon.potter@amd.com
536145Snate@binkert.org    ~NetDest()
548259SBrad.Beckmann@amd.com    { }
557054Snate@binkert.org
566145Snate@binkert.org    void add(MachineID newElement);
576145Snate@binkert.org    void addNetDest(const NetDest& netDest);
5810918Sbrandon.potter@amd.com    void addRandom();
599230Snilay@cs.wisc.edu    void setNetDest(MachineType machine, const Set& set);
609465Snilay@cs.wisc.edu    void remove(MachineID oldElement);
6110918Sbrandon.potter@amd.com    void removeNetDest(const NetDest& netDest);
626145Snate@binkert.org    void clear();
638259SBrad.Beckmann@amd.com    void broadcast();
647054Snate@binkert.org    void broadcast(MachineType machine);
656145Snate@binkert.org    int count() const;
666145Snate@binkert.org    bool isEqual(const NetDest& netDest) const;
677054Snate@binkert.org
689499Snilay@cs.wisc.edu    // return the logical OR of this netDest and orNetDest
699499Snilay@cs.wisc.edu    NetDest OR(const NetDest& orNetDest) const;
706145Snate@binkert.org
717054Snate@binkert.org    // return the logical AND of this netDest and andNetDest
7210370Snilay@cs.wisc.edu    NetDest AND(const NetDest& andNetDest) const;
7310370Snilay@cs.wisc.edu
747832Snate@binkert.org    // Returns true if the intersection of the two netDests is non-empty
757054Snate@binkert.org    bool intersectionIsNotEmpty(const NetDest& other_netDest) const;
7610311Snilay@cs.wisc.edu
777054Snate@binkert.org    // Returns true if the intersection of the two netDests is empty
788259SBrad.Beckmann@amd.com    bool intersectionIsEmpty(const NetDest& other_netDest) const;
796145Snate@binkert.org
807054Snate@binkert.org    bool isSuperset(const NetDest& test) const;
819863Snilay@cs.wisc.edu    bool isSubset(const NetDest& test) const { return test.isSuperset(*this); }
826145Snate@binkert.org    bool isElement(MachineID element) const;
836145Snate@binkert.org    bool isBroadcast() const;
847054Snate@binkert.org    bool isEmpty() const;
8510370Snilay@cs.wisc.edu
8610370Snilay@cs.wisc.edu    // For Princeton Network
876145Snate@binkert.org    std::vector<NodeID> getAllDest();
887054Snate@binkert.org
8910311Snilay@cs.wisc.edu    MachineID smallestElement() const;
9010370Snilay@cs.wisc.edu    MachineID smallestElement(MachineType machine) const;
9110370Snilay@cs.wisc.edu
9210370Snilay@cs.wisc.edu    void resize();
9310311Snilay@cs.wisc.edu    int getSize() const { return m_bits.size(); }
9410370Snilay@cs.wisc.edu
9510370Snilay@cs.wisc.edu    // get element for a index
9610370Snilay@cs.wisc.edu    NodeID elementAt(MachineID index);
9710370Snilay@cs.wisc.edu
9810311Snilay@cs.wisc.edu    void print(std::ostream& out) const;
9910311Snilay@cs.wisc.edu
10010311Snilay@cs.wisc.edu  private:
10110311Snilay@cs.wisc.edu    // returns a value >= MachineType_base_level("this machine")
10210311Snilay@cs.wisc.edu    // and < MachineType_base_level("next highest machine")
10310311Snilay@cs.wisc.edu    int
1047054Snate@binkert.org    vecIndex(MachineID m) const
1056145Snate@binkert.org    {
1066145Snate@binkert.org        int vec_index = MachineType_base_level(m.type);
1077054Snate@binkert.org        assert(vec_index < m_bits.size());
10810311Snilay@cs.wisc.edu        return vec_index;
10910311Snilay@cs.wisc.edu    }
1106145Snate@binkert.org
11110370Snilay@cs.wisc.edu    NodeID bitIndex(NodeID index) const { return index; }
11210370Snilay@cs.wisc.edu
11310370Snilay@cs.wisc.edu    std::vector<Set> m_bits;  // a vector of bit vectors - i.e. Sets
11410311Snilay@cs.wisc.edu};
1156145Snate@binkert.org
11610311Snilay@cs.wisc.eduinline std::ostream&
11710311Snilay@cs.wisc.eduoperator<<(std::ostream& out, const NetDest& obj)
1189465Snilay@cs.wisc.edu{
11910311Snilay@cs.wisc.edu    obj.print(out);
12010311Snilay@cs.wisc.edu    out << std::flush;
12110311Snilay@cs.wisc.edu    return out;
12210311Snilay@cs.wisc.edu}
12310311Snilay@cs.wisc.edu
12410895Snilay@cs.wisc.edu#endif // __MEM_RUBY_COMMON_NETDEST_HH__
12510311Snilay@cs.wisc.edu