16145SN/A/* 26145SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 36145SN/A * All rights reserved. 46145SN/A * 56145SN/A * Redistribution and use in source and binary forms, with or without 66145SN/A * modification, are permitted provided that the following conditions are 76145SN/A * met: redistributions of source code must retain the above copyright 86145SN/A * notice, this list of conditions and the following disclaimer; 96145SN/A * redistributions in binary form must reproduce the above copyright 106145SN/A * notice, this list of conditions and the following disclaimer in the 116145SN/A * documentation and/or other materials provided with the distribution; 126145SN/A * neither the name of the copyright holders nor the names of its 136145SN/A * contributors may be used to endorse or promote products derived from 146145SN/A * this software without specific prior written permission. 156145SN/A * 166145SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145SN/A */ 286145SN/A 2910441Snilay@cs.wisc.edu#ifndef __MEM_RUBY_STRUCTURES_TBETABLE_HH__ 3010441Snilay@cs.wisc.edu#define __MEM_RUBY_STRUCTURES_TBETABLE_HH__ 316145SN/A 327055SN/A#include <iostream> 3311168Sandreas.hansson@arm.com#include <unordered_map> 347055SN/A 356154SN/A#include "mem/ruby/common/Address.hh" 366145SN/A 376145SN/Atemplate<class ENTRY> 387039SN/Aclass TBETable 397039SN/A{ 407039SN/A public: 417039SN/A TBETable(int number_of_TBEs) 427039SN/A : m_number_of_TBEs(number_of_TBEs) 437039SN/A { 447039SN/A } 456145SN/A 4611025Snilay@cs.wisc.edu bool isPresent(Addr address) const; 4711025Snilay@cs.wisc.edu void allocate(Addr address); 4811025Snilay@cs.wisc.edu void deallocate(Addr address); 497039SN/A bool 5011111Snilay@cs.wisc.edu areNSlotsAvailable(int n, Tick current_time) const 517039SN/A { 527039SN/A return (m_number_of_TBEs - m_map.size()) >= n; 537039SN/A } 546145SN/A 5511111Snilay@cs.wisc.edu ENTRY *lookup(Addr address); 566145SN/A 577039SN/A // Print cache contents 587055SN/A void print(std::ostream& out) const; 596145SN/A 607039SN/A private: 617039SN/A // Private copy constructor and assignment operator 627039SN/A TBETable(const TBETable& obj); 637039SN/A TBETable& operator=(const TBETable& obj); 646145SN/A 657039SN/A // Data Members (m_prefix) 6611168Sandreas.hansson@arm.com std::unordered_map<Addr, ENTRY> m_map; 676145SN/A 687039SN/A private: 697039SN/A int m_number_of_TBEs; 706145SN/A}; 716145SN/A 726145SN/Atemplate<class ENTRY> 737055SN/Ainline std::ostream& 747055SN/Aoperator<<(std::ostream& out, const TBETable<ENTRY>& obj) 756145SN/A{ 767039SN/A obj.print(out); 777055SN/A out << std::flush; 787039SN/A return out; 796145SN/A} 806145SN/A 816145SN/Atemplate<class ENTRY> 827039SN/Ainline bool 8311025Snilay@cs.wisc.eduTBETable<ENTRY>::isPresent(Addr address) const 846145SN/A{ 8511025Snilay@cs.wisc.edu assert(address == makeLineAddress(address)); 867039SN/A assert(m_map.size() <= m_number_of_TBEs); 877455SN/A return !!m_map.count(address); 886145SN/A} 896145SN/A 906145SN/Atemplate<class ENTRY> 917039SN/Ainline void 9211025Snilay@cs.wisc.eduTBETable<ENTRY>::allocate(Addr address) 936145SN/A{ 947455SN/A assert(!isPresent(address)); 957039SN/A assert(m_map.size() < m_number_of_TBEs); 967455SN/A m_map[address] = ENTRY(); 977039SN/A} 987039SN/A 997039SN/Atemplate<class ENTRY> 1007039SN/Ainline void 10111025Snilay@cs.wisc.eduTBETable<ENTRY>::deallocate(Addr address) 1027039SN/A{ 1037455SN/A assert(isPresent(address)); 1047039SN/A assert(m_map.size() > 0); 1057039SN/A m_map.erase(address); 1066145SN/A} 1076145SN/A 1086145SN/A// looks an address up in the cache 1096145SN/Atemplate<class ENTRY> 1107839SN/Ainline ENTRY* 11111025Snilay@cs.wisc.eduTBETable<ENTRY>::lookup(Addr address) 1126145SN/A{ 11311321Ssteve.reinhardt@amd.com if (m_map.find(address) != m_map.end()) return &(m_map.find(address)->second); 1147839SN/A return NULL; 1156145SN/A} 1166145SN/A 1176145SN/A 1186145SN/Atemplate<class ENTRY> 1197039SN/Ainline void 1207055SN/ATBETable<ENTRY>::print(std::ostream& out) const 1216145SN/A{ 1226145SN/A} 1236145SN/A 12410441Snilay@cs.wisc.edu#endif // __MEM_RUBY_STRUCTURES_TBETABLE_HH__ 125