gem5  v21.1.0.2
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 GEM5_DEPRECATED_NAMESPACE(DecodeCache, decode_cache);
42 namespace decode_cache
43 {
44 
46 template <typename EMI>
47 using InstMap = std::unordered_map<EMI, StaticInstPtr>;
48 
50 template<class Value, Addr CacheChunkShift = 12>
51 class AddrMap
52 {
53  protected:
54  static constexpr Addr CacheChunkBytes = 1ULL << CacheChunkShift;
55 
56  static constexpr Addr
58  {
59  return addr & (CacheChunkBytes - 1);
60  }
61 
62  static constexpr Addr
64  {
65  return addr & ~(CacheChunkBytes - 1);
66  }
67 
68  // A chunk of cache entries.
69  struct CacheChunk
70  {
72  };
73  // A map of cache chunks which allows a sparse mapping.
74  typedef typename std::unordered_map<Addr, CacheChunk *> ChunkMap;
75  typedef typename ChunkMap::iterator ChunkIt;
76  // Mini cache of recent lookups.
79 
82  void
83  update(ChunkIt recentest)
84  {
85  recent[1] = recent[0];
86  recent[0] = recentest;
87  }
88 
93  CacheChunk *
95  {
96  Addr chunk_addr = chunkStart(addr);
97 
98  // Check against recent lookups.
99  if (recent[0] != chunkMap.end()) {
100  if (recent[0]->first == chunk_addr)
101  return recent[0]->second;
102  if (recent[1] != chunkMap.end() &&
103  recent[1]->first == chunk_addr) {
104  update(recent[1]);
105  // recent[1] has just become recent[0].
106  return recent[0]->second;
107  }
108  }
109 
110  // Actually look in the hash_map.
111  ChunkIt it = chunkMap.find(chunk_addr);
112  if (it != chunkMap.end()) {
113  update(it);
114  return it->second;
115  }
116 
117  // Didn't find an existing chunk, so add a new one.
118  CacheChunk *newChunk = new CacheChunk;
119  typename ChunkMap::value_type to_insert(chunk_addr, newChunk);
120  update(chunkMap.insert(to_insert).first);
121  return newChunk;
122  }
123 
124  public:
127  {
128  recent[0] = recent[1] = chunkMap.end();
129  }
130 
131  Value &
133  {
134  CacheChunk *chunk = getChunk(addr);
135  return chunk->items[chunkOffset(addr)];
136  }
137 };
138 
139 } // namespace decode_cache
140 } // namespace gem5
141 
142 #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:94
gem5::decode_cache::AddrMap::chunkMap
ChunkMap chunkMap
Definition: decode_cache.hh:78
gem5::decode_cache::InstMap
std::unordered_map< EMI, StaticInstPtr > InstMap
Hash for decoded instructions.
Definition: decode_cache.hh:47
gem5::decode_cache::AddrMap::chunkOffset
static constexpr Addr chunkOffset(Addr addr)
Definition: decode_cache.hh:57
gem5::decode_cache::AddrMap::recent
ChunkIt recent[2]
Definition: decode_cache.hh:77
gem5::decode_cache::AddrMap::CacheChunkBytes
static constexpr Addr CacheChunkBytes
Definition: decode_cache.hh:54
gem5::decode_cache::AddrMap::chunkStart
static constexpr Addr chunkStart(Addr addr)
Definition: decode_cache.hh:63
gem5::decode_cache::AddrMap::CacheChunk
Definition: decode_cache.hh:69
gem5::decode_cache::AddrMap::ChunkMap
std::unordered_map< Addr, CacheChunk * > ChunkMap
Definition: decode_cache.hh:74
bitfield.hh
gem5::decode_cache::AddrMap
A sparse map from an Addr to a Value, stored in page chunks.
Definition: decode_cache.hh:51
gem5::decode_cache::AddrMap::update
void update(ChunkIt recentest)
Update the mini cache of recent lookups.
Definition: decode_cache.hh:83
compiler.hh
gem5::decode_cache::AddrMap::AddrMap
AddrMap()
Constructor.
Definition: decode_cache.hh:126
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
gem5::decode_cache::AddrMap::ChunkIt
ChunkMap::iterator ChunkIt
Definition: decode_cache.hh:75
gem5::decode_cache::AddrMap::CacheChunk::items
Value items[CacheChunkBytes]
Definition: decode_cache.hh:71
gem5::statistics::Value
Definition: statistics.hh:1979
static_inst_fwd.hh
gem5::decode_cache::AddrMap::lookup
Value & lookup(Addr addr)
Definition: decode_cache.hh:132
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Tue Sep 21 2021 12:24:47 for gem5 by doxygen 1.8.17