feat(libSceJxr): implement the jxrlib SimpleBitIO reader #15148

Merged
r614 merged 1 commit from upstream-pr/15148 into main 2026-11-07 08:47:14 +00:00
r614 commented 2026-11-02 18:25:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by r614 on 2026-11-02T18:25:03Z.


What

Implements the five jxrlib SimpleBitIO exports of libSceJxr, which threw before: attach_SB, getBit32_SB, flushToByte_SB, getByteRead_SB and detach_SB.

They follow pinned jxrlib strcodec.c on a new 24-byte Jxr::SimpleBitIo with static_asserted offsets, matching jxrlib's LP64 SimpleBitIO.

getBit32_SB is written out rather than forwarded to native jxrlib, because it calls the stream's Read callback, which is guest code using the guest ABI. The call goes through the existing Jxr::Stream callback type, once per byte, with a GuestArena::HostWrite over the destination byte as in readIS. Its result is ignored, as jxrlib ignores it.

Where jxrlib reads through an invalid pointer, shifts by more than 31 or asserts, the export throws std::invalid_argument, as readIS/writeIS do: a null reader, a null stream or read callback when a byte is needed, more than 8 buffered bits, and buffered bits in detach_SB.

Console prototypes and layouts are unverified, and that the module is built from jxrlib is inferred from the export names, as for the existing entries.

This complements #14916 (merged), which covers the BitIOInfo bit I/O. SimpleBitIo.cpp carries jxrlib's licence notice, like Allocation.cpp and Export.cpp.

Tested

