TBETable.hh revision 6154
12440SN/A
22440SN/A/*
32440SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
42440SN/A * All rights reserved.
52440SN/A *
62440SN/A * Redistribution and use in source and binary forms, with or without
72440SN/A * modification, are permitted provided that the following conditions are
82440SN/A * met: redistributions of source code must retain the above copyright
92440SN/A * notice, this list of conditions and the following disclaimer;
102440SN/A * redistributions in binary form must reproduce the above copyright
112440SN/A * notice, this list of conditions and the following disclaimer in the
122440SN/A * documentation and/or other materials provided with the distribution;
132440SN/A * neither the name of the copyright holders nor the names of its
142440SN/A * contributors may be used to endorse or promote products derived from
152440SN/A * this software without specific prior written permission.
162440SN/A *
172440SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182440SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192440SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202440SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212440SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222440SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232440SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242440SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252440SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262440SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272665Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu */
292665Ssaidi@eecs.umich.edu
302440SN/A/*
312440SN/A * TBETable.h
322440SN/A *
332440SN/A * Description:
342440SN/A *
352440SN/A * $Id$
362440SN/A *
372972Sgblack@eecs.umich.edu */
382460SN/A
392440SN/A#ifndef TBETABLE_H
402440SN/A#define TBETABLE_H
412440SN/A
422440SN/A#include "mem/ruby/common/Global.hh"
432440SN/A#include "mem/gems_common/Map.hh"
442440SN/A#include "mem/ruby/common/Address.hh"
452440SN/A#include "mem/ruby/profiler/Profiler.hh"
462440SN/A#include "mem/ruby/slicc_interface/AbstractChip.hh"
472440SN/A#include "mem/ruby/system/System.hh"
482440SN/A
492440SN/Atemplate<class ENTRY>
502440SN/Aclass TBETable {
512440SN/Apublic:
522440SN/A
532440SN/A  // Constructors
542440SN/A  TBETable(AbstractChip* chip_ptr);
552440SN/A
562440SN/A  // Destructor
572467SN/A  //~TBETable();
582440SN/A
592440SN/A  // Public Methods
602440SN/A
612440SN/A  static void printConfig(ostream& out) { out << "TBEs_per_TBETable: " << NUMBER_OF_TBES << endl; }
622467SN/A
632440SN/A  bool isPresent(const Address& address) const;
642440SN/A  void allocate(const Address& address);
652440SN/A  void deallocate(const Address& address);
662440SN/A  bool areNSlotsAvailable(int n) const { return (NUMBER_OF_TBES - m_map.size()) >= n; }
672467SN/A
682440SN/A  ENTRY& lookup(const Address& address);
692440SN/A  const ENTRY& lookup(const Address& address) const;
702440SN/A
712440SN/A  // Print cache contents
722467SN/A  void print(ostream& out) const;
732440SN/Aprivate:
742440SN/A  // Private Methods
752440SN/A
762440SN/A  // Private copy constructor and assignment operator
772467SN/A  TBETable(const TBETable& obj);
782440SN/A  TBETable& operator=(const TBETable& obj);
792440SN/A
802440SN/A  // Data Members (m_prefix)
812440SN/A  Map<Address, ENTRY> m_map;
822440SN/A  AbstractChip* m_chip_ptr;
832467SN/A};
842440SN/A
852440SN/A// Output operator declaration
862440SN/A//ostream& operator<<(ostream& out, const TBETable<ENTRY>& obj);
872467SN/A
882440SN/A// ******************* Definitions *******************
892440SN/A
902440SN/A// Output operator definition
912440SN/Atemplate<class ENTRY>
922440SN/Aextern inline
932467SN/Aostream& operator<<(ostream& out, const TBETable<ENTRY>& obj)
942440SN/A{
952440SN/A  obj.print(out);
962440SN/A  out << flush;
972467SN/A  return out;
982440SN/A}
992440SN/A
1002440SN/A
1012440SN/A// ****************************************************************
1022440SN/A
1032440SN/Atemplate<class ENTRY>
1042440SN/Aextern inline
1052440SN/ATBETable<ENTRY>::TBETable(AbstractChip* chip_ptr)
1062440SN/A{
1072440SN/A  m_chip_ptr = chip_ptr;
1082440SN/A}
1092440SN/A
1102440SN/A// PUBLIC METHODS
1112440SN/A
1122680Sktlim@umich.edu// tests to see if an address is present in the cache
1132440SN/Atemplate<class ENTRY>
1142680Sktlim@umich.eduextern inline
1152680Sktlim@umich.edubool TBETable<ENTRY>::isPresent(const Address& address) const
1162440SN/A{
1172440SN/A  assert(address == line_address(address));
1182440SN/A  assert(m_map.size() <= NUMBER_OF_TBES);
1192467SN/A  return m_map.exist(address);
1202440SN/A}
1212440SN/A
1222440SN/Atemplate<class ENTRY>
1232440SN/Aextern inline
1242440SN/Avoid TBETable<ENTRY>::allocate(const Address& address)
1252440SN/A{
1262467SN/A  assert(isPresent(address) == false);
1272440SN/A  assert(m_map.size() < NUMBER_OF_TBES);
1282440SN/A  g_system_ptr->getProfiler()->L2tbeUsageSample(m_map.size());
1292467SN/A  m_map.add(address, ENTRY());
1302440SN/A}
1312440SN/A
1322467SN/Atemplate<class ENTRY>
1332467SN/Aextern inline
1342440SN/Avoid TBETable<ENTRY>::deallocate(const Address& address)
1352440SN/A{
1362467SN/A  assert(isPresent(address) == true);
1372440SN/A  assert(m_map.size() > 0);
1382467SN/A  m_map.erase(address);
1392440SN/A}
1402440SN/A
1412440SN/A// looks an address up in the cache
1422467SN/Atemplate<class ENTRY>
1432440SN/Aextern inline
1442440SN/AENTRY& TBETable<ENTRY>::lookup(const Address& address)
1452440SN/A{
1462680Sktlim@umich.edu  assert(isPresent(address) == true);
1472680Sktlim@umich.edu  return m_map.lookup(address);
1482440SN/A}
1492440SN/A
1502440SN/A// looks an address up in the cache
1512680Sktlim@umich.edutemplate<class ENTRY>
1522440SN/Aextern inline
1532680Sktlim@umich.educonst ENTRY& TBETable<ENTRY>::lookup(const Address& address) const
1542680Sktlim@umich.edu{
1552440SN/A  assert(isPresent(address) == true);
1562440SN/A  return m_map.lookup(address);
1572440SN/A}
1582440SN/A
1592440SN/Atemplate<class ENTRY>
160extern inline
161void TBETable<ENTRY>::print(ostream& out) const
162{
163}
164
165#endif //TBETABLE_H
166