TBETable.hh revision 7039
113511Sgabeblack@google.com/*
213511Sgabeblack@google.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
313511Sgabeblack@google.com * All rights reserved.
413511Sgabeblack@google.com *
513511Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
613511Sgabeblack@google.com * modification, are permitted provided that the following conditions are
713511Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
813511Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
913511Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1013511Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1113511Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1213511Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1313511Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1413511Sgabeblack@google.com * this software without specific prior written permission.
1513511Sgabeblack@google.com *
1613511Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1713511Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1813511Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1913513Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2013513Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2113511Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2213586Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2313586Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2413586Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2513511Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2613513Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2713513Sgabeblack@google.com */
2813511Sgabeblack@google.com
2913511Sgabeblack@google.com#ifndef __MEM_RUBY_SYSTEM_TBETABLE_HH__
3013511Sgabeblack@google.com#define __MEM_RUBY_SYSTEM_TBETABLE_HH__
3113511Sgabeblack@google.com
3213511Sgabeblack@google.com#include "mem/gems_common/Map.hh"
3313511Sgabeblack@google.com#include "mem/ruby/common/Address.hh"
3413511Sgabeblack@google.com#include "mem/ruby/common/Global.hh"
3513511Sgabeblack@google.com#include "mem/ruby/profiler/Profiler.hh"
3613511Sgabeblack@google.com#include "mem/ruby/system/System.hh"
3713511Sgabeblack@google.com
3813511Sgabeblack@google.comtemplate<class ENTRY>
3913511Sgabeblack@google.comclass TBETable
4013513Sgabeblack@google.com{
4113513Sgabeblack@google.com  public:
4213513Sgabeblack@google.com    TBETable(int number_of_TBEs)
4313513Sgabeblack@google.com        : m_number_of_TBEs(number_of_TBEs)
4413513Sgabeblack@google.com    {
4513513Sgabeblack@google.com    }
4613511Sgabeblack@google.com
4713513Sgabeblack@google.com    void
4813513Sgabeblack@google.com    printConfig(ostream& out)
4913513Sgabeblack@google.com    {
5013513Sgabeblack@google.com        out << "TBEs_per_TBETable: " << m_number_of_TBEs << endl;
5113513Sgabeblack@google.com    }
5213513Sgabeblack@google.com
5313511Sgabeblack@google.com    bool isPresent(const Address& address) const;
5413513Sgabeblack@google.com    void allocate(const Address& address);
5513513Sgabeblack@google.com    void deallocate(const Address& address);
5613513Sgabeblack@google.com    bool
5713513Sgabeblack@google.com    areNSlotsAvailable(int n) const
5813513Sgabeblack@google.com    {
5913513Sgabeblack@google.com        return (m_number_of_TBEs - m_map.size()) >= n;
6013513Sgabeblack@google.com    }
6113511Sgabeblack@google.com
6213513Sgabeblack@google.com    ENTRY& lookup(const Address& address);
6313511Sgabeblack@google.com    const ENTRY& lookup(const Address& address) const;
6413513Sgabeblack@google.com
6513513Sgabeblack@google.com    // Print cache contents
6613511Sgabeblack@google.com    void print(ostream& out) const;
6713513Sgabeblack@google.com
6813513Sgabeblack@google.com  private:
6913511Sgabeblack@google.com    // Private copy constructor and assignment operator
7013513Sgabeblack@google.com    TBETable(const TBETable& obj);
7113511Sgabeblack@google.com    TBETable& operator=(const TBETable& obj);
7213511Sgabeblack@google.com
7313513Sgabeblack@google.com    // Data Members (m_prefix)
7413513Sgabeblack@google.com    Map<Address, ENTRY> m_map;
7513513Sgabeblack@google.com
7613513Sgabeblack@google.com  private:
7713511Sgabeblack@google.com    int m_number_of_TBEs;
7813513Sgabeblack@google.com};
7913513Sgabeblack@google.com
8013513Sgabeblack@google.comtemplate<class ENTRY>
8113513Sgabeblack@google.cominline ostream&
8213513Sgabeblack@google.comoperator<<(ostream& out, const TBETable<ENTRY>& obj)
8313511Sgabeblack@google.com{
8413511Sgabeblack@google.com    obj.print(out);
8513513Sgabeblack@google.com    out << flush;
8613513Sgabeblack@google.com    return out;
8713513Sgabeblack@google.com}
8813513Sgabeblack@google.com
8913513Sgabeblack@google.comtemplate<class ENTRY>
9013513Sgabeblack@google.cominline bool
9113513Sgabeblack@google.comTBETable<ENTRY>::isPresent(const Address& address) const
9213513Sgabeblack@google.com{
9313513Sgabeblack@google.com    assert(address == line_address(address));
9413513Sgabeblack@google.com    assert(m_map.size() <= m_number_of_TBEs);
9513513Sgabeblack@google.com    return m_map.exist(address);
9613513Sgabeblack@google.com}
9713513Sgabeblack@google.com
9813511Sgabeblack@google.comtemplate<class ENTRY>
9913513Sgabeblack@google.cominline void
10013513Sgabeblack@google.comTBETable<ENTRY>::allocate(const Address& address)
10113513Sgabeblack@google.com{
10213513Sgabeblack@google.com    assert(isPresent(address) == false);
10313513Sgabeblack@google.com    assert(m_map.size() < m_number_of_TBEs);
10413513Sgabeblack@google.com    m_map.add(address, ENTRY());
10513513Sgabeblack@google.com}
10613513Sgabeblack@google.com
10713511Sgabeblack@google.comtemplate<class ENTRY>
10813513Sgabeblack@google.cominline void
10913513Sgabeblack@google.comTBETable<ENTRY>::deallocate(const Address& address)
11013511Sgabeblack@google.com{
11113511Sgabeblack@google.com    assert(isPresent(address) == true);
11213513Sgabeblack@google.com    assert(m_map.size() > 0);
11313513Sgabeblack@google.com    m_map.erase(address);
11413513Sgabeblack@google.com}
11513513Sgabeblack@google.com
11613513Sgabeblack@google.com// looks an address up in the cache
11713511Sgabeblack@google.comtemplate<class ENTRY>
11813513Sgabeblack@google.cominline ENTRY&
11913513Sgabeblack@google.comTBETable<ENTRY>::lookup(const Address& address)
12013513Sgabeblack@google.com{
12113513Sgabeblack@google.com    assert(isPresent(address) == true);
12213513Sgabeblack@google.com    return m_map.lookup(address);
12313511Sgabeblack@google.com}
12413513Sgabeblack@google.com
12513513Sgabeblack@google.com// looks an address up in the cache
12613511Sgabeblack@google.comtemplate<class ENTRY>
12713511Sgabeblack@google.cominline const ENTRY&
12813513Sgabeblack@google.comTBETable<ENTRY>::lookup(const Address& address) const
12913513Sgabeblack@google.com{
13013513Sgabeblack@google.com    assert(isPresent(address) == true);
13113513Sgabeblack@google.com    return m_map.lookup(address);
13213513Sgabeblack@google.com}
13313511Sgabeblack@google.com
13413513Sgabeblack@google.comtemplate<class ENTRY>
13513513Sgabeblack@google.cominline void
13613513Sgabeblack@google.comTBETable<ENTRY>::print(ostream& out) const
13713513Sgabeblack@google.com{
13813513Sgabeblack@google.com}
13913511Sgabeblack@google.com
14013513Sgabeblack@google.com#endif // __MEM_RUBY_SYSTEM_TBETABLE_HH__
14113513Sgabeblack@google.com