gem5  v20.1.0.0
TBETable.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #ifndef __MEM_RUBY_STRUCTURES_TBETABLE_HH__
42 #define __MEM_RUBY_STRUCTURES_TBETABLE_HH__
43 
44 #include <iostream>
45 #include <unordered_map>
46 
48 
49 template<class ENTRY>
50 class TBETable
51 {
52  public:
53  TBETable(int number_of_TBEs)
54  : m_number_of_TBEs(number_of_TBEs)
55  {
56  }
57 
58  bool isPresent(Addr address) const;
59  void allocate(Addr address);
60  void deallocate(Addr address);
61  bool
62  areNSlotsAvailable(int n, Tick current_time) const
63  {
64  return (m_number_of_TBEs - m_map.size()) >= n;
65  }
66 
67  ENTRY *getNullEntry();
68  ENTRY *lookup(Addr address);
69 
70  // Print cache contents
71  void print(std::ostream& out) const;
72 
73  private:
74  // Private copy constructor and assignment operator
75  TBETable(const TBETable& obj);
76  TBETable& operator=(const TBETable& obj);
77 
78  // Data Members (m_prefix)
79  std::unordered_map<Addr, ENTRY> m_map;
80 
81  private:
83 };
84 
85 template<class ENTRY>
86 inline std::ostream&
87 operator<<(std::ostream& out, const TBETable<ENTRY>& obj)
88 {
89  obj.print(out);
90  out << std::flush;
91  return out;
92 }
93 
94 template<class ENTRY>
95 inline bool
97 {
98  assert(address == makeLineAddress(address));
99  assert(m_map.size() <= m_number_of_TBEs);
100  return !!m_map.count(address);
101 }
102 
103 template<class ENTRY>
104 inline void
106 {
107  assert(!isPresent(address));
108  assert(m_map.size() < m_number_of_TBEs);
109  m_map[address] = ENTRY();
110 }
111 
112 template<class ENTRY>
113 inline void
115 {
116  assert(isPresent(address));
117  assert(m_map.size() > 0);
118  m_map.erase(address);
119 }
120 
121 template<class ENTRY>
122 inline ENTRY*
124 {
125  return nullptr;
126 }
127 
128 // looks an address up in the cache
129 template<class ENTRY>
130 inline ENTRY*
132 {
133  if (m_map.find(address) != m_map.end()) return &(m_map.find(address)->second);
134  return NULL;
135 }
136 
137 
138 template<class ENTRY>
139 inline void
140 TBETable<ENTRY>::print(std::ostream& out) const
141 {
142 }
143 
144 #endif // __MEM_RUBY_STRUCTURES_TBETABLE_HH__
TBETable::isPresent
bool isPresent(Addr address) const
Definition: TBETable.hh:96
makeLineAddress
Addr makeLineAddress(Addr addr)
Definition: Address.cc:54
TBETable::deallocate
void deallocate(Addr address)
Definition: TBETable.hh:114
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
TBETable::m_number_of_TBEs
int m_number_of_TBEs
Definition: TBETable.hh:82
TBETable
Definition: TBETable.hh:50
TBETable::getNullEntry
ENTRY * getNullEntry()
Definition: TBETable.hh:123
ArmISA::n
Bitfield< 31 > n
Definition: miscregs_types.hh:450
operator<<
std::ostream & operator<<(std::ostream &out, const TBETable< ENTRY > &obj)
Definition: TBETable.hh:87
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
TBETable::areNSlotsAvailable
bool areNSlotsAvailable(int n, Tick current_time) const
Definition: TBETable.hh:62
Address.hh
TBETable::print
void print(std::ostream &out) const
Definition: TBETable.hh:140
TBETable::allocate
void allocate(Addr address)
Definition: TBETable.hh:105
TBETable::operator=
TBETable & operator=(const TBETable &obj)
TBETable::TBETable
TBETable(int number_of_TBEs)
Definition: TBETable.hh:53
TBETable::lookup
ENTRY * lookup(Addr address)
Definition: TBETable.hh:131
TBETable::m_map
std::unordered_map< Addr, ENTRY > m_map
Definition: TBETable.hh:79

Generated on Wed Sep 30 2020 14:02:13 for gem5 by doxygen 1.8.17