libc: long double libm against the libc.prx bundled with PPSA10122 (SDK 5.00): bits, flags and errno on Windows #22838

Open
opened 2026-11-18 12:04:16 +00:00 by DerKarussellbremser · 0 comments
DerKarussellbremser commented 2026-11-18 12:04:16 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by DerKarussellbremser on 2026-11-18T12:04:16Z.


Where this libc's long double math stands against the libc.prx a title bundles, measured by running that copy natively on Windows. It is a map in the style of #9707, which did this for the single-precision functions. docs/dev/debt/libc.md says of expl, sinhl, coshl, tanhl, erfl and erfcl that the FreeBSD 11.4.0 source is the only evidence and that they are unverified against a console libc.prx; this is that comparison for one build.

Method

The module is sce_module/libc.prx of PPSA10122 01.101.000 (SDK 5.00), from my own dump. A scratch harness that is not in the repository maps its segments, applies its relocations and supplies __error. Every other import traps, and none was reached.

Each export was called next to the export with the same NID of this libc (core/libs/libs/libc.prx, main e524ed000a, WinLibs GCC 15.2.0 r7 UCRT, Release, Windows 11 10.0.26200) on the same 200,000 arguments per function. Half of the arguments are random 80-bit patterns with a canonical integer bit, half are random significands with exponents from 2^-15 to 2^16. Two-argument functions draw both arguments independently.

Each call starts with the x87 control word set (0x37f for 64-bit precision, 0x27f for 53-bit) and both exception registers cleared. A call is counted once, in the first column that applies: the result bits differ (two NaNs count as equal), else the union of the x87 and MXCSR exception flags differs, else errno differs.

Result

Of 43 functions, 24 agree on every argument at both precisions, in bits, flags and errno: sinl, cosl, tanl, asinl, acosl, atanl, asinhl, acoshl, atanhl, exp2l, logl, log2l, log10l, log1pl, cbrtl, rintl, nearbyintl, logbl, fabsl, atan2l, hypotl, fmaxl, fminl, copysignl.

The others:

Function Bits, 64-bit Flags only errno only Bits, 53-bit Flags only errno only
sinhl 33,329 50,010 61,180 55,890 50,010 61,180
coshl 23,243 8 61,180 48,237 8 61,180
tanhl 20,252 138,950 0 85,775 88,969 0
expl 34,579 28,503 32,681 71,361 28,500 32,681
expm1l 25,651 80,656 30,439 101,238 30,770 30,439
sqrtl 0 100,145 0 0 100,145 0
erfl 62,441 103,912 0 34,853 117,815 0
erfcl 12,230 72,797 41,012 16,325 72,800 41,012
lgammal 59,979 33,144 0 129,213 33,056 0
tgammal 90,445 34,732 0 102,567 34,699 0
ceill 0 2 0 0 2 0
floorl 0 2 0 0 2 0
truncl 0 6 0 0 6 0
roundl 0 49,686 0 21 49,700 0
powl 24,842 75,250 66,205 24,364 75,249 66,205
fmodl 0 10 0 10 7 0
remainderl 0 4 0 0 4 0
fdiml 0 97,898 0 0 100,224 0

nextafterl is exported by the module (0x48920) and not by this libc; #6295 is open for it.

What the differences are

