loader: native trampoline for VRSQRTPS under --amd-cpu #893
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!893
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/893/head"
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?
@ew-sudo on GitHub · 2026-09-28 20:40 UTC · original
ew-sudo:vrsqrtps-native→main· +519 −352 · 9 files · 1 commits · merged 2026-10-03 15:13 UTCDescription :
Problem
On Intel CPUs, Astro's Playroom (PPSA01325, v01.905, with the non-RT memory patch) crashes when loading Cooling Springs:
It reproduced 2/2 at the same guest PC. With
--amd-cpu(AMD-accurate VRSQRTPS emulation) the level loads and plays. So the NaN appears to come from the Intel/AMD difference in the VRSQRTPS approximation.However, with
--amd-cpuevery VRSQRTPS goes through the illegal-instruction trap. I measured more than 1,000,000 traps per second in that level, which dropped it to about 7 FPS.Change
When
--amd-cpuis enabled, VRSQRTPS sites (VEX.128, register form, the same onesIsReciprocalSquareRootalready selects) are relocated into a native trampoline instead of being trapped. It uses the same relocation path as the red-zone patcher.The trampoline computes exactly what
ReciprocalSquareRoot()inx64InstructionEmulator.cppcomputes:Sites that cannot be relocated keep the existing trap path.
KYTY_RSQRT_TRAP=1forces the old trap path for A/B testing. At load time the log printsVRSQRTPS patching: found=…, native=…, trapped=….Testing
ReciprocalSquareRoot(): 36M random lanes including zeros, denormals, infinities, NaNs and negatives, several dst/src register combinations (including dst == src), 0 mismatches. It also checked that the upper YMM half is zeroed, the scratch register is preserved and MXCSR is unchanged.--redzone --amd-cpu:@coderabbitai[bot] on GitHub · 2026-09-28 20:46 UTC · original · edited 2026-09-28 20:51 UTC
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
📝 Walkthrough
Walkthrough
The patch adds a native VEX sequence for
VRSQRTPSthat uses double-precision square root and division. It preserves RFLAGS and guest MXCSR, and saves and restores a temporary YMM register using stack storage.KYTY_RSQRT_TRAPselects the trap-emulation path when set. Patch reporting now separates native and trapped sites.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🔵 Low · up to
bfe3eThe native path can produce misleading patch counts and fail an existing Windows test. Both issues are bounded, but should be corrected or explicitly accepted before merging.
Security Architecture Review
Security architecture risk: 🟡 Moderate · up to
bfe3eNative execution is limited to selected instructions in loaded guest programs, and the trap fallback remains available. However, the new path relies on generated code preserving guest state, while its reported native-versus-trapped counts can misstate whether the fallback is in use.
Retained concerns
Security review details
Security Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-09-28 20:46 UTC · original
On
src/loader/redZonePatcher.cppline 841 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 9563
Update the reciprocal-square-root test contract for native patching.
On Windows,
CollectReciprocalSquareRootsenables native relocation by default. The test still requires the relocated instruction to incrementg_rsqrt_traps. The native path does not invokeReciprocalSquareRootHandler, so the test can fail unlessKYTY_RSQRT_TRAPis set.The test must either select trap mode explicitly or assert the native and trapped paths separately.
@coderabbitai[bot] on GitHub · 2026-09-28 20:46 UTC · original
On
src/loader/redZonePatcher.cppline 863 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5166
Count native generation, not relocation.
When
KYTY_RSQRT_TRAPis set, red-zone protection can relocate aVRSQRTPSsite without callingGenerateReciprocalSquareRoot. The relocation still follows the trap path, butApplyReciprocalSquareRootPatchescounts every address inmodule.patchedas native. Track whether the relocation emittedGenerateReciprocalSquareRootbefore reportingnativeandtrapped.@coderabbitai[bot] on GitHub · 2026-09-28 20:46 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
8fd96e13-1b32-49d0-bf23-9a51a4ca1838📥 Commits
Reviewing files that changed from the base of the PR and between
4b0de1b672and bfe3e0ddef6df2c17ba1789c9c6a04d076cbac3d.📒 Files selected for processing (1)
src/loader/redZonePatcher.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.