libc: single-precision libm on Windows vs titles' libc.prx, last-bit survey #9707

Open
opened 2026-10-22 09:27:46 +00:00 by JJenkx · 0 comments
JJenkx commented 2026-10-22 09:27:46 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T09:27:46Z.


Where the single-precision libm functions of this libc's Windows build stand against the libc.prx that titles ship, measured by running those copies natively. Posted as a map for whoever ports the next function (as #9668 does for acosf), not as a request.

Method. I loaded the decrypted libc.prx of PPSA07923 (no FMA in its math code) and PPSA13934 (an FMA-contracted build) into a scratch harness. It maps the ELF, applies its relocations and supplies __error. Each function's export was called next to <name>_nid_postfix from this libc's Windows build (main-based, WinLibs GCC 15.2.0 r7 UCRT, Release) on the same 20,000,000 inputs. Half were random bit patterns; half were random significands with exponents from 2^-15 to 2^16. I compared the result bits. NaN-only differences (both NaN, different bits) are left out.

Function Inputs that differ, PPSA07923 PPSA13934
sinf 17,324 17,324
cosf 17,895 17,895
tanf 1,642,294 1,642,294
asinf 112,951 113,984
acosf 118,842 118,945
atanf 135,693 135,693
sinhf 0 4,057
coshf 500,554 500,614
tanhf 1,459,269 1,458,960
asinhf 1,871,981 1,870,953
acoshf 216,017 216,024
atanhf 0 7,013
expf 400,433 400,499
exp2f 3,144,791 3,144,791
expm1f 2,257,079 2,257,069
logf 181,633 179,474
log2f 133,376 133,338
log10f 182,718 181,861
log1pf 1,418,660 1,417,529
sqrtf 0 0
cbrtf 6,032,304 6,032,304
erff 6,225,202 6,218,754
erfcf 778,561 777,906
tgammaf 895,517 895,517
floorf 0 0
ceilf 0 0
roundf 0 0
truncf 0 0
rintf 0 0
  • Identical: sqrtf and the rounding functions on both copies, and sinhf and atanhf on the non-FMA copy. Those follow the console's msun code here already.
  • Off by 1 ulp: almost every other difference. Those functions still go to the host's UCRT on Windows.
  • Not 1-ulp: tgammaf's 895,517 are the sign of a zero result. For example, for -4260.884765625 (0xc5852714) the console returns -0.0 and this libc +0.0.
  • The two copies disagree: the FMA-contracted build differs from the non-FMA one in the last bit of sinhf, atanhf, asinf, acosf, logf, erff and others. So for those functions no single implementation can match every title. The exhaustive acosf run is on #9668.

I'm not opening PRs for these: no title is known to depend on the last bit (#5239). Linux was not measured; there these functions call glibc. The harness and full logs are local and available on request.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5976698373 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9707). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T09:27:46Z. --- Where the single-precision libm functions of this libc's Windows build stand against the `libc.prx` that titles ship, measured by running those copies natively. Posted as a map for whoever ports the next function (as #9668 does for `acosf`), not as a request. **Method.** I loaded the decrypted `libc.prx` of PPSA07923 (no FMA in its math code) and PPSA13934 (an FMA-contracted build) into a scratch harness. It maps the ELF, applies its relocations and supplies `__error`. Each function's export was called next to `<name>_nid_postfix` from this libc's Windows build (`main`-based, WinLibs GCC 15.2.0 r7 UCRT, Release) on the same 20,000,000 inputs. Half were random bit patterns; half were random significands with exponents from 2^-15 to 2^16. I compared the result bits. NaN-only differences (both NaN, different bits) are left out. | Function | Inputs that differ, PPSA07923 | PPSA13934 | |---|---|---| | `sinf` | 17,324 | 17,324 | | `cosf` | 17,895 | 17,895 | | `tanf` | 1,642,294 | 1,642,294 | | `asinf` | 112,951 | 113,984 | | `acosf` | 118,842 | 118,945 | | `atanf` | 135,693 | 135,693 | | `sinhf` | 0 | 4,057 | | `coshf` | 500,554 | 500,614 | | `tanhf` | 1,459,269 | 1,458,960 | | `asinhf` | 1,871,981 | 1,870,953 | | `acoshf` | 216,017 | 216,024 | | `atanhf` | 0 | 7,013 | | `expf` | 400,433 | 400,499 | | `exp2f` | 3,144,791 | 3,144,791 | | `expm1f` | 2,257,079 | 2,257,069 | | `logf` | 181,633 | 179,474 | | `log2f` | 133,376 | 133,338 | | `log10f` | 182,718 | 181,861 | | `log1pf` | 1,418,660 | 1,417,529 | | `sqrtf` | 0 | 0 | | `cbrtf` | 6,032,304 | 6,032,304 | | `erff` | 6,225,202 | 6,218,754 | | `erfcf` | 778,561 | 777,906 | | `tgammaf` | 895,517 | 895,517 | | `floorf` | 0 | 0 | | `ceilf` | 0 | 0 | | `roundf` | 0 | 0 | | `truncf` | 0 | 0 | | `rintf` | 0 | 0 | - **Identical:** `sqrtf` and the rounding functions on both copies, and `sinhf` and `atanhf` on the non-FMA copy. Those follow the console's msun code here already. - **Off by 1 ulp:** almost every other difference. Those functions still go to the host's UCRT on Windows. - **Not 1-ulp:** `tgammaf`'s 895,517 are the sign of a zero result. For example, for `-4260.884765625` (`0xc5852714`) the console returns `-0.0` and this libc `+0.0`. - **The two copies disagree:** the FMA-contracted build differs from the non-FMA one in the last bit of `sinhf`, `atanhf`, `asinf`, `acosf`, `logf`, `erff` and others. So for those functions no single implementation can match every title. The exhaustive `acosf` run is on #9668. I'm not opening PRs for these: no title is known to depend on the last bit (#5239). Linux was not measured; there these functions call glibc. The harness and full logs are local and available on request. AI-assisted (Claude Code).
Sign in to join this conversation.
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#9707
No description provided.