feat(libc): export the std::__sce_v2 _Xtime_diff_to_millis2 helper #15490
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15490"
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 Danigamer05 on 2026-11-03T15:18:26Z.
What
Export the versioned
std::__sce_v2::_Xtime_diff_to_millis2from libc._ZNSt8__sce_v222_Xtime_diff_to_millis2EPK8timespecS2_qlkHBOfGcpQ0xC9A60The behavior comes from the
libc.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6).It returns the milliseconds from
nowuntiltarget, rounded up, or 0 whentargetis not later. As in the module:nowis subtracted as given, without normalizing it, borrowing one second when the target's nanoseconds are smaller;seconds * 1000 + (nanoseconds + 999999) / 1000000, with the module's 64-bit wraparound when a field is out of range.It sits in
TimeExtras.cppbeside_Xtime_diff_to_ts, and reuses the existingXtimelayout, which matchestimespec.Tested
Windows x86-64, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, main4f41f4c375f. Exact tested commit:a17174c0c35.Built libc, libkernel, their NID-patched production libraries and the related tests. The new
guest_sce_v2_xtime_diff_to_millis,guest_time_extras,public_headers,guest_math_exactandguest_dinkumware_float_bitspass, along with the otherguest_sce_v2_*CTests.The new test checks 26 pairs: whole and partial seconds, rounding up from one nanosecond and half a millisecond, borrowing a second, equal and past targets, negative, huge and lowest target nanoseconds, nanoseconds of exactly one and two seconds, unnormalized and negative
nownanoseconds, and wrapping seconds and milliseconds. It also checks that neither argument changes. Every expected value was taken from the original module, not from this implementation.The original function was loaded from the bundled module with its relocations applied. Its imports were bound by NID to this branch's libc and libkernel, with
__stack_chk_guardpointing at a local value. The function calls none of them.Side by side with the patched production library, the result, both arguments,
errno, MXCSR and the x87 control and status words agree in all 10,000,000 calls over two seeds. The inputs mixed edge values (0, ±1, 999,999, 10^6, 10^9 ± 1, 2·10^9 - 1, ±2·10^9,INT64_MIN,INT64_MAXand neighbors), random 64-bit fields, nearby seconds and realistic clock values.Negative control: four lines were altered one at a time:
The new CTest failed on each, and the side-by-side run reported differences each time. Two earlier alterations turned out to be equivalent: they never change the result. They were replaced, and a test row was added for the first alteration, which only a large negative nanosecond count exposes. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and the test and side-by-side run passed again.
Code conventions and
git diff --checkpass.tools/pr_overlap.pyread 1,717 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 36 branches that already conflict with main. None of them adds a line naming this export. Merging each of the 36 with this branch and with main usinggit merge-treegives the same conflict blocks. The branch also merges cleanly with #15336, #15471 and #15484.Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, harness or log is committed or uploaded.
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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-03T15:36:00Z.
Review: COMMENTED
Reviewed — no blocking findings; checks pending
I reviewed all five changed files at head
a17174c0c3593e0a7f7131889db441658c1e5977and found no substantiated blocking defect; hosted Windows and macOS jobs are not complete, so this is a COMMENTED result rather than an approval.What I ran
Reviewed head
a17174c0c3593e0a7f7131889db441658c1e5977against base4f41f4c375f5abb487dbd184fbc150f31994d762; the stack preview merges cleanly. Environment: Debian Linux x86_64, Python 3.11.2, GCC 12.2.0, Git 2.39.5. No local C++ build or CTest was run. The Windows CTest and binary differential results in the PR description are author-reported, not runs I performed.Results
Precheck table and raw check output
The precheck deliberately does not configure, build, or compile AnyPS5.git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...a17174c0c3593e0a7f7131889db441658c1e5977/usr/bin/python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head a17174c0c3593e0a7f7131889db441658c1e5977 --title feat(libc): export the std::__sce_v2 _Xtime_diff_to_millis2 helper --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15490-a17174c0c359/pr-body.md/usr/bin/python3 tools/pr_abi_audit.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 --head a17174c0c3593e0a7f7131889db441658c1e5977 --jsonNo changed Python implementation files.No changed tools/ module has an existing sibling tools/tests/test_<module>.py suite.No changed test_*.py files./usr/bin/python3 /marc/AnyPS5/tools/pr_stack_check.py 15490 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15490-a17174c0c359/stackNot run: C++ tests need exact-head binaries, which require a build; the precheck does not build./usr/bin/python3 /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15490-a17174c0c359/head-a17174c0c359-537f0f72/tools/pr_test_quality.py --root /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15490-a17174c0c359/head-a17174c0c359-537f0f72 --json core/libs/prx/libc/CMakeLists.txt core/libs/prx/libc/include/Api.hpp core/libs/prx/libc/src/TimeExtras.cpp core/libs/tests/GuestSceV2XtimeDiffToMillis.cpp docs/dev/debt/libc.mdNo changed Python test module in tools/ can be run as a no-build base-source control.Direct convention check:
ABI audit entry for the new symbol:
The audit also emitted three warnings outside this new export for
libc___cxa_finalize,longjmp_nid_postfix, andsetjmp_nid_postfix.Negative control
I did not run a mutation locally because the C++ test needs a build. The PR description reports four one-line mutations that made its new CTest fail and a restored-source differential run against the bundled module; I did not independently reproduce those results.
Findings
Blocking
None found in the inspected change.
Non-blocking
Sources
Not verified
I did not run the C++ test, build the library, repeat the reported binary differential, inspect the original private firmware module, or test Linux/macOS runtime or console behavior. The hosted Windows job and queued macOS jobs have not completed.
To get this to a good state
No code change is requested from this review. Let the pending hosted jobs finish; I will re-check their exact-head results and then approve only if they pass and no new issue appears.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T15:36:47Z.
Review: APPROVED
Reviewed — approved
The new libc export
std::__sce_v2::_Xtime_diff_to_millis2(NIDqlkHBOfGcpQ) merges cleanly and builds. Its test passes, and a negative control plus two mutations of my own each make the test fail. The one new failure in the scripted run is an AGC driver timing test this change cannot reach, and it passed on all three of my reruns.What I ran
Head
a17174c0c3593e0a7f7131889db441658c1e5977,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged treec6a2eed48267764ef9f01d6f1d60b02cc899d0c8. Release, GCC 14.2.0, Ninja,BUILD_TESTING=ON, Debian 13 VM (Xeon Gold 6136), lavapipe.Results
git diff --checkcheck_conventions.pylibs(script)guest_sce_v2_xtime_diff_to_millisguest_time_extraspublic_headersagc_driver_same_queue_label_wait_draw_pipeline(script reported it as a new failure)main(9) and theguest_net_ctlskipmain, not counted against this PRAbout the AGC failure: the PR only adds a libc function, a test and a debt entry. Nothing in the AGC test calls the new function. Its output (
attempt N: … bumps with 16 waits) shows a timing-dependent check, and it passed on all three reruns. I treat it as a flake and do not count it against the PR.Rerun output
Negative control
main: withTimeExtras.cppandApi.hpptaken frommain, the test no longer compiles ('_ZNSt8__sce_v222_Xtime_diff_to_millis2EPK8timespecS2__nid_postfix' was not declared in this scope).nanos + 999999tonanos + 999998makes the test fail withone nanosecond rounds up: 0.seconds -= now->secinstead ofseconds += ~now->sec) makes the test fail withborrow from seconds: 1001.c6a2eed4and rebuilt. Both tests pass again, andgit status --porcelainis empty.Findings
Blocking
None.
Non-blocking
None.
I checked the arithmetic by hand and it agrees with the description:
core/libs/prx/libc/src/TimeExtras.cpp:91-96): -1, -10^9, -10^9-1 and -2·10^9 come out as (sec-1, 10^9-1), (sec-1, 0), (sec-2, 10^9-1) and (sec-2, 0).TimeExtras.cpp:97-101): 10^9, 2·10^9-1, 2·10^9 and 3·10^9-1 come out correctly.TimeExtras.cpp:110has a positive divisor, so it cannot overflow.Api.hpp. There are no code comments. The debt entry indocs/dev/debt/libc.mdputs the gap first: console execution and other firmware or SDK versions are unverified. The checklist lines are present.Not verified
libc.prx. I do not have the module, so the 26 expected values and the claimed 10,000,000-call side-by-side agreement are the author's evidence, not mine.