Progress on fixing the cache simulator to support cbo instructions.

This commit is contained in:
Rose Thompson 2024-11-11 16:37:17 -06:00
parent 3137fd7db2
commit 0cf7b2e45a
2 changed files with 23 additions and 4 deletions

View file

@ -84,6 +84,14 @@ class Cache:
for way in self.ways:
for line in way:
line.dirty = False
# invalidate this specific line
def cboinvalidate(self, addr):
tag, setnum, _ = self.splitaddr(addr)
for waynum in range(self.numways):
line = self.ways[waynum][setnum]
if line.tag == tag and line.valid:
line.dirty = 0
# invalidates the cache by setting all valid bits to False
def invalidate(self):
@ -108,14 +116,15 @@ class Cache:
# performs a cache access with the given address.
# returns a character representing the outcome:
# H/M/E/D - hit, miss, eviction, or eviction with writeback
def cacheaccess(self, addr, write=False):
def cacheaccess(self, addr, write=False, clean=False):
tag, setnum, _ = self.splitaddr(addr)
# check our ways to see if we have a hit
#print(f"addr is {addr:x} Set is {setnum}")
for waynum in range(self.numways):
line = self.ways[waynum][setnum]
if line.tag == tag and line.valid:
line.dirty = line.dirty or write
line.dirty = 0 if clean else line.dirty or write
self.update_pLRU(waynum, setnum)
return 'H'
@ -132,6 +141,7 @@ class Cache:
# we need to evict. Select a victim and overwrite.
victim = self.getvictimway(setnum)
#print(f"addr is {addr:x} Victim is {victim} Set is {setnum}")
line = self.ways[victim][setnum]
prevdirty = line.dirty
line.tag = tag
@ -243,10 +253,15 @@ def main():
cache.invalidate()
if args.verbose:
print("I")
elif lninfo[1] == 'C' or lninfo[1] == 'L':
cache.cboinvalidate()
if args.verbose:
print("C");
else:
addr = int(lninfo[0], 16)
iswrite = lninfo[1] == 'W' or lninfo[1] == 'A'
result = cache.cacheaccess(addr, iswrite)
iswrite = lninfo[1] == 'W' or lninfo[1] == 'A' or lninfo[1] == 'Z'
iscboclean = lninfo[1] == 'C'
result = cache.cacheaccess(addr, iswrite, iscboclean)
if args.verbose:
tag, setnum, offset = cache.splitaddr(addr)