[PR #1534] image_bvh_census: fix v_cmpx/v_rcp/SDWA/CFG bugs and harden JSON I/O (IMAGE-BVH-CENSUS-DATAFLOW-CFG-AND-IO) #1563

Open
opened 2026-11-26 20:21:41 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1534
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/image-bvh-census-dataflow-io


📝 Commits (1)

  • c2d3224 image_bvh_census: fix v_cmpx/v_rcp/SDWA/CFG bugs and harden JSON I/O

📊 Changes

2 files changed (+279 additions, -21 deletions)

View changed files

📝 tests/test_image_bvh_census.py (+158 -0)
📝 tools/image_bvh_census.py (+121 -21)

📄 Description

What changed

  • Fix v_cmpx_* operand handling (tools/image_bvh_census.py:sgpr_step, mask_writes, source_args):
    • v_cmpx_*_e32 takes 2 source operands with an implicit EXEC destination (a[0] is a source, not a destination). Previously, sgpr_step() and mask_writes() treated a[0] as an SGPR write, wiping literal descriptor words and saved EXEC masks whenever a 2-operand v_cmpx_* read an SGPR in a[0].
    • v_cmpx_*_e64 (len(a) > 2) puts its destination in a[0] and sources in a[1:]; source_args() now excludes a[0], so product_reader() reports v_cmpx_gt_i32 with 0 instead of with 2 other operands.
  • Require unmodified v_rcp_f32 before tagging R1 (tools/image_bvh_census.py:site_transfer): align site_transfer() with classify() by checking plain(a[1]), not ins.get("mods"), and no _sdwa/_dpp suffix so v_rcp_f32_e64 v20, |v5| / -v5 / clamp does not falsely classify downstream v_mul_f32 as ratio.
  • Require a single VGPR in high_half_operand() and handle dual high-half operands (tools/image_bvh_census.py:high_half_operand, site_transfer): prevent SGPR operands (e.g. sext(s5)) from reading VGPR v5, prevent immediate operands (sext(1)) from raising KeyError: 'r', and select the operand holding word 1 when both SDWA operands use WORD_1.
  • Copy & float-immediate edge cases (tools/image_bvh_census.py:is_copy, imm32): check single-VGPR operands and plain(a[0]) on v_swap_b32 in is_copy(), and catch OverflowError in imm32() for out-of-range float32 literals.
  • CFG gap splitting & bad encodings (tools/image_bvh_census.py:blocks_of, analyse, load_program): start a new block on non-contiguous PCs and require next_pc(last) == starts[n + 1] before adding a fall-through edge (avoiding phantom fall-through across embedded data gaps), handle empty insns cleanly, and convert invalid hex encodings (parse_file / bytes.fromhex ValueError) to Skip.
  • Harden --out overwrite guards, OSError handling, and atomic JSON output (tools/image_bvh_census.py:main): use report_paths.same_report_path (plus os.path.samestat for hardlinks) to refuse overwriting scanned listings, index.json, or fssm/*.fssm; catch OSError during directory scanning with exit code 2; write --out atomically through a sibling temp file with file_mode.published_mode, replace_retry.replace, allow_nan=False, and a trailing LF.
  • Tests (tests/test_image_bvh_census.py): added 6 synthetic unit/CLI regression tests covering every fix above.

Claimed in the coordination issue as:

IMAGE-BVH-CENSUS-DATAFLOW-CFG-AND-IO (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7152125566)

How it was tested

  • python3 -I -W error tests/test_image_bvh_census.py: 21/21 passed (0 warnings).
  • python3 -I tests/test_text_write_line_endings.py: 3/3 passed.
  • python3 -I scripts/check_no_game_data.py tools/image_bvh_census.py tests/test_image_bvh_census.py: passed.
  • python3 -m compileall -q tools/image_bvh_census.py tests/test_image_bvh_census.py: passed.
  • Mutation check against unpatched main:tools/image_bvh_census.py: all 6 new tests fail (FAILED (failures=4, errors=2)), all 15 baseline tests pass.

Metadata

  • AI-assisted: yes
  • GPUs tested: none (CPU-only synthetic disassembly / CLI unit tests on macOS arm64; no game files used)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1534 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/image-bvh-census-dataflow-io` --- ### 📝 Commits (1) - [`c2d3224`](https://github.com/ubiquitarianism/leonida/commit/c2d32249e6845782f96495606652b346e851cfe0) image_bvh_census: fix v_cmpx/v_rcp/SDWA/CFG bugs and harden JSON I/O ### 📊 Changes **2 files changed** (+279 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_image_bvh_census.py` (+158 -0) 📝 `tools/image_bvh_census.py` (+121 -21) </details> ### 📄 Description ## What changed - **Fix `v_cmpx_*` operand handling (`tools/image_bvh_census.py:sgpr_step`, `mask_writes`, `source_args`)**: - `v_cmpx_*_e32` takes 2 source operands with an implicit `EXEC` destination (`a[0]` is a source, not a destination). Previously, `sgpr_step()` and `mask_writes()` treated `a[0]` as an SGPR write, wiping literal descriptor words and saved EXEC masks whenever a 2-operand `v_cmpx_*` read an SGPR in `a[0]`. - `v_cmpx_*_e64` (`len(a) > 2`) puts its destination in `a[0]` and sources in `a[1:]`; `source_args()` now excludes `a[0]`, so `product_reader()` reports `v_cmpx_gt_i32 with 0` instead of `with 2 other operands`. - **Require unmodified `v_rcp_f32` before tagging `R1` (`tools/image_bvh_census.py:site_transfer`)**: align `site_transfer()` with `classify()` by checking `plain(a[1])`, `not ins.get("mods")`, and no `_sdwa`/`_dpp` suffix so `v_rcp_f32_e64 v20, |v5|` / `-v5` / `clamp` does not falsely classify downstream `v_mul_f32` as `ratio`. - **Require a single VGPR in `high_half_operand()` and handle dual high-half operands (`tools/image_bvh_census.py:high_half_operand`, `site_transfer`)**: prevent SGPR operands (e.g. `sext(s5)`) from reading VGPR `v5`, prevent immediate operands (`sext(1)`) from raising `KeyError: 'r'`, and select the operand holding word 1 when both SDWA operands use `WORD_1`. - **Copy & float-immediate edge cases (`tools/image_bvh_census.py:is_copy`, `imm32`)**: check single-VGPR operands and `plain(a[0])` on `v_swap_b32` in `is_copy()`, and catch `OverflowError` in `imm32()` for out-of-range float32 literals. - **CFG gap splitting & bad encodings (`tools/image_bvh_census.py:blocks_of`, `analyse`, `load_program`)**: start a new block on non-contiguous PCs and require `next_pc(last) == starts[n + 1]` before adding a fall-through edge (avoiding phantom fall-through across embedded data gaps), handle empty `insns` cleanly, and convert invalid hex encodings (`parse_file` / `bytes.fromhex` `ValueError`) to `Skip`. - **Harden `--out` overwrite guards, `OSError` handling, and atomic JSON output (`tools/image_bvh_census.py:main`)**: use `report_paths.same_report_path` (plus `os.path.samestat` for hardlinks) to refuse overwriting scanned listings, `index.json`, or `fssm/*.fssm`; catch `OSError` during directory scanning with exit code 2; write `--out` atomically through a sibling temp file with `file_mode.published_mode`, `replace_retry.replace`, `allow_nan=False`, and a trailing LF. - **Tests (`tests/test_image_bvh_census.py`)**: added 6 synthetic unit/CLI regression tests covering every fix above. ## Claimed in the coordination issue as: `IMAGE-BVH-CENSUS-DATAFLOW-CFG-AND-IO` (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7152125566) ## How it was tested - `python3 -I -W error tests/test_image_bvh_census.py`: 21/21 passed (0 warnings). - `python3 -I tests/test_text_write_line_endings.py`: 3/3 passed. - `python3 -I scripts/check_no_game_data.py tools/image_bvh_census.py tests/test_image_bvh_census.py`: passed. - `python3 -m compileall -q tools/image_bvh_census.py tests/test_image_bvh_census.py`: passed. - Mutation check against unpatched `main:tools/image_bvh_census.py`: all 6 new tests fail (`FAILED (failures=4, errors=2)`), all 15 baseline tests pass. ## Metadata - AI-assisted: yes - GPUs tested: none (CPU-only synthetic disassembly / CLI unit tests on macOS arm64; no game files used) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1563
No description provided.