feat(libSceJsc): implement WTF::BitVector::filterSlow #19193

Merged
c1b3r-p3d1a merged 4 commits from upstream-pr/19193 into main 2026-11-13 10:47:17 +00:00
c1b3r-p3d1a commented 2026-11-12 23:29:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by c1b3r-p3d1a on 2026-11-12T23:29:00Z.


What

Implements WTF::BitVector::filterSlow(const BitVector&) (the out-of-line half of BitVector::filter, an in-place AND) in libSceJsc, which threw. It is ported from WebKit's BitVector.cpp at c55364d53f97, the revision libSceJsc's other WTF code follows. The new src/WtfBitVector.cpp starts with that file's licence notice (BSD-2-Clause) under a Derived from line.

The one-word layout follows BitVector.h: the inline flag is bit 63, out-of-line storage is the word shifted left by one, and a 64-bit bit count comes before the words. The three branches are kept as written:

  • Other vector inline: only the first out-of-line word of this vector is ANDed with the other's bits, flag cleared. The rest is left as is, as upstream does.
  • This vector inline: AND with the other's first word, then set the inline flag again.
  • Both out-of-line: AND the common words, then clear the words of this vector past the other's word count. The bit count is unchanged.

Where WebKit only asserts or would read through an invalid pointer, the export throws std::invalid_argument before writing: both vectors inline (the inline filter never calls filterSlow then), an empty (0) or deleted (1) vector read as out-of-line, and null arguments. The debt entry records what is unverified (console WTF version). The "throwing exports" count drops from 139 to 138.

Tested

