branlwyd / bdcpu16

DCPU-16 simulator based on version 1.7 of the DCPU-16 specification. See http://dcpu.com/.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Debug: improve decoded instruction cache

branlwyd opened this issue · comments

DebuggerFrame.DecodedInstructionCache is currently very inefficient:

  • Every time the CPU is paused, the entire cache is invalidated.
  • When invalidating a single instruction, also invalidates every instruction after that instruction.

Marked as low priority as, although this behavior is quite terrible, it only applies when single-stepping the debugger, where performance is not of extreme importance.

Improving this is likely going to require caching instructions using the current PC value as the "base" for decoding rather than 0. However this will pose a challenge as it's not immediately clear how to decode backwards--given an address, there may be multiple previous addresses that would put us where we currently are. Could scan backwards until we hit a point where there is no ambiguity--guaranteed to exist because we'll eventually hit 0. Not sure how often this would cause us to scan all the way back to 0 however--not sure how common ambiguities are. This would also be a fairly complicated algorithm to implement efficiently.