TBETable.hh revision 7039
16899SN/A/*
26899SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
36899SN/A * All rights reserved.
46899SN/A *
56899SN/A * Redistribution and use in source and binary forms, with or without
66899SN/A * modification, are permitted provided that the following conditions are
76899SN/A * met: redistributions of source code must retain the above copyright
86899SN/A * notice, this list of conditions and the following disclaimer;
96899SN/A * redistributions in binary form must reproduce the above copyright
106899SN/A * notice, this list of conditions and the following disclaimer in the
116899SN/A * documentation and/or other materials provided with the distribution;
126899SN/A * neither the name of the copyright holders nor the names of its
136899SN/A * contributors may be used to endorse or promote products derived from
146899SN/A * this software without specific prior written permission.
156899SN/A *
166899SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176899SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186899SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196899SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206899SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216899SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226899SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236899SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246899SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256899SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266899SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276899SN/A */
286899SN/A
296899SN/A#ifndef __MEM_RUBY_SYSTEM_TBETABLE_HH__
307056SN/A#define __MEM_RUBY_SYSTEM_TBETABLE_HH__
317632SBrad.Beckmann@amd.com
327632SBrad.Beckmann@amd.com#include "mem/gems_common/Map.hh"
337632SBrad.Beckmann@amd.com#include "mem/ruby/common/Address.hh"
346899SN/A#include "mem/ruby/common/Global.hh"
356899SN/A#include "mem/ruby/profiler/Profiler.hh"
367053SN/A#include "mem/ruby/system/System.hh"
376899SN/A
387053SN/Atemplate<class ENTRY>
397053SN/Aclass TBETable
406899SN/A{
417053SN/A  public:
427053SN/A    TBETable(int number_of_TBEs)
436899SN/A        : m_number_of_TBEs(number_of_TBEs)
447053SN/A    {
457053SN/A    }
467053SN/A
477053SN/A    void
487053SN/A    printConfig(ostream& out)
497053SN/A    {
507053SN/A        out << "TBEs_per_TBETable: " << m_number_of_TBEs << endl;
517053SN/A    }
526899SN/A
537053SN/A    bool isPresent(const Address& address) const;
547053SN/A    void allocate(const Address& address);
557053SN/A    void deallocate(const Address& address);
567053SN/A    bool
577053SN/A    areNSlotsAvailable(int n) const
587053SN/A    {
597053SN/A        return (m_number_of_TBEs - m_map.size()) >= n;
607053SN/A    }
617053SN/A
626899SN/A    ENTRY& lookup(const Address& address);
637053SN/A    const ENTRY& lookup(const Address& address) const;
647053SN/A
657053SN/A    // Print cache contents
667053SN/A    void print(ostream& out) const;
677053SN/A
687053SN/A  private:
697053SN/A    // Private copy constructor and assignment operator
706899SN/A    TBETable(const TBETable& obj);
716899SN/A    TBETable& operator=(const TBETable& obj);
726899SN/A
736899SN/A    // Data Members (m_prefix)
747053SN/A    Map<Address, ENTRY> m_map;
757053SN/A
767053SN/A  private:
776899SN/A    int m_number_of_TBEs;
786899SN/A};
797053SN/A
807053SN/Atemplate<class ENTRY>
816899SN/Ainline ostream&
827056SN/Aoperator<<(ostream& out, const TBETable<ENTRY>& obj)
837053SN/A{
847805Snilay@cs.wisc.edu    obj.print(out);
857053SN/A    out << flush;
866899SN/A    return out;
876899SN/A}
887053SN/A
897455SN/Atemplate<class ENTRY>
907053SN/Ainline bool
917053SN/ATBETable<ENTRY>::isPresent(const Address& address) const
927053SN/A{
937053SN/A    assert(address == line_address(address));
946899SN/A    assert(m_map.size() <= m_number_of_TBEs);
956899SN/A    return m_map.exist(address);
967053SN/A}
977053SN/A
987053SN/Atemplate<class ENTRY>
997053SN/Ainline void
1007455SN/ATBETable<ENTRY>::allocate(const Address& address)
1017053SN/A{
1027454SN/A    assert(isPresent(address) == false);
1036899SN/A    assert(m_map.size() < m_number_of_TBEs);
1046899SN/A    m_map.add(address, ENTRY());
1057053SN/A}
1067053SN/A
1076899SN/Atemplate<class ENTRY>
1087053SN/Ainline void
1096899SN/ATBETable<ENTRY>::deallocate(const Address& address)
1106899SN/A{
1117053SN/A    assert(isPresent(address) == true);
1127053SN/A    assert(m_map.size() > 0);
1136899SN/A    m_map.erase(address);
1147780Snilay@cs.wisc.edu}
1156899SN/A
1167455SN/A// looks an address up in the cache
1177455SN/Atemplate<class ENTRY>
1187455SN/Ainline ENTRY&
1197053SN/ATBETable<ENTRY>::lookup(const Address& address)
1207455SN/A{
1217455SN/A    assert(isPresent(address) == true);
1227455SN/A    return m_map.lookup(address);
1237455SN/A}
1246899SN/A
1256899SN/A// looks an address up in the cache
1267053SN/Atemplate<class ENTRY>
1277055SN/Ainline const ENTRY&
1286899SN/ATBETable<ENTRY>::lookup(const Address& address) const
1296899SN/A{
130    assert(isPresent(address) == true);
131    return m_map.lookup(address);
132}
133
134template<class ENTRY>
135inline void
136TBETable<ENTRY>::print(ostream& out) const
137{
138}
139
140#endif // __MEM_RUBY_SYSTEM_TBETABLE_HH__
141