Skip to content

feat(libSceFreeType): expose LP64 trigonometry - #9574

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
Ondra97:codex/feat-freetype-trigonometry
Oct 24, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
Ondra97:codex/feat-freetype-trigonometry

Conversation

@Ondra97

@Ondra97 Ondra97 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What

Add five fixed-point angle exports through the LP64 guest interface:

Export NID
FT_Cos yD4-QaNSink
FT_Sin L1uHkWTazkI
FT_Tan dojyaLKzKN0
FT_Vector_Unit 3WpTQrvGUcU
FT_Angle_Diff D1l8+Bu+-Y8

Preserve all 64 input bits by reducing angles modulo a full 16.16-degree turn before calling native cosine, sine and unit-vector routines. This gives the same quarter-turn sequence and residual CORDIC angle as the bundled implementation. Unit vectors write both complete eight-byte guest components; null outputs retain the native no-op behavior.

A direct Windows FT_Tan call loses the high quotient bits near its poles. At raw angle 5898240 (90 degrees), the bundled source compiled with LP64 types produces -640155090944, while native Windows FreeType returns -204963840. Use the bundled CORDIC steps and constants with a 64-bit rounded quotient, retaining the full fixed-point result. These are source-version results, not ideal real-number trigonometry.

Angle differences retain the native (-180, 180] interval without iterating through huge turn counts. Throw when the original signed 64-bit subtraction would overflow; the bundled source's behavior there is undefined. Console ABI, FreeType version and CORDIC equivalence remain unverified and are recorded in library debt.

Names/NIDs match the pinned PS5 3.20 inventory. Contracts and integer behavior follow bundled FreeType 2.13.3 fttrigon.c, ftcalc.c and fttrigon.h.

Merge after #9550 and #9560 for shared CMake, include, prototype, helper, test-call and debt insertions. Their declared chains cover the other reported insertion overlaps; implementations are independent and no open PR adds these five exports. Retain each source entry, declaration and test when resolving those insertions. No title unblock or performance improvement is claimed.

Tested

Rebased on upstream main 4997726a5f6b8cd263461508945a4676647ef482; tested head b393ef93cc1c830897a83c833b41a445b439a055. Windows 11 Pro 10.0.26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Ninja, Release, BUILD_TESTING=ON, bundled dependencies. CPU: AMD Ryzen 9 7900X; RAM: 32 GB; GPU: NVIDIA GeForce RTX 4070 Ti SUPER. Font rendering uses the CPU.

The original missing-feature baseline lacks the guest exports required by this regression. The 68 tangent goldens come from the bundled CORDIC/division source compiled with int64_t LP64 aliases; the earlier narrowing negative control was not repeated for this rebase. Console compatibility and title-level impact remain unverified; this rebase adds Windows host runtime validation only.

Checklist

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Progress report (4997726 → b393ef9)

📈 System libraries: 47.44% (+0.02%, +5 implemented functions)

✅ 5 implemented
Library Name
libSceFreeType FT_Angle_Diff_nid_postfix
libSceFreeType FT_Cos_nid_postfix
libSceFreeType FT_Sin_nid_postfix
libSceFreeType FT_Tan_nid_postfix
libSceFreeType FT_Vector_Unit_nid_postfix

@Ondra97

Ondra97 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

I opened #9588 for FT_Glyph_Get_CBox. I declared #9574 for merge order because the new query and its ownership dependency share debt/guest-record insertions with the existing FreeType chain. Retain the distinct glyph records, trigonometry/decomposition support and debt entries.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the five export implementations and the regression coverage against the pinned FreeType 2.13.3 trigonometry implementation. The full-width angle normalization, guest 64-bit output writes, CORDIC tangent path and overflow handling for the angle subtraction are consistent with the stated LP64 contract. The tests cover randomized and boundary angles, pole goldens, guard bytes, null output, glyph rendering and explicit negative controls; the report clearly limits its ABI evidence to the compiled LP64 model and Windows runtime.

The declared #9550 and #9560 merge order is explicit, and both prerequisites remain open and mergeable. Hosted eligibility, intake, labels, report and conventions checks pass. The hosted product-build jobs are skipped; I relied on the detailed author-reported local tests and did not treat those jobs as executed. No PS5 hardware or title runtime is claimed.

@jotitadev jotitadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux guest_freetype fails with this PR. The new pole-tangent loop assumes the host FT_Tan is the 32-bit (LLP64) one.

Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release (and an ASan build of the same target). Head 11957acba merged --no-commit onto main 17f533556 (clean).

  • guest_freetype aborts with FreeType check failed at line 174, in both Release and ASan:

    Require(static_cast<std::int64_t>(FT_Tan(static_cast<FT_Angle>(angle))) != tangent);

    This asserts that the host FreeType gets these poles wrong. That is true on Windows, where FT_Fixed is a 32-bit long. On Linux, and on macOS, long is 64-bit, so the bundled FreeType gives the same values as the guest table. Built against the same 3rdparty/freetype: sizeof(FT_Fixed) = 8, FT_Tan(5898239) = 640155090944, FT_Tan(5898240) = -640155090944, FT_Tan(17694720) = -640155090944. Those are exactly the poleTangents entries, so the inequality fails.

  • With that line guarded as if (sizeof(FT_Fixed) == 4) Require(...), and nothing else changed, guest_freetype and guest_freetype_charmap pass in Release, and guest_freetype passes under ASan (detect_leaks=1). So the implementation side is fine on Linux, and only the host-difference assertion needs to be limited to LLP64 hosts (or dropped).

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