Windows 11, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh r7), Release.

  • New jsc_wtf_bit_vector builds out-of-line vectors in aligned buffers with guard words. It covers an inline other vector, with a three-word target where only word 0 changes and with the other's flag bit not leaking in. It covers an inline target against an out-of-line vector whose first word has bit 63 set and clear (flag restored, other unchanged). It covers out-of-line pairs with longer and shorter targets at bit counts 130/65, 128/192 and 1/1: common words ANDed, the extra word cleared, guard words and bit counts untouched. It also checks that every invalid case throws with nothing written.
  • The test fails with each of these mutations: the old throwing stub; OR instead of AND; the tail not cleared; the inline flag not restored; the inline other's flag not cleared; the word count rounded down; the both-inline check dropped; the empty/deleted check dropped.
  • Disassembly of the built libSceJsc.prx: self in rdi, other in rsi, the inline test is the sign bit, storage is the word times 2, and the word count is (numBits + 63) >> 6.
  • The licence block is byte-identical to lines 1-24 of the pinned BitVector.cpp (cmp).
  • Rebased on main 3ba8523c06: all libSceJsc and public_headers tests pass (74 total); python tools/check_conventions.py --base origin/main passes.
  • On Windows a rebuilt libSceJsc.prx is not copied over the one staged in build/tests (#17895), so I copied it there before each run.
  • Not run: the full suite, Linux, a console.

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

Note for whoever merges after this: git merges this branch with #18430, #18442, #19104 or #14212 without a conflict, but the result has two copies of the "N throwing JavaScriptCore, Inspector, WTF and bmalloc exports" line in docs/dev/debt/libSceJsc.md. A change to that count alone does the same, so it comes from how those branches rewrite that section. After a merge, keep one line with the recomputed count. I will rebase and recompute it if one of them merges first.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5287028081 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19193). Originally posted by [c1b3r-p3d1a](https://github.com/c1b3r-p3d1a) on 2026-11-12T23:29:00Z. --- ### What Implements `WTF::BitVector::filterSlow(const BitVector&)` (the out-of-line half of `BitVector::filter`, an in-place AND) in libSceJsc, which threw. It is ported from WebKit's [BitVector.cpp](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WTF/wtf/BitVector.cpp#L130-L153) at `c55364d53f97`, the revision libSceJsc's other WTF code follows. The new `src/WtfBitVector.cpp` starts with that file's licence notice (BSD-2-Clause) under a `Derived from` line. The one-word layout follows [BitVector.h](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WTF/wtf/BitVector.h#L432-L486): the inline flag is bit 63, out-of-line storage is the word shifted left by one, and a 64-bit bit count comes before the words. The three branches are kept as written: - Other vector inline: only the first out-of-line word of this vector is ANDed with the other's bits, flag cleared. The rest is left as is, as upstream does. - This vector inline: AND with the other's first word, then set the inline flag again. - Both out-of-line: AND the common words, then clear the words of this vector past the other's word count. The bit count is unchanged. Where WebKit only asserts or would read through an invalid pointer, the export throws `std::invalid_argument` before writing: both vectors inline (the inline `filter` never calls `filterSlow` then), an empty (0) or deleted (1) vector read as out-of-line, and null arguments. The debt entry records what is unverified (console WTF version). The "throwing exports" count drops from 139 to 138. ### 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. --> Windows 11, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh r7), Release. - New `jsc_wtf_bit_vector` builds out-of-line vectors in aligned buffers with guard words. It covers an inline other vector, with a three-word target where only word 0 changes and with the other's flag bit not leaking in. It covers an inline target against an out-of-line vector whose first word has bit 63 set and clear (flag restored, other unchanged). It covers out-of-line pairs with longer and shorter targets at bit counts 130/65, 128/192 and 1/1: common words ANDed, the extra word cleared, guard words and bit counts untouched. It also checks that every invalid case throws with nothing written. - The test fails with each of these mutations: the old throwing stub; OR instead of AND; the tail not cleared; the inline flag not restored; the inline other's flag not cleared; the word count rounded down; the both-inline check dropped; the empty/deleted check dropped. - Disassembly of the built `libSceJsc.prx`: `self` in `rdi`, `other` in `rsi`, the inline test is the sign bit, storage is the word times 2, and the word count is `(numBits + 63) >> 6`. - The licence block is byte-identical to lines 1-24 of the pinned `BitVector.cpp` (`cmp`). - Rebased on `main` `3ba8523c06`: all libSceJsc and `public_headers` tests pass (74 total); `python tools/check_conventions.py --base origin/main` passes. - On Windows a rebuilt `libSceJsc.prx` is not copied over the one staged in `build/tests` (#17895), so I copied it there before each run. - Not run: the full suite, Linux, a console. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes Note for whoever merges after this: git merges this branch with #18430, #18442, #19104 or #14212 without a conflict, but the result has two copies of the "N throwing JavaScriptCore, Inspector, WTF and bmalloc exports" line in `docs/dev/debt/libSceJsc.md`. A change to that count alone does the same, so it comes from how those branches rewrite that section. After a merge, keep one line with the recomputed count. I will rebase and recompute it if one of them merges first.
MarcZX10 commented 2026-11-13 00:08:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-13T00:08:12Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional. The change implements WTF::BitVector::filterSlow in libSceJsc, and I found no defect in the code I read. Nothing was built or run here.

What I ran

  • Head: 1e0786e55de7511516b2b32453bcb09590825886, base main.
  • Read the description, commit list, manifest, and the full diff. No builds, no tests.
  • Repository searches with the reader:
python3 repo_read.py search filterSlow
python3 repo_read.py search configure_windows_unwind
python3 repo_read.py search "define APS5_VABI"
python3 repo_read.py search "omment" docs/dev/CONVENTIONS.md
python3 repo_read.py search "Copyright" core/libs/prx/libSceJsc

Results

Check Result Note
Diff read passed 8 of 8 files covered
Old stub removed passed No stale declaration in Export.cpp or Api.hpp
Helpers and macro exist passed configure_windows_unwind, APS5_VABI
Comment rule passed Licence header matches WtfStringSearch.cpp
Build and tests not run No builds in this review
check_conventions.py not run Author reports a pass

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceJsc/src/WtfBitVector.cpp:87 narrows the std::size_t word count to unsigned. This only matters above 2^38 bits. The second loop, a few lines below, has the same narrowing.
    for (std::size_t i = std::min(NumWords(a), NumWords(b)); i--;)

Sources

No WebKit behaviour claim was checked. The pinned permalinks in the description and in docs/dev/debt/libSceJsc.md were not opened.

Not verified

  • No build or test run. The Windows results and the mutation runs are the author's report, not run here.
  • Negative control: not run. The author's list of mutations is author-reported only.
  • Full text of Export.cpp, Api.hpp, CMakeLists.txt and libSceJsc.hpp was not read. Only their hunks in the diff were.
  • The licence block was not compared byte for byte with upstream BitVector.cpp.
  • The count change from 139 to 138 in the debt file was not recounted.
  • Console behaviour of the export is unverified, as the debt entry states.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5884071264 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19193#pullrequestreview-5884071264). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-13T00:08:12Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. The change implements `WTF::BitVector::filterSlow` in libSceJsc, and I found no defect in the code I read. Nothing was built or run here. ## What I ran - Head: `1e0786e55de7511516b2b32453bcb09590825886`, base `main`. - Read the description, commit list, manifest, and the full diff. No builds, no tests. - Repository searches with the reader: ``` python3 repo_read.py search filterSlow python3 repo_read.py search configure_windows_unwind python3 repo_read.py search "define APS5_VABI" python3 repo_read.py search "omment" docs/dev/CONVENTIONS.md python3 repo_read.py search "Copyright" core/libs/prx/libSceJsc ``` ## Results | Check | Result | Note | | --- | --- | --- | | Diff read | passed | 8 of 8 files covered | | Old stub removed | passed | No stale declaration in `Export.cpp` or `Api.hpp` | | Helpers and macro exist | passed | `configure_windows_unwind`, `APS5_VABI` | | Comment rule | passed | Licence header matches `WtfStringSearch.cpp` | | Build and tests | not run | No builds in this review | | `check_conventions.py` | not run | Author reports a pass | ## Findings **Blocking** None. **Non-blocking** - `core/libs/prx/libSceJsc/src/WtfBitVector.cpp:87` narrows the `std::size_t` word count to `unsigned`. This only matters above 2^38 bits. The second loop, a few lines below, has the same narrowing. ```suggestion for (std::size_t i = std::min(NumWords(a), NumWords(b)); i--;) ``` ## Sources No WebKit behaviour claim was checked. The pinned permalinks in the description and in `docs/dev/debt/libSceJsc.md` were not opened. ## Not verified - No build or test run. The Windows results and the mutation runs are the author's report, not run here. - Negative control: not run. The author's list of mutations is author-reported only. - Full text of `Export.cpp`, `Api.hpp`, `CMakeLists.txt` and `libSceJsc.hpp` was not read. Only their hunks in the diff were. - The licence block was not compared byte for byte with upstream `BitVector.cpp`. - The count change from 139 to 138 in the debt file was not recounted. - Console behaviour of the export is unverified, as the debt entry states. ## To get this to a good state Nothing is required.
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!19193
No description provided.