NetDest.hh revision 10086:bd1089db3a88
1360SN/A/* 21458SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 3360SN/A * All rights reserved. 4360SN/A * 5360SN/A * Redistribution and use in source and binary forms, with or without 6360SN/A * modification, are permitted provided that the following conditions are 7360SN/A * met: redistributions of source code must retain the above copyright 8360SN/A * notice, this list of conditions and the following disclaimer; 9360SN/A * redistributions in binary form must reproduce the above copyright 10360SN/A * notice, this list of conditions and the following disclaimer in the 11360SN/A * documentation and/or other materials provided with the distribution; 12360SN/A * neither the name of the copyright holders nor the names of its 13360SN/A * contributors may be used to endorse or promote products derived from 14360SN/A * this software without specific prior written permission. 15360SN/A * 16360SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17360SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18360SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19360SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20360SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21360SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22360SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23360SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24360SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25360SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26360SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu */ 282665Ssaidi@eecs.umich.edu 292665Ssaidi@eecs.umich.edu// NetDest specifies the network destination of a NetworkMessage 30360SN/A// This is backward compatible with the Set class that was previously 31360SN/A// used to specify network destinations. 321354SN/A// NetDest supports both node networks and component networks 331354SN/A 34360SN/A#ifndef __MEM_RUBY_COMMON_NETDEST_HH__ 352764Sstever@eecs.umich.edu#define __MEM_RUBY_COMMON_NETDEST_HH__ 362764Sstever@eecs.umich.edu 372064SN/A#include <iostream> 38360SN/A#include <vector> 39360SN/A 40360SN/A#include "mem/ruby/common/Set.hh" 41360SN/A#include "mem/ruby/system/MachineID.hh" 42360SN/A 43360SN/Aclass NetDest 441354SN/A{ 45360SN/A public: 461809SN/A // Constructors 471809SN/A // creates and empty set 481809SN/A NetDest(); 493113Sgblack@eecs.umich.edu explicit NetDest(int bit_size); 503113Sgblack@eecs.umich.edu 511999SN/A NetDest& operator=(const Set& obj); 52360SN/A 533113Sgblack@eecs.umich.edu ~NetDest() 542474SN/A { } 55360SN/A 562462SN/A void add(MachineID newElement); 571354SN/A void addNetDest(const NetDest& netDest); 582474SN/A void addRandom(); 592680Sktlim@umich.edu void setNetDest(MachineType machine, const Set& set); 602474SN/A void remove(MachineID oldElement); 612474SN/A void removeNetDest(const NetDest& netDest); 621354SN/A void clear(); 63360SN/A void broadcast(); 64360SN/A void broadcast(MachineType machine); 65360SN/A int count() const; 66360SN/A bool isEqual(const NetDest& netDest) const; 67360SN/A 68360SN/A // return the logical OR of this netDest and orNetDest 69360SN/A NetDest OR(const NetDest& orNetDest) const; 70360SN/A 71378SN/A // return the logical AND of this netDest and andNetDest 721450SN/A NetDest AND(const NetDest& andNetDest) const; 733114Sgblack@eecs.umich.edu 74360SN/A // Returns true if the intersection of the two netDests is non-empty 75360SN/A bool intersectionIsNotEmpty(const NetDest& other_netDest) const; 76360SN/A 77360SN/A // Returns true if the intersection of the two netDests is empty 78360SN/A bool intersectionIsEmpty(const NetDest& other_netDest) const; 79360SN/A 80360SN/A bool isSuperset(const NetDest& test) const; 81360SN/A bool isSubset(const NetDest& test) const { return test.isSuperset(*this); } 82360SN/A bool isElement(MachineID element) const; 832680Sktlim@umich.edu bool isBroadcast() const; 84360SN/A bool isEmpty() const; 85360SN/A 86360SN/A // For Princeton Network 87360SN/A std::vector<NodeID> getAllDest(); 88360SN/A 89360SN/A MachineID smallestElement() const; 90360SN/A MachineID smallestElement(MachineType machine) const; 91360SN/A 92360SN/A void resize(); 93360SN/A int getSize() const { return m_bits.size(); } 94360SN/A 953114Sgblack@eecs.umich.edu // get element for a index 96360SN/A NodeID elementAt(MachineID index); 97360SN/A 98360SN/A void print(std::ostream& out) const; 99360SN/A 100360SN/A private: 101360SN/A // returns a value >= MachineType_base_level("this machine") 102360SN/A // and < MachineType_base_level("next highest machine") 103360SN/A int 104360SN/A vecIndex(MachineID m) const 105360SN/A { 106360SN/A int vec_index = MachineType_base_level(m.type); 107360SN/A assert(vec_index < m_bits.size()); 108360SN/A return vec_index; 109360SN/A } 110360SN/A 111360SN/A NodeID bitIndex(NodeID index) const { return index; } 112360SN/A 113360SN/A std::vector<Set> m_bits; // a vector of bit vectors - i.e. Sets 114360SN/A}; 115360SN/A 116360SN/Ainline std::ostream& 1172400SN/Aoperator<<(std::ostream& out, const NetDest& obj) 118360SN/A{ 1192461SN/A obj.print(out); 120360SN/A out << std::flush; 121360SN/A return out; 122360SN/A} 123360SN/A 124360SN/A#endif // __MEM_RUBY_COMMON_NETDEST_HH__ 125360SN/A