EE Cache: Shrink tag size by 4 bytes

This commit is contained in:
Ty Lamontagne 2025-01-04 12:01:19 -05:00 committed by Ty
parent 3b5b3ffa91
commit 16b1095a7b
1 changed files with 25 additions and 10 deletions

View File

@ -23,10 +23,11 @@ namespace
// When this happens, the cache still fills with the data and when it gets evicted the data is lost. // When this happens, the cache still fills with the data and when it gets evicted the data is lost.
// We don't emulate memory access on a logic level, so we need to ensure that we don't try to load/store to a non-existant physical address. // We don't emulate memory access on a logic level, so we need to ensure that we don't try to load/store to a non-existant physical address.
// This fixes the Find My Own Way demo. // This fixes the Find My Own Way demo.
bool validPFN = true;
// The lower parts of a cache tags structure is as follows: // The lower parts of a cache tags structure is as follows:
// 31 - 12: The physical address cache tag. // 31 - 12: The physical address cache tag.
// 11 - 7: Unused. // 11: Used by PCSX2 to indicate if the physical address is valid.
// 10 - 7: Unused.
// 6: Dirty flag. // 6: Dirty flag.
// 5: Valid flag. // 5: Valid flag.
// 4: LRF flag - least recently filled flag. // 4: LRF flag - least recently filled flag.
@ -39,7 +40,8 @@ namespace
VALID_FLAG = 0x20, VALID_FLAG = 0x20,
LRF_FLAG = 0x10, LRF_FLAG = 0x10,
LOCK_FLAG = 0x8, LOCK_FLAG = 0x8,
ALL_FLAGS = 0xFFF ALL_FLAGS = 0x7FF,
ALL_BITS = 0xFFF
}; };
int flags() const int flags() const
@ -65,23 +67,36 @@ namespace
void clearLocked() { rawValue &= ~LOCK_FLAG; } void clearLocked() { rawValue &= ~LOCK_FLAG; }
void toggleLRF() { rawValue ^= LRF_FLAG; } void toggleLRF() { rawValue ^= LRF_FLAG; }
uptr addr() const { return rawValue & ~ALL_FLAGS; } uptr addr() const { return rawValue & ~ALL_BITS; }
void setAddr(uptr addr) void setAddr(uptr addr)
{ {
rawValue &= ALL_FLAGS; rawValue &= ALL_BITS;
rawValue |= (addr & ~ALL_FLAGS); rawValue |= (addr & ~ALL_BITS);
} }
bool matches(uptr other) const bool matches(uptr other) const
{ {
return isValid() && addr() == (other & ~ALL_FLAGS); return isValid() && addr() == (other & ~ALL_BITS);
} }
void clear() void clear()
{ {
rawValue &= LRF_FLAG; rawValue &= LRF_FLAG;
} }
constexpr bool isValidPFN() const
{
return rawValue & 0x800;
}
constexpr void setValidPFN(bool valid)
{
if (valid)
rawValue |= 0x800;
else
rawValue &= ~0x800;
}
}; };
struct CacheLine struct CacheLine
@ -103,7 +118,7 @@ namespace
uptr target = addr(); uptr target = addr();
CACHE_LOG("Write back at %zx", target); CACHE_LOG("Write back at %zx", target);
if (tag.validPFN) if (tag.isValidPFN())
*reinterpret_cast<CacheData*>(target) = data; *reinterpret_cast<CacheData*>(target) = data;
tag.clearDirty(); tag.clearDirty();
} }
@ -113,7 +128,7 @@ namespace
pxAssertMsg(!tag.isDirtyAndValid(), "Loaded a value into cache without writing back the old one!"); pxAssertMsg(!tag.isDirtyAndValid(), "Loaded a value into cache without writing back the old one!");
tag.setAddr(ppf); tag.setAddr(ppf);
if (!tag.validPFN) if (!tag.isValidPFN())
{ {
// Reading from invalid physical addresses seems to return 0 on hardware // Reading from invalid physical addresses seems to return 0 on hardware
std::memset(&data, 0, sizeof(data)); std::memset(&data, 0, sizeof(data));
@ -238,7 +253,7 @@ static int getFreeCache(u32 mem, int* way, bool validPFN)
CacheLine line = cache.lineAt(setIdx, newWay); CacheLine line = cache.lineAt(setIdx, newWay);
line.writeBackIfNeeded(); line.writeBackIfNeeded();
line.tag.validPFN = validPFN; line.tag.setValidPFN(validPFN);
line.load(ppf); line.load(ppf);
line.tag.toggleLRF(); line.tag.toggleLRF();
} }