gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
delta_correlating_prediction_tables.cc
Go to the documentation of this file.
1
28
30
31#include "debug/HWPrefetch.hh"
32#include "params/DCPTPrefetcher.hh"
33#include "params/DeltaCorrelatingPredictionTables.hh"
34
35namespace gem5
36{
37
38namespace prefetch
39{
40
42 const DeltaCorrelatingPredictionTablesParams &p) : SimObject(p),
43 deltaBits(p.delta_bits), deltaMaskBits(p.delta_mask_bits),
44 table((name() + "DCPT").c_str(), p.table_entries,
45 p.table_assoc, p.table_replacement_policy,
46 p.table_indexing_policy,
47 DCPTEntry(p.deltas_per_entry,
48 genTagExtractor(p.table_indexing_policy)))
49{
50}
51
52void
54{
56
57 deltas.flush();
58 while (!deltas.full()) {
59 deltas.push_back(0);
60 }
61 lastAddress = 0;
62}
63
64void
66 unsigned int delta_bits)
67{
68 if ((address - lastAddress) != 0) {
69 Addr delta = address - lastAddress;
70 // Account for the sign bit
71 Addr max_positive_delta = (1 << (delta_bits-1)) - 1;
72 if (address > lastAddress) {
73 // check positive delta overflow
74 if (delta > max_positive_delta) {
75 delta = 0;
76 }
77 } else {
78 // check negative delta overflow
79 if (lastAddress - address > (max_positive_delta + 1)) {
80 delta = 0;
81 }
82 }
83 deltas.push_back(delta);
84 lastAddress = address;
85 }
86}
87
88void
90 std::vector<Queued::AddrPriority> &pfs, unsigned int mask) const
91{
92 assert(deltas.full());
93
94 // Get the two most recent deltas
95 const int delta_penultimate = *(deltas.end() - 2);
96 const int delta_last = *(deltas.end() - 1);
97
98 // a delta 0 means that it overflowed, we can not match it
99 if (delta_last == 0 || delta_penultimate == 0) {
100 return;
101 }
102
103 // Try to find the two most recent deltas in a previous position on the
104 // delta circular array, if found, start issuing prefetches using the
105 // remaining deltas (adding each delta to the last Addr to generate the
106 // prefetched address.
107 auto it = deltas.begin();
108 for (; it != (deltas.end() - 2); ++it) {
109 const int prev_delta_penultimate = *it;
110 const int prev_delta_last = *(it + 1);
111 if ((prev_delta_penultimate >> mask) == (delta_penultimate >> mask) &&
112 (prev_delta_last >> mask) == (delta_last >> mask)) {
113 // Pattern found. Skip the matching pair and issue prefetches with
114 // the remaining deltas
115 it += 2;
117 while (it != deltas.end()) {
118 const int pf_delta = *(it++);
119 addr += pf_delta;
120 pfs.push_back(Queued::AddrPriority(addr, 0));
121 }
122 break;
123 }
124 }
125}
126
127void
129 const Base::PrefetchInfo &pfi,
131 const CacheAccessor &cache)
132{
133 if (!pfi.hasPC()) {
134 DPRINTF(HWPrefetch, "Ignoring request with no PC.\n");
135 return;
136 }
137 Addr address = pfi.getAddr();
138 Addr pc = pfi.getPC();
139 // Look up table entry
140 DCPTEntry *entry = table.findEntry(pc);
141 if (entry != nullptr) {
142 entry->addAddress(address, deltaBits);
143 //Delta correlating
144 entry->getCandidates(addresses, deltaMaskBits);
145 } else {
146 entry = table.findVictim(pc);
147
148 table.insertEntry(pc, entry);
149
150 entry->lastAddress = address;
151 }
152}
153
154DCPT::DCPT(const DCPTPrefetcherParams &p)
155 : Queued(p), dcpt(*p.dcpt)
156{
157}
158
159void
161 std::vector<AddrPriority> &addresses,
162 const CacheAccessor &cache)
163{
164 dcpt.calculatePrefetch(pfi, addresses, cache);
165}
166
167} // namespace prefetch
168} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
virtual void invalidate()
Invalidate the block.
virtual std::string name() const
Definition named.hh:60
Class containing the information needed by the prefetch to train and generate new prefetch requests.
Definition base.hh:113
Addr getPC() const
Returns the program counter that generated this request.
Definition base.hh:158
Addr getAddr() const
Obtains the address value of this Prefetcher address.
Definition base.hh:140
bool hasPC() const
Returns true if the associated program counter is valid.
Definition base.hh:168
DCPT(const DCPTPrefetcherParams &p)
DeltaCorrelatingPredictionTables & dcpt
DCPT object.
void calculatePrefetch(const PrefetchInfo &pfi, std::vector< AddrPriority > &addresses, const CacheAccessor &cache) override
DeltaCorrelatingPredictionTables(const DeltaCorrelatingPredictionTablesParams &p)
const unsigned int deltaBits
Number of bits of each delta.
void calculatePrefetch(const Base::PrefetchInfo &pfi, std::vector< Queued::AddrPriority > &addresses, const CacheAccessor &cache)
Computes the prefetch candidates given a prefetch event.
const unsigned int deltaMaskBits
Number of lower bits to ignore from the deltas.
Queued(const QueuedPrefetcherParams &p)
Definition queued.cc:100
std::pair< Addr, int32_t > AddrPriority
Definition queued.hh:192
STL vector class.
Definition stl.hh:37
SimObject(const Params &p)
Definition sim_object.cc:58
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
Bitfield< 4 > pc
Bitfield< 0 > p
Bitfield< 3 > addr
Definition types.hh:84
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
static constexpr auto genTagExtractor(BTBIndexingPolicy *ip)
This helper generates a tag extractor function object which will be typically used by Replaceable ent...
Definition btb_entry.hh:281
Provides generic cache lookup functions.
void addAddress(Addr address, unsigned int delta_num_bits)
Adds an address to the entry, if the entry already existed, a delta will be generated.
void getCandidates(std::vector< Queued::AddrPriority > &pfs, unsigned int mask_bits) const
Attempt to generate prefetch candidates using the two most recent deltas.

Generated on Mon May 26 2025 09:19:11 for gem5 by doxygen 1.13.2