expl, sinhl, coshl, tanhl, expm1l, erfl, erfcl. This libc follows FreeBSD msun 11.4.0 here (#18525, #19342, #19346). The module does not:

  • expl (0x47430) calls _LExp.
  • sinhl (0x504e0) and coshl (0x45ab0) are 11-instruction wrappers around _LSinh and _LCosh.
  • tanhl (0x51660) and expm1l (0x474c0) call expl.
  • erfl (0x46f60) and erfcl (0x47180) call _LExp and _LPoly.

Where the results differ it is in the last bits, for example expl(0x3ffe:cce56ce05f6cdac4): the module returns 0x4000:8e7cf75f6546c30b, this libc ...c30a. Two differences outside the result bits, seen for expl and sinhl:

  • On overflow the module stores ERANGE; this libc leaves errno unchanged.
  • Where expl underflows to +0 the module raises no flag; this libc raises FE_UNDERFLOW and FE_INEXACT. For arguments that sinhl and tanhl return unchanged, and where tanhl saturates to ±1, the module raises no flag and this libc raises FE_INEXACT.

I did not look at which side stores what in the errno column of coshl, expm1l, erfcl and powl.

powl, lgammal, tgammal. These return the host library's results in this libc. In the module powl (0x4c950) is a 12-instruction wrapper around an internal routine at 0x4bf70, which lgammal (0x4b830) also calls, as does the routine at 0x4bcf0 that lgammal and tgammal (0x526f0) share.

I have a rewrite of tgammal and of 0x4bcf0 that gives the module's bits, flags and errno on 400,000 arguments at each of 64-, 53- and 24-bit precision. It still calls the module's own helpers, so it is not a PR yet; the routine at 0x4bf70 has to be written first, and that would cover powl as well. I am working on it.

Flags only.

  • sqrtl of a negative finite argument: both return the default NaN and store EDOM. The module raises FE_INVALID only. This libc raises FE_INEXACT, with FE_OVERFLOW or FE_UNDERFLOW for large or small magnitudes, and not FE_INVALID.
  • roundl of an integral argument such as 0x4c9b:9333ddceb4331e0a: the module raises FE_INEXACT, this libc raises nothing.
  • fdiml returning +0: the module raises FE_INEXACT, this libc raises nothing. I looked at four such cases, not at all of them.

I did not look at the small counts (ceill, floorl, truncl, fmodl, remainderl, and the 21 and 10 result differences of roundl and fmodl at 53 bits).

Not covered

  • One module build. Other SDK versions, the system libSceLibcInternal and a console were not compared.
  • The survey was not run at 24-bit precision or in other rounding modes.
  • Only the Windows build of this libc was run.
  • 200,000 arguments per function do not prove the 24 functions identical.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6466708735 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/22838). Originally posted by [DerKarussellbremser](https://github.com/DerKarussellbremser) on 2026-11-18T12:04:16Z. --- Where this libc's `long double` math stands against the `libc.prx` a title bundles, measured by running that copy natively on Windows. It is a map in the style of #9707, which did this for the single-precision functions. `docs/dev/debt/libc.md` says of `expl`, `sinhl`, `coshl`, `tanhl`, `erfl` and `erfcl` that the FreeBSD 11.4.0 source is the only evidence and that they are unverified against a console `libc.prx`; this is that comparison for one build. ### Method The module is `sce_module/libc.prx` of PPSA10122 01.101.000 (SDK 5.00), from my own dump. A scratch harness that is not in the repository maps its segments, applies its relocations and supplies `__error`. Every other import traps, and none was reached. Each export was called next to the export with the same NID of this libc (`core/libs/libs/libc.prx`, `main` e524ed000a, WinLibs GCC 15.2.0 r7 UCRT, Release, Windows 11 10.0.26200) on the same 200,000 arguments per function. Half of the arguments are random 80-bit patterns with a canonical integer bit, half are random significands with exponents from 2^-15 to 2^16. Two-argument functions draw both arguments independently. Each call starts with the x87 control word set (0x37f for 64-bit precision, 0x27f for 53-bit) and both exception registers cleared. A call is counted once, in the first column that applies: the result bits differ (two NaNs count as equal), else the union of the x87 and MXCSR exception flags differs, else `errno` differs. ### Result Of 43 functions, 24 agree on every argument at both precisions, in bits, flags and `errno`: `sinl`, `cosl`, `tanl`, `asinl`, `acosl`, `atanl`, `asinhl`, `acoshl`, `atanhl`, `exp2l`, `logl`, `log2l`, `log10l`, `log1pl`, `cbrtl`, `rintl`, `nearbyintl`, `logbl`, `fabsl`, `atan2l`, `hypotl`, `fmaxl`, `fminl`, `copysignl`. The others: | Function | Bits, 64-bit | Flags only | `errno` only | Bits, 53-bit | Flags only | `errno` only | |---|---|---|---|---|---|---| | `sinhl` | 33,329 | 50,010 | 61,180 | 55,890 | 50,010 | 61,180 | | `coshl` | 23,243 | 8 | 61,180 | 48,237 | 8 | 61,180 | | `tanhl` | 20,252 | 138,950 | 0 | 85,775 | 88,969 | 0 | | `expl` | 34,579 | 28,503 | 32,681 | 71,361 | 28,500 | 32,681 | | `expm1l` | 25,651 | 80,656 | 30,439 | 101,238 | 30,770 | 30,439 | | `sqrtl` | 0 | 100,145 | 0 | 0 | 100,145 | 0 | | `erfl` | 62,441 | 103,912 | 0 | 34,853 | 117,815 | 0 | | `erfcl` | 12,230 | 72,797 | 41,012 | 16,325 | 72,800 | 41,012 | | `lgammal` | 59,979 | 33,144 | 0 | 129,213 | 33,056 | 0 | | `tgammal` | 90,445 | 34,732 | 0 | 102,567 | 34,699 | 0 | | `ceill` | 0 | 2 | 0 | 0 | 2 | 0 | | `floorl` | 0 | 2 | 0 | 0 | 2 | 0 | | `truncl` | 0 | 6 | 0 | 0 | 6 | 0 | | `roundl` | 0 | 49,686 | 0 | 21 | 49,700 | 0 | | `powl` | 24,842 | 75,250 | 66,205 | 24,364 | 75,249 | 66,205 | | `fmodl` | 0 | 10 | 0 | 10 | 7 | 0 | | `remainderl` | 0 | 4 | 0 | 0 | 4 | 0 | | `fdiml` | 0 | 97,898 | 0 | 0 | 100,224 | 0 | `nextafterl` is exported by the module (0x48920) and not by this libc; #6295 is open for it. ### What the differences are **`expl`, `sinhl`, `coshl`, `tanhl`, `expm1l`, `erfl`, `erfcl`.** This libc follows FreeBSD msun 11.4.0 here (#18525, #19342, #19346). The module does not: - `expl` (0x47430) calls `_LExp`. - `sinhl` (0x504e0) and `coshl` (0x45ab0) are 11-instruction wrappers around `_LSinh` and `_LCosh`. - `tanhl` (0x51660) and `expm1l` (0x474c0) call `expl`. - `erfl` (0x46f60) and `erfcl` (0x47180) call `_LExp` and `_LPoly`. Where the results differ it is in the last bits, for example `expl(0x3ffe:cce56ce05f6cdac4)`: the module returns `0x4000:8e7cf75f6546c30b`, this libc `...c30a`. Two differences outside the result bits, seen for `expl` and `sinhl`: - On overflow the module stores `ERANGE`; this libc leaves `errno` unchanged. - Where `expl` underflows to +0 the module raises no flag; this libc raises `FE_UNDERFLOW` and `FE_INEXACT`. For arguments that `sinhl` and `tanhl` return unchanged, and where `tanhl` saturates to ±1, the module raises no flag and this libc raises `FE_INEXACT`. I did not look at which side stores what in the `errno` column of `coshl`, `expm1l`, `erfcl` and `powl`. **`powl`, `lgammal`, `tgammal`.** These return the host library's results in this libc. In the module `powl` (0x4c950) is a 12-instruction wrapper around an internal routine at 0x4bf70, which `lgammal` (0x4b830) also calls, as does the routine at 0x4bcf0 that `lgammal` and `tgammal` (0x526f0) share. I have a rewrite of `tgammal` and of 0x4bcf0 that gives the module's bits, flags and `errno` on 400,000 arguments at each of 64-, 53- and 24-bit precision. It still calls the module's own helpers, so it is not a PR yet; the routine at 0x4bf70 has to be written first, and that would cover `powl` as well. I am working on it. **Flags only.** - `sqrtl` of a negative finite argument: both return the default NaN and store `EDOM`. The module raises `FE_INVALID` only. This libc raises `FE_INEXACT`, with `FE_OVERFLOW` or `FE_UNDERFLOW` for large or small magnitudes, and not `FE_INVALID`. - `roundl` of an integral argument such as `0x4c9b:9333ddceb4331e0a`: the module raises `FE_INEXACT`, this libc raises nothing. - `fdiml` returning +0: the module raises `FE_INEXACT`, this libc raises nothing. I looked at four such cases, not at all of them. I did not look at the small counts (`ceill`, `floorl`, `truncl`, `fmodl`, `remainderl`, and the 21 and 10 result differences of `roundl` and `fmodl` at 53 bits). ### Not covered - One module build. Other SDK versions, the system `libSceLibcInternal` and a console were not compared. - The survey was not run at 24-bit precision or in other rounding modes. - Only the Windows build of this libc was run. - 200,000 arguments per function do not prove the 24 functions identical. AI-assisted: yes (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#22838
No description provided.