feat(libSceCesCs): add the GB18030-2000 and GB18030-2005 profiles #9210

Merged
rooklz merged 1 commit from upstream-pr/9210 into main 2026-10-23 21:44:26 +00:00
rooklz commented 2026-10-21 15:19:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-21T15:19:00Z.


What

Implements sceCesUcsProfileInitGb18030_2000 and sceCesUcsProfileInitGb18030_2005. simonbronk said on #8993 that GB 18030 is not on his list and that I can go ahead after the stack, so this branch carries his stack and only the top commit is new.

  • Signatures follow the Orbital type database at b321fcd: both are union* (SceCesUcsProfileSheet* sheet), like sceCesUcsProfileInitGbkCp936, and they tag the sheet the same way.
  • Sources:
    • 2000: ICU's gb-18030-2000.ucm at d9d3a6ed with the gb18030Ranges of ucnvmbcs.c at 39f9a868. I picked the revision before ICU-8427 on purpose. That ticket (icu-data 91850aec, ICU 6206b737) copied the 2005 0xA8BC mapping into the 2000 file because ICU wanted an "updated GB18030 (2000 version)" as its built-in converter. The earlier revision is GB 18030-2000 as published, and it matches Python's gb18030 codec on every sequence. The current 2000 file differs from it only in U+1E3F and U+E7C7.
    • 2005: gb-18030-2005.ucm at 91850aec with the 14 gb18030Ranges of ucnvmbcs.cpp at release-74-2 (unchanged since ICU-8427).
    • Two-byte cells reuse the CP936 table from #8976. All 21,791 CP936 cells agree with both ucm files. The other 2,149 cells (the user-defined areas in the PUA and the GB 18030 additions such as 0xA2E3 U+20AC and 0xA8BF U+01F9) are stored as runs: 111 for 2000, 118 for 2005.
    • Four-byte sequences are runs of (first linear index, first code point, count) built from the explicit ucm entries plus ICU's ranges: 206 BMP runs for 2000 and 208 for 2005, plus one run for 0x90308130-0xE3329A35 = U+10000-U+10FFFF. There is no per-character table for them.
    • Gb18030.hpp is generated by a script I did not commit. Before writing it, the script checks the runs against the ucm mapping on every two-byte cell, every four-byte sequence up to past 0xE3329A35 and every scalar.
  • 2000 vs 2005, from diffing the two ucm files, is 26 sequences: 0xA8BC (U+E7C7 -> U+1E3F) and 0x8135F437 (U+1E3F -> U+E7C7); A6D9-A6DF, A6EC, A6ED, A6F3 -> U+FE10-U+FE19; FE59, FE61, FE66, FE67, FE6D, FE7E, FE90, FEA0 -> U+9FB4-U+9FBB; FE51, FE52, FE53, FE6C, FE76, FE91 -> U+20087, U+20089, U+200CC, U+215D7, U+2298F, U+241FE. In the 2005 file the old PUA code points are |1 fallbacks, so they still encode to those cells. The four-byte forms of U+FE10-U+FE19, U+9FB4-U+9FBB and the six ideographs still decode to them through ICU's ranges, but those characters encode to the two-byte cells, as ICU does.
  • 0x80 and 0xFF are invalid leads (the 0x80 euro is GBK only). 0x8431A530-0x8F39FE39 and everything from 0xE3329A36 are well formed but unassigned. Errors follow the GBK forms: a bad second, third or fourth byte gives INVALID_ENCODE, a cut sequence SRC_BUFFER_END, an unassigned one UNASSIGNED_CODE, and outputs are untouched on failure.
  • Wiring: isMbcs accepts both profiles, decodeMbcs and encodeMbcs dispatch them, and the sceCesGbTo* and sceCes*ToGb forms accept them, since they take the same "Gb" profile as GBK and sceCesGbUcsProfileSet4ByteCharRange only makes sense for GB 18030. GB 18030 is the first profile that produces supplementary characters, so the MBCS encode buffers grow from 3 to 4 bytes, encodeUtf8 writes 4-byte UTF-8, the UTF-16 outputs (the scalar forms, sceCesMbcsStrToUtf16Str and sceCesMbcsStrGetUtf16Len) write surrogate pairs, and the UCS-2 outputs answer UNASSIGNED_CODE for them as sceCesUtf8ToUcs2 does. Nothing changes for the existing profiles.
  • Still throwing: sceCesGbUcsProfileSet4ByteCharRange, sceCesGbUcsProfileSetUdaMapping and sceCesGbUcsProfileSetSbcs. I found nothing that says which values they take or what they change. I assume the full ucm mapping is the default they would change, and the debt entry says so.
  • Debt: a new "GB 18030 profiles" entry in docs/dev/debt/libSceCesCs.md after the GBK one, gap first. I also dropped "GB 18030 four-byte forms" from the GBK entry's not-handled list and changed the pending-exports count from 72 to 70.

