Repository navigation
fix(libkernel): start guest threads with the x87 control word 0x037f - #11849
oneandonlydean merged 2 commits into
Conversation
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
8ad5deb to
7393185
Compare
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed the exact head 7393185. The control word is set on the newly created host thread before the guest entry runs, and the change leaves the creator's state untouched. The initial-thread limitation is clearly recorded in the debt entry. I found no correctness issue in this narrow change.
I built guest_kernel_sys_thread_defaults_tests successfully. The direct CTest run stopped at the existing host CPU capability guard (this machine lacks AVX2/FMA); running the exact test executable under qemu-x86_64 -cpu max passed, including the new control-word case. The PR's Windows check also passes. I did not run the full suite independently.
MarcZX10
left a comment
There was a problem hiding this comment.
The current overlap report still lists this PR's changes to docs/dev/debt/libc.md with #10253 and docs/dev/debt/libkernel.md with #11865. It also says it could not compare Thread.cpp against #11865. #11865's current description records the debt-file conflict with this PR, but this PR still says Depends on: none and claims its overlap check found no other author's overlap. Please update the overlap report/checklist to record the agreed landing order for the shared debt entry, and manually compare the Thread.cpp change with #11865 before saying there is no overlap. The source change and test evidence otherwise look sound; this is a contribution-rule/merge-coordination blocker.
|
Follow-up to my overlap review: I compared #11865's current diff directly with this head. Its implementation is in |
|
Windows run at this PR's exact head Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
So on Windows the new check catches a missing AI-assisted: yes (Claude Code). |
7393185 to
4efa6aa
Compare
|
@MarcZX10 Rebased onto
|
MarcZX10
left a comment
There was a problem hiding this comment.
Re-reviewed new exact head 4efa6aae4ddd2230340b03d2fd131eccb1c11ef2. The changes resolve the earlier direct overlap: libc.md is no longer edited, the libkernel debt entry moved away from #11865's edited lines, and merge-tree checks of both current PR heads are clean.
One landing-order/content issue remains. This code changes the precision of newly created guest threads, while the existing asinl debt sentence in libc.md still says Windows guest threads run at 53 bits. The description says that sentence will be narrowed after #10253 lands, but the checklist still says Depends on: none. Please record #10253 as the dependency and, after it lands, update/rebase this PR to narrow the asinl note before merging; otherwise the code and documented behavior disagree.
|
Windows result for head Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release,
AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine. |
4efa6aa to
ac680b0
Compare
|
@MarcZX10 Done in ac680b0, rebased onto |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed exact head ac680b0c0bc37d6ef6fd78bdedfccdfafa076e99 against current main f2f759ae31f2e51f767b8eb83c6c7e7132cab6d8.
The fldcw executes on the newly created host thread before the guest entry starts, setting only that thread's x87 control word; the test also checks the creator retains its previous value. The initial-thread limitation is documented. The updated diff no longer edits libc.md, and the declared dependency on #10253 is explicit; keep that landing order and rebase/recheck if main changes before merge.
Local verification: Release guest_kernel_sys_thread_defaults_tests build succeeded from this exact head; the test passed three runs under QEMU Haswell. Native CTest reaches the repository's host CPU guard because this Xeon lacks AVX2/FMA and related features. Conventions and git diff --check passed, and a merge-tree preview against current main is clean. Hosted Windows, eligibility, conventions, labels, and report checks pass; Linux product and the relinker/register-context/write-watch matrix are skipped for this PR. Author-reported full-suite and Windows runs are described in the PR; I did not independently run the full suite or test on a PS5.
7ed8466 to
cd97f14
Compare
cd97f14 to
57c9f5d
Compare
MarcZX10
left a comment
There was a problem hiding this comment.
Re-checked — changes requested
The reported test demonstrates the x87 control-word reset and that the creator thread retains its own value. The branch is still based on main 3a2b919816, 36 commits behind current main 52c09d567d2fa453494dd720fcf53a98149468e4. The repository checklist requires a current-main base, and the reported whole-suite run is on an earlier head.
What I ran
- Reviewed exact head
57c9f5d2554deb338b1306b38b93d0f7ff129f36against currentmain. - Ran
git merge-tree --write-treeandgit diff --check. - Checked the exact-head thread test report and current hosted checks.
Results
| Check | Result |
|---|---|
| Current-main merge preview | Clean; current main is not in the branch history |
git diff --check |
Passed |
| Focused thread tests | Author reports 67 thread/pthread/fiber tests and three focused runs on the older 3a2b919816 base |
| Whole suite | Reported on an earlier head, not rerun after the rebase |
| Windows | Existing report is on earlier heads; current-head Windows behavior is not reported |
Please refresh onto current main and rerun the focused thread tests on that exact head. I did not build or run the C++ tests locally.
57c9f5d to
8b626e3
Compare
|
@MarcZX10 Rebased onto |
MarcZX10
left a comment
There was a problem hiding this comment.
Re-checked — changes requested
The exact-head report now includes three focused runs, the 67 thread/pthread/fiber tests, and notes that the default-thread test aborts with main's implementation but passes with this change. The branch is based on 1b580f13cf; current main is ba5b5330b3, with updates to the debt files this PR changes. Please merge current main and rerun the focused thread-default test on the resulting exact head. Keep the declared landing order with #10253, #11632 and #11634.
|
@MarcZX10 Merged One change to the order: #10253 was rebased yesterday and its entry no longer sits next to the |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Reviewed exact open head 950ce5a4fc7a0faa02e2f2a36f0f73891e72b53e; I found no blocking issue in the per-thread x87 control-word initialization, test, or dependency declaration.
What I ran
The PR base is 98ddd9c1792bbab016ceed5db267a93d1d61f00a. Its merge preview onto current main a5939f10a85fdbcd3e0fe75e5eea278f4fe3e52a is clean. Local checks ran on Linux (Debian, Python 3.11.2, GCC 12.2.0); I did not configure or build. I inspected the exact diff, CMake registration, prior discussion, and CI. The author reports the focused test passing three times on this exact head under Ubuntu 24.04/WSL2 with GCC 13.3; I did not independently run it.
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 11849
git diff --check 98ddd9c1792bbab016ceed5db267a93d1d61f00a...950ce5a4fc7a0faa02e2f2a36f0f73891e72b53e
git merge-tree --write-tree refs/remotes/upstream/main 950ce5a4fc7a0faa02e2f2a36f0f73891e72b53e
python3 tools/pr_stack_check.py 11849 --repo boykopovar/AnyPS5
python3 tools/pr_test_quality.py --root /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-11849-950ce5a4fc7a/head-950ce5a4fc7a-494f0c81 --json core/libs/tests/GuestKernelSysThreadDefaults.cppResults
| Check | Result |
|---|---|
| Diff check and conventions | Passed locally; hosted conventions passed on this head. |
| Merge preview | Clean against current main. |
| Dependency order | Directly verified as #11632 → #11634 → #11849. The stack helper reported a cycle, but the live PR bodies show #11632 has no dependency and #11634 depends only on #11632; this is a helper false positive. |
| Test registration | The heuristic flagged the new C++ test as possibly unregistered; exact-head core/libs/CMakeLists.txt registers guest_kernel_sys_thread_defaults_tests and the guest_kernel_sys_thread_defaults CTest. |
| Windows CI | Job succeeded and compiled the changed library sources. Its log says no changed guest test sources were selected, so it did not execute the new test. |
| Focused behavior test | Author reports three exact-head passes and that the test aborts against the base implementation; not independently run here. |
| No-build precheck | The convention/diff checks passed. Its isolated checkout lacked the local ABI and test-quality helper scripts, and its dependency helper reported the false cycle above. |
Selected unedited local output
All conventions checks passed.
1af306b7560db22f489bee4a435fe59bf28c15e8
No guest core/libs test sources changed
No guest core/libs test sources changed; the libs build still ran
{
"findings": [
{
"path": "core/libs/tests/GuestKernelSysThreadDefaults.cpp",
"line": 1,
"kind": "possible-unregistered-cpp-test",
"message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage."
}
],
"negative_control_candidates": [],
"limits": [
"Heuristics can miss weak assertions and can flag valid tests; inspect every finding.",
"A test that passes against base is not by itself proof that the PR test is inadequate.",
"Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error."
]
}Negative control
| Assertion | Change to code under test | Did the test fail? |
|---|---|---|
New guest threads start with control word 0x037f, while the creator retains 0x027f. |
Author reports testing against main's Thread.cpp without the fldcw change. |
Yes, author-reported; not independently run. |
Sources
Not verified
I did not build or run tests locally. The hosted Windows job did not execute the new CTest, and hosted Linux was skipped. The Windows focused result in the discussion is from an earlier head; the implementation and test logic are unchanged, but it is not an exact-current-head Windows run. No physical-console behavior was tested.
|
@MarcZX10 The approved head 950ce5a still merges cleanly into current |
What
A guest thread started with whatever x87 control word the host gave it: on Linux the creator's, on Windows
_beginthreadex's default0x027f(53-bit precision). On the console it starts with0x037f, as on FreeBSD 11:cpu_copy_threadclearsPCB_FPUINITDONEandPCB_USERFPUINITDONEfor the new thread, so its first FPU instruction goes throughfpudnaand loadsfpu_initialstate, whose control word is__INITIAL_FPUCW__(0x037F), whatever the creator uses. Newer FreeBSD copies the creator's FPU state instead; thelibc.prxthat titles bundle follows FreeBSD 11's msun.0x037f.RunThreadnow loads0x037fon the new thread before it runs the guest entry. MXCSR is not touched here; #7565 sets the measured0x9fc0.This matters for the long-double math in libc, which runs at the caller's x87 precision as the console's own code does (see #11260, #11632). At 53 bits,
asinl(0.75)returns mantissa0xd91a98ae3406e000instead of0xd91a98ae3406e041, andexp2lresults move far from the 64-bit ones. With this change, created guest threads compute at 64 bits, as on the console, unless the title changes the control word itself.The initial thread is not covered: the relinker's entry stub runs the guest entry on the host's main thread, which keeps the control word the host starts it with (
0x027fon Windows). The entry stub is where #7594 sets MXCSR for that thread, and the control word would go there too.A new libkernel debt entry records that
0x037fcomes from FreeBSD 11 and the fiber default, not from a measurement, and that the initial thread keeps the host's control word. It sits next to thepthread_attrentry, away from the lines other open PRs change.libc's
asinlentry said guest threads start at 53 bits on Windows; it now says that of the initial thread only, trimmed to stay under 1000 characters. #11632 and #11634 add thecbrtlandhypotlentries directly above that line, so this PR declaresDepends on: #11632, #11634and I'll rebase once they land. #12319, which rewrote theacosfline below, has merged, and this branch is rebased onto it.Tested
On Ubuntu 24.04 under WSL2 (GCC 13.3, Release), head 950ce5a, which merges
main98ddd9c into this PR's commit:guest_kernel_sys_thread_defaultsgainsCheckFpuControl. The main thread sets0x027fand creates a thread. The new thread must read0x037f, and the creator's own control word must still be0x027fafter the join. It passes 3 runs, with the otherguest_kernel_sys_thread*,pthreadandfibertests (67,main's newguest_pthread_cancel_inactive_wait_*cases included;agc_driver_optimize_on_fiberskips itself in this build, the other 66 pass); without thefldcwit aborts, because a Linux thread inherits the creator's0x027f.guest_kernel_sys_thread_defaultsat 7393185, where it passes 3 runs and aborts withThread.cppfrom the merge base; maskym ran it at 4efa6aa merged intomain1089f2b, where it passes.python3 tools/check_conventions.py --base origin/mainpasses.python3 tools/pr_overlap.py --branch fix/libkernel-guest-thread-x87-control-wordreports fix(libc): compute cbrtl with FreeBSD msun's ld80 code as the bundled libc.prx does #11632, fix(libc): compute hypotl with FreeBSD msun's ld80 code as the bundled libc.prx does #11634 and feat(libc): implement tgamma, lgamma, and gamma math functions #8417, all indocs/dev/debt/libc.md. The 79 pull requests it could not compare give the samegit merge-treeconflicts with this branch as withmain.Pthread/Posix/Thread.cpp, has merged, and this head contains it.asin/acosentry away from theasinlline, so the two merge cleanly in either order and this PR no longer depends on it.cbrtlandhypotlfrom the host-computed list and add their entries directly above that line, so they conflict with this PR there too. They land first; this PR declaresDepends onboth. With fix(libc): compute hypotl with FreeBSD msun's ld80 code as the bundled libc.prx does #11634's head 72ec427, which contains fix(libc): compute cbrtl with FreeBSD msun's ld80 code as the bundled libc.prx does #11632 andmain98ddd9c, merged into this head, they conflict only on that line, and keeping their entries with this PR'sasinlline leaves this PR's diff unchanged (4 files, +27 −1) and passescheck_conventions.py.acosfline directly belowasinl, has merged.tgammato the host-computed list line aboveasinl. It has had changes requested since October 26, so neither this PR nor fix(libc): compute cbrtl with FreeBSD msun's ld80 code as the bundled libc.prx does #11632 and fix(libc): compute hypotl with FreeBSD msun's ld80 code as the bundled libc.prx does #11634 wait for it.Pthread/src/Thread.cppwith fix(libkernel): keep the signal mask per thread #3986, fix(libkernel): keep a finished Windows thread's stack until it is joined or detached #4563, feat(aot): consolidate native ARM64 compiler, runtime and consumers #5021, fix(threads): run Windows pthread and small fiber stacks in guest VA range #7149, feat(libkernel): process, thread and clock queries on macOS hosts #7804 and fix(agc): defer Windows exceptions during shader preparation #8592, which conflict withmain. fix(libkernel): keep the signal mask per thread #3986 inserts a line right afterRunThread'sRegisterStack(self)and fix(agc): defer Windows exceptions during shader preparation #8592 one right beforeCurrentGuestState().current = self. Thefldcwnow sits between those two calls, and a three-way merge of each PR'sThread.cppwith this branch's gives no conflict; the other four do not touch those lines.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)