gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
decode_cache.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Google
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 __CPU_DECODE_CACHE_HH__
30 #define __CPU_DECODE_CACHE_HH__
31 
32 #include <unordered_map>
33 
34 #include "base/bitfield.hh"
35 #include "base/compiler.hh"
36 #include "cpu/static_inst_fwd.hh"
37 
38 namespace gem5
39 {
40 
41 namespace decode_cache
42 {
43 
45 template <typename EMI>
46 using InstMap = std::unordered_map<EMI, StaticInstPtr>;
47 
49 template<class Value, Addr CacheChunkShift = 12>
50 class AddrMap
51 {
52  protected:
53  static constexpr Addr CacheChunkBytes = 1ULL << CacheChunkShift;
54 
55  static constexpr Addr
57  {
58  return addr & (CacheChunkBytes - 1);
59  }
60 
61  static constexpr Addr
63  {
64  return addr & ~(CacheChunkBytes - 1);
65  }
66 
67  // A chunk of cache entries.
68  struct CacheChunk
69  {
71  };
72  // A map of cache chunks which allows a sparse mapping.
73  typedef typename std::unordered_map<Addr, CacheChunk *> ChunkMap;
74  typedef typename ChunkMap::iterator ChunkIt;
75  // Mini cache of recent lookups.
78 
81  void
82  update(ChunkIt recentest)
83  {
84  recent[1] = recent[0];
85  recent[0] = recentest;
86  }
87 
92  CacheChunk *
94  {
95  Addr chunk_addr = chunkStart(addr);
96 
97  // Check against recent lookups.
98  if (recent[0] != chunkMap.end()) {
99  if (recent[0]->first == chunk_addr)
100  return recent[0]->second;
101  if (recent[1] != chunkMap.end() &&
102  recent[1]->first == chunk_addr) {
103  update(recent[1]);
104  // recent[1] has just become recent[0].
105  return recent[0]->second;
106  }
107  }
108 
109  // Actually look in the hash_map.
110  ChunkIt it = chunkMap.find(chunk_addr);
111  if (it != chunkMap.end()) {
112  update(it);
113  return it->second;
114  }
115 
116  // Didn't find an existing chunk, so add a new one.
117  CacheChunk *newChunk = new CacheChunk;
118  typename ChunkMap::value_type to_insert(chunk_addr, newChunk);
119  update(chunkMap.insert(to_insert).first);
120  return newChunk;
121  }
122 
123  public:
126  {
127  recent[0] = recent[1] = chunkMap.end();
128  }
129 
130  Value &
132  {
133  CacheChunk *chunk = getChunk(addr);
134  return chunk->items[chunkOffset(addr)];
135  }
136 };
137 
138 } // namespace decode_cache
139 } // namespace gem5
140 
141 #endif // __CPU_DECODE_CACHE_HH__
gem5::decode_cache::AddrMap::getChunk
CacheChunk * getChunk(Addr addr)
Attempt to find the CacheChunk which goes with a particular address.
Definition: decode_cache.hh:93
gem5::decode_cache::AddrMap::chunkMap
ChunkMap chunkMap
Definition: decode_cache.hh:77
gem5::decode_cache::InstMap
std::unordered_map< EMI, StaticInstPtr > InstMap
Hash for decoded instructions.
Definition: decode_cache.hh:46
gem5::decode_cache::AddrMap::chunkOffset
static constexpr Addr chunkOffset(Addr addr)
Definition: decode_cache.hh:56
gem5::decode_cache::AddrMap::recent
ChunkIt recent[2]
Definition: decode_cache.hh:76
gem5::decode_cache::AddrMap::CacheChunkBytes
static constexpr Addr CacheChunkBytes
Definition: decode_cache.hh:53
gem5::decode_cache::AddrMap::chunkStart
static constexpr Addr chunkStart(Addr addr)
Definition: decode_cache.hh:62
gem5::decode_cache::AddrMap::CacheChunk
Definition: decode_cache.hh:68
gem5::decode_cache::AddrMap::ChunkMap
std::unordered_map< Addr, CacheChunk * > ChunkMap
Definition: decode_cache.hh:73
bitfield.hh
gem5::decode_cache::AddrMap
A sparse map from an Addr to a Value, stored in page chunks.
Definition: decode_cache.hh:50
gem5::decode_cache::AddrMap::update
void update(ChunkIt recentest)
Update the mini cache of recent lookups.
Definition: decode_cache.hh:82
compiler.hh
gem5::decode_cache::AddrMap::AddrMap
AddrMap()
Constructor.
Definition: decode_cache.hh:125
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::decode_cache::AddrMap::ChunkIt
ChunkMap::iterator ChunkIt
Definition: decode_cache.hh:74
gem5::decode_cache::AddrMap::CacheChunk::items
Value items[CacheChunkBytes]
Definition: decode_cache.hh:70
gem5::statistics::Value
Definition: statistics.hh:1981
static_inst_fwd.hh
gem5::decode_cache::AddrMap::lookup
Value & lookup(Addr addr)
Definition: decode_cache.hh:131
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Sun Jul 30 2023 01:56:50 for gem5 by doxygen 1.8.17