loader: enable the AMD CPU instruction patcher on macOS #1014

Manually merged
github merged 5 commits from gh-pr/1014/head into gh-pr/1014/base 2026-11-26 09:40:23 +00:00
Owner

@⁠wuboo on GitHub · 2026-10-03 17:50 UTC · original
wuboo:pr/sse4a-macos → main · +244 −43 · 5 files · 5 commits · merged 2026-10-06 17:55 UTC

What

The guest instruction patcher from #839 and the INSERTQ/RDPID/CLWB follow-up (19a9464b) is compiled out on
macOS (#if !defined(__APPLE__) around xbyak, PatchModule, Register/UnregisterGuestInstructionPatchModule),
and RuntimeLinker::LoadProgramToMemory forces emulate_amd = false there.

This PR:

  • builds guestInstructionPatcher.cpp on all hosts (xbyak is already linked everywhere) and drops the
    macOS stubs;
  • uses Config::AmdCpuEnabled() (--amd-cpu) on macOS exactly like on Windows and Linux, so the switch and
    its default are unchanged;
  • extends macos_sse4a to run the patcher on macOS.

No new flag and no change for other platforms.

Why

Rosetta 2 does not implement SSE4a, so every EXTRQ raises SIGILL and goes through the signal handler and
X64InstructionEmulator. On Apple Silicon (M3 Max, Rosetta 2) in Astro Bot one SIGILL costs about 17.9 us and the
game executes EXTRQ (register and immediate forms) at about 97 sites of the eboot, hundreds of thousands of
hits each. In a level the process took about 41k SIGILL/s, 95% of them EXTRQ.

Numbers from an earlier, independent version of this change on our fork (it rewrote EXTRQ/INSERTQ into SSE2
trampolines in the loader, commit 41d54224 on our bench branch; same idea as this patcher, not this code):

SIGILL/s level frames/s stalls
signal path ~41,800 4.65 34 (54 s)
trampolines ~490 5.61 (+21%) 0

Same binary, KYTY_OPT_OFF=sse4a_patch toggled, one run each; intro chase scene went from 4.42 to 9.86 frames/s.
These are results of that earlier version, not yet of this PR. In-game validation of this branch is pending.

How it was tested

  • macos_sse4a (x86-64 macOS, runs under Rosetta): maps an RWX code page with a trampoline page behind it,
    registers the module, runs PatchGuestInstructions with the host features Rosetta reports
    (no SSE4a/RDPID/CLWB) and compares against the SIGILL emulator on the same inputs:
    • EXTRQ immediate and REX.B (xmm10) become native trampolines, the patched copy raises no SIGILL and
      returns the same bytes as the emulator;
    • INSERTQ (immediate, indexed REX form, register form) is marked as a trap by the patcher, as on other
      hosts, and keeps going through the emulator with identical results;
    • with emulate_amd = false nothing is patched and SIGILL is still raised.
      The new test fails without the change (patcher stubbed out on macOS: "EXTRQ immediate found by the patcher").
  • Full ctest (50 tests) on macOS x86-64 compared with main at 19a9464b: identical results, 34 pass and 16 GPU tests skipped (no Vulkan loader on the test machine) in both trees; no regression.

Notes

  • INSERTQ stays a trap in the patcher (unchanged from main), so it still costs one SIGILL per execution on
    macOS; it was the minor part (about 5%) of the measured signals. A native INSERTQ trampoline can follow if
    wanted.
  • Interaction with #984 (wide-store split for Rosetta): both use the trampoline area right after the module.
    #984 is now rebased on main and starts its split trampolines behind the bytes this patcher has used
    (GetGuestInstructionTrampolineBytesUsed), so with --amd-cpu and the split both active on macOS they no
    longer overwrite each other. I have a test that loads one module with an EXTRQ and a page-crossing 256-bit
    store and checks both results and that the trampoline ranges are disjoint; it needs both changes, so I will add
    it to whichever of the two lands second.
**@⁠wuboo** on GitHub · 2026-10-03 17:50 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1014) `wuboo:pr/sse4a-macos` → `main` · +244 −43 · 5 files · 5 commits · merged 2026-10-06 17:55 UTC ## What The guest instruction patcher from #839 and the INSERTQ/RDPID/CLWB follow-up (19a9464b) is compiled out on macOS (`#if !defined(__APPLE__)` around xbyak, `PatchModule`, `Register/UnregisterGuestInstructionPatchModule`), and `RuntimeLinker::LoadProgramToMemory` forces `emulate_amd = false` there. This PR: - builds `guestInstructionPatcher.cpp` on all hosts (xbyak is already linked everywhere) and drops the macOS stubs; - uses `Config::AmdCpuEnabled()` (`--amd-cpu`) on macOS exactly like on Windows and Linux, so the switch and its default are unchanged; - extends `macos_sse4a` to run the patcher on macOS. No new flag and no change for other platforms. ## Why Rosetta 2 does not implement SSE4a, so every `EXTRQ` raises SIGILL and goes through the signal handler and `X64InstructionEmulator`. On Apple Silicon (M3 Max, Rosetta 2) in Astro Bot one SIGILL costs about 17.9 us and the game executes `EXTRQ` (register and immediate forms) at about 97 sites of the eboot, hundreds of thousands of hits each. In a level the process took about 41k SIGILL/s, 95% of them `EXTRQ`. Numbers from an earlier, independent version of this change on our fork (it rewrote `EXTRQ`/`INSERTQ` into SSE2 trampolines in the loader, commit 41d54224 on our bench branch; same idea as this patcher, not this code): | | SIGILL/s | level frames/s | stalls | |---|---|---|---| | signal path | ~41,800 | 4.65 | 34 (54 s) | | trampolines | ~490 | 5.61 (+21%) | 0 | Same binary, `KYTY_OPT_OFF=sse4a_patch` toggled, one run each; intro chase scene went from 4.42 to 9.86 frames/s. These are results of that earlier version, not yet of this PR. In-game validation of this branch is pending. ## How it was tested - `macos_sse4a` (x86-64 macOS, runs under Rosetta): maps an RWX code page with a trampoline page behind it, registers the module, runs `PatchGuestInstructions` with the host features Rosetta reports (no SSE4a/RDPID/CLWB) and compares against the SIGILL emulator on the same inputs: - `EXTRQ` immediate and REX.B (xmm10) become native trampolines, the patched copy raises no SIGILL and returns the same bytes as the emulator; - `INSERTQ` (immediate, indexed REX form, register form) is marked as a trap by the patcher, as on other hosts, and keeps going through the emulator with identical results; - with `emulate_amd = false` nothing is patched and SIGILL is still raised. The new test fails without the change (patcher stubbed out on macOS: "EXTRQ immediate found by the patcher"). - Full `ctest` (50 tests) on macOS x86-64 compared with `main` at 19a9464b: identical results, 34 pass and 16 GPU tests skipped (no Vulkan loader on the test machine) in both trees; no regression. ## Notes - `INSERTQ` stays a trap in the patcher (unchanged from main), so it still costs one SIGILL per execution on macOS; it was the minor part (about 5%) of the measured signals. A native `INSERTQ` trampoline can follow if wanted. - Interaction with #984 (wide-store split for Rosetta): both use the trampoline area right after the module. #984 is now rebased on main and starts its split trampolines behind the bytes this patcher has used (`GetGuestInstructionTrampolineBytesUsed`), so with `--amd-cpu` and the split both active on macOS they no longer overwrite each other. I have a test that loads one module with an `EXTRQ` and a page-crossing 256-bit store and checks both results and that the trampoline ranges are disjoint; it needs both changes, so I will add it to whichever of the two lands second.
The guest instruction patcher was compiled out on macOS and runtimeLinker forced emulate_amd off,
so under Rosetta every SSE4a EXTRQ/INSERTQ took the SIGILL path (about 18 us each). Build the
patcher on all hosts and let --amd-cpu enable it on macOS like on Windows and Linux. The host
feature probe already reports no SSE4a under Rosetta, so EXTRQ becomes a native trampoline and the
remaining fallbacks keep using the x64 instruction emulator through the host exception handler.
Patch EXTRQ/INSERTQ blobs in an RWX area with a trampoline page behind it, with the host features of
Rosetta (no SSE4a/RDPID/CLWB), and compare against the SIGILL emulator: EXTRQ must become a native
trampoline without SIGILL, INSERTQ stays a trap handled by the emulator, and nothing is touched
without emulate_amd.
The AMD CPU patcher marks VRSQRTPS it cannot relocate by clearing a reserved
VEX.vvvv bit, which raises #UD on every host including Rosetta. The macOS build
left TryEmulateReciprocalSquareRoot and TryEmulateMonitorxMwaitx out, so the
guest died with an unhandled SIGILL at the first such site.

