Repository navigation
refactor: route the libraries' fenv, TSC, cpuid and pause instructions through helpers - #15797
oberonlift wants to merge 5 commits into
Conversation
✅ NVIDIA GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (3, not counted against this PR)Validation IDs already present on main (13 IDs in 805 tests)Skipped (53)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
✅ AMD GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (11, not counted against this PR)Validation IDs already present on main (8 IDs in 805 tests)Skipped (62)ReproduceAutomated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
1401634 to
b4102f1
Compare
✅ NVIDIA GPU test: passedPR head
Unstable on main (4, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (3, not counted against this PR)Validation IDs already present on main (9 IDs in 810 tests)Skipped (59)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
✅ AMD GPU test: passedPR head
Unstable on main (2, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (13, not counted against this PR)Validation IDs already present on main (4 IDs in 810 tests)Skipped (68)ReproduceAutomated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
b4102f1 to
8a26976
Compare
8a26976 to
66a4af5
Compare
✅ NVIDIA GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (3, not counted against this PR)Validation IDs already present on main (9 IDs in 806 tests)Skipped (60)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
66a4af5 to
91d532a
Compare
✅ NVIDIA GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (3, not counted against this PR)Passed on retry (3, failed in the parallel run, passed when re-run with a 360 s timeout; not counted against this PR)Validation IDs already present on main (9 IDs in 813 tests)Skipped (61)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
b416b43 to
a719c5d
Compare
The fenv functions read and write the x87 control, status and environment and MXCSR through GuestCpu's inline helpers, which issue the same x87 and SSE instructions, so a build for another host replaces them in one header. feholdexcept keeps the exceptions masked as the fnstenv it replaces did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sceKernelReadTsc and the TSC frequency measurement read the counter through GuestCpu::ReadTsc, which is __rdtsc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Spin loops in the driver yield through PreciseSpinPause, which is now defined on every platform and uses the aarch64 yield hint, and WriteChanged falls back to its byte loop on targets other than x86-64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…able helpers The worker's spin timing reads the counter through GuestCpu::ReadTsc and pauses through PreciseSpinPause. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
webrtc's CPU feature query runs cpuid and xgetbv through new GuestCpu helpers, which issue the same instructions as <cpuid.h>. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a719c5d to
90c2dd1
Compare
Merge first. The ps5lift PRs after it merge in this order: #15798, #15799, #15800, #15801, #15802, #15803, #15804, then #15805, #15806 and #15807.
ps5lift is a static recompiler for PS5 executables: it lifts a game's x86-64 code to LLVM IR and compiles it ahead of time to aarch64, which runs on Linux against AnyPS5's own libraries with no interpreter or JIT. It runs AnyPS5's PS5-style test programs and a homebrew media player to its home screen; commercial games are not playable yet. Branch
ps5lift-previewmerges all of its PRs (how to try it); native Apple Silicon support is coming along fast. It is a separate approach from the ARM64 compiler in #5021; #1835 has an introduction.This is 1 of 8 PRs that let AnyPS5's libraries run a lifted program, and it needs none of the others; the lifter itself follows them.
x86-64: behaviour unchanged: every fenv function leaves the same x87 control word, status flags, saved environment and MXCSR as before. Some take a few more instructions:
fegetenv,feholdexceptandfeupdateenv:feholdexcept, for example, masks the x87 exceptions with an explicitfldcwinstead of relying onfnstenv's side effect._Feraise,feraiseexcept,fesetexceptflagandfeclearexceptof some of the flags read the x87 status with an extrafnstsw.fesetenvcopies the environment to a stack temporary before itsfldenv.webrtc's CPU feature query compiles to the same object.
What
The CPU-specific instructions in the places below go through inline helpers in
GuestCpu.hpp, which are the instructions the code used before. The header supports x86-64 and stops the build elsewhere with an#error; a later PR in this series adds itsANYPS5_GUEST_LIFTEDhalf, whose functions ps5lift's runtime provides.GuestCpu.feholdexceptkeeps the exceptions masked as thefnstenvit replaces did.sceKernelReadTscand the TSC frequency measurement read the counter throughGuestCpu::ReadTsc, which is__rdtscon x86-64.cpuidandxgetbvthroughGuestCpu::CpuidandGuestCpu::Xgetbv, which issue the same instructions as GCC's<cpuid.h>.PreciseSpinPause, now defined on every platform and using the aarch64 yield hint, andWriteChangedfalls back to its byte loop on targets other than x86-64.GuestCpu::ReadTsctoo, so in a lifted build they read the counter the guest reads.#5021 also changes some of the same files:
Time.cpp,WaitMemory.cpp,GuestMemory.cpp.Tested
Compiled for x86-64 Linux before and after this PR (GCC 13, same flags): 170 of the 173 objects it reaches are byte-identical. In
FloatingPoint.cppandMath.cpponly the fenv functions differ, andTexture.cppdiffers only in the generated name of a switch table.Built and run on x86-64 Linux (Intel N100, GCC 15.2, Ubuntu 26.04, in a container) as the Linux CI job builds it, on
mainand on this branch:guest_floating_point,guest_update_env,guest_set_env,guest_raise_except),agc_driver_pm4and its variants, which runWriteChanged,agc_handoff_spin, theguest_process_timeTSC tests,guest_webrtc_cpu_featuresand the JobManager tests.mainfails on this branch. The 54 tests that fail on both need guest write watch or/dev/udmabuf, which the container lacked, or time out there.agc_handoff_spin,agc_driver_pm4, and the finisher-label, pipelined-fill and same-queue-label-wait tests, with and without the draw pipeline) pass on the N100's GPU on both withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1. The layer loaded, and neither log reports aVUID-error. The partially-resident snapshot tests skip there without write watch.On a DGX Spark (aarch64 Linux, NVIDIA GB10, LLVM 18), with all eight PRs and ps5lift on top: every library builds for a lifted program, 2,288 of AnyPS5's own tests pass in that build on lavapipe, and ps5lift's 69 tests pass, among them its libc, exceptions, kernel, fiber and module-loading fixtures and upstream's libc test programs. The same focused AGC tests, and the partially-resident snapshot tests, pass on the GB10 with the validation layer and report no
VUID-errors.The new
GuestCpuhelpers and libwebrtc'sCpuFeatures.cppcompile for Windows with MinGW-w64 GCC (syntax only). The conventions check passes on this branch.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)🤖 Generated with Claude Code