tools: a short carry form's SGPR source is not its carry destination (CENSUS-SHORT-CARRY-SRC) #2837

Closed
Neutron-0 wants to merge 2 commits from upstream-pr/2837 into main
Neutron-0 commented 2026-12-01 05:32:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-01T05:32:16Z.


Claimed in the coordination issue as: CENSUS-SHORT-CARRY-SRC (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7301864505)

What and why

tools/image_bvh_census.py builds the SGPR literal map (sgpr_step) and the per-instruction write set (mask_writes). Both took operand a[1] of every _co_ op (and v_div_scale) as the carry/scale destination. The three-operand carry forms - v_add_co_ci_u32 v1, s8, v2 - print dst, src0, src1 with VCC implicit, so a[1] is a source: s8's literal was dropped and a ray-intersection site reading descriptor s[8:11] reported word 0 as unknown. The explicit-VCC spelling of the same bytes (v_add_co_ci_u32_e32 v1, vcc, s8, v2, vcc) kept it, which is how the bug showed up (item 2 of the pre-existing finding in the coordination issue).

a[1] is now taken as a written SGPR only for the forms that print it: VOP3b, and the e32 form with explicit VCC, both of which have four or more operands. Nothing else changes.

Tested

  • python -I tests/test_image_bvh_census.py - fails on main 60f7dcd90 (the new test: the three short forms and the mask_writes pair) and 22 tests OK with the change.
  • python -m compileall -q tools tests - OK.
  • python -I scripts/check_no_game_data.py tools/image_bvh_census.py tests/test_image_bvh_census.py - OK.
  • Synthetic listings only; no game files, no GPU.

GPUs tested: n/a (offline census tool and its unit test, CPU only)

AI-assisted: yes - OpenCode (DeepSeek V4.1 Flash Free)

Checklist

  • Based on current main and merges cleanly (branch based on 60f7dcd90).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
    Not applicable: offline census tool, no translator rule.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5579718513 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2837). Originally posted by [Neutron-0](https://github.com/Neutron-0) on 2026-12-01T05:32:16Z. --- Claimed in the coordination issue as: CENSUS-SHORT-CARRY-SRC (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7301864505) ### What and why `tools/image_bvh_census.py` builds the SGPR literal map (`sgpr_step`) and the per-instruction write set (`mask_writes`). Both took operand `a[1]` of every `_co_` op (and `v_div_scale`) as the carry/scale destination. The three-operand carry forms - `v_add_co_ci_u32 v1, s8, v2` - print `dst, src0, src1` with VCC implicit, so `a[1]` is a *source*: `s8`'s literal was dropped and a ray-intersection site reading descriptor `s[8:11]` reported word 0 as unknown. The explicit-VCC spelling of the same bytes (`v_add_co_ci_u32_e32 v1, vcc, s8, v2, vcc`) kept it, which is how the bug showed up (item 2 of the pre-existing finding in the coordination issue). `a[1]` is now taken as a written SGPR only for the forms that print it: VOP3b, and the e32 form with explicit VCC, both of which have four or more operands. Nothing else changes. ### Tested - `python -I tests/test_image_bvh_census.py` - **fails on `main` `60f7dcd90`** (the new test: the three short forms and the `mask_writes` pair) and **22 tests OK with the change**. - `python -m compileall -q tools tests` - OK. - `python -I scripts/check_no_game_data.py tools/image_bvh_census.py tests/test_image_bvh_census.py` - OK. - Synthetic listings only; no game files, no GPU. GPUs tested: n/a (offline census tool and its unit test, CPU only) AI-assisted: yes - OpenCode (DeepSeek V4.1 Flash Free) ### Checklist - [x] Based on current `main` and merges cleanly (branch based on `60f7dcd90`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. Not applicable: offline census tool, no translator rule.
fiestorra commented 2026-12-01 05:38:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-01T05:38:00Z.


Verified on Windows, and the control bites: the suite fails four cases with main's copy of the tool.

main 640b0d0df, cherry-picked (one commit, merge-base 1fc92830b), Python 3.13.14:

python -m pytest tests/test_image_bvh_census.py -q
  with this pull request:      22 passed, 4 subtests passed
  with tools/image_bvh_census.py from main:   4 failed, 21 passed, 1 subtests passed

So the four cases this adds are tied to the tool's change and not to fixtures the file already had. That is the control I want on a fix to a parser - the new cases read the old tool and fail.

What the change is, from the diff: tools/image_bvh_census.py decides which SGPR a short carry form's source is, and the test file gains the four cases that name it. The tool's other 21 tests pass in both trees, so nothing else moved.

What I could not test: a real title's BVH census - that needs the game. The parser and its tests are what I ran.

AI-assisted: yes - DeepSeek v4.1 (flash), both arms on the machine above.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7301975244 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2837#issuecomment-7301975244). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-01T05:38:00Z. --- **Verified on Windows, and the control bites: the suite fails four cases with `main`'s copy of the tool.** **`main` `640b0d0df`, cherry-picked (one commit, `merge-base` `1fc92830b`), Python 3.13.14:** ``` python -m pytest tests/test_image_bvh_census.py -q with this pull request: 22 passed, 4 subtests passed with tools/image_bvh_census.py from main: 4 failed, 21 passed, 1 subtests passed ``` **So the four cases this adds are tied to the tool's change and not to fixtures the file already had.** **That is the control I want on a fix to a parser - the new cases read the old tool and fail.** **What the change is, from the diff**: `tools/image_bvh_census.py` decides which SGPR a short carry form's source is, **and the test file gains the four cases that name it.** **The tool's other 21 tests pass in both trees, so nothing else moved.** **What I could not test**: **a real title's BVH census** - **that needs the game.** **The parser and its tests are what I ran.** **AI-assisted:** yes - DeepSeek v4.1 (flash), both arms on the machine above. Written with an AI assistant.
KelboLive commented 2026-12-01 06:02:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T06:02:49Z.

Review: COMMENTED


The rule matches the printed forms, and the probe confirms it rather than just the test: a[1] is the carry/scale SGPR only for the four-plus-operand spellings (_e64 or explicit VCC), while the short three-operand _co_ci forms print dst, src0, src1 with VCC implicit — so keeping s8 as a source is right. My six-form probe behaves as intended: v_add_co_ci_u32 v1, s8, v2 (short), the immediate form, and the s[8:9] pair now decode descriptor word 0 as literal 5, while _e64, v_div_scale_f32 and the explicit-VCC e32 still drop it, and a synthetic census summary moves exactly those three sites from "not a literal" to "literal 5". Reverting the fix fails 4 of 22 tests, so it is pinned.

Two caveats worth recording, both about the heuristic rather than this diff:

  • len(a) > 3 is an operand-count proxy, not an encoding check. A future four-operand _co_ spelling with a source at a[1] would be misclassified the same way the short form was; keying on _e64/explicit VCC would be direct and does not depend on how many operands the formatter prints.
  • v_mad_u64_u32 / v_mad_i64_i32 also write an SGPR at a[1] (see tests/test_audit_shader4_regs.py:73) and match neither condition, before or after — a pre-existing gap in the SGPR map, out of this PR's scope, but the same class of bug and worth a finding: in the coordination issue if nobody has it.

Test coverage: the three short forms, the explicit e32 and the e64 mask_writes case are covered; the immediate and s[8:9] pair forms are not, though the code handles them (verified). Two sub-tests would close that.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6125959692 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2837#pullrequestreview-6125959692). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-01T06:02:49Z. **Review:** COMMENTED --- The rule matches the printed forms, and the probe confirms it rather than just the test: `a[1]` is the carry/scale SGPR only for the four-plus-operand spellings (`_e64` or explicit VCC), while the short three-operand `_co_ci` forms print `dst, src0, src1` with VCC implicit — so keeping `s8` as a source is right. My six-form probe behaves as intended: `v_add_co_ci_u32 v1, s8, v2` (short), the immediate form, and the `s[8:9]` pair now decode descriptor word 0 as literal 5, while `_e64`, `v_div_scale_f32` and the explicit-VCC e32 still drop it, and a synthetic census summary moves exactly those three sites from "not a literal" to "literal 5". Reverting the fix fails 4 of 22 tests, so it is pinned. Two caveats worth recording, both about the heuristic rather than this diff: - `len(a) > 3` is an **operand-count proxy**, not an encoding check. A future four-operand `_co_` spelling with a source at `a[1]` would be misclassified the same way the short form was; keying on `_e64`/explicit VCC would be direct and does not depend on how many operands the formatter prints. - `v_mad_u64_u32` / `v_mad_i64_i32` also write an SGPR at `a[1]` (see `tests/test_audit_shader4_regs.py:73`) and match neither condition, before or after — a pre-existing gap in the SGPR map, out of this PR's scope, but the same class of bug and worth a `finding:` in the coordination issue if nobody has it. Test coverage: the three short forms, the explicit e32 and the e64 `mask_writes` case are covered; the **immediate** and `s[8:9]` pair forms are not, though the code handles them (verified). Two sub-tests would close that.
Neutron-0 commented 2026-12-01 10:43:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-01T10:43:26Z.


Temporarily closed: GitHub will not let this account open a second pull request in this repository while one of its pull requests is open (the same CreatePullRequest permission error other contributors report, e.g. aznohonza's note in this issue). The branch, the review and the verification stay as they are; this pull request is reopened as soon as the slot is free.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7308613460 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2837#issuecomment-7308613460). Originally posted by [Neutron-0](https://github.com/Neutron-0) on 2026-12-01T10:43:26Z. --- Temporarily closed: GitHub will not let this account open a second pull request in this repository while one of its pull requests is open (the same `CreatePullRequest` permission error other contributors report, e.g. aznohonza's note in this issue). The branch, the review and the verification stay as they are; this pull request is reopened as soon as the slot is free.
Neutron-0 commented 2026-12-01 10:43:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-01T10:43:42Z.


The reopen was refused, and the answer says why: You've reached this repository's open pull request limit (reopenPullRequest). The slot is taken by #2864 (the PSV0 name table), so this pull request waits for it to be merged; it is reopened then, and the three other fixes of this account follow one at a time.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7308620509 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2837#issuecomment-7308620509). Originally posted by [Neutron-0](https://github.com/Neutron-0) on 2026-12-01T10:43:42Z. --- **The reopen was refused**, and the answer says why: `You've reached this repository's open pull request limit (reopenPullRequest)`. The slot is taken by #2864 (the `PSV0` name table), so this pull request waits for it to be merged; it is reopened then, and the three other fixes of this account follow one at a time.
Neutron-0 commented 2026-12-01 11:20:10 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-01T11:20:10Z.


The whole standard-library suite passes on this branch's head, with the CI's own selection.

.github/workflows/ci.yml runs the standard-library tests through scripts/run_standalone_tests.py, with the files that do not need pytest and have a __main__ block. That selection, on this branch (Windows 11, Python 3.13.5):

630 files, 0 files failed

For the record, the suite without the CI's selection predicate (every tests/test_*.py outside tests/semantic, including the ones that need pytest) ends with 20 failures, and all 20 are files the CI runs under python -m pytest instead - test_cube_sample.py, test_f16_*.py, test_gs_*.py, test_mesh_*.py, test_translate.py, test_values.py and the rest. That is the predicate's doing, not this pull request's.

The change here is one file (tools/image_bvh_census.py) and one test file (tests/test_image_bvh_census.py); neither is in the 630 files' dependency path of the others' results.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7309498188 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2837#issuecomment-7309498188). Originally posted by [Neutron-0](https://github.com/Neutron-0) on 2026-12-01T11:20:10Z. --- **The whole standard-library suite passes on this branch's head, with the CI's own selection.** `.github/workflows/ci.yml` runs the standard-library tests through `scripts/run_standalone_tests.py`, with the files that do not need pytest and have a `__main__` block. That selection, on this branch (Windows 11, Python 3.13.5): ``` 630 files, 0 files failed ``` For the record, the suite without the CI's selection predicate (every `tests/test_*.py` outside `tests/semantic`, including the ones that need pytest) ends with 20 failures, and all 20 are files the CI runs under `python -m pytest` instead - `test_cube_sample.py`, `test_f16_*.py`, `test_gs_*.py`, `test_mesh_*.py`, `test_translate.py`, `test_values.py` and the rest. That is the predicate's doing, not this pull request's. The change here is one file (`tools/image_bvh_census.py`) and one test file (`tests/test_image_bvh_census.py`); neither is in the 630 files' dependency path of the others' results.
Neutron-0 commented 2026-12-01 19:10:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-01T19:10:30Z.


Reopened: the slot this account may hold in this repository is free again.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7322326850 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2837#issuecomment-7322326850). Originally posted by [Neutron-0](https://github.com/Neutron-0) on 2026-12-01T19:10:30Z. --- Reopened: the slot this account may hold in this repository is free again.
Neutron-0 commented 2026-12-02 05:39:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-02T05:39:00Z.


Reopened: the slot this account may hold in this repository is free again.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7336150634 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2837#issuecomment-7336150634). Originally posted by [Neutron-0](https://github.com/Neutron-0) on 2026-12-02T05:39:00Z. --- Reopened: the slot this account may hold in this repository is free again.
Neutron-0 commented 2026-12-02 05:42:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-02T05:42:20Z.


Reopened: the slot this account may hold in this repository is free again.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7336208416 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2837#issuecomment-7336208416). Originally posted by [Neutron-0](https://github.com/Neutron-0) on 2026-12-02T05:42:20Z. --- Reopened: the slot this account may hold in this repository is free again.

Pull request closed

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
ProjectLeonida/mandy!2837
No description provided.