TBETable.hh revision 10441
11758SN/A/* 21762SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 31758SN/A * All rights reserved. 41758SN/A * 51758SN/A * Redistribution and use in source and binary forms, with or without 61758SN/A * modification, are permitted provided that the following conditions are 71758SN/A * met: redistributions of source code must retain the above copyright 81758SN/A * notice, this list of conditions and the following disclaimer; 91758SN/A * redistributions in binary form must reproduce the above copyright 101758SN/A * notice, this list of conditions and the following disclaimer in the 111758SN/A * documentation and/or other materials provided with the distribution; 121758SN/A * neither the name of the copyright holders nor the names of its 131758SN/A * contributors may be used to endorse or promote products derived from 141758SN/A * this software without specific prior written permission. 151758SN/A * 161758SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171758SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181758SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191758SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201758SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211758SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221758SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231758SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241758SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251758SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261758SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu */ 282665Ssaidi@eecs.umich.edu 292665Ssaidi@eecs.umich.edu#ifndef __MEM_RUBY_STRUCTURES_TBETABLE_HH__ 301758SN/A#define __MEM_RUBY_STRUCTURES_TBETABLE_HH__ 312SN/A 322984Sgblack@eecs.umich.edu#include <iostream> 33732SN/A 343565Sgblack@eecs.umich.edu#include "base/hashmap.hh" 35732SN/A#include "mem/ruby/common/Address.hh" 362984Sgblack@eecs.umich.edu 375953Ssaidi@eecs.umich.edutemplate<class ENTRY> 385882Snate@binkert.orgclass TBETable 391717SN/A{ 402683Sktlim@umich.edu public: 412680Sktlim@umich.edu TBETable(int number_of_TBEs) 422710Sstever@eecs.umich.edu : m_number_of_TBEs(number_of_TBEs) 432SN/A { 445568Snate@binkert.org } 455566Snate@binkert.org 4612406Sgabeblack@google.com bool isPresent(const Address& address) const; 4712406Sgabeblack@google.com void allocate(const Address& address); 4812406Sgabeblack@google.com void deallocate(const Address& address); 4912406Sgabeblack@google.com bool 5012406Sgabeblack@google.com areNSlotsAvailable(int n) const 5112406Sgabeblack@google.com { 5212406Sgabeblack@google.com return (m_number_of_TBEs - m_map.size()) >= n; 5312406Sgabeblack@google.com } 5412406Sgabeblack@google.com 5512406Sgabeblack@google.com ENTRY* lookup(const Address& address); 5612406Sgabeblack@google.com 5712406Sgabeblack@google.com // Print cache contents 5812406Sgabeblack@google.com void print(std::ostream& out) const; 5912406Sgabeblack@google.com 6012406Sgabeblack@google.com private: 6112406Sgabeblack@google.com // Private copy constructor and assignment operator 6212406Sgabeblack@google.com TBETable(const TBETable& obj); 6312406Sgabeblack@google.com TBETable& operator=(const TBETable& obj); 642SN/A 652SN/A // Data Members (m_prefix) 662SN/A m5::hash_map<Address, ENTRY> m_map; 672SN/A 682SN/A private: 695568Snate@binkert.org int m_number_of_TBEs; 702SN/A}; 712680Sktlim@umich.edu 72190SN/Atemplate<class ENTRY> 732680Sktlim@umich.eduinline std::ostream& 742680Sktlim@umich.eduoperator<<(std::ostream& out, const TBETable<ENTRY>& obj) 752114SN/A{ 765568Snate@binkert.org obj.print(out); 772700Sktlim@umich.edu out << std::flush; 787720Sgblack@eecs.umich.edu return out; 792700Sktlim@umich.edu} 802700Sktlim@umich.edu 812SN/Atemplate<class ENTRY> 822SN/Ainline bool 831133SN/ATBETable<ENTRY>::isPresent(const Address& address) const 84716SN/A{ 855568Snate@binkert.org assert(address == line_address(address)); 86716SN/A assert(m_map.size() <= m_number_of_TBEs); 87716SN/A return !!m_map.count(address); 88739SN/A} 89739SN/A 902683Sktlim@umich.edutemplate<class ENTRY> 9113611Sgabeblack@google.cominline void 92716SN/ATBETable<ENTRY>::allocate(const Address& address) 93716SN/A{ 944997Sgblack@eecs.umich.edu assert(!isPresent(address)); 954997Sgblack@eecs.umich.edu assert(m_map.size() < m_number_of_TBEs); 964997Sgblack@eecs.umich.edu m_map[address] = ENTRY(); 974997Sgblack@eecs.umich.edu} 984997Sgblack@eecs.umich.edu 995568Snate@binkert.orgtemplate<class ENTRY> 1004997Sgblack@eecs.umich.eduinline void 1014997Sgblack@eecs.umich.eduTBETable<ENTRY>::deallocate(const Address& address) 1024997Sgblack@eecs.umich.edu{ 1034997Sgblack@eecs.umich.edu assert(isPresent(address)); 1044997Sgblack@eecs.umich.edu assert(m_map.size() > 0); 1055568Snate@binkert.org m_map.erase(address); 1064997Sgblack@eecs.umich.edu} 1074997Sgblack@eecs.umich.edu 1084997Sgblack@eecs.umich.edu// looks an address up in the cache 1094997Sgblack@eecs.umich.edutemplate<class ENTRY> 11013614Sgabeblack@google.cominline ENTRY* 1116330Sgblack@eecs.umich.eduTBETable<ENTRY>::lookup(const Address& address) 1122159SN/A{ 1135543Ssaidi@eecs.umich.edu if(m_map.find(address) != m_map.end()) return &(m_map.find(address)->second); 1142SN/A return NULL; 1152SN/A} 1165568Snate@binkert.org 1175568Snate@binkert.org 1185568Snate@binkert.orgtemplate<class ENTRY> 1195568Snate@binkert.orginline void 1205568Snate@binkert.orgTBETable<ENTRY>::print(std::ostream& out) const 1215568Snate@binkert.org{ 1225568Snate@binkert.org} 1235568Snate@binkert.org 1245568Snate@binkert.org#endif // __MEM_RUBY_STRUCTURES_TBETABLE_HH__ 1255568Snate@binkert.org