Skip to content

feat(libSceJxr): implement the BitIOInfo bit writer helpers - #15402

Closed
Jawschamp wants to merge 1 commit into
boykopovar:mainfrom
Jawschamp:feat/jxr-bit-writer
Closed

Jawschamp wants to merge 1 commit into
boykopovar:mainfrom
Jawschamp:feat/jxr-bit-writer

Conversation

@Jawschamp

Copy link
Copy Markdown
Contributor

What

Implements putBit16z, putBit16, putBit32, fillToByte, getSizeRead, getSizeWrite and getPosRead (libSceJxr) over the BitIOInfo layout already used by readIS and writeIS, following the non-ARM bit writer and size helpers in the pinned jxrlib strcodec.c (f7521879862b9085318e814c6157490dd9dbbdb4, lines 980-1060). They threw NotImplemented_nid_no_patch as parameterless placeholders before; those and their declarations are replaced by real prototypes, and docs/dev/debt/libSceJxr.md goes from 132 to 125 additional exports.

  • Each write adds the bits to the 32-bit accumulator, stores the big-endian halfword ending at the current bit position, then advances the cursor by (bitsUsed >> 3) & 2 bytes through the iMask pointer mask and keeps bitsUsed & 15. putBit32 splits widths above 16, fillToByte pads with putBit16z(0, (16 - bitsUsed) & 7), and the size helpers compute the ring-buffer distances of the reference.
  • Where the reference asserts or has undefined behaviour, std::invalid_argument is thrown and the state is left unchanged: a null state, a width above 16 (32 for putBit32), a value wider than its width in putBit16z, and a null cursor before or after the write. With no pending bit and a width of 0 the reference shifts by 32, which is undefined; the x86-64 result is reproduced and checked against the native build. This is listed in the debt doc with a pinned source link. The prototypes are inferred from the shared names; nothing was measured on a PS5.
  • Not included: flushToByte (needs flushBit16 from the reader, which is a separate change), so it still throws. This PR is based on main and does not depend on the reader code.
  • New guest test guest_jxr_bit_writer checks hand-computed bytes and states, the size helpers, ring wrap-around and the rejected arguments, then runs 256,000 random operations against the natively built vendored jxrlib on identical state and compares results, all 48 bytes of state and the whole 8 KiB ring after every step.

Tested

Linux x86_64, GCC 14.2 (g++ extracted from Debian trixie packages), -DBUILD_TESTING=ON, full configure with all submodules. Hardware and titles: not tested.

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

@Jawschamp Jawschamp closed this Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Progress report (d1ae628 → d2f6368)

📈 System libraries: 26.49% (+0.02%, +7 implemented functions)

✅ 7 implemented
Library Name
libSceJxr fillToByte_nid_postfix
libSceJxr getPosRead_nid_postfix
libSceJxr getSizeRead_nid_postfix
libSceJxr getSizeWrite_nid_postfix
libSceJxr putBit16_nid_postfix
libSceJxr putBit16z_nid_postfix
libSceJxr putBit32_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceJxr 4/136 (2.94%) 11/136 (8.09%) +5.15%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant