gem5 v24.0.0.0
Loading...
Searching...
No Matches
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"
37
38namespace gem5
39{
40
41namespace decode_cache
42{
43
45template <typename EMI>
46using InstMap = std::unordered_map<EMI, StaticInstPtr>;
47
49template<class Value, Addr CacheChunkShift = 12>
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.
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__
A sparse map from an Addr to a Value, stored in page chunks.
static constexpr Addr chunkOffset(Addr addr)
CacheChunk * getChunk(Addr addr)
Attempt to find the CacheChunk which goes with a particular address.
static constexpr Addr chunkStart(Addr addr)
void update(ChunkIt recentest)
Update the mini cache of recent lookups.
ChunkMap::iterator ChunkIt
std::unordered_map< Addr, CacheChunk * > ChunkMap
static constexpr Addr CacheChunkBytes
Value & lookup(Addr addr)
Bitfield< 3 > addr
Definition types.hh:84
std::unordered_map< EMI, StaticInstPtr > InstMap
Hash for decoded instructions.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria 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

Generated on Tue Jun 18 2024 16:24:01 for gem5 by doxygen 1.11.0