fix(libc): exp2 leaves errno unchanged #3599

Merged
CouchRiv merged 1 commit from upstream-pr/3599 into main 2026-10-12 12:24:16 +00:00
CouchRiv commented 2026-10-11 14:07:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-11T14:07:18Z.


What

exp2(1024.0) sets errno to 34 on main. FreeBSD msun reports math errors through floating-point exceptions only and never sets errno (math.h#L67-L69), so a caller that checks errno after exp2 sees a stale error on main.

exp2 now saves errno before the host call and restores it after; the result and the floating-point flags do not change.

Tested

CachyOS Linux, RTX 4070 Ti (NVIDIA) and Radeon 610M (RADV), lavapipe for CI parity.

  • guest_math: the new exp2_nid_postfix checks fail on main and pass with the change; 1/1 on NVIDIA, RADV and lavapipe.
  • tools/check_conventions.py --base origin/main and git diff --check: clean.
  • Windows and macOS not run.

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 in TechnicalDebt
  • 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

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4819645926 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3599). Originally posted by [CouchRiv](https://github.com/CouchRiv) on 2026-10-11T14:07:18Z. --- ### What `exp2(1024.0)` sets errno to 34 on `main`. FreeBSD msun reports math errors through floating-point exceptions only and never sets errno ([math.h#L67-L69](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/msun/src/math.h#L67-L69)), so a caller that checks errno after `exp2` sees a stale error on `main`. `exp2` now saves errno before the host call and restores it after; the result and the floating-point flags do not change. ### Tested CachyOS Linux, RTX 4070 Ti (NVIDIA) and Radeon 610M (RADV), lavapipe for CI parity. - guest_math: the new `exp2_nid_postfix` checks fail on `main` and pass with the change; 1/1 on NVIDIA, RADV and lavapipe. - `tools/check_conventions.py --base origin/main` and `git diff --check`: clean. - Windows and macOS not run. ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 AI-assisted: yes
blawesom commented 2026-10-11 15:20:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-11T15:20:14Z.


Independent pre-review on Linux (full CI runs only happen on manual trigger, so recording one): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON.

  • Builds; tools/check_conventions.py --base origin/main passes.
  • Full suite: 832/832 passed (all tests including the Vulkan suites on AMD RX 9070 XT / RADV).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6110521932 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3599#issuecomment-6110521932). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-11T15:20:14Z. --- Independent pre-review on **Linux** (full CI runs only happen on manual trigger, so recording one): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`. - Builds; `tools/check_conventions.py --base origin/main` passes. - Full suite: **832/832 passed** (all tests including the Vulkan suites on AMD RX 9070 XT / RADV).
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!3599
No description provided.