feat(libSceIcu): implement the three UComparator helpers from ICU 68.2 #19955

Merged
MarcZX10 merged 9 commits from upstream-pr/19955 into main 2026-11-14 13:34:17 +00:00
MarcZX10 commented 2026-11-14 09:29:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T09:29:54Z.


What

Three libSceIcu exports are still stubs that throw NotImplemented_nid_no_patch: uprv_int32Comparator, uprv_uint32Comparator and uprv_uint16Comparator. They are ICU's UComparator helpers from common/uarrsort.cpp, with the ICU 68 names already used for their NIDs in LegacyExports.cpp.

This PR implements them in a new file, core/libs/prx/libSceIcu/ArrayComparators.cpp, following ICU 68.2's uarrsort.cpp:
github.com/unicode-org/icu@84e1f26ea7/icu4c/source/common/uarrsort.cpp

Each comparator is one commit: implementation, with its stub removed and its declaration given the real (context, left, right) signature. Then one test commit per comparator, the first of which also registers guest_icu_array_comparators in CMakeLists.txt. The last commit updates docs/dev/debt/libSceIcu.md.

Behaviour note

ICU computes *left - *right in int32_t, which overflows for some inputs. That is undefined in C++. This implementation subtracts as unsigned and converts back, which gives the two's-complement result ICU's builds produce. The tests pin exact differences and ordering without overflow; they do not pin the overflowing cases. The debt entry says so.

Licence (please confirm)

The adapted code comes from ICU, distributed under the Unicode licence (icu4c/LICENSE, linked from the file header). This repository is GPL-2.0. The author of this PR believes the Unicode licence is compatible; maintainers should check before merging. The header of ArrayComparators.cpp keeps ICU's copyright notice and the pinned licence link.

Tested

  • Environment: Linux x86-64 (Debian 12, GCC 12.2), throwaway archive build of the branch head 15eaa77443.
  • ctest -R '^guest_icu': 44 of 44 tests pass, including the new guest_icu_array_comparators.
  • The new test checks exact differences for int32 (for example -1 vs 1 gives -2), ordering and equality for uint32 including 0xFFFFFFFF, and uint16 differences over the full 16-bit range (0xFFFF vs 0 gives 65535).
  • Negative control: not run. On the base the three names are stubs that throw, so the new tests are expected to abort on base; that expectation has not been checked.
  • tools/check_conventions.py --base upstream/main: passed. git diff --check: empty.
  • tools/pr_precheck.py (no-build): see the comment on this PR.

Not run: the console, Windows, macOS, and any sorting caller. No behaviour is measured on the console; the debt doc says so.

Overlap

  • No open PR names or adds these three functions in its title, body or diff (checked against every open PR that touches the libSceIcu legacy files).
  • tools/pr_overlap.py --branch fails closed: CMakeLists.txt, LegacyExports.cpp, include/LegacyExports.hpp and docs/dev/debt/libSceIcu.md are shared with many open PRs, so the tool could not complete the comparison. A textual conflict with a neighbouring hunk in another PR is still possible; it would be resolved by rebasing this branch.
  • This branch is independent of PR #19951 (the ASCII helpers). Both touch LegacyExports and the CMake list, so whichever merges second may need a rebase.

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:5309720510 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19955). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T09:29:54Z. --- ### What Three libSceIcu exports are still stubs that throw `NotImplemented_nid_no_patch`: `uprv_int32Comparator`, `uprv_uint32Comparator` and `uprv_uint16Comparator`. They are ICU's `UComparator` helpers from `common/uarrsort.cpp`, with the ICU 68 names already used for their NIDs in `LegacyExports.cpp`. This PR implements them in a new file, `core/libs/prx/libSceIcu/ArrayComparators.cpp`, following ICU 68.2's `uarrsort.cpp`: https://github.com/unicode-org/icu/blob/84e1f26ea77152936e70d53178a816dbfbf69989/icu4c/source/common/uarrsort.cpp Each comparator is one commit: implementation, with its stub removed and its declaration given the real `(context, left, right)` signature. Then one test commit per comparator, the first of which also registers `guest_icu_array_comparators` in `CMakeLists.txt`. The last commit updates `docs/dev/debt/libSceIcu.md`. ### Behaviour note ICU computes `*left - *right` in `int32_t`, which overflows for some inputs. That is undefined in C++. This implementation subtracts as unsigned and converts back, which gives the two's-complement result ICU's builds produce. The tests pin exact differences and ordering without overflow; they do not pin the overflowing cases. The debt entry says so. ### Licence (please confirm) The adapted code comes from ICU, distributed under the Unicode licence (`icu4c/LICENSE`, linked from the file header). This repository is GPL-2.0. The author of this PR believes the Unicode licence is compatible; maintainers should check before merging. The header of `ArrayComparators.cpp` keeps ICU's copyright notice and the pinned licence link. ### Tested - Environment: Linux x86-64 (Debian 12, GCC 12.2), throwaway archive build of the branch head `15eaa77443`. - `ctest -R '^guest_icu'`: 44 of 44 tests pass, including the new `guest_icu_array_comparators`. - The new test checks exact differences for `int32` (for example `-1` vs `1` gives `-2`), ordering and equality for `uint32` including `0xFFFFFFFF`, and `uint16` differences over the full 16-bit range (`0xFFFF` vs `0` gives `65535`). - Negative control: not run. On the base the three names are stubs that throw, so the new tests are expected to abort on base; that expectation has not been checked. - `tools/check_conventions.py --base upstream/main`: passed. `git diff --check`: empty. - `tools/pr_precheck.py` (no-build): see the comment on this PR. Not run: the console, Windows, macOS, and any sorting caller. No behaviour is measured on the console; the debt doc says so. ### Overlap - No open PR names or adds these three functions in its title, body or diff (checked against every open PR that touches the libSceIcu legacy files). - `tools/pr_overlap.py --branch` fails closed: `CMakeLists.txt`, `LegacyExports.cpp`, `include/LegacyExports.hpp` and `docs/dev/debt/libSceIcu.md` are shared with many open PRs, so the tool could not complete the comparison. A textual conflict with a neighbouring hunk in another PR is still possible; it would be resolved by rebasing this branch. - This branch is independent of PR #19951 (the ASCII helpers). Both touch `LegacyExports` and the CMake list, so whichever merges second may need a rebase. ### 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-14 09:38:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T09:38:39Z.

