MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / getFreeCache

Function getFreeCache

pcsx2/Cache.cpp:205–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203}
204
205static int getFreeCache(u32 mem, int* way, bool validPFN)
206{
207 const int setIdx = cache.setIdxFor(mem);
208 CacheSet& set = cache.sets[setIdx];
209 VTLBVirtual vmv = vtlbdata.vmap[mem >> VTLB_PAGE_BITS];
210
211 *way = set.tags[0].lrf() ^ set.tags[1].lrf();
212 if (validPFN)
213 pxAssertMsg(!vmv.isHandler(mem), "Cache currently only supports non-handler addresses!");
214
215 uptr ppf = vmv.assumePtr(mem);
216
217 [[unlikely]]
218 if ((cpuRegs.CP0.n.Config & 0x10000) == 0)
219 CACHE_LOG("Cache off!");
220
221 if (findInCache(set, ppf, way))
222 {
223 [[unlikely]]
224 if (set.tags[*way].isLocked())
225 {
226 // Check the other way
227 if (set.tags[*way ^ 1].isLocked())
228 {
229 Console.Error("CACHE: SECOND WAY IS LOCKED.", setIdx, *way);
230 }
231 else
232 {
233 // Force the unlocked way
234 *way ^= 1;
235 }
236 }
237 }
238 else
239 {
240 int newWay = set.tags[0].lrf() ^ set.tags[1].lrf();
241 [[unlikely]]
242 if (set.tags[newWay].isLocked())
243 {
244 // If the new way is locked, we force the unlocked way, ignoring the lrf bits.
245 newWay = newWay ^ 1;
246 [[unlikely]]
247 if (set.tags[newWay].isLocked())
248 {
249 Console.Warning("CACHE: SECOND WAY IS LOCKED.", setIdx, *way);
250 }
251 }
252 *way = newWay;
253
254 CacheLine line = cache.lineAt(setIdx, newWay);
255 line.writeBackIfNeeded();
256 line.tag.setValidPFN(validPFN);
257 line.load(ppf);
258 line.tag.toggleLRF();
259 }
260
261 return setIdx;
262}

Callers 1

prepareCacheAccessFunction · 0.85

Calls 13

findInCacheFunction · 0.85
setIdxForMethod · 0.80
lrfMethod · 0.80
isLockedMethod · 0.80
lineAtMethod · 0.80
writeBackIfNeededMethod · 0.80
setValidPFNMethod · 0.80
toggleLRFMethod · 0.80
isHandlerMethod · 0.45
assumePtrMethod · 0.45
ErrorMethod · 0.45
WarningMethod · 0.45

Tested by

no test coverage detected