TBETable.hh revision 10441
112853Sgabeblack@google.com/* 212853Sgabeblack@google.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 312853Sgabeblack@google.com * All rights reserved. 412853Sgabeblack@google.com * 512853Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612853Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712853Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812853Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912853Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012853Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112853Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212853Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312853Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412853Sgabeblack@google.com * this software without specific prior written permission. 1512853Sgabeblack@google.com * 1612853Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712853Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812853Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912853Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012853Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112853Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212853Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312853Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412853Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512853Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612853Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712853Sgabeblack@google.com */ 2812853Sgabeblack@google.com 2912853Sgabeblack@google.com#ifndef __MEM_RUBY_STRUCTURES_TBETABLE_HH__ 3012853Sgabeblack@google.com#define __MEM_RUBY_STRUCTURES_TBETABLE_HH__ 3112853Sgabeblack@google.com 3212853Sgabeblack@google.com#include <iostream> 3312853Sgabeblack@google.com 3412853Sgabeblack@google.com#include "base/hashmap.hh" 3512853Sgabeblack@google.com#include "mem/ruby/common/Address.hh" 3612853Sgabeblack@google.com 3712853Sgabeblack@google.comtemplate<class ENTRY> 3812853Sgabeblack@google.comclass TBETable 3912853Sgabeblack@google.com{ 4012853Sgabeblack@google.com public: 4112853Sgabeblack@google.com TBETable(int number_of_TBEs) 4212853Sgabeblack@google.com : m_number_of_TBEs(number_of_TBEs) 4312853Sgabeblack@google.com { 4412853Sgabeblack@google.com } 4512853Sgabeblack@google.com 4612853Sgabeblack@google.com bool isPresent(const Address& address) const; 4712853Sgabeblack@google.com void allocate(const Address& address); 4812853Sgabeblack@google.com void deallocate(const Address& address); 4912853Sgabeblack@google.com bool 5012853Sgabeblack@google.com areNSlotsAvailable(int n) const 5112853Sgabeblack@google.com { 5212853Sgabeblack@google.com return (m_number_of_TBEs - m_map.size()) >= n; 5312853Sgabeblack@google.com } 5412853Sgabeblack@google.com 5512853Sgabeblack@google.com ENTRY* lookup(const Address& address); 5612853Sgabeblack@google.com 5712853Sgabeblack@google.com // Print cache contents 5812853Sgabeblack@google.com void print(std::ostream& out) const; 5912853Sgabeblack@google.com 6012853Sgabeblack@google.com private: 6112853Sgabeblack@google.com // Private copy constructor and assignment operator 6212853Sgabeblack@google.com TBETable(const TBETable& obj); 6312853Sgabeblack@google.com TBETable& operator=(const TBETable& obj); 6412853Sgabeblack@google.com 6512853Sgabeblack@google.com // Data Members (m_prefix) 6612853Sgabeblack@google.com m5::hash_map<Address, ENTRY> m_map; 6712853Sgabeblack@google.com 6812853Sgabeblack@google.com private: 6912853Sgabeblack@google.com int m_number_of_TBEs; 7012853Sgabeblack@google.com}; 7112853Sgabeblack@google.com 7212853Sgabeblack@google.comtemplate<class ENTRY> 7312853Sgabeblack@google.cominline std::ostream& 7412853Sgabeblack@google.comoperator<<(std::ostream& out, const TBETable<ENTRY>& obj) 7512853Sgabeblack@google.com{ 7612853Sgabeblack@google.com obj.print(out); 7712853Sgabeblack@google.com out << std::flush; 7812853Sgabeblack@google.com return out; 7912853Sgabeblack@google.com} 8012853Sgabeblack@google.com 8112853Sgabeblack@google.comtemplate<class ENTRY> 8212853Sgabeblack@google.cominline bool 8312853Sgabeblack@google.comTBETable<ENTRY>::isPresent(const Address& address) const 8412853Sgabeblack@google.com{ 8512853Sgabeblack@google.com assert(address == line_address(address)); 8612853Sgabeblack@google.com assert(m_map.size() <= m_number_of_TBEs); 8712853Sgabeblack@google.com return !!m_map.count(address); 8812853Sgabeblack@google.com} 8912853Sgabeblack@google.com 9012853Sgabeblack@google.comtemplate<class ENTRY> 9112853Sgabeblack@google.cominline void 9212853Sgabeblack@google.comTBETable<ENTRY>::allocate(const Address& address) 9312853Sgabeblack@google.com{ 9412853Sgabeblack@google.com assert(!isPresent(address)); 9512853Sgabeblack@google.com assert(m_map.size() < m_number_of_TBEs); 9612853Sgabeblack@google.com m_map[address] = ENTRY(); 9712853Sgabeblack@google.com} 9812853Sgabeblack@google.com 9912853Sgabeblack@google.comtemplate<class ENTRY> 10012853Sgabeblack@google.cominline void 10112853Sgabeblack@google.comTBETable<ENTRY>::deallocate(const Address& address) 10212853Sgabeblack@google.com{ 10312853Sgabeblack@google.com assert(isPresent(address)); 10412853Sgabeblack@google.com assert(m_map.size() > 0); 10512853Sgabeblack@google.com m_map.erase(address); 10612853Sgabeblack@google.com} 10712853Sgabeblack@google.com 10812853Sgabeblack@google.com// looks an address up in the cache 10912853Sgabeblack@google.comtemplate<class ENTRY> 11012853Sgabeblack@google.cominline ENTRY* 11112853Sgabeblack@google.comTBETable<ENTRY>::lookup(const Address& address) 11212853Sgabeblack@google.com{ 11312853Sgabeblack@google.com if(m_map.find(address) != m_map.end()) return &(m_map.find(address)->second); 11412853Sgabeblack@google.com return NULL; 11512853Sgabeblack@google.com} 11612853Sgabeblack@google.com 11712853Sgabeblack@google.com 11812853Sgabeblack@google.comtemplate<class ENTRY> 11912853Sgabeblack@google.cominline void 12012853Sgabeblack@google.comTBETable<ENTRY>::print(std::ostream& out) const 12112853Sgabeblack@google.com{ 12212853Sgabeblack@google.com} 12312853Sgabeblack@google.com 12412853Sgabeblack@google.com#endif // __MEM_RUBY_STRUCTURES_TBETABLE_HH__ 12512853Sgabeblack@google.com