feat(libSceFreeTypeOt): export the fixed-point arithmetic helpers #16823

Closed
juanpimg wants to merge 1 commit from upstream-pr/16823 into main
juanpimg commented 2026-11-07 17:03:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by juanpimg on 2026-11-07T17:03:37Z.


What

Adds six libSceFreeTypeOt exports: FT_MulDiv, FT_MulFix, FT_DivFix, FT_RoundFix, FT_CeilFix and FT_FloorFix, following the FreeType 2.4.12 arithmetic in ftcalc.c. The console prototypes and FreeType version equivalence are unverified.

The module links the bundled FreeType, whose own definitions own the plain FT_* names, so the implementations use the library's resolved-name convention: <name>_nid_postfix, which tools/nid_names.py hashes to the inventory NID, with no APS5_EXPORT. The suffix keeps them distinct from the bundled symbols, so there is no interposition and no linker flag.

The three matrix and vector transform names this PR used to carry (FT_Matrix_Multiply, FT_Matrix_Invert, FT_Vector_Transform) are now exported by libSceFreeType (#9419), so they are removed here to keep one provider per NID. The six remaining names overlap with #9410, which implements them in libSceFreeType; this PR is sequenced with Depends on: #9410. If #9410 lands first, this branch will be reduced to APS5_DUMMY_FUN declarations or closed.

Tested

CachyOS Linux, kernel 7.3.1-1-cachyos, GCC 16.2.1, CMake 3.31.6, Ninja 1.12.1, Release build, rebased onto current main (d792f1ad5f).

  • guest_freetype_corner, guest_freetype_ot_constants, guest_freetype_ot_memory, guest_freetype_ot_raccess: 4/4 pass, covering positive, negative, rounding, zero-divisor, overflow and boundary cases for the six functions.
  • The nid_patcher resolves all six names to their inventory NIDs (Q+ysHCIzphI, 774ZHX0Z3Cc, fp-jO+c8Rfk, IdtpBr-PoD0, 92e4jZiW9Tc, EqN+ED6P2FA) in the patched libSceFreeTypeOt.prx; the bundled plain FT_* symbols stay LOCAL.
  • python3 tools/check_conventions.py --base origin/main: passes, with no cross-library duplicate.
  • git diff --check: clean.
  • No title was run: the contributor has no PS5 and no game dumps.

Checklist

  • Based on current main; the only overlap is #9410 (same six arithmetic names in libSceFreeType), sequenced with Depends on: #9410
  • 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: #9410
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5203962589 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16823). Originally posted by [juanpimg](https://github.com/juanpimg) on 2026-11-07T17:03:37Z. --- ### What Adds six `libSceFreeTypeOt` exports: `FT_MulDiv`, `FT_MulFix`, `FT_DivFix`, `FT_RoundFix`, `FT_CeilFix` and `FT_FloorFix`, following the FreeType 2.4.12 arithmetic in `ftcalc.c`. The console prototypes and FreeType version equivalence are unverified. The module links the bundled FreeType, whose own definitions own the plain `FT_*` names, so the implementations use the library's resolved-name convention: `<name>_nid_postfix`, which `tools/nid_names.py` hashes to the inventory NID, with no `APS5_EXPORT`. The suffix keeps them distinct from the bundled symbols, so there is no interposition and no linker flag. The three matrix and vector transform names this PR used to carry (`FT_Matrix_Multiply`, `FT_Matrix_Invert`, `FT_Vector_Transform`) are now exported by `libSceFreeType` (#9419), so they are removed here to keep one provider per NID. The six remaining names overlap with #9410, which implements them in `libSceFreeType`; this PR is sequenced with `Depends on: #9410`. If #9410 lands first, this branch will be reduced to `APS5_DUMMY_FUN` declarations or closed. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> CachyOS Linux, kernel 7.3.1-1-cachyos, GCC 16.2.1, CMake 3.31.6, Ninja 1.12.1, Release build, rebased onto current `main` (`d792f1ad5f`). - `guest_freetype_corner`, `guest_freetype_ot_constants`, `guest_freetype_ot_memory`, `guest_freetype_ot_raccess`: **4/4 pass**, covering positive, negative, rounding, zero-divisor, overflow and boundary cases for the six functions. - The `nid_patcher` resolves all six names to their inventory NIDs (`Q+ysHCIzphI`, `774ZHX0Z3Cc`, `fp-jO+c8Rfk`, `IdtpBr-PoD0`, `92e4jZiW9Tc`, `EqN+ED6P2FA`) in the patched `libSceFreeTypeOt.prx`; the bundled plain `FT_*` symbols stay LOCAL. - `python3 tools/check_conventions.py --base origin/main`: passes, with no cross-library duplicate. - `git diff --check`: clean. - No title was run: the contributor has no PS5 and no game dumps. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; the only overlap is #9410 (same six arithmetic names in `libSceFreeType`), sequenced with `Depends on: #9410` - [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: #9410 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
coptergui-ops commented 2026-11-07 18:56:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coptergui-ops on 2026-11-07T18:56:26Z.

Review: CHANGES_REQUESTED


NID sourcing and arithmetic check out, the naming deviates from the convention this library itself set — please rework before merge.

Verified good:

  • All nine NIDs are in the PS5 3.20 inventory for libSceFreeTypeOt (checked the DNNDHH blob: sprx_dlsym("Q+ysHCIzphI", &__ptr_FT_MulDiv) etc., all nine name↔NID pairs match the PR exactly), and tools/nid_names.py --name FT_MulDiv … computes the same nine NIDs.
  • The math follows the cited FreeType 2.4.12 forms: round helpers (a + 0x8000 - (a<0)) & ~0xFFFF, ceil (a + 0xFFFF) & ~0xFFFF, floor a & ~0xFFFF match ftcalc.c; FT_DivFix(a,b) = MulDiv(a, 0x10000, b); FT_Matrix_Invert is the delta = MulFix cross-product then DivFix chain, null and singular return before writing, which the tests pin; Invalid_Argument = 6 matches the same library's debt entry for the memory exports (Invalid_Argument 0x06).
  • Tests cover the corner behaviours with real controls: exact-vs-rounded against FT_MulDiv_No_Round, identity, rotation inverse, half scaling, singular/zero/null, and the null-pointer calls; and FT_Matrix_Multiply_Scaled(…, 1)/FT_Vector_Transform_Scaled(…, 1) equivalence holds under this library's own debt entry ("the scaled calls divide each term by 0x10000 * scaling").

Findings:

  1. Naming: the nine helpers break the library's own convention. RESOLVED names should be _nid_postfix with no APS5_EXPORT — this library already does exactly that for implemented exports (ft_mem_qalloc_nid_postfix in src/Memory.cpp, FT_Trace_Get_Name_nid_postfix in Export.cpp), and implemented stubs with explicit aliases keep the resolved name plus _nid_no_patch (FT_Trace_Get_Name_nid_no_patch with APS5_EXPORT("64XMq6sDxUo", …)). FreetypeMulDiv follows neither form. The collision concern in the description does not apply to the convention name: FT_MulDiv_nid_postfix is a distinct symbol from bundled FreeType's FT_MulDiv, so nothing is interposed. Use the resolved names with _nid_postfix and drop the explicit aliases.
  2. The new debt entry is 1462 characters; entries stay under 1000 — tools/check_conventions.py flags it as a [debt-length] warning. State the gap first (NIDs present in the 3.20 inventory; prototypes, console ABI and version equivalence unverified) and keep only what the gap needs.
  3. #9410 is still open and implements FT_MulDiv, FT_MulFix, FT_DivFix, FT_RoundFix, FT_CeilFix and FT_FloorFix in libSceFreeType, six of the same nine names. The repo allows both libraries but requires the two PRs to be sequenced via Depends on: (or one closed) — the body says "Depends on: none" and claims no other open PR implements the same functions.

Nothing about the semantics themselves is wrong — rename, trim the entry, and declare the sequence with #9410 and this is good.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5814429210 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16823#pullrequestreview-5814429210). Originally posted by [coptergui-ops](https://github.com/coptergui-ops) on 2026-11-07T18:56:26Z. **Review:** CHANGES_REQUESTED --- NID sourcing and arithmetic check out, the naming deviates from the convention this library itself set — please rework before merge. Verified good: - All nine NIDs are in the PS5 3.20 inventory for libSceFreeTypeOt (checked the DNNDHH blob: `sprx_dlsym("Q+ysHCIzphI", &__ptr_FT_MulDiv)` etc., all nine name↔NID pairs match the PR exactly), and `tools/nid_names.py --name FT_MulDiv …` computes the same nine NIDs. - The math follows the cited FreeType 2.4.12 forms: round helpers `(a + 0x8000 - (a<0)) & ~0xFFFF`, ceil `(a + 0xFFFF) & ~0xFFFF`, floor `a & ~0xFFFF` match ftcalc.c; `FT_DivFix(a,b) = MulDiv(a, 0x10000, b)`; `FT_Matrix_Invert` is the delta = MulFix cross-product then `DivFix` chain, null and singular return before writing, which the tests pin; `Invalid_Argument = 6` matches the same library's debt entry for the memory exports (`Invalid_Argument 0x06`). - Tests cover the corner behaviours with real controls: exact-vs-rounded against `FT_MulDiv_No_Round`, identity, rotation inverse, half scaling, singular/zero/null, and the null-pointer calls; and `FT_Matrix_Multiply_Scaled(…, 1)`/`FT_Vector_Transform_Scaled(…, 1)` equivalence holds under this library's own debt entry ("the scaled calls divide each term by 0x10000 * scaling"). Findings: 1. Naming: the nine helpers break the library's own convention. RESOLVED names should be `_nid_postfix` with no `APS5_EXPORT` — this library already does exactly that for implemented exports (`ft_mem_qalloc_nid_postfix` in `src/Memory.cpp`, `FT_Trace_Get_Name_nid_postfix` in `Export.cpp`), and implemented stubs with explicit aliases keep the resolved name plus `_nid_no_patch` (`FT_Trace_Get_Name_nid_no_patch` with `APS5_EXPORT("64XMq6sDxUo", …)`). `FreetypeMulDiv` follows neither form. The collision concern in the description does not apply to the convention name: `FT_MulDiv_nid_postfix` is a distinct symbol from bundled FreeType's `FT_MulDiv`, so nothing is interposed. Use the resolved names with `_nid_postfix` and drop the explicit aliases. 2. The new debt entry is 1462 characters; entries stay under 1000 — `tools/check_conventions.py` flags it as a [debt-length] warning. State the gap first (NIDs present in the 3.20 inventory; prototypes, console ABI and version equivalence unverified) and keep only what the gap needs. 3. #9410 is still open and implements `FT_MulDiv`, `FT_MulFix`, `FT_DivFix`, `FT_RoundFix`, `FT_CeilFix` and `FT_FloorFix` in libSceFreeType, six of the same nine names. The repo allows both libraries but requires the two PRs to be sequenced via `Depends on:` (or one closed) — the body says "Depends on: none" and claims no other open PR implements the same functions. Nothing about the semantics themselves is wrong — rename, trim the entry, and declare the sequence with #9410 and this is good.
coptergui-ops commented 2026-11-08 03:34:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coptergui-ops on 2026-11-08T03:34:44Z.

Review: APPROVED


Re-reviewed at rework head 66786c6239 — all three of my earlier findings are addressed and independently confirmed here:

  • Naming: all nine definitions are now <Base>_nid_postfix with no APS5_EXPORT (FT_MulDiv, FT_MulFix, FT_DivFix, FT_RoundFix, FT_CeilFix, FT_FloorFix, FT_Matrix_Multiply, FT_Matrix_Invert, FT_Vector_Transform); the two composite bodies delegate as expected (FT_Matrix_Multiply_Scaled_nid_postfix(a, b, 1), FT_Vector_Transform_Scaled_nid_postfix(vector, matrix, 1)).
  • Debt: the rewritten entry measures 821 characters at this head, gap-first, and tools/check_conventions.py --base origin/main --head 66786c62 reports no debt findings (only body-template complaints from this run, as the PR body here is the real template-filled one).
  • Sequencing: the six overlapping names against #9410 are declared Depends on in the body rather than silently duplicated.

No new findings against the rework.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5816450306 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16823#pullrequestreview-5816450306). Originally posted by [coptergui-ops](https://github.com/coptergui-ops) on 2026-11-08T03:34:44Z. **Review:** APPROVED --- Re-reviewed at rework head `66786c6239` — all three of my earlier findings are addressed and independently confirmed here: - Naming: all nine definitions are now `<Base>_nid_postfix` with no `APS5_EXPORT` (`FT_MulDiv`, `FT_MulFix`, `FT_DivFix`, `FT_RoundFix`, `FT_CeilFix`, `FT_FloorFix`, `FT_Matrix_Multiply`, `FT_Matrix_Invert`, `FT_Vector_Transform`); the two composite bodies delegate as expected (`FT_Matrix_Multiply_Scaled_nid_postfix(a, b, 1)`, `FT_Vector_Transform_Scaled_nid_postfix(vector, matrix, 1)`). - Debt: the rewritten entry measures 821 characters at this head, gap-first, and `tools/check_conventions.py --base origin/main --head 66786c62` reports no debt findings (only body-template complaints from this run, as the PR body here is the real template-filled one). - Sequencing: the six overlapping names against #9410 are declared `Depends on` in the body rather than silently duplicated. No new findings against the rework.
adriadam10 commented 2026-11-11 11:52:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-11T11:52:44Z.

Review: CHANGES_REQUESTED


Checked the six implementations against FreeType 2.4.12 ftcalc.c and the CheckedMulDiv rules already in this module; the arithmetic is right. Blocking points:

  • Overlap with #9410. It exports the same six names from libSceFreeType, and check_conventions rejects a name already exported by another library (duplicate-export), so whichever lands second fails. This PR says it depends on #9410 but its code does not change either way. Please settle the order: once #9410 is merged, reduce this branch to APS5_DUMMY_FUN declarations (or close it), and if the two differ in behaviour (2.4.12 throwing outside 32-bit range here vs 2.13.3 narrowing there), say which one the console build matches and put the other under debt.
  • Tests (core/libs/tests/GuestFreeTypeCorner.cpp:169-235): the PR body says overflow and zero-divisor cases are covered, but the six new checks pin none of the throwing paths (operand above 0x7FFFFFFF, quotient above 0xFFFFFFFF, zero divisor with zero factor). FT_MulFix also has no case that rounds up (e.g. FT_MulFix(1, 0x8000) == 1).
  • FT_CeilFix/FT_RoundFix (Export.cpp:443-449) overflow signed int64_t near INT64_MAX; do the addition in uint64_t so the wraparound is defined.

Happy to re-review once #9410 is resolved.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5858283299 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16823#pullrequestreview-5858283299). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-11-11T11:52:44Z. **Review:** CHANGES_REQUESTED --- Checked the six implementations against FreeType 2.4.12 `ftcalc.c` and the `CheckedMulDiv` rules already in this module; the arithmetic is right. Blocking points: - **Overlap with #9410.** It exports the same six names from `libSceFreeType`, and `check_conventions` rejects a name already exported by another library (`duplicate-export`), so whichever lands second fails. This PR says it depends on #9410 but its code does not change either way. Please settle the order: once #9410 is merged, reduce this branch to `APS5_DUMMY_FUN` declarations (or close it), and if the two differ in behaviour (2.4.12 throwing outside 32-bit range here vs 2.13.3 narrowing there), say which one the console build matches and put the other under debt. - **Tests** (`core/libs/tests/GuestFreeTypeCorner.cpp:169-235`): the PR body says overflow and zero-divisor cases are covered, but the six new checks pin none of the throwing paths (operand above 0x7FFFFFFF, quotient above 0xFFFFFFFF, zero divisor with zero factor). `FT_MulFix` also has no case that rounds up (e.g. `FT_MulFix(1, 0x8000) == 1`). - `FT_CeilFix`/`FT_RoundFix` (`Export.cpp:443-449`) overflow signed `int64_t` near `INT64_MAX`; do the addition in `uint64_t` so the wraparound is defined. Happy to re-review once #9410 is resolved.
MarcZX10 commented 2026-11-20 20:22:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T20:22:12Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the documented prototype, ABI, and FreeType equivalence caveats remain unverified.

What I ran

Read the prepared diff and the changed source, declarations, tests, and debt entry at head 03be4e958eb09cdbdf3ae706724f7baf42defd2b. No commands or tests were run. The reported build and checks are author-reported.

Results

Check Result Note
Changed code review passed Four changed files read
Build and reported tests not run Results supplied in description
PS5 title behavior not run No console run reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

Console prototypes, ABI, and equivalence to the console's FreeType version were not verified, as documented in the PR. No tests were run during this review. files.json was not available through the reader; the manifest lists four changed files, all included, and all four were read. No files were excluded in the manifest.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5998838209 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16823#pullrequestreview-5998838209). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T20:22:12Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the documented prototype, ABI, and FreeType equivalence caveats remain unverified. ## What I ran Read the prepared diff and the changed source, declarations, tests, and debt entry at head `03be4e958eb09cdbdf3ae706724f7baf42defd2b`. No commands or tests were run. The reported build and checks are author-reported. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Four changed files read | | Build and reported tests | not run | Results supplied in description | | PS5 title behavior | not run | No console run reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Console prototypes, ABI, and equivalence to the console's FreeType version were not verified, as documented in the PR. No tests were run during this review. `files.json` was not available through the reader; the manifest lists four changed files, all included, and all four were read. No files were excluded in the manifest. ## To get this to a good state Nothing is required.

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