NetDest.hh revision 8232
1955SN/A/*
2955SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
37816Ssteve.reinhardt@amd.com * All rights reserved.
45871Snate@binkert.org *
51762SN/A * Redistribution and use in source and binary forms, with or without
6955SN/A * modification, are permitted provided that the following conditions are
7955SN/A * met: redistributions of source code must retain the above copyright
8955SN/A * notice, this list of conditions and the following disclaimer;
9955SN/A * redistributions in binary form must reproduce the above copyright
10955SN/A * notice, this list of conditions and the following disclaimer in the
11955SN/A * documentation and/or other materials provided with the distribution;
12955SN/A * neither the name of the copyright holders nor the names of its
13955SN/A * contributors may be used to endorse or promote products derived from
14955SN/A * this software without specific prior written permission.
15955SN/A *
16955SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17955SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18955SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19955SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20955SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21955SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22955SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23955SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24955SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25955SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26955SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27955SN/A */
28955SN/A
29955SN/A// NetDest specifies the network destination of a NetworkMessage
302665Ssaidi@eecs.umich.edu// This is backward compatible with the Set class that was previously
312665Ssaidi@eecs.umich.edu// used to specify network destinations.
325863Snate@binkert.org// NetDest supports both node networks and component networks
33955SN/A
34955SN/A#ifndef __MEM_RUBY_COMMON_NETDEST_HH__
35955SN/A#define __MEM_RUBY_COMMON_NETDEST_HH__
36955SN/A
37955SN/A#include <iostream>
388878Ssteve.reinhardt@amd.com#include <vector>
392632Sstever@eecs.umich.edu
408878Ssteve.reinhardt@amd.com#include "debug/RubyMemory.hh"
412632Sstever@eecs.umich.edu#include "mem/protocol/MachineType.hh"
42955SN/A#include "mem/ruby/common/Global.hh"
438878Ssteve.reinhardt@amd.com#include "mem/ruby/common/Set.hh"
442632Sstever@eecs.umich.edu#include "mem/ruby/system/MachineID.hh"
452761Sstever@eecs.umich.edu#include "mem/ruby/system/NodeID.hh"
462632Sstever@eecs.umich.edu
472632Sstever@eecs.umich.educlass NetDest
482632Sstever@eecs.umich.edu{
492761Sstever@eecs.umich.edu  public:
502761Sstever@eecs.umich.edu    // Constructors
512761Sstever@eecs.umich.edu    // creates and empty set
528878Ssteve.reinhardt@amd.com    NetDest();
538878Ssteve.reinhardt@amd.com    explicit NetDest(int bit_size);
542761Sstever@eecs.umich.edu
552761Sstever@eecs.umich.edu    NetDest& operator=(const Set& obj);
562761Sstever@eecs.umich.edu
572761Sstever@eecs.umich.edu    ~NetDest()
582761Sstever@eecs.umich.edu    { }
598878Ssteve.reinhardt@amd.com
608878Ssteve.reinhardt@amd.com    void add(MachineID newElement);
612632Sstever@eecs.umich.edu    void addNetDest(const NetDest& netDest);
622632Sstever@eecs.umich.edu    void addRandom();
638878Ssteve.reinhardt@amd.com    void setNetDest(MachineType machine, const Set& set);
648878Ssteve.reinhardt@amd.com    void remove(MachineID oldElement);
652632Sstever@eecs.umich.edu    void removeNetDest(const NetDest& netDest);
66955SN/A    void clear();
67955SN/A    void broadcast();
68955SN/A    void broadcast(MachineType machine);
695863Snate@binkert.org    int count() const;
705863Snate@binkert.org    bool isEqual(const NetDest& netDest);
715863Snate@binkert.org
725863Snate@binkert.org    // return the logical OR of this netDest and orNetDest
735863Snate@binkert.org    NetDest OR(const NetDest& orNetDest) const;
745863Snate@binkert.org
755863Snate@binkert.org    // return the logical AND of this netDest and andNetDest
765863Snate@binkert.org    NetDest AND(const NetDest& andNetDest) const;
775863Snate@binkert.org
785863Snate@binkert.org    // Returns true if the intersection of the two netDests is non-empty
795863Snate@binkert.org    bool intersectionIsNotEmpty(const NetDest& other_netDest) const;
808878Ssteve.reinhardt@amd.com
815863Snate@binkert.org    // Returns true if the intersection of the two netDests is empty
825863Snate@binkert.org    bool intersectionIsEmpty(const NetDest& other_netDest) const;
835863Snate@binkert.org
845863Snate@binkert.org    bool isSuperset(const NetDest& test) const;
855863Snate@binkert.org    bool isSubset(const NetDest& test) const { return test.isSuperset(*this); }
865863Snate@binkert.org    bool isElement(MachineID element) const;
875863Snate@binkert.org    bool isBroadcast() const;
885863Snate@binkert.org    bool isEmpty() const;
895863Snate@binkert.org
905863Snate@binkert.org    // For Princeton Network
915863Snate@binkert.org    std::vector<NodeID> getAllDest();
925863Snate@binkert.org
935863Snate@binkert.org    MachineID smallestElement() const;
945863Snate@binkert.org    MachineID smallestElement(MachineType machine) const;
955863Snate@binkert.org
968878Ssteve.reinhardt@amd.com    void resize();
975863Snate@binkert.org    int getSize() const { return m_bits.size(); }
985863Snate@binkert.org
995863Snate@binkert.org    // get element for a index
1006654Snate@binkert.org    NodeID elementAt(MachineID index);
101955SN/A
1025396Ssaidi@eecs.umich.edu    void print(std::ostream& out) const;
1035863Snate@binkert.org
1045863Snate@binkert.org  private:
1054202Sbinkertn@umich.edu    // returns a value >= MachineType_base_level("this machine")
1065863Snate@binkert.org    // and < MachineType_base_level("next highest machine")
1075863Snate@binkert.org    int
1085863Snate@binkert.org    vecIndex(MachineID m) const
1095863Snate@binkert.org    {
110955SN/A        int vec_index = MachineType_base_level(m.type);
1116654Snate@binkert.org        assert(vec_index < m_bits.size());
1125273Sstever@gmail.com        return vec_index;
1135871Snate@binkert.org    }
1145273Sstever@gmail.com
1156655Snate@binkert.org    NodeID
1168878Ssteve.reinhardt@amd.com    bitIndex(NodeID index) const
1176655Snate@binkert.org    {
1186655Snate@binkert.org        return index;
1196655Snate@binkert.org    }
1206655Snate@binkert.org
1215871Snate@binkert.org    std::vector<Set> m_bits;  // a vector of bit vectors - i.e. Sets
1226654Snate@binkert.org};
1238947Sandreas.hansson@arm.com
1245396Ssaidi@eecs.umich.eduinline std::ostream&
1258120Sgblack@eecs.umich.eduoperator<<(std::ostream& out, const NetDest& obj)
1268120Sgblack@eecs.umich.edu{
1278120Sgblack@eecs.umich.edu    obj.print(out);
1288120Sgblack@eecs.umich.edu    out << std::flush;
1298120Sgblack@eecs.umich.edu    return out;
1308120Sgblack@eecs.umich.edu}
1318120Sgblack@eecs.umich.edu
1328120Sgblack@eecs.umich.edu#endif // __MEM_RUBY_COMMON_NETDEST_HH__
1338879Ssteve.reinhardt@amd.com
1348879Ssteve.reinhardt@amd.com