Overlap: #9175 (my *ToMbc PR on the same stack) and #9107 edit nearby lines in Export.cpp, PendingExports.cpp and the debt file, and so does my strict JIS X 0208 profiles PR #9204 on the same stack. None of them implements these exports; whichever lands second needs a small rebase.

Tested

Ubuntu 24.04 x86-64 in a Docker container under Rosetta on an Apple M5 Mac, GCC 13.3, Release:

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
ninja -C build -j4 libSceCesCs libSceCesCs-module guest_ces_{,dbcs_,unicode_,japanese_,wide_,chinese_,mbc_}{,module_}tests
cd build && ctest -R guest_ces --output-on-failure

All 14 guest_ces* tests pass; guest_ces_chinese and guest_ces_chinese_module take 0.05 s each. I extended GuestCesChinese.cpp (the GBK and EUC-CN test) so that it checks, for both profiles:

  • every two-byte cell (23,940) decodes and encodes back to itself, and an FNV-1a hash of the decoded code points equals the one my script computed straight from the ucm;
  • every BMP four-byte sequence (39,420) decodes, with a matching hash; the sequences that do not encode back to themselves are 0 for 2000 and the 18 one-way forms above for 2005;
  • every BMP scalar from U+0080 encodes, with a matching hash of the bytes; the code points that do not decode back are 0 for 2000 and the 24 PUA fallbacks for 2005;
  • 1,052 supplementary sequences and 1,052 supplementary code points at a stride of 997, hashed, and 88 listed sequences in both directions: both ends of every ICU range and their neighbours, the first and last BMP sequence, U+n0000 and U+nFFFF of every supplementary plane, and the unassigned 8431A530, 8F39FE39, E3329A36, FD308130 and FE39FE39;
  • the 26 sequences that differ between 2000 and 2005, both ways, and the 24 fallbacks;
  • 80, FF, cut 81, 81 30 and 81 30 81, bad second bytes (00, 2F, 3A, 7F, FF), bad third (80, FF, 30) and fourth (2F, 3A, 81) bytes and unassigned sequences, through sceCesGbToUtf32 and sceCesMbcToUcs2, with outputs and lengths untouched;
  • supplementary output: UCS-2 gives UNASSIGNED_CODE, UTF-8 gives 4 bytes, UTF-16 native, be and le give surrogate pairs, and short buffers give DST_BUFFER_END with nothing written; 4-byte UTF-8 and surrogate-pair UTF-16 into sceCes*ToGb; an MBCS context round trip through UTF-8, UTF-16 and the UTF-16 length form, and UNASSIGNED_CODE from sceCesMbcsStrToUcs2Str.

Oracle: the ucm files are the primary oracle. As an independent check I compared both mappings with Python 3.14.8's gb18030 codec on every two-byte cell, every four-byte sequence from 81308130 to past E3329A35, and every scalar. Python implements GB 18030-2000, not 2005: it matches the 2000 profile with no differences in either direction, and it differs from the 2005 profile in exactly the 26 decodes and 26 encodes listed above (it keeps 0xA8BC = U+E7C7 and the PUA). The 2000 column of the 88 listed sequences was also checked against Python.

Negative control: with Export.cpp and PendingExports.cpp from HEAD~1, guest_ces_chinese and guest_ces_chinese_module abort with sceCesUcsProfileInitGb18030_2000 not implemented and the other 12 tests pass. With the library restored but Gb18030.hpp regenerated from the current ICU 2000 file (after ICU-8427), both tests abort too. After restoring everything, all 14 pass.

python3 tools/progress.py --module libSceCesCs: 215/287 before, 217/287 after. python3 tools/check_conventions.py --base 15e71dbe11 passes. Not tested on a console, on Windows or with a title.

Hosted runs on my fork (GitHub runners), this branch 85ced7905 and the stack head c020ce893 as the base:

  • Ubuntu 24.04 x86-64, GCC 13.3, full build with the CI configure flags, tests on lavapipe: 1811/1815 with the change, 1811/1815 on the base; the same four fail on both (the three net_dontwait_blocking_* tests and the intermittent agc_driver_sgpr_pattern_fill_keys, #8708).
  • Windows Server 2025, WinLibs GCC 15.2.0, full build: it builds, and all 14 guest_ces* tests pass (14/14 on the base).

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: #8993, the top of simonbronk's stack #8967 -> #8972 -> #8976 -> #8993
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4953958377 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9210). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-21T15:19:00Z. --- ### What Implements `sceCesUcsProfileInitGb18030_2000` and `sceCesUcsProfileInitGb18030_2005`. simonbronk said on #8993 that GB 18030 is not on his list and that I can go ahead after the stack, so this branch carries his stack and only the top commit is new. - Signatures follow the [Orbital type database at b321fcd](https://github.com/AlexAltea/orbital/blob/b321fcdbd700cc02da1cb1ad25412781d5ec73c6/tools/ida/db_types.json): both are `union* (SceCesUcsProfileSheet* sheet)`, like `sceCesUcsProfileInitGbkCp936`, and they tag the sheet the same way. - Sources: - 2000: ICU's [gb-18030-2000.ucm at d9d3a6ed](https://github.com/unicode-org/icu-data/blob/d9d3a6ed27bb98a7106763e940258f0be8cd995b/charset/data/ucm/gb-18030-2000.ucm) with the `gb18030Ranges` of [ucnvmbcs.c at 39f9a868](https://github.com/unicode-org/icu/blob/39f9a8686ff29e0654f1fb0025cfcded20a80c99/icu4c/source/common/ucnvmbcs.c). I picked the revision before ICU-8427 on purpose. That ticket ([icu-data 91850aec](https://github.com/unicode-org/icu-data/commit/91850aec0209fee0f91248731c9dd4b2b768d2b5), [ICU 6206b737](https://github.com/unicode-org/icu/commit/6206b7369dee3784c95372fef01b678fb20e6c52)) copied the 2005 `0xA8BC` mapping into the 2000 file because ICU wanted an "updated GB18030 (2000 version)" as its built-in converter. The earlier revision is GB 18030-2000 as published, and it matches Python's `gb18030` codec on every sequence. The current 2000 file differs from it only in U+1E3F and U+E7C7. - 2005: [gb-18030-2005.ucm at 91850aec](https://github.com/unicode-org/icu-data/blob/91850aec0209fee0f91248731c9dd4b2b768d2b5/charset/data/ucm/gb-18030-2005.ucm) with the 14 `gb18030Ranges` of [ucnvmbcs.cpp at release-74-2](https://github.com/unicode-org/icu/blob/2d029329c82c7792b985024b2bdab5fc7278fbc8/icu4c/source/common/ucnvmbcs.cpp) (unchanged since ICU-8427). - Two-byte cells reuse the CP936 table from #8976. All 21,791 CP936 cells agree with both ucm files. The other 2,149 cells (the user-defined areas in the PUA and the GB 18030 additions such as `0xA2E3` U+20AC and `0xA8BF` U+01F9) are stored as runs: 111 for 2000, 118 for 2005. - Four-byte sequences are runs of (first linear index, first code point, count) built from the explicit ucm entries plus ICU's ranges: 206 BMP runs for 2000 and 208 for 2005, plus one run for `0x90308130`-`0xE3329A35` = U+10000-U+10FFFF. There is no per-character table for them. - `Gb18030.hpp` is generated by a script I did not commit. Before writing it, the script checks the runs against the ucm mapping on every two-byte cell, every four-byte sequence up to past `0xE3329A35` and every scalar. - 2000 vs 2005, from diffing the two ucm files, is 26 sequences: `0xA8BC` (U+E7C7 -> U+1E3F) and `0x8135F437` (U+1E3F -> U+E7C7); `A6D9`-`A6DF`, `A6EC`, `A6ED`, `A6F3` -> U+FE10-U+FE19; `FE59`, `FE61`, `FE66`, `FE67`, `FE6D`, `FE7E`, `FE90`, `FEA0` -> U+9FB4-U+9FBB; `FE51`, `FE52`, `FE53`, `FE6C`, `FE76`, `FE91` -> U+20087, U+20089, U+200CC, U+215D7, U+2298F, U+241FE. In the 2005 file the old PUA code points are `|1` fallbacks, so they still encode to those cells. The four-byte forms of U+FE10-U+FE19, U+9FB4-U+9FBB and the six ideographs still decode to them through ICU's ranges, but those characters encode to the two-byte cells, as ICU does. - `0x80` and `0xFF` are invalid leads (the `0x80` euro is GBK only). `0x8431A530`-`0x8F39FE39` and everything from `0xE3329A36` are well formed but unassigned. Errors follow the GBK forms: a bad second, third or fourth byte gives `INVALID_ENCODE`, a cut sequence `SRC_BUFFER_END`, an unassigned one `UNASSIGNED_CODE`, and outputs are untouched on failure. - Wiring: `isMbcs` accepts both profiles, `decodeMbcs` and `encodeMbcs` dispatch them, and the `sceCesGbTo*` and `sceCes*ToGb` forms accept them, since they take the same "Gb" profile as GBK and `sceCesGbUcsProfileSet4ByteCharRange` only makes sense for GB 18030. GB 18030 is the first profile that produces supplementary characters, so the MBCS encode buffers grow from 3 to 4 bytes, `encodeUtf8` writes 4-byte UTF-8, the UTF-16 outputs (the scalar forms, `sceCesMbcsStrToUtf16Str` and `sceCesMbcsStrGetUtf16Len`) write surrogate pairs, and the UCS-2 outputs answer `UNASSIGNED_CODE` for them as `sceCesUtf8ToUcs2` does. Nothing changes for the existing profiles. - Still throwing: `sceCesGbUcsProfileSet4ByteCharRange`, `sceCesGbUcsProfileSetUdaMapping` and `sceCesGbUcsProfileSetSbcs`. I found nothing that says which values they take or what they change. I assume the full ucm mapping is the default they would change, and the debt entry says so. - Debt: a new "GB 18030 profiles" entry in `docs/dev/debt/libSceCesCs.md` after the GBK one, gap first. I also dropped "GB 18030 four-byte forms" from the GBK entry's not-handled list and changed the pending-exports count from 72 to 70. Overlap: #9175 (my `*ToMbc` PR on the same stack) and #9107 edit nearby lines in `Export.cpp`, `PendingExports.cpp` and the debt file, and so does my strict JIS X 0208 profiles PR #9204 on the same stack. None of them implements these exports; whichever lands second needs a small rebase. ### 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. --> Ubuntu 24.04 x86-64 in a Docker container under Rosetta on an Apple M5 Mac, GCC 13.3, Release: ``` cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache ninja -C build -j4 libSceCesCs libSceCesCs-module guest_ces_{,dbcs_,unicode_,japanese_,wide_,chinese_,mbc_}{,module_}tests cd build && ctest -R guest_ces --output-on-failure ``` All 14 `guest_ces*` tests pass; `guest_ces_chinese` and `guest_ces_chinese_module` take 0.05 s each. I extended `GuestCesChinese.cpp` (the GBK and EUC-CN test) so that it checks, for both profiles: - every two-byte cell (23,940) decodes and encodes back to itself, and an FNV-1a hash of the decoded code points equals the one my script computed straight from the ucm; - every BMP four-byte sequence (39,420) decodes, with a matching hash; the sequences that do not encode back to themselves are 0 for 2000 and the 18 one-way forms above for 2005; - every BMP scalar from U+0080 encodes, with a matching hash of the bytes; the code points that do not decode back are 0 for 2000 and the 24 PUA fallbacks for 2005; - 1,052 supplementary sequences and 1,052 supplementary code points at a stride of 997, hashed, and 88 listed sequences in both directions: both ends of every ICU range and their neighbours, the first and last BMP sequence, U+n0000 and U+nFFFF of every supplementary plane, and the unassigned `8431A530`, `8F39FE39`, `E3329A36`, `FD308130` and `FE39FE39`; - the 26 sequences that differ between 2000 and 2005, both ways, and the 24 fallbacks; - `80`, `FF`, cut `81`, `81 30` and `81 30 81`, bad second bytes (`00`, `2F`, `3A`, `7F`, `FF`), bad third (`80`, `FF`, `30`) and fourth (`2F`, `3A`, `81`) bytes and unassigned sequences, through `sceCesGbToUtf32` and `sceCesMbcToUcs2`, with outputs and lengths untouched; - supplementary output: UCS-2 gives `UNASSIGNED_CODE`, UTF-8 gives 4 bytes, UTF-16 native, `be` and `le` give surrogate pairs, and short buffers give `DST_BUFFER_END` with nothing written; 4-byte UTF-8 and surrogate-pair UTF-16 into `sceCes*ToGb`; an MBCS context round trip through UTF-8, UTF-16 and the UTF-16 length form, and `UNASSIGNED_CODE` from `sceCesMbcsStrToUcs2Str`. Oracle: the ucm files are the primary oracle. As an independent check I compared both mappings with Python 3.14.8's `gb18030` codec on every two-byte cell, every four-byte sequence from `81308130` to past `E3329A35`, and every scalar. Python implements GB 18030-2000, not 2005: it matches the 2000 profile with no differences in either direction, and it differs from the 2005 profile in exactly the 26 decodes and 26 encodes listed above (it keeps `0xA8BC` = U+E7C7 and the PUA). The 2000 column of the 88 listed sequences was also checked against Python. Negative control: with `Export.cpp` and `PendingExports.cpp` from `HEAD~1`, `guest_ces_chinese` and `guest_ces_chinese_module` abort with `sceCesUcsProfileInitGb18030_2000 not implemented` and the other 12 tests pass. With the library restored but `Gb18030.hpp` regenerated from the current ICU 2000 file (after ICU-8427), both tests abort too. After restoring everything, all 14 pass. `python3 tools/progress.py --module libSceCesCs`: 215/287 before, 217/287 after. `python3 tools/check_conventions.py --base 15e71dbe11` passes. Not tested on a console, on Windows or with a title. Hosted runs on my fork (GitHub runners), this branch `85ced7905` and the stack head `c020ce893` as the base: - Ubuntu 24.04 x86-64, GCC 13.3, full build with the CI configure flags, tests on lavapipe: 1811/1815 with the change, 1811/1815 on the base; the same four fail on both (the three `net_dontwait_blocking_*` tests and the intermittent `agc_driver_sgpr_pattern_fill_keys`, #8708). - Windows Server 2025, WinLibs GCC 15.2.0, full build: it builds, and all 14 `guest_ces*` tests pass (14/14 on the base). ### 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: #8993, the top of simonbronk's stack #8967 -> #8972 -> #8976 -> #8993 <!-- #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 -->
ycbuzi commented 2026-10-21 20:49:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T20:49:18Z.