Both are plain SSE2/libc, so enable them on macOS. The Darwin context also
gains ClearUpperYmm so the VEX.128 result zeroes YMM[255:128] when the thread
has the AVX context. macos_sse4a covers the trapped VRSQRTPS and MWAITX.
The existing case started from an instruction that was already marked as a trap. The
new cases feed the ordinary encoding to PatchGuestInstructions and compare the result
with the emulated reference, both through a native trampoline and, when the instruction
cannot be relocated, through the trap mark and the signal emulator.
Share the emulator dispatch chain while keeping SHA emulation limited to non-Apple hosts and preserving handler order. Remove a duplicate VRSQRTPS signal test already covered by both native and trapped patcher cases, plus blank lines left by removed platform guards.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:40:22 +00:00
github manually merged commit e2afc57499 into gh-pr/1014/base 2026-11-26 09:40:23 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-03 17:59 UTC · original · edited 2026-10-06 17:54 UTC

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c7511823-cb51-4d2d-af21-16bed2a3275d
📥 Commits

Reviewing files that changed from the base of the PR and between 91e2f2b7ec and e2afc57499.

📒 Files selected for processing (3)
  • src/loader/guestInstructionPatcher.cpp
  • src/loader/x64InstructionEmulator.cpp
  • tests/macosSse4aTests.cpp
