NetDest.hh revision 7055
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>
387055Snate@binkert.org
397055Snate@binkert.org#include "mem/gems_common/Vector.hh"
407055Snate@binkert.org#include "mem/protocol/MachineType.hh"
416154Snate@binkert.org#include "mem/ruby/common/Global.hh"
427055Snate@binkert.org#include "mem/ruby/common/Set.hh"
437055Snate@binkert.org#include "mem/ruby/system/MachineID.hh"
446154Snate@binkert.org#include "mem/ruby/system/NodeID.hh"
456145Snate@binkert.org
467039Snate@binkert.orgclass NetDest
477039Snate@binkert.org{
487039Snate@binkert.org  public:
497039Snate@binkert.org    // Constructors
507039Snate@binkert.org    // creates and empty set
517039Snate@binkert.org    NetDest();
527039Snate@binkert.org    explicit NetDest(int bit_size);
536145Snate@binkert.org
547039Snate@binkert.org    NetDest& operator=(const Set& obj);
556145Snate@binkert.org
567039Snate@binkert.org    ~NetDest()
577039Snate@binkert.org    {
587039Snate@binkert.org        DEBUG_MSG(MEMORY_COMP, LowPrio, "NetDest Destructor");
597039Snate@binkert.org    }
606145Snate@binkert.org
617039Snate@binkert.org    void add(MachineID newElement);
627039Snate@binkert.org    void addNetDest(const NetDest& netDest);
637039Snate@binkert.org    void addRandom();
647039Snate@binkert.org    void setNetDest(MachineType machine, const Set& set);
657039Snate@binkert.org    void remove(MachineID oldElement);
667039Snate@binkert.org    void removeNetDest(const NetDest& netDest);
677039Snate@binkert.org    void clear();
687039Snate@binkert.org    void broadcast();
697039Snate@binkert.org    void broadcast(MachineType machine);
707039Snate@binkert.org    int count() const;
717039Snate@binkert.org    bool isEqual(const NetDest& netDest);
726145Snate@binkert.org
737039Snate@binkert.org    // return the logical OR of this netDest and orNetDest
747039Snate@binkert.org    NetDest OR(const NetDest& orNetDest) const;
756145Snate@binkert.org
767039Snate@binkert.org    // return the logical AND of this netDest and andNetDest
777039Snate@binkert.org    NetDest AND(const NetDest& andNetDest) const;
786145Snate@binkert.org
797039Snate@binkert.org    // Returns true if the intersection of the two netDests is non-empty
807039Snate@binkert.org    bool intersectionIsNotEmpty(const NetDest& other_netDest) const;
816145Snate@binkert.org
827039Snate@binkert.org    // Returns true if the intersection of the two netDests is empty
837039Snate@binkert.org    bool intersectionIsEmpty(const NetDest& other_netDest) const;
846145Snate@binkert.org
857039Snate@binkert.org    bool isSuperset(const NetDest& test) const;
867039Snate@binkert.org    bool isSubset(const NetDest& test) const { return test.isSuperset(*this); }
877039Snate@binkert.org    bool isElement(MachineID element) const;
887039Snate@binkert.org    bool isBroadcast() const;
897039Snate@binkert.org    bool isEmpty() const;
906145Snate@binkert.org
917039Snate@binkert.org    // For Princeton Network
927039Snate@binkert.org    Vector<NodeID> getAllDest();
936145Snate@binkert.org
947039Snate@binkert.org    MachineID smallestElement() const;
957039Snate@binkert.org    MachineID smallestElement(MachineType machine) const;
966145Snate@binkert.org
977039Snate@binkert.org    void setSize();
987039Snate@binkert.org    int getSize() const { return m_bits.size(); }
996145Snate@binkert.org
1007039Snate@binkert.org    // get element for a index
1017039Snate@binkert.org    NodeID elementAt(MachineID index);
1026145Snate@binkert.org
1037055Snate@binkert.org    void print(std::ostream& out) const;
1046145Snate@binkert.org
1057039Snate@binkert.org  private:
1067039Snate@binkert.org    // returns a value >= MachineType_base_level("this machine")
1077039Snate@binkert.org    // and < MachineType_base_level("next highest machine")
1087039Snate@binkert.org    int
1097039Snate@binkert.org    vecIndex(MachineID m) const
1107039Snate@binkert.org    {
1117039Snate@binkert.org        int vec_index = MachineType_base_level(m.type);
1127039Snate@binkert.org        assert(vec_index < m_bits.size());
1137039Snate@binkert.org        return vec_index;
1147039Snate@binkert.org    }
1156145Snate@binkert.org
1167039Snate@binkert.org    NodeID
1177039Snate@binkert.org    bitIndex(NodeID index) const
1187039Snate@binkert.org    {
1197039Snate@binkert.org        return index;
1207039Snate@binkert.org    }
1216145Snate@binkert.org
1227039Snate@binkert.org    Vector <Set> m_bits;  // a Vector of bit vectors - i.e. Sets
1236145Snate@binkert.org};
1246145Snate@binkert.org
1257055Snate@binkert.orginline std::ostream&
1267055Snate@binkert.orgoperator<<(std::ostream& out, const NetDest& obj)
1276145Snate@binkert.org{
1287039Snate@binkert.org    obj.print(out);
1297055Snate@binkert.org    out << std::flush;
1307039Snate@binkert.org    return out;
1316145Snate@binkert.org}
1326145Snate@binkert.org
1337039Snate@binkert.org#endif // __MEM_RUBY_COMMON_NETDEST_HH__
1346145Snate@binkert.org
135