Skip to content

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 into
ProjectLeonida:mainfrom
Neutron-0:fix/tools-bvh-census-short-carry-source
Closed

Neutron-0 wants to merge 2 commits into
ProjectLeonida:mainfrom
Neutron-0:fix/tools-bvh-census-short-carry-source

Conversation

@Neutron-0

@Neutron-0 Neutron-0 commented Dec 1, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as: CENSUS-SHORT-CARRY-SRC (#2570 (comment))

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.

…(CENSUS-SHORT-CARRY-SRC)

image_bvh_census's sgpr_step and mask_writes list a[1] as a written SGPR
for every _co_ or v_div_scale op. The three-operand carry forms print
dst, src0, src1 with VCC implicit, so a[1] is a source there: a descriptor
literal used there was dropped and the census reported descriptor word 0
as unknown, while the form with explicit VCC operands kept it.

Take a[1] as the carry or scale destination only where the form prints it:
VOP3b, and the e32 form with explicit VCC, which have four or more
operands.

Test: tests/test_image_bvh_census.py fails on 1fc9283 and passes with
the change (22 tests OK, three short forms plus the mask_writes pair).
@fiestorra

Copy link
Copy Markdown
Contributor

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 KelboLive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Neutron-0 commented Dec 1, 2026 •

Copy link
Copy Markdown
Author

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 Neutron-0 closed this Dec 1, 2026
@Neutron-0

Neutron-0 commented Dec 1, 2026 •

Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown
Author

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.

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.

3 participants