gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
49namespace gem5
50{
51
52namespace ruby
53{
54
55template<class ENTRY>
57{
58 public:
59 TBETable(int number_of_TBEs)
60 : m_number_of_TBEs(number_of_TBEs)
61 {
62 }
63
64 bool isPresent(Addr address) const;
65 void allocate(Addr address);
66 void deallocate(Addr address);
67 bool
68 areNSlotsAvailable(int n, Tick current_time) const
69 {
70 return (m_number_of_TBEs - m_map.size()) >= n;
71 }
72
73 void setBlockSize(const int block_size) { m_block_size = block_size; }
74
75 ENTRY *getNullEntry();
76 ENTRY *lookup(Addr address);
77
78 // Print cache contents
79 void print(std::ostream& out) const;
80
81 protected:
82 // Protected copy constructor and assignment operator
83 TBETable(const TBETable& obj);
85
86 // Data Members (m_prefix)
87 std::unordered_map<Addr, ENTRY> m_map;
88
89 private:
91 int m_block_size = 0;
92};
93
94template<class ENTRY>
95inline std::ostream&
96operator<<(std::ostream& out, const TBETable<ENTRY>& obj)
97{
98 obj.print(out);
99 out << std::flush;
100 return out;
101}
102
103template<class ENTRY>
104inline bool
106{
107 assert(address == makeLineAddress(address, floorLog2(m_block_size)));
108 assert(m_map.size() <= m_number_of_TBEs);
109 return !!m_map.count(address);
110}
111
112template<class ENTRY>
113inline void
115{
116 assert(!isPresent(address));
117 assert(m_map.size() < m_number_of_TBEs);
118 assert(m_block_size > 0);
119 m_map.emplace(address, ENTRY(m_block_size));
120}
121
122template<class ENTRY>
123inline void
125{
126 assert(isPresent(address));
127 assert(m_map.size() > 0);
128 m_map.erase(address);
129}
130
131template<class ENTRY>
132inline ENTRY*
134{
135 return nullptr;
136}
137
138// looks an address up in the cache
139template<class ENTRY>
140inline ENTRY*
142{
143 if (m_map.find(address) != m_map.end()) return &(m_map.find(address)->second);
144 return NULL;
145}
146
147
148template<class ENTRY>
149inline void
150TBETable<ENTRY>::print(std::ostream& out) const
151{
152}
153
154} // namespace ruby
155} // namespace gem5
156
157#endif // __MEM_RUBY_STRUCTURES_TBETABLE_HH__
std::unordered_map< Addr, ENTRY > m_map
Definition TBETable.hh:87
ENTRY * getNullEntry()
Definition TBETable.hh:133
TBETable(const TBETable &obj)
void setBlockSize(const int block_size)
Definition TBETable.hh:73
bool areNSlotsAvailable(int n, Tick current_time) const
Definition TBETable.hh:68
bool isPresent(Addr address) const
Definition TBETable.hh:105
TBETable(int number_of_TBEs)
Definition TBETable.hh:59
ENTRY * lookup(Addr address)
Definition TBETable.hh:141
void print(std::ostream &out) const
Definition TBETable.hh:150
void allocate(Addr address)
Definition TBETable.hh:114
void deallocate(Addr address)
Definition TBETable.hh:124
TBETable & operator=(const TBETable &obj)
static constexpr std::enable_if_t< std::is_integral_v< T >, int > floorLog2(T x)
Definition intmath.hh:59
Bitfield< 31 > n
Addr makeLineAddress(Addr addr, int cacheLineBits)
Definition Address.cc:61
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint64_t Tick
Tick count type.
Definition types.hh:58
std::ostream & operator<<(std::ostream &os, const BaseSemihosting::InPlaceArg &ipa)

Generated on Mon Jan 13 2025 04:28:40 for gem5 by doxygen 1.9.8