[PR #1530] sampler_source_census: fix V#/pointer/SMEM/v_mov dataflow and harden JSON I/O (SAMPLER-SOURCE-CENSUS-DATAFLOW-AND-IO) #1559

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

📋 Pull Request Information

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

Base: main ← Head: fix/sampler-source-census-dataflow-io


📝 Commits (1)

  • a9413ce sampler_source_census: fix V#/pointer/SMEM/v_mov dataflow and harden JSON I/O

📊 Changes

2 files changed (+340 additions, -16 deletions)

View changed files

📝 tests/test_sampler_source_census.py (+184 -0)
📝 tools/sampler_source_census.py (+156 -16)

📄 Description

What changed

  • V# per-dword offset preservation (tools/sampler_source_census.py:one_load_source): collect [source(t, seen) for t in base] and check agreement on the source origin ({g[0] for g in got}) while combining any(g[1]) and max(g[2]), instead of requiring all four dwords to have identical (where, dyn, k) tuples. Previously, adding a static or dynamic offset to word 0 of a user V# dropped it to undetermined (V# from different sources).
  • 64-bit pointer high-word zero and offset tracking (tools/sampler_source_census.py:one_load_source): recognize 3-tuple unary-folded zero constants (("const", 0, op) from s_not_b32/s_brev_b32) as a zero high word, and propagate dyn/k from a user high word instead of ignoring them.
  • SMEM offset:IMM modifier tracking (tools/sampler_source_census.py:analyse, one_load_source, one_load): parse offset:N from ins["mods"] so combined sOFF offset:IMM loads count IMM in max_pointer_constant (dynamic) and max_static_offset (constant SGPR + offset:IMM).
  • Spill-copy soundness (tools/sampler_source_census.py:step): do not treat v_mov_b32_sdwa, v_mov_b32_dpp, instructions with modifiers (clamp, etc.), or register operands with neg/abs/sext as lossless spill copies.
  • Robustness (tools/sampler_source_census.py:anchored, blocks_of, analyse, census): convert invalid hex in anchored() into hic.Skip instead of crashing with ValueError, handle empty instruction lists cleanly in blocks_of([])/analyse([], ...), and validate positive non-bool integers for limit and jobs in census().
  • Pre-scan --json guards, atomic write, and OSError handling (tools/sampler_source_census.py:main): refuse --json targeting a folder, index.json, anything inside disasm, or any .dxbc / fssm/*.fssm / .s input (via report_paths.same_report_path and os.path.samestat for hardlinks); catch OSError from census() with exit code 2; write --json atomically through a sibling temp file with file_mode.published_mode, replace_retry.replace, allow_nan=False, and explicit newline="\n".
  • Tests (tests/test_sampler_source_census.py): added 7 synthetic unit/CLI regression tests covering every fix above.

Claimed in the coordination issue as:

SAMPLER-SOURCE-CENSUS-DATAFLOW-AND-IO (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7152027644)

How it was tested

  • python3 -I -W error tests/test_sampler_source_census.py: 37/37 passed (0 warnings).
  • python3 -I tests/test_text_write_line_endings.py: 3/3 passed.
  • python3 -I scripts/check_no_game_data.py tools/sampler_source_census.py tests/test_sampler_source_census.py: passed.
  • python3 -m compileall -q tools/sampler_source_census.py tests/test_sampler_source_census.py: passed.
  • Mutation check against unpatched main:tools/sampler_source_census.py: all 7 new tests fail (FAILED (failures=6, errors=1)), all 30 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/1530 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/sampler-source-census-dataflow-io` --- ### 📝 Commits (1) - [`a9413ce`](https://github.com/ubiquitarianism/leonida/commit/a9413ce4d64cbf438cb92e60ca45323141aa0f8e) sampler_source_census: fix V#/pointer/SMEM/v_mov dataflow and harden JSON I/O ### 📊 Changes **2 files changed** (+340 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_sampler_source_census.py` (+184 -0) 📝 `tools/sampler_source_census.py` (+156 -16) </details> ### 📄 Description ## What changed - **V# per-dword offset preservation (`tools/sampler_source_census.py:one_load_source`)**: collect `[source(t, seen) for t in base]` and check agreement on the source origin (`{g[0] for g in got}`) while combining `any(g[1])` and `max(g[2])`, instead of requiring all four dwords to have identical `(where, dyn, k)` tuples. Previously, adding a static or dynamic offset to word 0 of a user V# dropped it to `undetermined` (`V# from different sources`). - **64-bit pointer high-word zero and offset tracking (`tools/sampler_source_census.py:one_load_source`)**: recognize 3-tuple unary-folded zero constants (`("const", 0, op)` from `s_not_b32`/`s_brev_b32`) as a zero high word, and propagate `dyn`/`k` from a user high word instead of ignoring them. - **SMEM `offset:IMM` modifier tracking (`tools/sampler_source_census.py:analyse`, `one_load_source`, `one_load`)**: parse `offset:N` from `ins["mods"]` so combined `sOFF offset:IMM` loads count `IMM` in `max_pointer_constant` (dynamic) and `max_static_offset` (constant SGPR + `offset:IMM`). - **Spill-copy soundness (`tools/sampler_source_census.py:step`)**: do not treat `v_mov_b32_sdwa`, `v_mov_b32_dpp`, instructions with modifiers (`clamp`, etc.), or register operands with `neg`/`abs`/`sext` as lossless spill copies. - **Robustness (`tools/sampler_source_census.py:anchored`, `blocks_of`, `analyse`, `census`)**: convert invalid hex in `anchored()` into `hic.Skip` instead of crashing with `ValueError`, handle empty instruction lists cleanly in `blocks_of([])`/`analyse([], ...)`, and validate positive non-bool integers for `limit` and `jobs` in `census()`. - **Pre-scan `--json` guards, atomic write, and `OSError` handling (`tools/sampler_source_census.py:main`)**: refuse `--json` targeting a folder, `index.json`, anything inside `disasm`, or any `.dxbc` / `fssm/*.fssm` / `.s` input (via `report_paths.same_report_path` and `os.path.samestat` for hardlinks); catch `OSError` from `census()` with exit code 2; write `--json` atomically through a sibling temp file with `file_mode.published_mode`, `replace_retry.replace`, `allow_nan=False`, and explicit `newline="\n"`. - **Tests (`tests/test_sampler_source_census.py`)**: added 7 synthetic unit/CLI regression tests covering every fix above. ## Claimed in the coordination issue as: `SAMPLER-SOURCE-CENSUS-DATAFLOW-AND-IO` (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7152027644) ## How it was tested - `python3 -I -W error tests/test_sampler_source_census.py`: 37/37 passed (0 warnings). - `python3 -I tests/test_text_write_line_endings.py`: 3/3 passed. - `python3 -I scripts/check_no_game_data.py tools/sampler_source_census.py tests/test_sampler_source_census.py`: passed. - `python3 -m compileall -q tools/sampler_source_census.py tests/test_sampler_source_census.py`: passed. - Mutation check against unpatched `main:tools/sampler_source_census.py`: all 7 new tests fail (`FAILED (failures=6, errors=1)`), all 30 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#1559
No description provided.