feat(libSceFreeType): implement the fixed-point square root #11996

Closed
santhoshkumar-dev wants to merge 1 commit from upstream-pr/11996 into main
santhoshkumar-dev commented 2026-10-27 16:03:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-27T16:03:43Z.


What

Add FT_SqrtFixed (JgtSc0g3G6E) to the physical libSceFreeType adapter. Its signed 32-bit interface returns zero for nonpositive inputs; for positive inputs the result is floor(sqrt(bits << 16)), the 16.16 fixed-point integer square root. An independently authored bounded search uses 64-bit products; no third-party code is copied.

The name/NID is in the PS5 3.20 inventory (alongside FT_Sqrt32). The signed contract and nonpositive-input zero follow legacy FreeType 2.4.12 ftcalc.c; the bundled 2.13.3 build exports only an unsigned variant, so it is not forwarded to. Console ABI/arithmetic equivalence is unverified and recorded in debt.

The matching OT inventory helper is named sceFreeTypeOtSqrtFixed_nid_no_patch and declared in the public header reachable through its umbrella. Its existing no-parameter placeholder, explicit NID alias and throwing behavior remain; this is not an OT-provider implementation or a claim about its console prototype. Implementation and tests include the canonical square-root header.

Ordering: whole-branch comparisons at this head against current main e0cd1259a95e6dfaf97f8f73e74410bbc5d8d199 and against #11613 are clean. #11878 and this branch both add one include line at the same include/Api.hpp spot and conflict only there (both lines are kept on rebase); CMakeLists.txt, libSceFreeTypeOt/Export.cpp and the debt entry auto-merge. No code from that PR is included and there is no functional or build dependency. Whole-branch combinations with #9465 and #10897 conflict in docs/dev/debt/libSceFreeTypeOt.md only; baseline comparisons of those heads against current main produce exactly that same conflict, and this PR does not change that file. Neither peer changes the square-root export; open/closed/merged history was rechecked for FT_SqrtFixed/JgtSc0g3G6E immediately before opening, with no match.

Tested

Submitted and tested head dbd9df9e946bb3107812511e60f1ced8aaa46c6d, based on upstream main 2222bae20b123d4545c7c70a0bbe388e9c8c29c1; it merges cleanly into current main e0cd1259a95e6dfaf97f8f73e74410bbc5d8d199 with no files changed by this contribution touched since.

Windows 11 x64 / WinLibs GCC 15.2.0 r7 and local Ubuntu 24.04.1 x86-64 under WSL2 / GCC 13.3.0 / glibc 2.39: Ninja Release, bundled dependencies, BUILD_TESTING=ON, ANYPS5_ENABLE_SPIRV_TOOLS=OFF. On each platform the complete libs target (including all packaged-NID .prx patching) and selected test executables build, and 70/70 CTests pass: public-header audit, all 64 header compilation batches, both square-root export modes (unpatched symbol and packaged NID JgtSc0g3G6E), charmap checks and the packaged-library loader.

The fixture resolves the actual unpatched symbol and packaged NID separately. Each mode checks zero for 0, -1, -65536 and INT32_MIN; exact fixed points 65536 -> 65536 and 262144 -> 131072; the first and last input and the preceding transition of every non-empty result interval across the full positive domain (11,863,284 result values, covering the maximum input 0x7FFFFFFF); and 65,536 deterministic LCG samples verified by square inequalities. Outside the repository, an exhaustive harness compared this implementation with the legacy 2.4.12 digit-by-digit algorithm over every positive int32 input plus negatives and INT32_MIN: zero mismatches.

No full application/test-suite, macOS, title or physical-console run is claimed.

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: #11878
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5037110355 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11996). Originally posted by [santhoshkumar-dev](https://github.com/santhoshkumar-dev) on 2026-10-27T16:03:43Z. --- ### What Add `FT_SqrtFixed` (`JgtSc0g3G6E`) to the physical `libSceFreeType` adapter. Its signed 32-bit interface returns zero for nonpositive inputs; for positive inputs the result is `floor(sqrt(bits << 16))`, the 16.16 fixed-point integer square root. An independently authored bounded search uses 64-bit products; no third-party code is copied. The name/NID is in the [PS5 3.20 inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceFreeTypeOt.c) (alongside `FT_Sqrt32`). The signed contract and nonpositive-input zero follow legacy [FreeType 2.4.12 ftcalc.c](https://github.com/freetype/freetype/blob/cecf93ef90c660a8b0b45e5adbbfb5ea443fb6b9/src/base/ftcalc.c#L801-L829); the bundled 2.13.3 build exports only an unsigned variant, so it is not forwarded to. Console ABI/arithmetic equivalence is unverified and recorded in debt. The matching OT inventory helper is named `sceFreeTypeOtSqrtFixed_nid_no_patch` and declared in the public header reachable through its umbrella. Its existing no-parameter placeholder, explicit NID alias and throwing behavior remain; this is not an OT-provider implementation or a claim about its console prototype. Implementation and tests include the canonical square-root header. Ordering: whole-branch comparisons at this head against current main `e0cd1259a95e6dfaf97f8f73e74410bbc5d8d199` and against #11613 are clean. #11878 and this branch both add one include line at the same `include/Api.hpp` spot and conflict only there (both lines are kept on rebase); `CMakeLists.txt`, `libSceFreeTypeOt/Export.cpp` and the debt entry auto-merge. No code from that PR is included and there is no functional or build dependency. Whole-branch combinations with #9465 and #10897 conflict in `docs/dev/debt/libSceFreeTypeOt.md` only; baseline comparisons of those heads against current main produce exactly that same conflict, and this PR does not change that file. Neither peer changes the square-root export; open/closed/merged history was rechecked for `FT_SqrtFixed`/`JgtSc0g3G6E` immediately before opening, with no match. ### Tested Submitted and tested head `dbd9df9e946bb3107812511e60f1ced8aaa46c6d`, based on upstream main `2222bae20b123d4545c7c70a0bbe388e9c8c29c1`; it merges cleanly into current main `e0cd1259a95e6dfaf97f8f73e74410bbc5d8d199` with no files changed by this contribution touched since. Windows 11 x64 / WinLibs GCC 15.2.0 r7 and local Ubuntu 24.04.1 x86-64 under WSL2 / GCC 13.3.0 / glibc 2.39: Ninja Release, bundled dependencies, `BUILD_TESTING=ON`, `ANYPS5_ENABLE_SPIRV_TOOLS=OFF`. On each platform the complete `libs` target (including all packaged-NID `.prx` patching) and selected test executables build, and **70/70 CTests pass**: public-header audit, all 64 header compilation batches, both square-root export modes (unpatched symbol and packaged NID `JgtSc0g3G6E`), charmap checks and the packaged-library loader. The fixture resolves the actual unpatched symbol and packaged NID separately. Each mode checks zero for `0`, `-1`, `-65536` and `INT32_MIN`; exact fixed points `65536 -> 65536` and `262144 -> 131072`; the first and last input and the preceding transition of every non-empty result interval across the full positive domain (11,863,284 result values, covering the maximum input `0x7FFFFFFF`); and 65,536 deterministic LCG samples verified by square inequalities. Outside the repository, an exhaustive harness compared this implementation with the legacy 2.4.12 digit-by-digit algorithm over every positive `int32` input plus negatives and `INT32_MIN`: zero mismatches. No full application/test-suite, macOS, title or physical-console run is claimed. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: #11878 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->

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