feat(libc): implement fabs, trunc and fma #3314

Merged
reyani-dev merged 1 commit from upstream-pr/3314 into main 2026-10-11 07:28:25 +00:00
reyani-dev commented 2026-10-11 07:10:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T07:10:01Z.


What

fabs (388LcMWHRCA), trunc and fma from libSceLibcInternal, redone on current main from the closed #2167. sqrt from that PR has since landed in #3233.

@babyhuey reported on #2167 that PSBox Cloud Gaming (PPSA99810) now stops at fabs on main 52ce9b8a (Linux, catalog build with sce_module/libc.prx unwrapped as #2605 requires):

app.elf: symbol lookup error: app.elf: undefined symbol: 388LcMWHRCA

With fabs, trunc and fma added, PSBox goes on to _umtx_op (#1482).

The three are direct std::fabs, std::trunc and std::fma, all exact operations with no rounding choice. They sit next to sqrt/sqrtf in Math.cpp.

guest_math gains CheckExactOperations:

  • fabs clears the sign of -0 (bit pattern 0) and of a negative NaN.
  • trunc keeps the sign of -0.5 (result -0), keeps 2^52 + 1 and -1e300 exact, and passes infinity and NaN through.
  • fma(0.1, 10, -1) is 2^-54, which a separate multiply and add would round to 0; fma(2^1023, 2, -2^1023) doesn't overflow in the intermediate.

Tested

Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release, full build with BUILD_TESTING=ON, on main 1690db9a:

  • guest_math passes 5/5 (--repeat until-fail:5). Without the change it doesn't link, and with fma replaced by a separate multiply and add it fails.
  • ctest -E "^agc_|video_out": 414/414.
  • tools/import_audit.py on PSBox Cloud Gaming's registry: 388LcMWHRCA (fabs) is no longer absent, and no new absent import appears.
  • check_conventions.py passes, and pr_overlap.py reports no overlap.

The title stop is babyhuey's Linux run on #2167; I don't run the catalog titles.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4817299108 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3314). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T07:10:01Z. --- ### What `fabs` (`388LcMWHRCA`), `trunc` and `fma` from `libSceLibcInternal`, redone on current `main` from the closed #2167. `sqrt` from that PR has since landed in #3233. @babyhuey reported on #2167 that PSBox Cloud Gaming (PPSA99810) now stops at `fabs` on `main` 52ce9b8a (Linux, catalog build with `sce_module/libc.prx` unwrapped as #2605 requires): ``` app.elf: symbol lookup error: app.elf: undefined symbol: 388LcMWHRCA ``` With `fabs`, `trunc` and `fma` added, PSBox goes on to `_umtx_op` (#1482). The three are direct `std::fabs`, `std::trunc` and `std::fma`, all exact operations with no rounding choice. They sit next to `sqrt`/`sqrtf` in `Math.cpp`. `guest_math` gains `CheckExactOperations`: - `fabs` clears the sign of `-0` (bit pattern 0) and of a negative NaN. - `trunc` keeps the sign of `-0.5` (result `-0`), keeps `2^52 + 1` and `-1e300` exact, and passes infinity and NaN through. - `fma(0.1, 10, -1)` is `2^-54`, which a separate multiply and add would round to 0; `fma(2^1023, 2, -2^1023)` doesn't overflow in the intermediate. ### Tested Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release, full build with `BUILD_TESTING=ON`, on `main` `1690db9a`: - `guest_math` passes 5/5 (`--repeat until-fail:5`). Without the change it doesn't link, and with `fma` replaced by a separate multiply and add it fails. - `ctest -E "^agc_|video_out"`: 414/414. - `tools/import_audit.py` on PSBox Cloud Gaming's registry: `388LcMWHRCA` (`fabs`) is no longer absent, and no new absent import appears. - `check_conventions.py` passes, and `pr_overlap.py` reports no overlap. The title stop is babyhuey's Linux run on #2167; I don't run the catalog titles. ### 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 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-11 07:10:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T07:10:21Z.


Progress report (bae9962 → ffeb263)

📈 System libraries: 85.81% (+0.01%, +3 implemented functions)

✅ 3 implemented
Library Name
libc fabs_nid_postfix
libc fma_nid_postfix
libc trunc_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106542606 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3314#issuecomment-6106542606). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T07:10:21Z. --- <!-- progress-report --> ### Progress report (bae9962 → ffeb263) 📈 **System libraries**: 85.81% (+0.01%, +3 implemented functions) <details> <summary>✅ 3 implemented</summary> | Library | Name | | - | - | | libc | `fabs_nid_postfix` | | libc | `fma_nid_postfix` | | libc | `trunc_nid_postfix` | </details>
Mouhand-Kaddo commented 2026-10-11 07:18:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T07:18:36Z.


Additional platform validation of standalone PR head ffeb26365474436638f56e2f3351560c686e7595 (2026-10-11):

Linux: passed — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja; Release, BUILD_TESTING=ON.

1 checks, 0 failures, 0 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run.

Checks: guest_math.

Command after building: ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^guest_math$".

No title/gameplay validation. These results cover the standalone head, not a merge with current main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106605212 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3314#issuecomment-6106605212). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-11T07:18:36Z. --- <!-- anyps5-platform-validation:ffeb26365474436638f56e2f3351560c686e7595 --> Additional platform validation of standalone PR head `ffeb26365474436638f56e2f3351560c686e7595` (2026-10-11): **Linux: passed** — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja; Release, `BUILD_TESTING=ON`. 1 checks, 0 failures, 0 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run. Checks: `guest_math`. Command after building: `ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^guest_math$"`. No title/gameplay validation. These results cover the standalone head, not a merge with current main.
adriadam10 commented 2026-10-11 07:28:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:28:22Z.


Checked on Linux: scoped build + ctest green, guest_math passes, and it fails to link without the change. fabs/trunc/fma are exact IEEE operations and the test pins the edge cases (-0, NaN sign, 2^52+1, fma without intermediate rounding or overflow). No overlap with other open PRs; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106678814 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3314#issuecomment-6106678814). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T07:28:22Z. --- Checked on Linux: scoped build + ctest green, `guest_math` passes, and it fails to link without the change. `fabs`/`trunc`/`fma` are exact IEEE operations and the test pins the edge cases (-0, NaN sign, 2^52+1, fma without intermediate rounding or overflow). No overlap with other open PRs; merging.
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!3314
No description provided.