💤 Files with no reviewable changes (2)
  • src/loader/guestInstructionPatcher.cpp
  • tests/macosSse4aTests.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/loader/x64InstructionEmulator.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

macOS now uses the shared guest-instruction patching and module registry implementations. The runtime linker reads the AMD emulation setting on macOS. Apple instruction dispatch now attempts reciprocal-square-root and MONITORX/MWAITX emulation. The macOS SSE4a test target includes the patcher and Xbyak. New tests cover VRSQRTPS, MWAITX, and EXTRQ and INSERTQ patching.

Priority: ➖ Normal

Change: Feature

Merge Risk: ⚪ Minimal · up to e2afc

This change enables the AMD guest-instruction patcher on macOS and adds emulation paths for trapped instructions. No actionable merge-blocking risk was identified in the supplied context. In-game validation was reported as pending by the author.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 6218c

The change remains optional and disabled by default, and it reuses existing execution permissions rather than adding privileges. No introduced security vulnerability was established, but reliable code publication and interrupted or concurrent lifecycle behavior remain incompletely validated.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Guest instruction bytes and exception-frame metadata newly reach the shared patching path on macOS when AMD compatibility is enabled. A patching defect could affect the emulator process and its loaded program mappings; no separate tenant, remote service, or additional privilege scope was established.

Trust Boundaries and Controls

  • observed — The existing configuration gates macOS rewriting. Patching requires a registered module and function starts; loader load/unload operations use a loader mutex, and code mutation uses a per-module mutex. These controls do not independently establish safety for concurrent direct API calls or execution during unload.

Resilience and Maintainability Implications

  • observed — The patcher requests cache publication for rewritten segments and generated trampolines, but macOS selects a POSIX implementation that simply returns success. Whether additional publication is necessary for this x86-64/Rosetta path remains unresolved; a stale-code failure was not demonstrated.

Hardening Proposals

  • proposed — Make the patcher's ownership and publication contract explicit: identify the serialized owner of registry operations, require execution quiescence before releasing patched mappings, and establish the applicable Rosetta code-publication guarantee. These are assurance proposals, not verified vulnerabilities.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.79% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: enabling the AMD guest-instruction patcher on macOS.