Windows 11, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r7), Release build. Linux and macOS were not built.

  • New guest_jxr_simple_bit_io:
    • A known big-endian pattern and the callback arguments.
    • Byte counting, flush and detach.
    • Every rejected argument, with checks that rejected calls leave the reader unchanged.
    • A differential run against native jxrlib built from the pinned submodule (GuestJxrSimpleBitIoReference.c, the same pattern as GuestJxrLookupReference.c): 1,250 random operations over 4 KiB: 1,172 reads of 0 to 40 bits (230 wider than 32) and 78 flushes. The result, byte count, accumulator and buffered bit count are compared after every call. The guest callback returns an error to show it is ignored.
  • Rebased on main 82fcf46d25: ctest -R guest_jxr 13/13 passed, including guest_jxr_bitio, guest_jxr_glue, guest_jxr_quantizer and the _patched lookup tests.
  • Mutating the implementation (bit count, accumulator shift, byte count, result shift) makes the test fail.
  • public_headers passes.
  • python3 tools/check_conventions.py --base origin/main passes.
  • python3 tools/pr_overlap.py --branch feat/jxr-simple-bit-io finds no other PR sharing an export or a new file. It could not compare #15645, #15646, #15684, #15771, #15772 and #15774, which conflict with main; their diffs touch none of these exports.
  • Not tested with a title or homebrew: no known title calls these exports.

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:5125327287 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15148). Originally posted by [r614](https://github.com/r614) on 2026-11-02T18:25:03Z. --- ### What Implements the five jxrlib `SimpleBitIO` exports of libSceJxr, which threw before: `attach_SB`, `getBit32_SB`, `flushToByte_SB`, `getByteRead_SB` and `detach_SB`. They follow pinned jxrlib [strcodec.c](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/strcodec.c#L604-L662) on a new 24-byte `Jxr::SimpleBitIo` with `static_assert`ed offsets, matching jxrlib's LP64 `SimpleBitIO`. `getBit32_SB` is written out rather than forwarded to native jxrlib, because it calls the stream's `Read` callback, which is guest code using the guest ABI. The call goes through the existing `Jxr::Stream` callback type, once per byte, with a `GuestArena::HostWrite` over the destination byte as in `readIS`. Its result is ignored, as jxrlib ignores it. Where jxrlib reads through an invalid pointer, shifts by more than 31 or asserts, the export throws `std::invalid_argument`, as `readIS`/`writeIS` do: a null reader, a null stream or read callback when a byte is needed, more than 8 buffered bits, and buffered bits in `detach_SB`. Console prototypes and layouts are unverified, and that the module is built from jxrlib is inferred from the export names, as for the existing entries. This complements #14916 (merged), which covers the `BitIOInfo` bit I/O. `SimpleBitIo.cpp` carries jxrlib's licence notice, like `Allocation.cpp` and `Export.cpp`. ### Tested Windows 11, WinLibs GCC 15.2.0 (`x86_64-ucrt-posix-seh`, r7), Release build. Linux and macOS were not built. - New `guest_jxr_simple_bit_io`: - A known big-endian pattern and the callback arguments. - Byte counting, flush and detach. - Every rejected argument, with checks that rejected calls leave the reader unchanged. - A differential run against native jxrlib built from the pinned submodule (`GuestJxrSimpleBitIoReference.c`, the same pattern as `GuestJxrLookupReference.c`): 1,250 random operations over 4 KiB: 1,172 reads of 0 to 40 bits (230 wider than 32) and 78 flushes. The result, byte count, accumulator and buffered bit count are compared after every call. The guest callback returns an error to show it is ignored. - Rebased on `main` 82fcf46d25: `ctest -R guest_jxr` 13/13 passed, including `guest_jxr_bitio`, `guest_jxr_glue`, `guest_jxr_quantizer` and the `_patched` lookup tests. - Mutating the implementation (bit count, accumulator shift, byte count, result shift) makes the test fail. - `public_headers` passes. - `python3 tools/check_conventions.py --base origin/main` passes. - `python3 tools/pr_overlap.py --branch feat/jxr-simple-bit-io` finds no other PR sharing an export or a new file. It could not compare #15645, #15646, #15684, #15771, #15772 and #15774, which conflict with `main`; their diffs touch none of these exports. - Not tested with a title or homebrew: no known title calls these exports. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
BunnyFl commented 2026-11-02 20:28:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T20:28:02Z.

Review: APPROVED


Matches pinned jxrlib strcodec.c line for line: attach_SB zeroes the three counters, getBit32_SB has the same shift-and-refill loop (one Read of one byte per refill, result ignored), flushToByte_SB clears the accumulator and bit count, getByteRead_SB returns cbRead, and detach_SB clears the stream where jxrlib asserts cBitLeft == 0. The layout matches strcodec.h (pWS, U32 cbRead, U8 bAccumulator, U32 cBitLeft: offsets 0, 8, 12, 16 and 24 bytes on LP64). ERR is long in windowsmediaphoto.h, so the std::int64_t returns fit.

Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged onto main: all 10 guest_jxr* tests pass, nothing skipped. With main's Export.cpp and Api.hpp, the new test doesn't build against the old stubs.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5742872246 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15148#pullrequestreview-5742872246). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T20:28:02Z. **Review:** APPROVED --- Matches pinned jxrlib [strcodec.c](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/strcodec.c#L604-L662) line for line: `attach_SB` zeroes the three counters, `getBit32_SB` has the same shift-and-refill loop (one `Read` of one byte per refill, result ignored), `flushToByte_SB` clears the accumulator and bit count, `getByteRead_SB` returns `cbRead`, and `detach_SB` clears the stream where jxrlib asserts `cBitLeft == 0`. The layout matches [strcodec.h](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/strcodec.h#L560-L566) (`pWS`, `U32 cbRead`, `U8 bAccumulator`, `U32 cBitLeft`: offsets 0, 8, 12, 16 and 24 bytes on LP64). `ERR` is `long` in [windowsmediaphoto.h](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/windowsmediaphoto.h#L243), so the `std::int64_t` returns fit. Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged onto `main`: all 10 `guest_jxr*` tests pass, nothing skipped. With `main`'s `Export.cpp` and `Api.hpp`, the new test doesn't build against the old stubs.
BunnyFl commented 2026-11-06 16:34:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-06T16:34:40Z.

Review: APPROVED


@r614 re-checked at e4779042ae. My approval was on 52e4f47616.

git range-diff 52e4f47616~1..52e4f47616 e4779042ae~1..e4779042ae lists two changes:

  • Rebase onto current main: the new source joins main's longer libSceJxr source list in CMakeLists.txt, and the removed stubs and declarations now sit between main's newer neighbours in Export.cpp and include/Api.hpp. The code of src/SimpleBitIo.cpp is the same as what I approved.
  • Licence notice: src/SimpleBitIo.cpp:1-27 now carries jxrlib's Microsoft copyright and BSD notice. That's the same block main's core/libs/prx/libSceJxr/src/Allocation.cpp starts with (its line 3 is the same Copyright © Microsoft Corp. line), so it follows that file's precedent.

The count is still right after the rebase. The debt line says "The 88 remaining additional stubs" (docs/dev/debt/libSceJxr.md:41 at e4779042ae). In the tree merged with main 23d549a9c7, Export.cpp has 88 throwing stubs (93 on main).

What I ran. This head merged onto main 23d549a9c7 (merge c166002a8f, clean), Windows 11 Pro, WinLibs GCC, Release:

  • ^guest_jxr: 13 of 13 pass, none unbuilt.
  • Putting back main's Export.cpp and include/Api.hpp makes JxrSimpleBitIo.cpp fail to build against the old parameterless stubs, as before.
  • Two mutations of src/SimpleBitIo.cpp on the merge, each rebuilt and run; both fail guest_jxr_simple_bit_io:
    • dropping ++io->bytesRead in getBit32_SB;
    • dropping the accumulator shift after a read.
  • tools/pr_overlap.py --branch at this head: no other PR changes the same exports. The line conflicts are libSceJxr neighbours: the source list, the stub declarations next to these five, and the debt count line every libSceJxr PR edits. Seven PRs couldn't be compared (#15232, #15645, #15646, #15771, #15772, #15774, #16300); none of their GitHub patches has a changed line naming attach_SB, getBit32_SB, flushToByte_SB, getByteRead_SB or detach_SB.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5803529628 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15148#pullrequestreview-5803529628). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-06T16:34:40Z. **Review:** APPROVED --- @r614 re-checked at `e4779042ae`. My approval was on `52e4f47616`. `git range-diff 52e4f47616~1..52e4f47616 e4779042ae~1..e4779042ae` lists two changes: - **Rebase onto current `main`:** the new source joins `main`'s longer `libSceJxr` source list in `CMakeLists.txt`, and the removed stubs and declarations now sit between `main`'s newer neighbours in `Export.cpp` and `include/Api.hpp`. The code of `src/SimpleBitIo.cpp` is the same as what I approved. - **Licence notice:** `src/SimpleBitIo.cpp:1-27` now carries jxrlib's Microsoft copyright and BSD notice. That's the same block `main`'s `core/libs/prx/libSceJxr/src/Allocation.cpp` starts with (its line 3 is the same `Copyright © Microsoft Corp.` line), so it follows that file's precedent. The count is still right after the rebase. The debt line says "The 88 remaining additional stubs" (`docs/dev/debt/libSceJxr.md:41` at `e4779042ae`). In the tree merged with `main` `23d549a9c7`, `Export.cpp` has 88 throwing stubs (93 on `main`). **What I ran.** This head merged onto `main` `23d549a9c7` (merge `c166002a8f`, clean), Windows 11 Pro, WinLibs GCC, Release: - `^guest_jxr`: 13 of 13 pass, none unbuilt. - Putting back `main`'s `Export.cpp` and `include/Api.hpp` makes `JxrSimpleBitIo.cpp` fail to build against the old parameterless stubs, as before. - Two mutations of `src/SimpleBitIo.cpp` on the merge, each rebuilt and run; both fail `guest_jxr_simple_bit_io`: - dropping `++io->bytesRead` in `getBit32_SB`; - dropping the accumulator shift after a read. - `tools/pr_overlap.py --branch` at this head: no other PR changes the same exports. The line conflicts are `libSceJxr` neighbours: the source list, the stub declarations next to these five, and the debt count line every `libSceJxr` PR edits. Seven PRs couldn't be compared (#15232, #15645, #15646, #15771, #15772, #15774, #16300); none of their GitHub patches has a changed line naming `attach_SB`, `getBit32_SB`, `flushToByte_SB`, `getByteRead_SB` or `detach_SB`. AI-assisted: yes (Claude Code)
BunnyFl commented 2026-11-06 19:50:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-06T19:50:29Z.

Review: APPROVED


@r614 re-checked at 3150e49dae. My approval was on e4779042ae.

git range-diff e4779042ae~1..e4779042ae 3150e49dae~1..3150e49dae shows a rebase onto current main with one change in the PR's own lines: the debt count line. main now has 92 throwing libSceJxr stubs (93 when I approved), and the line now says "The 87 remaining additional stubs" (docs/dev/debt/libSceJxr.md:43 at 3150e49dae). I recounted from the files: Export.cpp has 92 NotImplemented_nid_no_patch stubs on main c9f43dfa1d and 87 at 3150e49dae, so 87 is right. src/SimpleBitIo.cpp and the test are unchanged.

What I ran. This head merged onto main c9f43dfa1d (merge cbd5c97fd9, clean), Windows 11 Pro, WinLibs GCC, Release:

  • ^guest_jxr: 13 of 13 pass, none unbuilt.
  • Putting back main's Export.cpp and include/Api.hpp makes JxrSimpleBitIo.cpp fail to build against the old parameterless stubs, as before.
  • The same two mutations of src/SimpleBitIo.cpp, each rebuilt and run; both fail guest_jxr_simple_bit_io:
    • dropping ++io->bytesRead in getBit32_SB;
    • dropping the accumulator shift after a read.
  • tools/pr_overlap.py --branch at this head: 34 libSceJxr PRs couldn't be compared because they conflict with main. I read each one's GitHub patch: none has a changed line naming attach_SB, getBit32_SB, flushToByte_SB, getByteRead_SB or detach_SB. The shared files are the stub declarations, the source list and the debt count line that every libSceJxr PR edits.
  • tools/check_conventions.py --base upstream/main at this head: all checks pass.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5806081148 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15148#pullrequestreview-5806081148). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-06T19:50:29Z. **Review:** APPROVED --- @r614 re-checked at `3150e49dae`. My approval was on `e4779042ae`. `git range-diff e4779042ae~1..e4779042ae 3150e49dae~1..3150e49dae` shows a rebase onto current `main` with one change in the PR's own lines: the debt count line. `main` now has 92 throwing `libSceJxr` stubs (93 when I approved), and the line now says "The 87 remaining additional stubs" (`docs/dev/debt/libSceJxr.md:43` at `3150e49dae`). I recounted from the files: `Export.cpp` has 92 `NotImplemented_nid_no_patch` stubs on `main` `c9f43dfa1d` and 87 at `3150e49dae`, so 87 is right. `src/SimpleBitIo.cpp` and the test are unchanged. **What I ran.** This head merged onto `main` `c9f43dfa1d` (merge `cbd5c97fd9`, clean), Windows 11 Pro, WinLibs GCC, Release: - `^guest_jxr`: 13 of 13 pass, none unbuilt. - Putting back `main`'s `Export.cpp` and `include/Api.hpp` makes `JxrSimpleBitIo.cpp` fail to build against the old parameterless stubs, as before. - The same two mutations of `src/SimpleBitIo.cpp`, each rebuilt and run; both fail `guest_jxr_simple_bit_io`: - dropping `++io->bytesRead` in `getBit32_SB`; - dropping the accumulator shift after a read. - `tools/pr_overlap.py --branch` at this head: 34 `libSceJxr` PRs couldn't be compared because they conflict with `main`. I read each one's GitHub patch: none has a changed line naming `attach_SB`, `getBit32_SB`, `flushToByte_SB`, `getByteRead_SB` or `detach_SB`. The shared files are the stub declarations, the source list and the debt count line that every `libSceJxr` PR edits. - `tools/check_conventions.py --base upstream/main` at this head: all checks pass. AI-assisted: yes (Claude Code)
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!15148
No description provided.