Windows run of 85ced79051 merged onto main 0c6a5bd593 (c34236ab75, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON.

Built libSceCesCs and the 14 guest_ces* test executables with no errors or warnings. ctest --repeat until-fail:2 on the 14 tests these executables register on Windows: all pass on both repeats. The 14 are the base guest_ces and the guest_ces_* tests and their _module variants (dbcs, unicode, japanese, wide, chinese, mbc). Not run: a title.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6326237110 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9210#issuecomment-6326237110). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-21T20:49:18Z. --- Windows run of 85ced79051 merged onto `main` 0c6a5bd593 (c34236ab75, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, `BUILD_TESTING=ON`. Built `libSceCesCs` and the 14 `guest_ces*` test executables with no errors or warnings. `ctest --repeat until-fail:2` on the 14 tests these executables register on Windows: all pass on both repeats. The 14 are the base `guest_ces` and the `guest_ces_*` tests and their `_module` variants (dbcs, unicode, japanese, wide, chinese, mbc). Not run: a title.
rooklz commented 2026-10-22 13:34:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T13:34:22Z.


Rebased onto current main (8b3e39832a): head 5f7e0da3bc, same diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6342075962 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9210#issuecomment-6342075962). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-22T13:34:22Z. --- Rebased onto current `main` (`8b3e39832a`): head `5f7e0da3bc`, same diff.
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!9210
No description provided.