codegen: handle continuation PCs and nested callee yields#115
Closed
jlsandri wants to merge 3 commits intoran-j:mainfrom
Closed
codegen: handle continuation PCs and nested callee yields#115jlsandri wants to merge 3 commits intoran-j:mainfrom
jlsandri wants to merge 3 commits intoran-j:mainfrom
Conversation
… only to register_functions
When a callee yields at an internal continuation PC, the caller now re-enters it in a while loop until it exits to the real fallthrough. Prevents nested continuations from leaking as false PC_MISMATCH.
ab38ace to
ffeaddc
Compare
Author
|
Closing as part of a batch cleanup after #107 landed. The runtime ecosystem refactor in #107 substantially reworked the files this PR touched, and I would like to re-audit the underlying fix against the new code structure before putting it back in front of you. If the fix is still needed after that re-audit, I will re-open as a focused PR rebased onto current main. Thanks for your patience. |
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.
Problem
The recompiler's "continuation PC" model assumed a 1:1 mapping between continuation targets and emitted entry functions, and that calls into functions with continuation PCs would always yield back at the single expected fallthrough address.
Two related failure modes:
entry_...wrapper, the codegen path assumed the entry existed and produced a call that couldn't be dispatched.PC_MISMATCHin A's caller — a false positive, because A was still mid-execution and just hadn't reached its outer fallthrough yet.Fix
Two commits:
Handle continuation PCs without separate entry functions. Teach
code_generator.cpp/ps2_recompiler.cppto dispatch continuation targets directly when no entry wrapper exists, instead of assuming the wrapper is always present. Adds a new bookkeeping field to the codegen header.Add a continuation re-entry loop for nested callee yields. After a call, emit a
whileloop that keeps re-entering the callee while its yieldedctx->pclies inside the callee's own range, only exiting to the caller when the real fallthrough PC is reached.These go together — the re-entry loop depends on the first commit's bookkeeping to know where a continuation target lives.
Scope
ps2xRecomp/include/ps2recomp/code_generator.h: +3 / -0ps2xRecomp/src/lib/code_generator.cpp: +124 / -6ps2xRecomp/src/lib/ps2_recompiler.cpp: +41 / -17Rationale
Continuation PCs were already a supported concept in the recompiler; this PR just makes the handling robust to the two edge cases above, which were producing false
PC_MISMATCHaborts in otherwise well-formed code.