fix(tests): compare x87 pointer words in guest_floating_point only when both images have ES set #10937

Merged
TechLevelZero merged 5 commits from upstream-pr/10937 into main 2026-11-01 21:16:57 +00:00
TechLevelZero commented 2026-10-25 11:09:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TechLevelZero on 2026-10-25T11:09:09Z.


What

guest_floating_point failed at random on AMD hosts, as #10899 describes. The test compared whole 28-byte fnstenv images. Those include the last x87 instruction pointer, its selector and opcode, and the last operand pointer and its selector (words 3 to 6). AMD CPUs save these only while an unmasked exception is pending (status ES bit; AMD64 Programmer's Manual, FXSAVE). So when the thread is switched out between two images, the restored words come back as zero.

  • A new SameEnvironment compares the control, status and tag words and MXCSR. It compares words 3 to 6 only when both images have ES set.
  • SameEnvironment is used in three checks: feholdexcept saves the full original environment, null feholdexcept preserves the environment, and the check after the worker threads are joined.
  • feholdexcept preserves x87 tags and instruction/data state is now feholdexcept preserves x87 tags. feholdexcept clears ES there (the test checks this), so those pointer words are never guaranteed on AMD.

None of the states this test builds has ES set, so in practice the pointer words are no longer compared. Keeping a pointer check that holds on AMD would need a state with ES set and an unmasked exception pending. That would be a separate change.

Fixes #10899.

Tested

guest_floating_point_tests libc.prx in a loop, idle. main and the branch were built from the same tree (Ubuntu 24.04, GCC 14.2.0, Release):

CPU main branch
AMD EPYC 7281 (Zen 1), Proxmox VM 117 / 300 0 / 300, then 0 / 1500
AMD Ryzen 7 9700X (Zen 5), bare metal, Fedora 44 88 / 300 (87 after the join, 1 in null feholdexcept) 0 / 300, then 0 / 1500
Intel Xeon Gold 6252, VM 0 / 300 0 / 300, then 0 / 1500

Reported on #10899 by others:

  • AMD Ryzen 7 PRO 5850U (Zen 3), bare metal (babyhuey): main 98 / 300, branch 0 / 600. An earlier version that only narrowed the check after the join still failed 2 / 300 there, in CheckHold; this version fixes that.
  • AMD Ryzen 9 7900 (Zen 4), Windows 11 (ycbuzi): 0 / 300 on both.

Negative controls, 30 runs each on the EPYC, all failing at the expected check:

  • x87 rounding flipped before the check after the join;
  • MXCSR FTZ flipped before the check after the join;
  • x87 rounding flipped before the null feholdexcept check;
  • MXCSR rounding corrupted in the image feholdexcept saved.

python3 tools/check_conventions.py --base origin/main passes. python3 tools/pr_overlap.py --branch fix/floating-point-thread-check-fpu-pointers reports no overlap.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: #10899
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5004169713 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10937). Originally posted by [TechLevelZero](https://github.com/TechLevelZero) on 2026-10-25T11:09:09Z. --- ### What `guest_floating_point` failed at random on AMD hosts, as #10899 describes. The test compared whole 28-byte `fnstenv` images. Those include the last x87 instruction pointer, its selector and opcode, and the last operand pointer and its selector (words 3 to 6). AMD CPUs save these only while an unmasked exception is pending (status ES bit; AMD64 Programmer's Manual, FXSAVE). So when the thread is switched out between two images, the restored words come back as zero. - A new `SameEnvironment` compares the control, status and tag words and MXCSR. It compares words 3 to 6 only when both images have ES set. - `SameEnvironment` is used in three checks: `feholdexcept saves the full original environment`, `null feholdexcept preserves the environment`, and the check after the worker threads are joined. - `feholdexcept preserves x87 tags and instruction/data state` is now `feholdexcept preserves x87 tags`. `feholdexcept` clears ES there (the test checks this), so those pointer words are never guaranteed on AMD. None of the states this test builds has ES set, so in practice the pointer words are no longer compared. Keeping a pointer check that holds on AMD would need a state with ES set and an unmasked exception pending. That would be a separate change. Fixes #10899. ### Tested `guest_floating_point_tests libc.prx` in a loop, idle. `main` and the branch were built from the same tree (Ubuntu 24.04, GCC 14.2.0, Release): | CPU | `main` | branch | | --- | --- | --- | | AMD EPYC 7281 (Zen 1), Proxmox VM | 117 / 300 | 0 / 300, then 0 / 1500 | | AMD Ryzen 7 9700X (Zen 5), bare metal, Fedora 44 | 88 / 300 (87 after the join, 1 in `null feholdexcept`) | 0 / 300, then 0 / 1500 | | Intel Xeon Gold 6252, VM | 0 / 300 | 0 / 300, then 0 / 1500 | Reported on #10899 by others: - AMD Ryzen 7 PRO 5850U (Zen 3), bare metal (babyhuey): `main` 98 / 300, branch 0 / 600. An earlier version that only narrowed the check after the join still failed 2 / 300 there, in `CheckHold`; this version fixes that. - AMD Ryzen 9 7900 (Zen 4), Windows 11 (ycbuzi): 0 / 300 on both. Negative controls, 30 runs each on the EPYC, all failing at the expected check: - x87 rounding flipped before the check after the join; - MXCSR FTZ flipped before the check after the join; - x87 rounding flipped before the `null feholdexcept` check; - MXCSR rounding corrupted in the image `feholdexcept` saved. `python3 tools/check_conventions.py --base origin/main` passes. `python3 tools/pr_overlap.py --branch fix/floating-point-thread-check-fpu-pointers` reports no overlap. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: #10899 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-25 11:22:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T11:22:28Z.

Review: APPROVED


Reviewed exact head 8c058aa. The comparison ignores x87 instruction/data pointer fields unless both environments have ES set, while still comparing control/status/tag and MXCSR; the three whole-environment assertions use this helper, and the hold test no longer asserts pointer fields after feholdexcept clears ES. This narrows the test to state the host guarantees. Local conventions and diff checks passed. The reported AMD/Intel repeated runs are author-reported; hosted product jobs are skipped by path policy.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5642904302 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10937#pullrequestreview-5642904302). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T11:22:28Z. **Review:** APPROVED --- Reviewed exact head 8c058aa. The comparison ignores x87 instruction/data pointer fields unless both environments have ES set, while still comparing control/status/tag and MXCSR; the three whole-environment assertions use this helper, and the hold test no longer asserts pointer fields after feholdexcept clears ES. This narrows the test to state the host guarantees. Local conventions and diff checks passed. The reported AMD/Intel repeated runs are author-reported; hosted product jobs are skipped by path policy.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10937
No description provided.