feat(libc): keep the guest's x87 long double exactly in lifted builds #15802
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15802"
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:24:01Z.
Merge after #15801. Until the PRs before it merge, this PR also shows their changes; oberonlift/AnyPS5#12 shows only its own.
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 6 of 8 PRs that let AnyPS5's libraries run a lifted program; the lifter itself follows them.
x86-64: behaviour unchanged. There
GuestLongDoubleislong doubleand its helpers are the standard functions, sostrtoldis stillstd::strtold;ldexplandscalbnlnow callstd::scalblnanddremcallsstd::remquo, which return the same values.What
A lifted libc held the guest's x87
long doublein the host's: IEEE binary128 on aarch64 Linux, which holds every 80-bit value but rounds each step differently, and a plain double on macOS, which holds neither.GuestLongDoubleloads and stores the guest's 80-bit values where libc takes them in and hands them out (formatting, scanning,strtold,modfl,_LDtest), and long doubles that host callers pass through ava_listare rounded to the guest's precision. On an x87 host it only copies.GuestLongDouble, laid out as the guest stores it. Arithmetic, square root, integer rounding and conversions to double, float and integers run through the ps5lift runtime's x87, so they round, honour precision control and raise exceptions as the guest's control and status words say. Comparisons, conversions from integers and doubles,frexp,scalbn,fmod,remainder,remquo,modf,logband the fixed-direction roundings work on the bits; a NaN operand or a domain error infmod,remainderandremquogoes through the x87, so the NaN propagates or invalid is raised as on the guest._LDint,_LDscale,_LDunscale,_LFpcompand_LPolyhelpers takeGuestLongDoubletoo; in lifted builds_LDscaleand_LDunscalescale and split the value on its bits.strtoldandscanf("%Lf")parse with exact big-integer arithmetic, correctly rounded in the guest's rounding mode.long doublewherever it is wider than 80 bits too, such as Emscripten's wasm64 target: therestrtoldis still the host's.cbrtlruns FreeBSD's x87 algorithm, as onmain, onGuestLongDouble, and in lifted buildsremainder,remainderf,remquoandremquoftake their result and quotient bits from its exact remainder instead offprem1.lfunctions andfmalstill compute in the host's widest type and round the result. The libc debt notes say so, and record that lifted builds don't build__mulxc3and__divxc3and that long double scans store the guest's format for host callers too.#5021 also changes some of the same files:
Strings.cpp,WindowsFormatting.hpp.Tested
Compiled for x86-64 Linux before and after this PR (GCC 13, same flags): 137 of the 146 objects it reaches are byte-identical. libSceNet's
Export.cppdiffers only in the generated name of a switch table andStrings.cppin an out-of-line copy of the inlinestrtoldwrapper; the other seven are libc's long double, formatting and scanning sources.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,285 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 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
Pull request closed