feat(libSceJxr): implement bit I/O through the pinned jxrlib #14916

Merged
Noxy-HNR merged 7 commits from upstream-pr/14916 into main 2026-11-05 23:07:49 +00:00
Noxy-HNR commented 2026-11-02 01:16:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Noxy-HNR on 2026-11-02T01:16:22Z.


What

Sixteen libSceJxr bit reader/writer exports currently throw: peekBit16, flushBit16, getBit16, getBool16, getBit16s, getBit32, flushToByte, putBit16z, putBit16, putBit32, fillToByte, getBit16_S, getSizeRead, getSizeWrite, getPosRead and dquantBits.

They now call the non-ARM bit I/O in strcodec.c, built from 3rdparty/jxrlib, through a C bridge (src/NativeBitIo.c) on the existing guest Jxr::BitIo / BitIOInfo layout (48 bytes). No jxrlib logic is copied into core/.

The C++ adapters reject bit counts over 16 (15 for getBit16s, 32 for getBit32/putBit32), a putBit16z value wider than its count, an odd read wrap mask, a write position of 16 bits or more, a write pointer not aligned for a 16-bit store, and a null state or current pointer. getBit16_S is getBit16 followed by the existing readIS, as jxrlib's readIS_L1 is readIS.

Review fix 369b743519 defines the accepted boundaries that jxrlib leaves undefined in C. A zero-bit peek returns 0; zero-bit getBit16/getBit32 use the defined flushBit16(0) path and return 0. An empty store or byte fill at a word boundary leaves the state and buffer unchanged. Masked writes use unsigned masks and the dependency's putBit16z, in 16-bit parts for a 32-bit write. The unmodified strcodec.c and segdec.c are built with jxrlib's existing aligned-load branch through a per-file _M_IA64 definition. The implementation remains in the pinned submodule. Follow-up 99a3aaaf67 rejects odd byte write positions before changing state or memory; these otherwise reach an undefined U16 store in the dependency.

That the console's module uses these prototypes is inferred from the export names; nothing is checked on a console. The debt file records these inferred contracts and the defined boundary behavior that still needs console verification. No title unblock is claimed.

Tested

Latest independent verification at 99a3aaaf67: Windows 11 x86-64, WinLibs GCC 15.2.0, Release. Rebuilt guest_jxr_bitio_tests, guest_jxr_stream_tests and guest_jxr_tests; 3/3 passed.

Linux source-level sanitizer probe: Ubuntu 26.04, GCC 15.2.0, -fsanitize=undefined -fno-sanitize-recover=all, UBSAN_OPTIONS=halt_on_error=1, using the exact adapter, C bridge and pinned native bit functions. Zero-bit reads, word-boundary stores, unsigned masking, 20/32-bit writes and 2-byte-aligned read positions pass without a sanitizer diagnostic. The same probe using the pre-fix adapter/bridge from f3a9091e51 stops on the native shift by 32. The expanded probe also detects an undefined odd-position store at 369b743519; 99a3aaaf67 rejects that input without a sanitizer report. The Windows regression covers all four write/fill entry points at bit positions 0, 1, 8 and 15 and checks unchanged state and buffer after rejection. This is a focused source probe, not a full Linux guest-runtime run.

Earlier reported validation:

New guest_jxr_bitio test:

  • 128 rounds of 2,000 random reads or writes on a 16 KiB-aligned ring buffer, run through the guest exports and through jxrlib directly. Each step compares the results, accumulator, bit count, wrap position, reference offset and the whole buffer.

  • dquantBits for all 256 inputs.

  • A read wrapping at the ring end, and getBit16_S with and without a packet crossing.

  • Every rejected argument.

  • Linux x86-64 (Ubuntu 24.04, GCC 13), Release, upstream 93dbd0f82a: ctest -R guest_jxr 10/10 passed.

  • Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release: ctest -R guest_jxr 10/10 passed, including the _patched lookup tests against the patched libSceJxr.prx.

  • python tools/check_conventions.py --base upstream/main, git diff --check and python core/libs/tests/test_public_headers.py --audit-only (399 libraries, 26,813 exports): passed.

  • python tools/pr_overlap.py --branch claude/jxr-bitio (1,859 open PRs): #14425, #14631 and #14905 touch neighbouring lines of CMakeLists.txt, include/Api.hpp and the debt file. None shares an export or a new file. Merge order is #14905, then this PR, then #14933. Their implementations are functionally independent, but the combined branches conflict in shared files; each later PR needs a rebase and focused tests after its prerequisites merge. The checklist records this integration order.

