gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TBETable.hh
Go to the documentation of this file.
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_STRUCTURES_TBETABLE_HH__
30 #define __MEM_RUBY_STRUCTURES_TBETABLE_HH__
31 
32 #include <iostream>
33 #include <unordered_map>
34 
36 
37 template<class ENTRY>
38 class TBETable
39 {
40  public:
41  TBETable(int number_of_TBEs)
42  : m_number_of_TBEs(number_of_TBEs)
43  {
44  }
45 
46  bool isPresent(Addr address) const;
47  void allocate(Addr address);
48  void deallocate(Addr address);
49  bool
50  areNSlotsAvailable(int n, Tick current_time) 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  std::unordered_map<Addr, ENTRY> m_map;
67 
68  private:
70 };
71 
72 template<class ENTRY>
73 inline std::ostream&
74 operator<<(std::ostream& out, const TBETable<ENTRY>& obj)
75 {
76  obj.print(out);
77  out << std::flush;
78  return out;
79 }
80 
81 template<class ENTRY>
82 inline bool
84 {
85  assert(address == makeLineAddress(address));
86  assert(m_map.size() <= m_number_of_TBEs);
87  return !!m_map.count(address);
88 }
89 
90 template<class ENTRY>
91 inline void
93 {
94  assert(!isPresent(address));
95  assert(m_map.size() < m_number_of_TBEs);
96  m_map[address] = ENTRY();
97 }
98 
99 template<class ENTRY>
100 inline void
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
109 template<class ENTRY>
110 inline ENTRY*
112 {
113  if (m_map.find(address) != m_map.end()) return &(m_map.find(address)->second);
114  return NULL;
115 }
116 
117 
118 template<class ENTRY>
119 inline void
120 TBETable<ENTRY>::print(std::ostream& out) const
121 {
122 }
123 
124 #endif // __MEM_RUBY_STRUCTURES_TBETABLE_HH__
bool isPresent(Addr address) const
Definition: TBETable.hh:83
void deallocate(Addr address)
Definition: TBETable.hh:101
bool areNSlotsAvailable(int n, Tick current_time) const
Definition: TBETable.hh:50
Bitfield< 31 > n
Definition: miscregs.hh:1636
int m_number_of_TBEs
Definition: TBETable.hh:69
uint64_t Tick
Tick count type.
Definition: types.hh:63
void allocate(Addr address)
Definition: TBETable.hh:92
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
ENTRY * lookup(Addr address)
Definition: TBETable.hh:111
Addr makeLineAddress(Addr addr)
Definition: Address.cc:112
void print(std::ostream &out) const
Definition: TBETable.hh:120
TBETable & operator=(const TBETable &obj)
std::unordered_map< Addr, ENTRY > m_map
Definition: TBETable.hh:66
TBETable(int number_of_TBEs)
Definition: TBETable.hh:41

Generated on Fri Jun 9 2017 13:03:50 for gem5 by doxygen 1.8.6