TBETable.hh revision 11025:4872dbdea907
13549SN/A/* 23549SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 33549SN/A * All rights reserved. 43549SN/A * 53549SN/A * Redistribution and use in source and binary forms, with or without 63549SN/A * modification, are permitted provided that the following conditions are 73549SN/A * met: redistributions of source code must retain the above copyright 83549SN/A * notice, this list of conditions and the following disclaimer; 93549SN/A * redistributions in binary form must reproduce the above copyright 103549SN/A * notice, this list of conditions and the following disclaimer in the 113549SN/A * documentation and/or other materials provided with the distribution; 123549SN/A * neither the name of the copyright holders nor the names of its 133549SN/A * contributors may be used to endorse or promote products derived from 143549SN/A * this software without specific prior written permission. 153549SN/A * 163549SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 173549SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 183549SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 193549SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 203549SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 213549SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 223549SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 233549SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 243549SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 253549SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 263549SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 273549SN/A */ 283549SN/A 293549SN/A#ifndef __MEM_RUBY_STRUCTURES_TBETABLE_HH__ 303549SN/A#define __MEM_RUBY_STRUCTURES_TBETABLE_HH__ 313549SN/A 323565Sgblack@eecs.umich.edu#include <iostream> 3311793Sbrandon.potter@amd.com 343565Sgblack@eecs.umich.edu#include "base/hashmap.hh" 353549SN/A#include "mem/ruby/common/Address.hh" 363549SN/A 375567Snate@binkert.orgtemplate<class ENTRY> 383549SN/Aclass TBETable 393549SN/A{ 403549SN/A public: 413549SN/A TBETable(int number_of_TBEs) 425569Snate@binkert.org : m_number_of_TBEs(number_of_TBEs) 435569Snate@binkert.org { 445569Snate@binkert.org } 455569Snate@binkert.org 463549SN/A bool isPresent(Addr address) const; 473549SN/A void allocate(Addr address); 48 void deallocate(Addr address); 49 bool 50 areNSlotsAvailable(int n) const 51 { 52 return (m_number_of_TBEs - m_map.size()) >= n; 53 } 54 55 ENTRY* lookup(Addr address); 56 57 // Print cache contents 58 void print(std::ostream& out) const; 59 60 private: 61 // Private copy constructor and assignment operator 62 TBETable(const TBETable& obj); 63 TBETable& operator=(const TBETable& obj); 64 65 // Data Members (m_prefix) 66 m5::hash_map<Addr, ENTRY> m_map; 67 68 private: 69 int m_number_of_TBEs; 70}; 71 72template<class ENTRY> 73inline std::ostream& 74operator<<(std::ostream& out, const TBETable<ENTRY>& obj) 75{ 76 obj.print(out); 77 out << std::flush; 78 return out; 79} 80 81template<class ENTRY> 82inline bool 83TBETable<ENTRY>::isPresent(Addr address) const 84{ 85 assert(address == makeLineAddress(address)); 86 assert(m_map.size() <= m_number_of_TBEs); 87 return !!m_map.count(address); 88} 89 90template<class ENTRY> 91inline void 92TBETable<ENTRY>::allocate(Addr address) 93{ 94 assert(!isPresent(address)); 95 assert(m_map.size() < m_number_of_TBEs); 96 m_map[address] = ENTRY(); 97} 98 99template<class ENTRY> 100inline void 101TBETable<ENTRY>::deallocate(Addr address) 102{ 103 assert(isPresent(address)); 104 assert(m_map.size() > 0); 105 m_map.erase(address); 106} 107 108// looks an address up in the cache 109template<class ENTRY> 110inline ENTRY* 111TBETable<ENTRY>::lookup(Addr address) 112{ 113 if(m_map.find(address) != m_map.end()) return &(m_map.find(address)->second); 114 return NULL; 115} 116 117 118template<class ENTRY> 119inline void 120TBETable<ENTRY>::print(std::ostream& out) const 121{ 122} 123 124#endif // __MEM_RUBY_STRUCTURES_TBETABLE_HH__ 125