NetDest.hh revision 10301
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
296145Snate@binkert.org// NetDest specifies the network destination of a NetworkMessage
306145Snate@binkert.org// This is backward compatible with the Set class that was previously
316145Snate@binkert.org// used to specify network destinations.
326145Snate@binkert.org// NetDest supports both node networks and component networks
336145Snate@binkert.org
347039Snate@binkert.org#ifndef __MEM_RUBY_COMMON_NETDEST_HH__
357039Snate@binkert.org#define __MEM_RUBY_COMMON_NETDEST_HH__
366145Snate@binkert.org
377055Snate@binkert.org#include <iostream>
387454Snate@binkert.org#include <vector>
397055Snate@binkert.org
407055Snate@binkert.org#include "mem/ruby/common/Set.hh"
4110301Snilay@cs.wisc.edu#include "mem/ruby/common/MachineID.hh"
426145Snate@binkert.org
437039Snate@binkert.orgclass NetDest
447039Snate@binkert.org{
457039Snate@binkert.org  public:
467039Snate@binkert.org    // Constructors
477039Snate@binkert.org    // creates and empty set
487039Snate@binkert.org    NetDest();
497039Snate@binkert.org    explicit NetDest(int bit_size);
506145Snate@binkert.org
517039Snate@binkert.org    NetDest& operator=(const Set& obj);
526145Snate@binkert.org
537039Snate@binkert.org    ~NetDest()
548054Sksewell@umich.edu    { }
556145Snate@binkert.org
567039Snate@binkert.org    void add(MachineID newElement);
577039Snate@binkert.org    void addNetDest(const NetDest& netDest);
587039Snate@binkert.org    void addRandom();
597039Snate@binkert.org    void setNetDest(MachineType machine, const Set& set);
607039Snate@binkert.org    void remove(MachineID oldElement);
617039Snate@binkert.org    void removeNetDest(const NetDest& netDest);
627039Snate@binkert.org    void clear();
637039Snate@binkert.org    void broadcast();
647039Snate@binkert.org    void broadcast(MachineType machine);
657039Snate@binkert.org    int count() const;
6610004Snilay@cs.wisc.edu    bool isEqual(const NetDest& netDest) const;
676145Snate@binkert.org
687039Snate@binkert.org    // return the logical OR of this netDest and orNetDest
697039Snate@binkert.org    NetDest OR(const NetDest& orNetDest) const;
706145Snate@binkert.org
717039Snate@binkert.org    // return the logical AND of this netDest and andNetDest
727039Snate@binkert.org    NetDest AND(const NetDest& andNetDest) const;
736145Snate@binkert.org
747039Snate@binkert.org    // Returns true if the intersection of the two netDests is non-empty
757039Snate@binkert.org    bool intersectionIsNotEmpty(const NetDest& other_netDest) const;
766145Snate@binkert.org
777039Snate@binkert.org    // Returns true if the intersection of the two netDests is empty
787039Snate@binkert.org    bool intersectionIsEmpty(const NetDest& other_netDest) const;
796145Snate@binkert.org
807039Snate@binkert.org    bool isSuperset(const NetDest& test) const;
817039Snate@binkert.org    bool isSubset(const NetDest& test) const { return test.isSuperset(*this); }
827039Snate@binkert.org    bool isElement(MachineID element) const;
837039Snate@binkert.org    bool isBroadcast() const;
847039Snate@binkert.org    bool isEmpty() const;
856145Snate@binkert.org
867039Snate@binkert.org    // For Princeton Network
877454Snate@binkert.org    std::vector<NodeID> getAllDest();
886145Snate@binkert.org
897039Snate@binkert.org    MachineID smallestElement() const;
907039Snate@binkert.org    MachineID smallestElement(MachineType machine) const;
916145Snate@binkert.org
927454Snate@binkert.org    void resize();
937039Snate@binkert.org    int getSize() const { return m_bits.size(); }
946145Snate@binkert.org
957039Snate@binkert.org    // get element for a index
967039Snate@binkert.org    NodeID elementAt(MachineID index);
976145Snate@binkert.org
987055Snate@binkert.org    void print(std::ostream& out) const;
996145Snate@binkert.org
1007039Snate@binkert.org  private:
1017039Snate@binkert.org    // returns a value >= MachineType_base_level("this machine")
1027039Snate@binkert.org    // and < MachineType_base_level("next highest machine")
1037039Snate@binkert.org    int
1047039Snate@binkert.org    vecIndex(MachineID m) const
1057039Snate@binkert.org    {
1067039Snate@binkert.org        int vec_index = MachineType_base_level(m.type);
1077039Snate@binkert.org        assert(vec_index < m_bits.size());
1087039Snate@binkert.org        return vec_index;
1097039Snate@binkert.org    }
1106145Snate@binkert.org
11110086Snilay@cs.wisc.edu    NodeID bitIndex(NodeID index) const { return index; }
1126145Snate@binkert.org
1137454Snate@binkert.org    std::vector<Set> m_bits;  // a vector of bit vectors - i.e. Sets
1146145Snate@binkert.org};
1156145Snate@binkert.org
1167055Snate@binkert.orginline std::ostream&
1177055Snate@binkert.orgoperator<<(std::ostream& out, const NetDest& obj)
1186145Snate@binkert.org{
1197039Snate@binkert.org    obj.print(out);
1207055Snate@binkert.org    out << std::flush;
1217039Snate@binkert.org    return out;
1226145Snate@binkert.org}
1236145Snate@binkert.org
1247039Snate@binkert.org#endif // __MEM_RUBY_COMMON_NETDEST_HH__
125