Description check ✅ Passed The description explains the macOS patcher changes, motivation, tests, and known limitations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-03 17:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1014#issuecomment-5971920567) · edited 2026-10-06 17:54 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1014?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `c7511823-cb51-4d2d-af21-16bed2a3275d` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 91e2f2b7ec2922ee1994bed59ee159af7659f712 and e2afc57499f461188aebcdd035341895aa87d1e1. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/loader/guestInstructionPatcher.cpp` * `src/loader/x64InstructionEmulator.cpp` * `tests/macosSse4aTests.cpp` </details> <details> <summary>💤 Files with no reviewable changes (2)</summary> * src/loader/guestInstructionPatcher.cpp * tests/macosSse4aTests.cpp </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary> * src/loader/x64InstructionEmulator.cpp </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough macOS now uses the shared guest-instruction patching and module registry implementations. The runtime linker reads the AMD emulation setting on macOS. Apple instruction dispatch now attempts reciprocal-square-root and MONITORX/MWAITX emulation. The macOS SSE4a test target includes the patcher and Xbyak. New tests cover VRSQRTPS, MWAITX, and EXTRQ and INSERTQ patching. </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"e2afc57499f461188aebcdd035341895aa87d1e1" --> **Change:** Feature <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `e2afc` <!-- final_review_risk_coverage:{"sourceCommitId":"e2afc57499f461188aebcdd035341895aa87d1e1","coveredCommitId":"e2afc57499f461188aebcdd035341895aa87d1e1","kind":"reviewed"} --> This change enables the AMD guest-instruction patcher on macOS and adds emulation paths for trapped instructions. No actionable merge-blocking risk was identified in the supplied context. In-game validation was reported as pending by the author. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _🔵 Low_ · up to `6218c` The change remains optional and disabled by default, and it reuses existing execution permissions rather than adding privileges. No introduced security vulnerability was established, but reliable code publication and interrupted or concurrent lifecycle behavior remain incompletely validated. **Retained concerns** No architecture-level concerns identified. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — Guest instruction bytes and exception-frame metadata newly reach the shared patching path on macOS when AMD compatibility is enabled. A patching defect could affect the emulator process and its loaded program mappings; no separate tenant, remote service, or additional privilege scope was established. **Trust Boundaries and Controls** - _observed_ — The existing configuration gates macOS rewriting. Patching requires a registered module and function starts; loader load/unload operations use a loader mutex, and code mutation uses a per-module mutex. These controls do not independently establish safety for concurrent direct API calls or execution during unload. **Resilience and Maintainability Implications** - _observed_ — The patcher requests cache publication for rewritten segments and generated trampolines, but macOS selects a POSIX implementation that simply returns success. Whether additional publication is necessary for this x86-64/Rosetta path remains unresolved; a stale-code failure was not demonstrated. **Hardening Proposals** - _proposed_ — Make the patcher's ownership and publication contract explicit: identify the serialized owner of registry operations, require execution quiescence before releasing patched mappings, and establish the applicable Rosetta code-publication guarantee. These are assurance proposals, not verified vulnerabilities. </details> <!-- architecture_review_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 15.79% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 2 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly summarizes the main change: enabling the AMD guest-instruction patcher on macOS. | | Description check | ✅ Passed | The description explains the macOS patcher changes, motivation, tests, and known limitations. | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1014)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠wuboo on GitHub · 2026-10-06 06:19 UTC · original

I rebased this branch on current main and pushed a follow-up commit:

loader: emulate the patcher's VRSQRTPS trap and MWAITX on macOS

With the AMD CPU patcher enabled on macOS, a VRSQRTPS that the patcher cannot relocate is marked as a trap
by clearing a reserved VEX.vvvv bit. That raises #UD on every host, Rosetta included. On macOS
TryEmulateReciprocalSquareRoot and TryEmulateMonitorxMwaitx were still under #if !defined(__APPLE__), so the
first such site ended in an unhandled SIGILL when running with --amd-cpu.

Both emulators are plain SSE2/libc, so they are now built on macOS and dispatched from TryEmulate. The Darwin
Context gains ClearUpperYmm so the VEX.128 result zeroes YMM[255:128] when the thread has the AVX state
(uc_mcsize check). macos_sse4a now covers a trapped VRSQRTPS (including +0, negative, +inf inputs and the upper
half of YMM) and MWAITX.

Verification: full ctest (50 tests) matches the main baseline (34 pass, 16 skipped only because the Vulkan loader is
not available in the test run, 0 failures). macos_sse4a fails with "unexpected emulator refusal" when the
emulator change is reverted and passes with it.

**@⁠wuboo** on GitHub · 2026-10-06 06:19 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1014#issuecomment-6010601274) I rebased this branch on current main and pushed a follow-up commit: **loader: emulate the patcher's VRSQRTPS trap and MWAITX on macOS** With the AMD CPU patcher enabled on macOS, a VRSQRTPS that the patcher cannot relocate is marked as a trap by clearing a reserved VEX.vvvv bit. That raises #UD on every host, Rosetta included. On macOS `TryEmulateReciprocalSquareRoot` and `TryEmulateMonitorxMwaitx` were still under `#if !defined(__APPLE__)`, so the first such site ended in an unhandled SIGILL when running with `--amd-cpu`. Both emulators are plain SSE2/libc, so they are now built on macOS and dispatched from `TryEmulate`. The Darwin `Context` gains `ClearUpperYmm` so the VEX.128 result zeroes YMM[255:128] when the thread has the AVX state (`uc_mcsize` check). `macos_sse4a` now covers a trapped VRSQRTPS (including +0, negative, +inf inputs and the upper half of YMM) and MWAITX. Verification: full `ctest` (50 tests) matches the main baseline (34 pass, 16 skipped only because the Vulkan loader is not available in the test run, 0 failures). `macos_sse4a` fails with "unexpected emulator refusal" when the emulator change is reverted and passes with it.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 06:34 UTC · original · reviewed

