optimize fast path of v2p

This commit is contained in:
Neil Webber 2023-09-29 09:36:13 -05:00
parent afdd35bc9a
commit ed1fdfdc5a

16
mmu.py
View file

@ -279,8 +279,10 @@ class MemoryMgmt:
segno = vaddr >> 13 segno = vaddr >> 13
# the segment number and these other parameters form # the segment number and these other parameters form
# a "translation key" used in several places # a "translation key" used in several places. Unfortunately,
xkey = self.TransKey(segno, mode, space, cycle) # the namedtuple construction is enough overhead to matter in
# this critical/fast path, so caching uses tuple key
tuplexkey = (segno, mode, space, cycle)
# All this translation code takes quite some time; caching # All this translation code takes quite some time; caching
# dramatically improves performance. # dramatically improves performance.
@ -288,12 +290,14 @@ class MemoryMgmt:
if self.nocache and self.segcache: if self.nocache and self.segcache:
self.segcache = {} self.segcache = {}
try: try:
xoff, validation_func = self.segcache[xkey] xoff, validation_func = self.segcache[tuplexkey]
if validation_func(vaddr): if (validation_func is None) or validation_func(vaddr):
return vaddr + xoff return vaddr + xoff
except KeyError: except KeyError:
pass pass
xkey = self.TransKey(segno, mode, space, cycle)
# not cached; do the translation... # not cached; do the translation...
par, pdr = self._getapr(xkey) par, pdr = self._getapr(xkey)
@ -349,7 +353,7 @@ class MemoryMgmt:
# only non-trapping can be cached # only non-trapping can be cached
if straps == 0: if straps == 0:
self._encache(xkey, pdr, pa - vaddr) self._encache(tuplexkey, pdr, pa - vaddr)
return pa return pa
def _encache(self, k, pdr, offs): def _encache(self, k, pdr, offs):
@ -362,7 +366,7 @@ class MemoryMgmt:
elif (pdr & 0o10) == 0 and plf < 0o177: elif (pdr & 0o10) == 0 and plf < 0o177:
self.segcache[k] = (offs, lambda a: ((a >> 6) & 0o177) <= plf) self.segcache[k] = (offs, lambda a: ((a >> 6) & 0o177) <= plf)
else: else:
self.segcache[k] = (offs, lambda a: True) # full segment self.segcache[k] = (offs, None) # full segment
def _foldspaces(self, mode, space): def _foldspaces(self, mode, space):
"""Folds DSPACE back into ISPACE if DSPACE not enabled for mode""" """Folds DSPACE back into ISPACE if DSPACE not enabled for mode"""