Review: CHANGES_REQUESTED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_icu_array_comparators_tests built cleanly.
  • CTest (guest_icu_array_comparators):
    1/1 Test #3420: guest_icu_array_comparators ......   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceIcu/LegacyExports.cpp, core/libs/prx/libSceIcu/include/LegacyExports.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified that uprv_int32Comparator_nid_postfix, uprv_uint32Comparator_nid_postfix, and uprv_uint16Comparator_nid_postfix in core/libs/prx/libSceIcu/ArrayComparators.cpp match ICU 68.2 common/uarrsort.cpp comparator logic, including unsigned subtraction for two's-complement int32 differences.
    • Verified that core/libs/prx/libSceIcu/include/LegacyExports.hpp and core/libs/prx/libSceIcu/ArrayComparators.cpp consistently declare and define all three exports under extern "C" with APS5_VABI and the (const void* context, const void* left, const void* right) signature returning std::int32_t.
    • Verified that the NotImplemented_nid_no_patch stubs for uprv_int32Comparator_nid_postfix, uprv_uint32Comparator_nid_postfix, and uprv_uint16Comparator_nid_postfix were cleanly removed from core/libs/prx/libSceIcu/LegacyExports.cpp.
    • Verified that core/libs/tests/GuestIcuArrayComparators.cpp exercises all three comparators across ordering, equality, negative values, full 16-bit differences (0xFFFF vs 0), and 32-bit unsigned boundary values (0xFFFFFFFFu vs 0).
    • Verified LP64/LLP64 type portability in ArrayComparators.cpp through consistent usage of fixed-width std::int32_t, std::uint32_t, and std::uint16_t types without platform-dependent long types.
    • Verified technical debt documentation updates in docs/dev/debt/libSceIcu.md noting the functional implementation status and absence of console verification.
  • Concerns:
    • core/libs/prx/libSceIcu/ArrayComparators.cpp:1-12: AGENTS.md explicitly prohibits comments in code ("No comments in code, except #endif and namespace ends."). Lines 1-12 contain comments describing ICU 68.2 provenance, copyright notices, license URLs, and arithmetic overflow details; these notes belong exclusively in docs/dev/debt/libSceIcu.md and the pull request description rather than in the source file.
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5903470332 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19955#pullrequestreview-5903470332). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-14T09:38:39Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `15eaa77443`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_icu_array_comparators_tests` built cleanly. - **CTest** (`guest_icu_array_comparators`): ``` 1/1 Test #3420: guest_icu_array_comparators ...... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceIcu/LegacyExports.cpp`, `core/libs/prx/libSceIcu/include/LegacyExports.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified that uprv_int32Comparator_nid_postfix, uprv_uint32Comparator_nid_postfix, and uprv_uint16Comparator_nid_postfix in core/libs/prx/libSceIcu/ArrayComparators.cpp match ICU 68.2 common/uarrsort.cpp comparator logic, including unsigned subtraction for two's-complement int32 differences. - Verified that core/libs/prx/libSceIcu/include/LegacyExports.hpp and core/libs/prx/libSceIcu/ArrayComparators.cpp consistently declare and define all three exports under extern "C" with APS5_VABI and the (const void* context, const void* left, const void* right) signature returning std::int32_t. - Verified that the NotImplemented_nid_no_patch stubs for uprv_int32Comparator_nid_postfix, uprv_uint32Comparator_nid_postfix, and uprv_uint16Comparator_nid_postfix were cleanly removed from core/libs/prx/libSceIcu/LegacyExports.cpp. - Verified that core/libs/tests/GuestIcuArrayComparators.cpp exercises all three comparators across ordering, equality, negative values, full 16-bit differences (0xFFFF vs 0), and 32-bit unsigned boundary values (0xFFFFFFFFu vs 0). - Verified LP64/LLP64 type portability in ArrayComparators.cpp through consistent usage of fixed-width std::int32_t, std::uint32_t, and std::uint16_t types without platform-dependent long types. - Verified technical debt documentation updates in docs/dev/debt/libSceIcu.md noting the functional implementation status and absence of console verification. - **Concerns**: - core/libs/prx/libSceIcu/ArrayComparators.cpp:1-12: AGENTS.md explicitly prohibits comments in code ("No comments in code, except #endif and namespace ends."). Lines 1-12 contain comments describing ICU 68.2 provenance, copyright notices, license URLs, and arithmetic overflow details; these notes belong exclusively in docs/dev/debt/libSceIcu.md and the pull request description rather than in the source file. - Note: the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-14 10:39:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T10:39:25Z.