🧹 Nitpick comments (1)
tests/macosSse4aTests.cpp (1)

256-277: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Exercise VRSQRTPS through the macOS patcher.

TestTrappedReciprocalSquareRoot maps an already trap-marked instruction directly, so it tests emulation but not patcher discovery or trap marking. The patcher integration tests cover EXTRQ and INSERTQ, not VRSQRTPS. Add a case that sends the ordinary VEX.128 encoding through the patcher and checks the emulation path. Without it, the macos_sse4a tests provide no regression coverage for the Apple patcher’s VRSQRTPS path.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 65948759-ad27-4711-9b03-9591e84925ea
📥 Commits

Reviewing files that changed from the base of the PR and between 6218c9064ed46aad1fbc9aa0c1048a87069d4b2e and b452d04e4b.

📒 Files selected for processing (4)
  • src/loader/guestInstructionPatcher.cpp
  • src/loader/runtimeLinker.cpp
  • src/loader/x64InstructionEmulator.cpp
  • tests/macosSse4aTests.cpp
💤 Files with no reviewable changes (2)
  • src/loader/runtimeLinker.cpp
  • src/loader/guestInstructionPatcher.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-06 06:34 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1014#pullrequestreview-5424640924) · **reviewed** <details> <summary>🧹 Nitpick comments (1)</summary><blockquote> <details> <summary>tests/macosSse4aTests.cpp (1)</summary><blockquote> `256-277`: **📐 Maintainability & Code Quality** | **🔵 Trivial** | **⚡ Quick win** **Exercise VRSQRTPS through the macOS patcher.** `TestTrappedReciprocalSquareRoot` maps an already trap-marked instruction directly, so it tests emulation but not patcher discovery or trap marking. The patcher integration tests cover EXTRQ and INSERTQ, not VRSQRTPS. Add a case that sends the ordinary VEX.128 encoding through the patcher and checks the emulation path. Without it, the `macos_sse4a` tests provide no regression coverage for the Apple patcher’s VRSQRTPS path. <!-- cr-comment:v1:41603297120c52f6e585718d --> </blockquote></details> </blockquote></details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `65948759-ad27-4711-9b03-9591e84925ea` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 6218c9064ed46aad1fbc9aa0c1048a87069d4b2e and b452d04e4b8a272980ce5805705f0d1af724f6ed. </details> <details> <summary>📒 Files selected for processing (4)</summary> * `src/loader/guestInstructionPatcher.cpp` * `src/loader/runtimeLinker.cpp` * `src/loader/x64InstructionEmulator.cpp` * `tests/macosSse4aTests.cpp` </details> <details> <summary>💤 Files with no reviewable changes (2)</summary> * src/loader/runtimeLinker.cpp * src/loader/guestInstructionPatcher.cpp </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=51c0da0e-7ad9-4115-8630-583862eef0b8 attempt=221799e7-4590-446e-add3-4d5da88d53d3 batch=1/1 -->
Author
Owner

@⁠wuboo on GitHub · 2026-10-06 08:04 UTC · original

Good catch. The old VRSQRTPS case started from an instruction that was already marked as a trap, so it never went through the patcher. 91e2f2b7 adds cases that feed the ordinary VEX.128 encoding (c5 f8 52 c8) to PatchGuestInstructions and compare the result with the emulated reference, in both ways the patcher can handle it: a native trampoline (no SIGILL), and, when the instruction cannot be relocated, the in-place trap mark (c5 f8 -> c5 f0) plus the signal emulator. Disabling the trap mark makes the test fail.

**@⁠wuboo** on GitHub · 2026-10-06 08:04 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1014#issuecomment-6012058243) Good catch. The old `VRSQRTPS` case started from an instruction that was already marked as a trap, so it never went through the patcher. 91e2f2b7 adds cases that feed the ordinary VEX.128 encoding (`c5 f8 52 c8`) to `PatchGuestInstructions` and compare the result with the emulated reference, in both ways the patcher can handle it: a native trampoline (no SIGILL), and, when the instruction cannot be relocated, the in-place trap mark (`c5 f8` -> `c5 f0`) plus the signal emulator. Disabling the trap mark makes the test fail.
This discussion has been locked. Commenting is limited to contributors.
No description provided.