feat(relinker): replace guest cache flushes with NOPs in every conversion #26606
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26606"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-11-24T10:54:43Z.
What
Every conversion target (
--to-intel,--to-rosetta,--to-avx) now replaces the memory forms of CLFLUSH, CLFLUSHOPT and CLWB with NOPs of the same length. Before this, only--to-rosettaand--to-avxdid it, and only for CLWB.clflushoptloop over its 7.9 MB linear render targets right after the label, so the store runs synchronously and waits for the GPU. #25912 has the measurements: with a local Windows trap prototype, NOPing that one flush took the race from 33.5 to 26 ms per frame, the same as skipping the store.docs/dev/debt/libkernel.md).The changes:
DecodedInstructiongetsIsClflush(0F AE /7, memory form, no prefix) andIsClflushopt(the same with66).Amd64OnlyInstructionMatcher::Matchreplaces CLFLUSH, CLFLUSHOPT and CLWB in place before the target-specific checks, and_emitInPlaceaccepts the three names.0F AE 3Fis now reported as CLFLUSH, where before it was only checked not to be XSAVEOPT;66 0F AE 38is now reported as CLFLUSHOPT, where before it was only checked not to be CLWB;disp8,disp32and REX forms, and checks that the register forms0F AE F8(SFENCE) and66 0F AE F8stay untouched.docs/user/USAGE.mdmentions the replacement under--to-intel. A debt fragment records that a relink without a conversion, as on AMD hosts, keeps the flushes.Tested
Windows 11 (10.0.26300), WinLibs GCC 15.2.0 r7, Release.
amd64_only_converterpasses onmain0c2fee0b6fand with this change.The relinker tests (
ctest -R 'amd64|relinker|codegen|x64_|red_zone|guest_module|conversion|elfpatcher|syscall_scan|game_patch', 46 tests) pass with this change.SuperTuxKart (PPSA69421), relinked by
tools/title_run.pywith--to-intelon an i5-10600K and an RTX 5060 Ti (621.24). The base is the stack I use for this title in #25912:main0d8e695ad2with #10442, #24445, #24869 and #25280 merged (b24225548f). The change is that base plus this commit (8948b0c50c); only the relinker differs, and it was rebuilt at each switch. The scene is the tutorial race with a recorded pad timeline,--profile performance --trace-seconds 80:10 --seconds 110 --warmup-seconds 110, in the order base, change, change, base. The relinker reportedCLFLUSH× 20 andCLFLUSHOPT× 2 replaced, and the race ran normally.tools/trace_digest.py, seconds 80:10:Without any read trap, the flushes themselves cost 2 to 5 ms per frame here. The traces are available on request.
tools/check_conventions.pyandtools/debt_fold.py --checkpass.Overlap:
tools/pr_overlap.py --branchfound textual conflicts indocs/user/USAGE.mdwith #23781 and #24967. After the USAGE change moved from the option table to the--to-intelnote, both merge cleanly. #12678, #23842 and #11525 also touchAmd64OnlyInstructionMatcher.cpp,USAGE.mdorAmd64OnlyConverterTests.cpp, but each already conflicts withmainin that same file, so this change adds no conflict of its own.Not run: Linux, macOS.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-24T10:57:04Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
0c7be832ff:tools/check_conventions.pypassed.amd64_only_converter_testsbuilt cleanly.amd64_only_converter):core/relinker/codegen/include/codegen/x86/Amd64OnlySubstitutionTable.hpp,core/relinker/codegen/include/codegen/x86/DecodedInstruction.hpp,core/relinker/codegen/src/x86/Amd64OnlyInstructionMatcher.cpp,core/relinker/codegen/src/x86/DecodedInstruction.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-24T11:22:52Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
0fff855c74:tools/check_conventions.pypassed.amd64_only_converter_testsbuilt cleanly.amd64_only_converter):core/relinker/codegen/include/codegen/x86/Amd64OnlySubstitutionTable.hpp,core/relinker/codegen/include/codegen/x86/DecodedInstruction.hpp,core/relinker/codegen/src/x86/Amd64OnlyInstructionMatcher.cpp,core/relinker/codegen/src/x86/DecodedInstruction.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T07:37:09Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected decoder, matcher, and length-preserving replacement paths support the described behavior.
What I ran
Reviewed head
0fff855c7417f761c0a193f20782854c9f8aba15. No commands or tests were run; the reported Windows test and performance results are author-supplied.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Read all eight changed files listed in the manifest, including the full text of each file. Did not independently run tests, verify the author-reported performance measurements, or assess Linux/macOS behavior. The prepared bundle listed no excluded changed files.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T12:45:00Z.
Review: APPROVED
Reviewed — looks good
The cache flush substitutions and LOCK-prefix rejection are consistent with the documented conversion behavior at head
0dd344049735bbab58a19886323ef8e6e8feb232; I found no verified blocking defect.What I ran
Read the prepared description, commits, manifest and diff, then inspected the changed decoder, matcher, unit and relinker tests, and documentation using the pinned
repo_read.pyreader. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The
files.jsonpath was not available through the reader, so I could not independently verify its reviewed/excluded breakdown. The prepared manifest lists seven changed files and marks each full text as included; I read all seven. Linux and macOS behavior and the author-reported Windows test and performance results were not independently verified.To get this to a good state
Nothing is required.