NetDest.hh revision 10004
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 408232Snate@binkert.org#include "debug/RubyMemory.hh" 417055Snate@binkert.org#include "mem/protocol/MachineType.hh" 426154Snate@binkert.org#include "mem/ruby/common/Global.hh" 437055Snate@binkert.org#include "mem/ruby/common/Set.hh" 447055Snate@binkert.org#include "mem/ruby/system/MachineID.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() 578054Sksewell@umich.edu { } 586145Snate@binkert.org 597039Snate@binkert.org void add(MachineID newElement); 607039Snate@binkert.org void addNetDest(const NetDest& netDest); 617039Snate@binkert.org void addRandom(); 627039Snate@binkert.org void setNetDest(MachineType machine, const Set& set); 637039Snate@binkert.org void remove(MachineID oldElement); 647039Snate@binkert.org void removeNetDest(const NetDest& netDest); 657039Snate@binkert.org void clear(); 667039Snate@binkert.org void broadcast(); 677039Snate@binkert.org void broadcast(MachineType machine); 687039Snate@binkert.org int count() const; 6910004Snilay@cs.wisc.edu bool isEqual(const NetDest& netDest) const; 706145Snate@binkert.org 717039Snate@binkert.org // return the logical OR of this netDest and orNetDest 727039Snate@binkert.org NetDest OR(const NetDest& orNetDest) const; 736145Snate@binkert.org 747039Snate@binkert.org // return the logical AND of this netDest and andNetDest 757039Snate@binkert.org NetDest AND(const NetDest& andNetDest) const; 766145Snate@binkert.org 777039Snate@binkert.org // Returns true if the intersection of the two netDests is non-empty 787039Snate@binkert.org bool intersectionIsNotEmpty(const NetDest& other_netDest) const; 796145Snate@binkert.org 807039Snate@binkert.org // Returns true if the intersection of the two netDests is empty 817039Snate@binkert.org bool intersectionIsEmpty(const NetDest& other_netDest) const; 826145Snate@binkert.org 837039Snate@binkert.org bool isSuperset(const NetDest& test) const; 847039Snate@binkert.org bool isSubset(const NetDest& test) const { return test.isSuperset(*this); } 857039Snate@binkert.org bool isElement(MachineID element) const; 867039Snate@binkert.org bool isBroadcast() const; 877039Snate@binkert.org bool isEmpty() const; 886145Snate@binkert.org 897039Snate@binkert.org // For Princeton Network 907454Snate@binkert.org std::vector<NodeID> getAllDest(); 916145Snate@binkert.org 927039Snate@binkert.org MachineID smallestElement() const; 937039Snate@binkert.org MachineID smallestElement(MachineType machine) const; 946145Snate@binkert.org 957454Snate@binkert.org void resize(); 967039Snate@binkert.org int getSize() const { return m_bits.size(); } 976145Snate@binkert.org 987039Snate@binkert.org // get element for a index 997039Snate@binkert.org NodeID elementAt(MachineID index); 1006145Snate@binkert.org 1017055Snate@binkert.org void print(std::ostream& out) const; 1026145Snate@binkert.org 1037039Snate@binkert.org private: 1047039Snate@binkert.org // returns a value >= MachineType_base_level("this machine") 1057039Snate@binkert.org // and < MachineType_base_level("next highest machine") 1067039Snate@binkert.org int 1077039Snate@binkert.org vecIndex(MachineID m) const 1087039Snate@binkert.org { 1097039Snate@binkert.org int vec_index = MachineType_base_level(m.type); 1107039Snate@binkert.org assert(vec_index < m_bits.size()); 1117039Snate@binkert.org return vec_index; 1127039Snate@binkert.org } 1136145Snate@binkert.org 1147039Snate@binkert.org NodeID 1157039Snate@binkert.org bitIndex(NodeID index) const 1167039Snate@binkert.org { 1177039Snate@binkert.org return index; 1187039Snate@binkert.org } 1196145Snate@binkert.org 1207454Snate@binkert.org std::vector<Set> m_bits; // a vector of bit vectors - i.e. Sets 1216145Snate@binkert.org}; 1226145Snate@binkert.org 1237055Snate@binkert.orginline std::ostream& 1247055Snate@binkert.orgoperator<<(std::ostream& out, const NetDest& obj) 1256145Snate@binkert.org{ 1267039Snate@binkert.org obj.print(out); 1277055Snate@binkert.org out << std::flush; 1287039Snate@binkert.org return out; 1296145Snate@binkert.org} 1306145Snate@binkert.org 1317039Snate@binkert.org#endif // __MEM_RUBY_COMMON_NETDEST_HH__ 1326145Snate@binkert.org 133