TBETable.hh revision 7455
1/* 2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#ifndef __MEM_RUBY_SYSTEM_TBETABLE_HH__ 30#define __MEM_RUBY_SYSTEM_TBETABLE_HH__ 31 32#include <iostream> 33 34#include "base/hashmap.hh" 35#include "mem/ruby/common/Address.hh" 36#include "mem/ruby/common/Global.hh" 37#include "mem/ruby/profiler/Profiler.hh" 38#include "mem/ruby/system/System.hh" 39 40template<class ENTRY> 41class TBETable 42{ 43 public: 44 TBETable(int number_of_TBEs) 45 : m_number_of_TBEs(number_of_TBEs) 46 { 47 } 48 49 void 50 printConfig(std::ostream& out) 51 { 52 out << "TBEs_per_TBETable: " << m_number_of_TBEs << std::endl; 53 } 54 55 bool isPresent(const Address& address) const; 56 void allocate(const Address& address); 57 void deallocate(const Address& address); 58 bool 59 areNSlotsAvailable(int n) const 60 { 61 return (m_number_of_TBEs - m_map.size()) >= n; 62 } 63 64 ENTRY& lookup(const Address& address); 65 const ENTRY& lookup(const Address& address) const; 66 67 // Print cache contents 68 void print(std::ostream& out) const; 69 70 private: 71 // Private copy constructor and assignment operator 72 TBETable(const TBETable& obj); 73 TBETable& operator=(const TBETable& obj); 74 75 // Data Members (m_prefix) 76 m5::hash_map<Address, ENTRY> m_map; 77 78 private: 79 int m_number_of_TBEs; 80}; 81 82template<class ENTRY> 83inline std::ostream& 84operator<<(std::ostream& out, const TBETable<ENTRY>& obj) 85{ 86 obj.print(out); 87 out << std::flush; 88 return out; 89} 90 91template<class ENTRY> 92inline bool 93TBETable<ENTRY>::isPresent(const Address& address) const 94{ 95 assert(address == line_address(address)); 96 assert(m_map.size() <= m_number_of_TBEs); 97 return !!m_map.count(address); 98} 99 100template<class ENTRY> 101inline void 102TBETable<ENTRY>::allocate(const Address& address) 103{ 104 assert(!isPresent(address)); 105 assert(m_map.size() < m_number_of_TBEs); 106 m_map[address] = ENTRY(); 107} 108 109template<class ENTRY> 110inline void 111TBETable<ENTRY>::deallocate(const Address& address) 112{ 113 assert(isPresent(address)); 114 assert(m_map.size() > 0); 115 m_map.erase(address); 116} 117 118// looks an address up in the cache 119template<class ENTRY> 120inline ENTRY& 121TBETable<ENTRY>::lookup(const Address& address) 122{ 123 assert(isPresent(address)); 124 return m_map.find(address)->second; 125} 126 127// looks an address up in the cache 128template<class ENTRY> 129inline const ENTRY& 130TBETable<ENTRY>::lookup(const Address& address) const 131{ 132 assert(isPresent(address)); 133 return m_map.find(address)->second; 134} 135 136template<class ENTRY> 137inline void 138TBETable<ENTRY>::print(std::ostream& out) const 139{ 140} 141 142#endif // __MEM_RUBY_SYSTEM_TBETABLE_HH__ 143