refactor: route the libraries' fenv, TSC, cpuid and pause instructions through helpers #15797
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15797"
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 oberonlift on 2026-11-04T16:23:47Z.
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