fix(libc): compute powl with FreeBSD msun's ld80 algorithm #18481

Closed
AlfaRojo wants to merge 10 commits from upstream-pr/18481 into main
AlfaRojo commented 2026-11-11 17:50:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlfaRojo on 2026-11-11T17:50:13Z.


What

powl returned the host's std::pow, so its low bits depended on the host math library (WinLibs' powl is off by up to hundreds of ulps on some inputs, e.g. 1.5^100.75 by 30 ulp, 3^-1234.5 by 540 ulp). It now ports FreeBSD release/11.4.0 lib/msun/ld80/e_powl.c (Moshier's powl and powil, lines 135-662): https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/msun/ld80/e_powl.c. The Moshier licence notice is kept. The debt entry in docs/dev/debt/libc.md is split out of the host-computed list and records that console equivalence is unverified, that errno is untouched, and the msun quirk of +inf on odd negative integer overflow.

Tested

  • Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, based on upstream/main f57c971559.

  • guest_math 3/3 runs pass: C99 Annex F special cases (bit-exact), plus 14 regular values (decimal exponents, integer-power path, negative bases, denormal result) whose expected bits come from the port and were cross-checked against mpmath at 300 bits (msun within 0.9 ulp on every normal case).

  • Pinned powl at +-LDBL_MAX (x = +-LDBL_MAX with y = 0.5 and -1, four checks) to msun's results (+inf, +0, +inf, -0), confirmed on the original e_powl.c built with the host gcc; msun treats +-LDBL_MAX as infinite (lines 297 and 321) and the debt entry says so.

  • Port vs the original e_powl.c compiled with the host gcc: 28,000,900 operand pairs including specials, 0 differences.

  • Negative control: with std::pow restored the test fails ("Guest powl failed for 10 -3.5"); host powl here differs from msun on most regular values. On a glibc host it may match more of them; the pinned values are from the algorithm, not the host.

  • tools/check_conventions.py --base upstream/main passes; tools/check_test_registration.py passes.

  • Head d7a8a42294 (merged with upstream/main including #11266's exp2l b975a42ca5): guest_math, guest_math_elementary and guest_math_exact pass in 3/3 runs. Two new pins, powl(-0.5L, 20001.0L) and powl(-2.0L, -20001.0L), both +0 as in the original e_powl.c built with the host gcc; tools/check_conventions.py --base upstream/main passes.

  • tools/pr_overlap.py failed closed (1963 open PRs; 32 not compared because they conflict with main). No open PR implements powl. #11262 (atanl), #11266 (exp2l) and #18110 (logl, log10l, log2l) edit the same docs/dev/debt/libc.md list entry that this PR splits, and #11266 and #18110 also touch the neighbouring lines of Math.cpp, so whichever merges second needs a trivial rebase; none changes powl. #18122 forwards powl_nid_disambig1 to powl_nid_no_patch, which calls powl_nid_postfix, so it composes with this change. I grepped the diffs of every reported PR for powl and powil: the only hits are those entries, the unchanged std::pow line as context in #11266 and #18110, and the #18122 forwards; #6295, #7544 and #11109 (not compared, touch Math.cpp) do not mention them. #5021's diff is too large for gh pr diff; its per-file patches for docs/dev/debt/libc.md and its two math files do not mention powl.

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: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5264219069 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18481). Originally posted by [AlfaRojo](https://github.com/AlfaRojo) on 2026-11-11T17:50:13Z. --- ### What `powl` returned the host's `std::pow`, so its low bits depended on the host math library (WinLibs' `powl` is off by up to hundreds of ulps on some inputs, e.g. 1.5^100.75 by 30 ulp, 3^-1234.5 by 540 ulp). It now ports FreeBSD release/11.4.0 `lib/msun/ld80/e_powl.c` (Moshier's `powl` and `powil`, lines 135-662): https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/msun/ld80/e_powl.c. The Moshier licence notice is kept. The debt entry in `docs/dev/debt/libc.md` is split out of the host-computed list and records that console equivalence is unverified, that errno is untouched, and the msun quirk of +inf on odd negative integer overflow. ### Tested - Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, based on upstream/main f57c971559. - `guest_math` 3/3 runs pass: C99 Annex F special cases (bit-exact), plus 14 regular values (decimal exponents, integer-power path, negative bases, denormal result) whose expected bits come from the port and were cross-checked against mpmath at 300 bits (msun within 0.9 ulp on every normal case). - Pinned `powl` at +-`LDBL_MAX` (x = +-LDBL_MAX with y = 0.5 and -1, four checks) to msun's results (+inf, +0, +inf, -0), confirmed on the original e_powl.c built with the host gcc; msun treats +-`LDBL_MAX` as infinite (lines 297 and 321) and the debt entry says so. - Port vs the original e_powl.c compiled with the host gcc: 28,000,900 operand pairs including specials, 0 differences. - Negative control: with `std::pow` restored the test fails ("Guest powl failed for 10 -3.5"); host `powl` here differs from msun on most regular values. On a glibc host it may match more of them; the pinned values are from the algorithm, not the host. - `tools/check_conventions.py --base upstream/main` passes; `tools/check_test_registration.py` passes. - Head `d7a8a42294` (merged with upstream/main including #11266's `exp2l` `b975a42ca5`): `guest_math`, `guest_math_elementary` and `guest_math_exact` pass in 3/3 runs. Two new pins, `powl(-0.5L, 20001.0L)` and `powl(-2.0L, -20001.0L)`, both +0 as in the original e_powl.c built with the host gcc; `tools/check_conventions.py --base upstream/main` passes. - `tools/pr_overlap.py` failed closed (1963 open PRs; 32 not compared because they conflict with main). No open PR implements `powl`. #11262 (atanl), #11266 (exp2l) and #18110 (logl, log10l, log2l) edit the same `docs/dev/debt/libc.md` list entry that this PR splits, and #11266 and #18110 also touch the neighbouring lines of `Math.cpp`, so whichever merges second needs a trivial rebase; none changes `powl`. #18122 forwards `powl_nid_disambig1` to `powl_nid_no_patch`, which calls `powl_nid_postfix`, so it composes with this change. I grepped the diffs of every reported PR for `powl` and `powil`: the only hits are those entries, the unchanged `std::pow` line as context in #11266 and #18110, and the #18122 forwards; #6295, #7544 and #11109 (not compared, touch `Math.cpp`) do not mention them. #5021's diff is too large for `gh pr diff`; its per-file patches for `docs/dev/debt/libc.md` and its two math files do not mention `powl`. ### 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 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: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-11 18:03:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T18:03:05Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against b57be95210:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_math_tests built cleanly.
  • CTest (guest_math, guest_math_elementary, guest_math_exact):
    1/3 Test  #994: guest_math_elementary ............***Not Run   0.00 sec
    2/3 Test #1067: guest_math_exact .................***Not Run   0.00 sec
    3/3 Test  #993: guest_math .......................   Passed    0.05 sec
    33% tests passed, 2 tests failed out of 3
    
    The following tests FAILED:
    
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5863277997 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18481#pullrequestreview-5863277997). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-11T18:03:05Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `b57be95210`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_math_tests` built cleanly. - **CTest** (`guest_math`, `guest_math_elementary`, `guest_math_exact`): ``` 1/3 Test #994: guest_math_elementary ............***Not Run 0.00 sec 2/3 Test #1067: guest_math_exact .................***Not Run 0.00 sec 3/3 Test #993: guest_math ....................... Passed 0.05 sec 33% tests passed, 2 tests failed out of 3 ``` ``` The following tests FAILED: ``` - Note: the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-11 18:38:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T18:38:58Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against b57be95210:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_math_tests built cleanly.
  • CTest (guest_math, guest_math_elementary, guest_math_exact):
    1/3 Test  #994: guest_math_elementary ............   Passed    0.02 sec
    2/3 Test  #993: guest_math .......................   Passed    0.03 sec
    3/3 Test #1067: guest_math_exact .................   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 3
    
  • Negative control: with core/libs/prx/libc/src/Math.cpp reverted to main and the new tests kept, the suite fails:
    1/3 Test  #994: guest_math_elementary ............   Passed    0.02 sec
    2/3 Test #1067: guest_math_exact .................   Passed    0.06 sec
    3/3 Test  #993: guest_math .......................Subprocess aborted***Exception:   0.42 sec
    67% tests passed, 1 tests failed out of 3
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libc/src/Math.cpp (powl_nid_postfix / PowlExceptionalOperands): Verified special operand handling for NaN, zero bases (0.0L, -0.0L), and zero exponents (y = 0.0L, -0.0L), confirming x^(+-0) = 1.0L even for NaN operands per C99 Annex F.
    • core/libs/prx/libc/src/Math.cpp (PowlBase2Log / PowlExponential): Verified table indexing and bounds for PowlA[33], PowlB[17], PowlLogP, PowlLogQ, and PowlExp2R, confirming all polynomial loops terminate within array bounds and do not exceed table ranges.
    • core/libs/prx/libc/src/Math.cpp (PowlIntegerPower): Verified integer-exponent binary exponentiation (std::fabs(y) < 32768.0L), checking sign propagation and overflow checks against PowlMaxLog and PowlMinLog.
    • core/libs/tests/GuestMath.cpp (CheckLongDoublePower): Verified test suite coverage in GuestMath.cpp, confirming 14 fixed test vectors, special cases, subnormal results (2.0L^-16440.5L), and test function registration in main().
    • docs/dev/debt/libc.md: Verified documentation of technical debt, confirming that splitting powl out of the host-computed list, unverified console equivalence, untouched errno, and positive infinity on odd negative integer overflow are documented.
  • Concerns:
    • core/libs/prx/libc/src/Math.cpp:3971: PowlExceptionalOperands checks x >= std::numeric_limits<long double>::max() using >= against finite LDBL_MAX instead of checking for infinity via std::isinf(x). For input powl_nid_postfix(std::numeric_limits<long double>::max(), 0.5L), x >= max() evaluates to true and the function returns std::numeric_limits<long double>::infinity() instead of the finite normal square root approx 1.090748135619426e+2466L. For input powl_nid_postfix(std::numeric_limits<long double>::max(), -0.5L), it returns 0.0L instead of 1 / sqrt(LDBL_MAX) approx 9.168019e-2467L.
    • core/libs/prx/libc/src/Math.cpp:3977: PowlNonPositiveBase checks x <= -std::numeric_limits<long double>::max() using <= against finite -LDBL_MAX instead of checking for negative infinity via std::isinf(x) && x < 0.0L. For input powl_nid_postfix(-std::numeric_limits<long double>::max(), 0.5L), x <= -max() evaluates to true and intercepts execution before the non-integer exponent check on line 3980, returning std::numeric_limits<long double>::infinity() instead of NaN for a finite negative base raised to a non-integer exponent as required by ISO C99 7.12.7.4 and Annex F.9.4.4. For powl_nid_postfix(-std::numeric_limits<long double>::max(), -1.0L), it returns -0.0L instead of -1.0L / LDBL_MAX.
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5863732898 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18481#pullrequestreview-5863732898). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-11T18:38:58Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `b57be95210`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_math_tests` built cleanly. - **CTest** (`guest_math`, `guest_math_elementary`, `guest_math_exact`): ``` 1/3 Test #994: guest_math_elementary ............ Passed 0.02 sec 2/3 Test #993: guest_math ....................... Passed 0.03 sec 3/3 Test #1067: guest_math_exact ................. Passed 0.01 sec 100% tests passed, 0 tests failed out of 3 ``` - **Negative control**: with `core/libs/prx/libc/src/Math.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/3 Test #994: guest_math_elementary ............ Passed 0.02 sec 2/3 Test #1067: guest_math_exact ................. Passed 0.06 sec 3/3 Test #993: guest_math .......................Subprocess aborted***Exception: 0.42 sec 67% tests passed, 1 tests failed out of 3 ``` Restoring the change makes it pass again. - **Code reading**: - core/libs/prx/libc/src/Math.cpp (powl_nid_postfix / PowlExceptionalOperands): Verified special operand handling for NaN, zero bases (0.0L, -0.0L), and zero exponents (y = 0.0L, -0.0L), confirming x^(+-0) = 1.0L even for NaN operands per C99 Annex F. - core/libs/prx/libc/src/Math.cpp (PowlBase2Log / PowlExponential): Verified table indexing and bounds for PowlA[33], PowlB[17], PowlLogP, PowlLogQ, and PowlExp2R, confirming all polynomial loops terminate within array bounds and do not exceed table ranges. - core/libs/prx/libc/src/Math.cpp (PowlIntegerPower): Verified integer-exponent binary exponentiation (std::fabs(y) < 32768.0L), checking sign propagation and overflow checks against PowlMaxLog and PowlMinLog. - core/libs/tests/GuestMath.cpp (CheckLongDoublePower): Verified test suite coverage in GuestMath.cpp, confirming 14 fixed test vectors, special cases, subnormal results (2.0L^-16440.5L), and test function registration in main(). - docs/dev/debt/libc.md: Verified documentation of technical debt, confirming that splitting powl out of the host-computed list, unverified console equivalence, untouched errno, and positive infinity on odd negative integer overflow are documented. - **Concerns**: - core/libs/prx/libc/src/Math.cpp:3971: PowlExceptionalOperands checks `x >= std::numeric_limits<long double>::max()` using `>=` against finite LDBL_MAX instead of checking for infinity via `std::isinf(x)`. For input `powl_nid_postfix(std::numeric_limits<long double>::max(), 0.5L)`, `x >= max()` evaluates to true and the function returns `std::numeric_limits<long double>::infinity()` instead of the finite normal square root approx 1.090748135619426e+2466L. For input `powl_nid_postfix(std::numeric_limits<long double>::max(), -0.5L)`, it returns `0.0L` instead of 1 / sqrt(LDBL_MAX) approx 9.168019e-2467L. - core/libs/prx/libc/src/Math.cpp:3977: PowlNonPositiveBase checks `x <= -std::numeric_limits<long double>::max()` using `<=` against finite -LDBL_MAX instead of checking for negative infinity via `std::isinf(x) && x < 0.0L`. For input `powl_nid_postfix(-std::numeric_limits<long double>::max(), 0.5L)`, `x <= -max()` evaluates to true and intercepts execution before the non-integer exponent check on line 3980, returning `std::numeric_limits<long double>::infinity()` instead of `NaN` for a finite negative base raised to a non-integer exponent as required by ISO C99 7.12.7.4 and Annex F.9.4.4. For `powl_nid_postfix(-std::numeric_limits<long double>::max(), -1.0L)`, it returns `-0.0L` instead of -1.0L / LDBL_MAX. - Note: the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-12 06:08:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T06:08:16Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against e80966de1d:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_math_tests built cleanly.
  • CTest (guest_math, guest_math_elementary, guest_math_exact):
    1/3 Test #1067: guest_math_exact .................   Passed    0.01 sec
    2/3 Test  #994: guest_math_elementary ............   Passed    0.01 sec
    3/3 Test  #993: guest_math .......................   Passed    0.03 sec
    100% tests passed, 0 tests failed out of 3
    
  • Negative control: with core/libs/prx/libc/src/Math.cpp reverted to main and the new tests kept, the suite fails:
    1/3 Test #1067: guest_math_exact .................   Passed    0.02 sec
    2/3 Test  #994: guest_math_elementary ............   Passed    0.02 sec
    3/3 Test  #993: guest_math .......................Subprocess aborted***Exception:   0.37 sec
    67% tests passed, 1 tests failed out of 3
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libc/src/Math.cpp: PowlMsun and PowlExceptionalOperands accurately handle C99 Annex F exceptional operand pairs, including powl(x, ±0.0L) == 1.0L, powl(1.0L, y) == 1.0L, powl(-1.0L, ±inf) == 1.0L, and quiet NaN propagation.
    • core/libs/prx/libc/src/Math.cpp: PowlNonPositiveBase and PowlHugeExponent properly enforce FreeBSD msun's ld80 handling for ±LDBL_MAX boundaries, negative zero bases with odd/even integer exponents, and non-integer exponents on negative bases yielding NaN.
    • core/libs/prx/libc/src/Math.cpp: Verified array indexing and bounds for PowlLogP (degree 3, size 4), PowlLogQ (degree 3, size 3), PowlExp2R (degree 6, size 7), PowlA (size 33, index 32 * i - e in [0, 32]), and PowlB (size 17, index i / 2 in [0, 16]).
    • core/libs/prx/libc/src/Math.cpp: PowlIntegerPower correctly executes binary exponentiation for integral exponents (|y| < 32768), preserving odd/even parity and reciprocal scaling without integer negation overflow.
    • core/libs/prx/libc/src/Math.cpp: Validated x87 80-bit extended precision assumptions on LP64 and LLP64 platforms; volatile definitions for PowlHuge prevent undesirable compiler folding while preserving subnormal scaling.
    • docs/dev/debt/libc.md and core/libs/tests/GuestMath.cpp: Debt entry conforms to AGENTS.md requirements, and CheckLongDoublePower is correctly registered in main() with comprehensive coverage spanning Annex F special cases, subnormals, and bit-exact outputs.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5869880278 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18481#pullrequestreview-5869880278). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-12T06:08:16Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `e80966de1d`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_math_tests` built cleanly. - **CTest** (`guest_math`, `guest_math_elementary`, `guest_math_exact`): ``` 1/3 Test #1067: guest_math_exact ................. Passed 0.01 sec 2/3 Test #994: guest_math_elementary ............ Passed 0.01 sec 3/3 Test #993: guest_math ....................... Passed 0.03 sec 100% tests passed, 0 tests failed out of 3 ``` - **Negative control**: with `core/libs/prx/libc/src/Math.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/3 Test #1067: guest_math_exact ................. Passed 0.02 sec 2/3 Test #994: guest_math_elementary ............ Passed 0.02 sec 3/3 Test #993: guest_math .......................Subprocess aborted***Exception: 0.37 sec 67% tests passed, 1 tests failed out of 3 ``` Restoring the change makes it pass again. - **Code reading**: - core/libs/prx/libc/src/Math.cpp: PowlMsun and PowlExceptionalOperands accurately handle C99 Annex F exceptional operand pairs, including powl(x, ±0.0L) == 1.0L, powl(1.0L, y) == 1.0L, powl(-1.0L, ±inf) == 1.0L, and quiet NaN propagation. - core/libs/prx/libc/src/Math.cpp: PowlNonPositiveBase and PowlHugeExponent properly enforce FreeBSD msun's ld80 handling for ±LDBL_MAX boundaries, negative zero bases with odd/even integer exponents, and non-integer exponents on negative bases yielding NaN. - core/libs/prx/libc/src/Math.cpp: Verified array indexing and bounds for PowlLogP (degree 3, size 4), PowlLogQ (degree 3, size 3), PowlExp2R (degree 6, size 7), PowlA (size 33, index 32 * i - e in [0, 32]), and PowlB (size 17, index i / 2 in [0, 16]). - core/libs/prx/libc/src/Math.cpp: PowlIntegerPower correctly executes binary exponentiation for integral exponents (|y| < 32768), preserving odd/even parity and reciprocal scaling without integer negation overflow. - core/libs/prx/libc/src/Math.cpp: Validated x87 80-bit extended precision assumptions on LP64 and LLP64 platforms; volatile definitions for PowlHuge prevent undesirable compiler folding while preserving subnormal scaling. - docs/dev/debt/libc.md and core/libs/tests/GuestMath.cpp: Debt entry conforms to AGENTS.md requirements, and CheckLongDoublePower is correctly registered in main() with comprehensive coverage spanning Annex F special cases, subnormals, and bit-exact outputs. - Note: the AI-assisted checkbox can stay. Looks Good To Me
MarcZX10 commented 2026-11-12 14:27:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T14:27:33Z.

Review: COMMENTED


Reviewed the powl port — no blocking findings

The diff ports FreeBSD msun's ld80 powl into libc, and the code I read shows no concrete blocking defect; nothing was built or run in this review.

What I ran

  • Head SHA: e80966de1d28ad1afd34bb5940bdd94be28aa49e
  • Read description.md, commits.md, manifest.json, files.json and diff.patch from the run folder.
  • Read the house-rule sections "Readable reviews", "Accuracy and evidence" and "Standard PR response format" from the ruling file.
  • Reader lookups (search): powil, ExtendedBits(, powl_nid_postfix, comment in CONVENTIONS.md.
  • No build, no test run, no gh write.

Results

Check Result Note
Diff read, 3 of 3 files passed Read through diff.patch
Full file text read not run No files/ text was read
Build and GuestMath run not run Not built here
check_conventions.py / check_test_registration.py not run Author-reported only

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libc/src/Math.cpp:3997 (diff line 163): on underflow with a negative base and an odd integer exponent, PowlIntegerPower returns +0. C99 Annex F requires -0 there, e.g. pow(-0.5, 20001). The debt entry (docs/dev/debt/libc.md:88) records only the overflow sign quirk, not this one. Read from the code; not executed.
  • docs/dev/debt/libc.md:88 (diff line 405): the sentence "Whether Sony wraps powl as acosl is wrapped is unmeasured" is garbled and should read something like "Whether Sony wraps powl the way it wraps acosl is unmeasured".
  • core/libs/prx/libc/src/Math.cpp:3851 (diff line 17): the "Adapted from" line is an extra code comment. The Moshier licence notice must stay, but the PR checklist says "no comments in code except technical debt", so this line needs a decision.
  • core/libs/prx/libc/src/Math.cpp:3975 (diff line 141) and docs/dev/debt/libc.md:88: the text says the port follows powl and powil, but no powil symbol exists in the diff. The integer path is PowlIntegerPower, inside powl. The wording should say so.

Not verified

  • Bit-exact equivalence with the original e_powl.c (28,000,900 pairs), the mpmath cross-check, and the negative control: author-reported, not reproduced.
  • The CheckLongDoublePower expected values come from the port itself. They pin current behaviour; they do not prove it matches msun or the console.
  • Whether the test passes on the stated Windows/WinLibs toolchain, and whether the file compiles on other hosts.
  • Console behaviour of powl (libc.prx): unmeasured, as the debt entry says.
  • The full text of core/libs/prx/libc/src/Math.cpp, core/libs/tests/GuestMath.cpp and docs/dev/debt/libc.md was not read; only the changed hunks and targeted reader lookups were.

To get this to a good state

  • Fix the garbled sentence at docs/dev/debt/libc.md:88.
  • Either document the underflow sign difference next to the overflow one, or fix PowlIntegerPower to return -0 for an odd negative base.
  • Drop the "Adapted from" comment, or record it as an accepted exception to the no-comments rule.
  • Correct the powil wording, or add a powil function if it is meant to be a separate entry point.
  • Rerun the GuestMath test on the new head and attach the output.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5876121223 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18481#pullrequestreview-5876121223). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-12T14:27:33Z. **Review:** COMMENTED --- # Reviewed the powl port — no blocking findings The diff ports FreeBSD msun's ld80 `powl` into libc, and the code I read shows no concrete blocking defect; nothing was built or run in this review. ## What I ran - Head SHA: `e80966de1d28ad1afd34bb5940bdd94be28aa49e` - Read `description.md`, `commits.md`, `manifest.json`, `files.json` and `diff.patch` from the run folder. - Read the house-rule sections "Readable reviews", "Accuracy and evidence" and "Standard PR response format" from the ruling file. - Reader lookups (`search`): `powil`, `ExtendedBits(`, `powl_nid_postfix`, `comment` in `CONVENTIONS.md`. - No build, no test run, no `gh` write. ## Results | Check | Result | Note | | --- | --- | --- | | Diff read, 3 of 3 files | passed | Read through `diff.patch` | | Full file text read | not run | No `files/` text was read | | Build and `GuestMath` run | not run | Not built here | | `check_conventions.py` / `check_test_registration.py` | not run | Author-reported only | ## Findings ### Blocking None. ### Non-blocking - `core/libs/prx/libc/src/Math.cpp:3997` (diff line 163): on underflow with a negative base and an odd integer exponent, `PowlIntegerPower` returns `+0`. C99 Annex F requires `-0` there, e.g. `pow(-0.5, 20001)`. The debt entry (`docs/dev/debt/libc.md:88`) records only the overflow sign quirk, not this one. Read from the code; not executed. - `docs/dev/debt/libc.md:88` (diff line 405): the sentence "Whether Sony wraps `powl` as `acosl` is wrapped is unmeasured" is garbled and should read something like "Whether Sony wraps `powl` the way it wraps `acosl` is unmeasured". - `core/libs/prx/libc/src/Math.cpp:3851` (diff line 17): the "Adapted from" line is an extra code comment. The Moshier licence notice must stay, but the PR checklist says "no comments in code except technical debt", so this line needs a decision. - `core/libs/prx/libc/src/Math.cpp:3975` (diff line 141) and `docs/dev/debt/libc.md:88`: the text says the port follows `powl` and `powil`, but no `powil` symbol exists in the diff. The integer path is `PowlIntegerPower`, inside `powl`. The wording should say so. ## Not verified - Bit-exact equivalence with the original `e_powl.c` (28,000,900 pairs), the mpmath cross-check, and the negative control: author-reported, not reproduced. - The `CheckLongDoublePower` expected values come from the port itself. They pin current behaviour; they do not prove it matches msun or the console. - Whether the test passes on the stated Windows/WinLibs toolchain, and whether the file compiles on other hosts. - Console behaviour of `powl` (`libc.prx`): unmeasured, as the debt entry says. - The full text of `core/libs/prx/libc/src/Math.cpp`, `core/libs/tests/GuestMath.cpp` and `docs/dev/debt/libc.md` was not read; only the changed hunks and targeted reader lookups were. ## To get this to a good state - Fix the garbled sentence at `docs/dev/debt/libc.md:88`. - Either document the underflow sign difference next to the overflow one, or fix `PowlIntegerPower` to return `-0` for an odd negative base. - Drop the "Adapted from" comment, or record it as an accepted exception to the no-comments rule. - Correct the `powil` wording, or add a `powil` function if it is meant to be a separate entry point. - Rerun the `GuestMath` test on the new head and attach the output.

Pull request closed

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!18481
No description provided.