Review: CHANGES_REQUESTED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_icu_array_comparators_tests built cleanly.
  • CTest (guest_icu_array_comparators):
    1/1 Test #3420: guest_icu_array_comparators ......   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceIcu/LegacyExports.cpp, core/libs/prx/libSceIcu/include/LegacyExports.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified core/libs/prx/libSceIcu/ArrayComparators.cpp:15-20 (uprv_int32Comparator_nid_postfix) converts through std::uint32_t to avoid undefined behavior from signed overflow while matching ICU 68.2's two's-complement difference semantics.
    • Verified core/libs/prx/libSceIcu/ArrayComparators.cpp:22-29 (uprv_uint32Comparator_nid_postfix) trichotomy comparisons correctly return -1, 0, or 1 across the full 32-bit unsigned range including 0xFFFFFFFFu boundaries.
    • Verified core/libs/prx/libSceIcu/ArrayComparators.cpp:31-34 (uprv_uint16Comparator_nid_postfix) converts to std::int32_t before subtraction, preventing underflow/overflow across the full 16-bit range differences [-65535, 65535].
    • Verified core/libs/prx/libSceIcu/include/LegacyExports.hpp and LegacyExports.cpp match comparator prototypes (const void*, const void*, const void*) and properly remove old NotImplemented stubs.
    • Verified core/libs/tests/GuestIcuArrayComparators.cpp and CMakeLists.txt correctly register and execute test cases covering equality, ordering, and range limits.
    • Verified docs/dev/debt/libSceIcu.md accurately documents the new exports and records known gaps against PS5 console ABI verification.
  • Concerns:
    • core/libs/prx/libSceIcu/ArrayComparators.cpp:1-9: The file contains a 9-line comment block with upstream adaptation notes and copyright/license notices. AGENTS.md strictly dictates: 'No comments in code, except #endif and namespace ends.' As acknowledged by the author in the PR discussion, no maintainer decision has approved an exception to this repository rule; licence and attribution facts belong in docs/dev/debt/libSceIcu.md rather than source code comments.
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5903874553 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19955#pullrequestreview-5903874553). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-14T10:39:25Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `4f4b41a1d2`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_icu_array_comparators_tests` built cleanly. - **CTest** (`guest_icu_array_comparators`): ``` 1/1 Test #3420: guest_icu_array_comparators ...... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceIcu/LegacyExports.cpp`, `core/libs/prx/libSceIcu/include/LegacyExports.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified core/libs/prx/libSceIcu/ArrayComparators.cpp:15-20 (uprv_int32Comparator_nid_postfix) converts through std::uint32_t to avoid undefined behavior from signed overflow while matching ICU 68.2's two's-complement difference semantics. - Verified core/libs/prx/libSceIcu/ArrayComparators.cpp:22-29 (uprv_uint32Comparator_nid_postfix) trichotomy comparisons correctly return -1, 0, or 1 across the full 32-bit unsigned range including 0xFFFFFFFFu boundaries. - Verified core/libs/prx/libSceIcu/ArrayComparators.cpp:31-34 (uprv_uint16Comparator_nid_postfix) converts to std::int32_t before subtraction, preventing underflow/overflow across the full 16-bit range differences [-65535, 65535]. - Verified core/libs/prx/libSceIcu/include/LegacyExports.hpp and LegacyExports.cpp match comparator prototypes (const void*, const void*, const void*) and properly remove old NotImplemented stubs. - Verified core/libs/tests/GuestIcuArrayComparators.cpp and CMakeLists.txt correctly register and execute test cases covering equality, ordering, and range limits. - Verified docs/dev/debt/libSceIcu.md accurately documents the new exports and records known gaps against PS5 console ABI verification. - **Concerns**: - core/libs/prx/libSceIcu/ArrayComparators.cpp:1-9: The file contains a 9-line comment block with upstream adaptation notes and copyright/license notices. AGENTS.md strictly dictates: 'No comments in code, except #endif and namespace ends.' As acknowledged by the author in the PR discussion, no maintainer decision has approved an exception to this repository rule; licence and attribution facts belong in docs/dev/debt/libSceIcu.md rather than source code comments. - Note: the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-14 11:31:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T11:31:16Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_icu_array_comparators_tests built cleanly.
  • CTest (guest_icu_array_comparators):
    1/1 Test #3420: guest_icu_array_comparators ......   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceIcu/LegacyExports.cpp, core/libs/prx/libSceIcu/include/LegacyExports.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified core/libs/prx/libSceIcu/ArrayComparators.cpp uprv_uint32Comparator_nid_postfix performs three-way unsigned comparison (<, ==, >) returning -1, 0, or 1, avoiding subtraction wrap-around on boundary inputs such as 0xFFFFFFFFu vs 0.
    • Verified core/libs/prx/libSceIcu/ArrayComparators.cpp uprv_uint16Comparator_nid_postfix promotes uint16_t operands to std::int32_t before subtraction, preventing integer overflow and covering differences across [-65535, 65535].
    • Verified core/libs/prx/libSceIcu/ArrayComparators.cpp uprv_int32Comparator_nid_postfix evaluates differences using std::uint32_t modular arithmetic before casting to std::int32_t, avoiding signed integer overflow undefined behavior under C++20 while matching ICU 68.2 uarrsort.cpp wrapping behavior as documented in docs/dev/debt/libSceIcu.md.
    • Verified core/libs/prx/libSceIcu/include/LegacyExports.hpp and core/libs/prx/libSceIcu/LegacyExports.cpp replace the previous zero-argument NotImplemented stubs with correct UComparator (const void* context, const void* left, const void* right) signatures under the APS5_VABI calling convention.
    • Verified core/libs/tests/GuestIcuArrayComparators.cpp comprehensively tests ordering, exact differences, and boundary values for all three comparators, and is properly registered with Windows unwind and a 20-second timeout in core/libs/prx/libSceIcu/CMakeLists.txt.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5904106437 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19955#pullrequestreview-5904106437). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-14T11:31:16Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `1d0a0e35ee`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_icu_array_comparators_tests` built cleanly. - **CTest** (`guest_icu_array_comparators`): ``` 1/1 Test #3420: guest_icu_array_comparators ...... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceIcu/LegacyExports.cpp`, `core/libs/prx/libSceIcu/include/LegacyExports.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified core/libs/prx/libSceIcu/ArrayComparators.cpp uprv_uint32Comparator_nid_postfix performs three-way unsigned comparison (<, ==, >) returning -1, 0, or 1, avoiding subtraction wrap-around on boundary inputs such as 0xFFFFFFFFu vs 0. - Verified core/libs/prx/libSceIcu/ArrayComparators.cpp uprv_uint16Comparator_nid_postfix promotes uint16_t operands to std::int32_t before subtraction, preventing integer overflow and covering differences across [-65535, 65535]. - Verified core/libs/prx/libSceIcu/ArrayComparators.cpp uprv_int32Comparator_nid_postfix evaluates differences using std::uint32_t modular arithmetic before casting to std::int32_t, avoiding signed integer overflow undefined behavior under C++20 while matching ICU 68.2 uarrsort.cpp wrapping behavior as documented in docs/dev/debt/libSceIcu.md. - Verified core/libs/prx/libSceIcu/include/LegacyExports.hpp and core/libs/prx/libSceIcu/LegacyExports.cpp replace the previous zero-argument NotImplemented stubs with correct UComparator (const void* context, const void* left, const void* right) signatures under the APS5_VABI calling convention. - Verified core/libs/tests/GuestIcuArrayComparators.cpp comprehensively tests ordering, exact differences, and boundary values for all three comparators, and is properly registered with Windows unwind and a 20-second timeout in core/libs/prx/libSceIcu/CMakeLists.txt. - Note: the AI-assisted checkbox can stay. Looks Good To Me
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!19955
No description provided.