@jotitadev jotitadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-ran on Linux after 68a5a7093 (pole check split by sizeof(FT_Fixed)).

Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release. Head 8aa308c7b merged --no-commit onto main d6eafa54d (clean).

  • guest_freetype and guest_freetype_charmap pass, 3 of 3 runs: 4226 scalar cases, 4226 vectors, 1764 angle differences, 68 LP64 tangent goldens, 10 rendered glyphs. The new else branch holds here (sizeof(FT_Fixed) == 8, host FT_Tan equals the goldens).
  • The test still catches a broken CORDIC on Linux: dropping the (x >> 1) rounding term in FT_Tan_nid_postfix aborts at line 173.
  • For reference, on this LP64 host FT_Tan_nid_postfix forwarding to the native FT_Tan(NormalizeAngle(angle)) also passes the whole test, so the custom tangent path only differs from the host one on LLP64 (Windows).

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

@MarcZX10 MarcZX10 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the test-only update at head 8aa308c7becd831013b02b5cf1b23de61aa77314. The sizeof(FT_Fixed) split correctly expects the Windows LLP64 host to differ from the 64-bit guest tangent table while requiring the Linux LP64 host to match it. The independent Linux reviewer reports both focused FreeType tests pass 3/3 on this head and confirms the CORDIC rounding negative control still fails. Conventions and diff --check pass against current upstream/main; the exact-head Windows build/test report is author-provided, and hosted product jobs are skipped. One repository requirement remains. check_main_sync.py reports 5 ahead / 58 behind current main (merge base 4a17c7175); please refresh the branch and repeat the focused verification. The declared #9550/#9560 sequence is clear, and I found no new implementation issue in this test correction.

I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.

@MarcZX10

Copy link
Copy Markdown
Contributor

Correction to my 10:53 review: I withdraw the intake/queue objection. Your contribution-count eligibility means no title unblock or intake exception is required for this generic addition.

The current-base request remains. Exact head 8aa308c7becd831013b02b5cf1b23de61aa77314 is based on 4a17c71757644170c6a0acfcc67fb17f81cff93f, 101 commits behind current upstream/main 8b3e39832af85f404c6195418d11b3e1ebd1924d. git diff --check, current-main conventions, and merge-tree pass, with no merge conflict. The Windows full build and 3/3 focused tests are author-reported; the independent Linux run reports both focused tests passing 3/3 and the tangent negative control still failing as intended. Those runs are on this exact head but its older base. Please merge/rebase the latest main and rerun the focused FreeType tests/checks before merge. I found no new implementation issue in this pass; the declared #9550/#9560 integration order remains clear.

@MarcZX10

Copy link
Copy Markdown
Contributor

I’ve noticed that my earlier request to hold this PR based on #5239 was unnecessary. It’s fine to keep submitting PRs; maintainers will handle them in due course. Please disregard that request.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 9848 core/libs/prx/libSceFreeType/CMakeLists.txt
docs/dev/debt/libSceFreeType.md

@Ondra97
Ondra97 force-pushed the codex/feat-freetype-trigonometry branch from eae845f to b27a56a Compare October 23, 2026 03:17
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 23, 2026
@Ondra97 Ondra97 mentioned this pull request Oct 23, 2026
12 tasks done
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 23, 2026
@Ondra97
Ondra97 force-pushed the codex/feat-freetype-trigonometry branch from b27a56a to b393ef9 Compare October 23, 2026 14:52
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 23, 2026
@adriadam10 adriadam10 self-assigned this Oct 23, 2026
@adriadam10
adriadam10 dismissed MarcZX10’s stale review October 24, 2026 11:24

Dismissing a stale review: the requested changes were addressed after it (new head) and the merge queue blocks on it. Please request changes again if anything is still open.

@adriadam10
adriadam10 merged commit cb807e0 into boykopovar:main Oct 24, 2026
11 of 12 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the five exports against bundled FreeType 2.13.3 fttrigon.c/ftcalc.c (angle reduction, quarter-turn steps, CORDIC rounding, x == 0 tangent, FT_Angle_Diff interval and overflow throw), the tests against the native library (scalar/vector/difference sweeps, pole tangents split by sizeof(FT_Fixed), rendering), and the debt entry; re-checked against current main (clean merge, no duplicate exports); merged.

@Ondra97
Ondra97 deleted the codex/feat-freetype-trigonometry branch October 25, 2026 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants