Account the 7-cycle hardware interrupt entry cost in cycle accounting - #290
Merged
Conversation
…ame budgets, and device ticking
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Hardware IRQ/NMI entry previously consumed 0 cycles in cycle accounting; real 6502-family entry takes 7 (two dummy opcode reads, three stack pushes, two vector reads — the bus sequence itself was implemented in #289). Follow-up scheduled from that work.
What changes
CPU.ProcessPendingInterrupts(and the internal boundary servicing) returns the cycles consumed: newCPU.InterruptEntryCycles(7) when an interrupt was serviced, else 0.InstructionExecResult(newWithAdditionalCycles) before statistics update, so every cycle-paced consumer sees real elapsed time with no further changes:ExecStatetotals (Apple II disk motor/speaker/game-port clocks),LastInstructionExecResult(Apple II / VIC-20 frame budgets and VIA ticking), evaluators, and theInstructionExecutedevent.Executepath,NmiAcknowledgingnow fires beforeInstructionExecuted(servicing moved before stats update); the only NmiAcknowledging consumer (C64) uses the minimal path and is unaffected.Impact
Frame budgets now fit ~7 fewer CPU cycles per serviced interrupt (~0.04% per raster-IRQ frame on C64) — matching real hardware. All existing C64/VIC-20/Apple II timing tests pass unchanged; benchmarks at parity (hot path gained only a return-value check).
Tests
+4 in
CPUInterruptBoundaryTests: IRQ entry costs 2+7 on the minimal path (result and ExecState views), NMI costs 2+7 on the full path,ProcessPendingInterruptsreturns 7/0, and a no-interrupt control keeps plain instruction cycles.Public API note:
ProcessPendingInterruptschangedvoid→ulong(source-compatible for callers ignoring the result; package is alpha).