gem5  v20.1.0.0
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 "cpu/static_inst_fwd.hh"
36 
37 namespace DecodeCache
38 {
39 
41 template <typename EMI>
42 using InstMap = std::unordered_map<EMI, StaticInstPtr>;
43 
45 template<class Value, Addr CacheChunkShift = 12>
46 class AddrMap
47 {
48  protected:
49  static constexpr Addr CacheChunkBytes = 1ULL << CacheChunkShift;
50 
51  static constexpr Addr
53  {
54  return addr & (CacheChunkBytes - 1);
55  }
56 
57  static constexpr Addr
59  {
60  return addr & ~(CacheChunkBytes - 1);
61  }
62 
63  // A chunk of cache entries.
64  struct CacheChunk
65  {
67  };
68  // A map of cache chunks which allows a sparse mapping.
69  typedef typename std::unordered_map<Addr, CacheChunk *> ChunkMap;
70  typedef typename ChunkMap::iterator ChunkIt;
71  // Mini cache of recent lookups.
74 
77  void
78  update(ChunkIt recentest)
79  {
80  recent[1] = recent[0];
81  recent[0] = recentest;
82  }
83 
88  CacheChunk *
90  {
91  Addr chunk_addr = chunkStart(addr);
92 
93  // Check against recent lookups.
94  if (recent[0] != chunkMap.end()) {
95  if (recent[0]->first == chunk_addr)
96  return recent[0]->second;
97  if (recent[1] != chunkMap.end() &&
98  recent[1]->first == chunk_addr) {
99  update(recent[1]);
100  // recent[1] has just become recent[0].
101  return recent[0]->second;
102  }
103  }
104 
105  // Actually look in the hash_map.
106  ChunkIt it = chunkMap.find(chunk_addr);
107  if (it != chunkMap.end()) {
108  update(it);
109  return it->second;
110  }
111 
112  // Didn't find an existing chunk, so add a new one.
113  CacheChunk *newChunk = new CacheChunk;
114  typename ChunkMap::value_type to_insert(chunk_addr, newChunk);
115  update(chunkMap.insert(to_insert).first);
116  return newChunk;
117  }
118 
119  public:
122  {
123  recent[0] = recent[1] = chunkMap.end();
124  }
125 
126  Value &
128  {
129  CacheChunk *chunk = getChunk(addr);
130  return chunk->items[chunkOffset(addr)];
131  }
132 };
133 
134 } // namespace DecodeCache
135 
136 #endif // __CPU_DECODE_CACHE_HH__
DecodeCache::AddrMap::chunkStart
static constexpr Addr chunkStart(Addr addr)
Definition: decode_cache.hh:58
DecodeCache::AddrMap::chunkMap
ChunkMap chunkMap
Definition: decode_cache.hh:73
DecodeCache::AddrMap::CacheChunk::items
Value items[CacheChunkBytes]
Definition: decode_cache.hh:66
DecodeCache::AddrMap
A sparse map from an Addr to a Value, stored in page chunks.
Definition: decode_cache.hh:46
DecodeCache::AddrMap::ChunkIt
ChunkMap::iterator ChunkIt
Definition: decode_cache.hh:70
DecodeCache::AddrMap::lookup
Value & lookup(Addr addr)
Definition: decode_cache.hh:127
bitfield.hh
DecodeCache::AddrMap::getChunk
CacheChunk * getChunk(Addr addr)
Attempt to find the CacheChunk which goes with a particular address.
Definition: decode_cache.hh:89
DecodeCache::InstMap
std::unordered_map< EMI, StaticInstPtr > InstMap
Hash for decoded instructions.
Definition: decode_cache.hh:42
DecodeCache::AddrMap::chunkOffset
static constexpr Addr chunkOffset(Addr addr)
Definition: decode_cache.hh:52
DecodeCache::AddrMap::recent
ChunkIt recent[2]
Definition: decode_cache.hh:72
DecodeCache::AddrMap::CacheChunk
Definition: decode_cache.hh:64
DecodeCache
Definition: decode_cache.hh:37
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
DecodeCache::AddrMap::update
void update(ChunkIt recentest)
Update the mini cache of recent lookups.
Definition: decode_cache.hh:78
static_inst_fwd.hh
addr
ip6_addr_t addr
Definition: inet.hh:423
DecodeCache::AddrMap::ChunkMap
std::unordered_map< Addr, CacheChunk * > ChunkMap
Definition: decode_cache.hh:69
DecodeCache::AddrMap::CacheChunkBytes
static constexpr Addr CacheChunkBytes
Definition: decode_cache.hh:49
DecodeCache::AddrMap::AddrMap
AddrMap()
Constructor.
Definition: decode_cache.hh:121
ULL
#define ULL(N)
uint64_t constant
Definition: types.hh:50

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