No console or retail-title test.

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: #14905
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5113468053 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14916). Originally posted by [Noxy-HNR](https://github.com/Noxy-HNR) on 2026-11-02T01:16:22Z. --- ### What Sixteen libSceJxr bit reader/writer exports currently throw: `peekBit16`, `flushBit16`, `getBit16`, `getBool16`, `getBit16s`, `getBit32`, `flushToByte`, `putBit16z`, `putBit16`, `putBit32`, `fillToByte`, `getBit16_S`, `getSizeRead`, `getSizeWrite`, `getPosRead` and `dquantBits`. They now call the non-ARM bit I/O in [strcodec.c](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/strcodec.c#L905-L1061), built from `3rdparty/jxrlib`, through a C bridge (`src/NativeBitIo.c`) on the existing guest `Jxr::BitIo` / `BitIOInfo` layout (48 bytes). No jxrlib logic is copied into `core/`. The C++ adapters reject bit counts over 16 (15 for `getBit16s`, 32 for `getBit32`/`putBit32`), a `putBit16z` value wider than its count, an odd read wrap mask, a write position of 16 bits or more, a write pointer not aligned for a 16-bit store, and a null state or current pointer. `getBit16_S` is `getBit16` followed by the existing `readIS`, as jxrlib's `readIS_L1` is `readIS`. Review fix `369b743519` defines the accepted boundaries that jxrlib leaves undefined in C. A zero-bit peek returns 0; zero-bit `getBit16`/`getBit32` use the defined `flushBit16(0)` path and return 0. An empty store or byte fill at a word boundary leaves the state and buffer unchanged. Masked writes use unsigned masks and the dependency's `putBit16z`, in 16-bit parts for a 32-bit write. The unmodified `strcodec.c` and `segdec.c` are built with jxrlib's existing aligned-load branch through a per-file `_M_IA64` definition. The implementation remains in the pinned submodule. Follow-up `99a3aaaf67` rejects odd byte write positions before changing state or memory; these otherwise reach an undefined `U16` store in the dependency. That the console's module uses these prototypes is inferred from the export names; nothing is checked on a console. The debt file records these inferred contracts and the defined boundary behavior that still needs console verification. No title unblock is claimed. ### 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. --> Latest independent verification at `99a3aaaf67`: Windows 11 x86-64, WinLibs GCC 15.2.0, Release. Rebuilt `guest_jxr_bitio_tests`, `guest_jxr_stream_tests` and `guest_jxr_tests`; **3/3 passed**. Linux source-level sanitizer probe: Ubuntu 26.04, GCC 15.2.0, `-fsanitize=undefined -fno-sanitize-recover=all`, `UBSAN_OPTIONS=halt_on_error=1`, using the exact adapter, C bridge and pinned native bit functions. Zero-bit reads, word-boundary stores, unsigned masking, 20/32-bit writes and 2-byte-aligned read positions pass without a sanitizer diagnostic. The same probe using the pre-fix adapter/bridge from `f3a9091e51` stops on the native shift by 32. The expanded probe also detects an undefined odd-position store at `369b743519`; `99a3aaaf67` rejects that input without a sanitizer report. The Windows regression covers all four write/fill entry points at bit positions 0, 1, 8 and 15 and checks unchanged state and buffer after rejection. This is a focused source probe, not a full Linux guest-runtime run. Earlier reported validation: New `guest_jxr_bitio` test: - 128 rounds of 2,000 random reads or writes on a 16 KiB-aligned ring buffer, run through the guest exports and through jxrlib directly. Each step compares the results, accumulator, bit count, wrap position, reference offset and the whole buffer. - `dquantBits` for all 256 inputs. - A read wrapping at the ring end, and `getBit16_S` with and without a packet crossing. - Every rejected argument. - Linux x86-64 (Ubuntu 24.04, GCC 13), Release, upstream `93dbd0f82a`: `ctest -R guest_jxr` **10/10 passed**. - Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release: `ctest -R guest_jxr` **10/10 passed**, including the `_patched` lookup tests against the patched `libSceJxr.prx`. - `python tools/check_conventions.py --base upstream/main`, `git diff --check` and `python core/libs/tests/test_public_headers.py --audit-only` (399 libraries, 26,813 exports): passed. - `python tools/pr_overlap.py --branch claude/jxr-bitio` (1,859 open PRs): #14425, #14631 and #14905 touch neighbouring lines of `CMakeLists.txt`, `include/Api.hpp` and the debt file. None shares an export or a new file. Merge order is #14905, then this PR, then #14933. Their implementations are functionally independent, but the combined branches conflict in shared files; each later PR needs a rebase and focused tests after its prerequisites merge. The checklist records this integration order. No console or retail-title test. ### 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: #14905 <!-- #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 -->
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!14916
No description provided.