tooling: sign-extend the SMEM immediate offset in disasm_rdna2 #1984

Manually merged
github merged 2 commits from gh-pr/1984/head into gh-pr/1984/base 2026-11-26 23:47:40 +00:00
Owner

@⁠RenzoWit35 on GitHub · 2026-11-24 22:36 UTC · original
RenzoWit35:tooling/disasm-smem-signed-offset → main · +21 −9 · 5 files · 2 commits · merged 2026-11-24 23:15 UTC

Change

On GFX9+ and RDNA 2 the SMEM OFFSET[20:0] field is a signed 21-bit byte offset, and LLVM's AMDGPU disassembler sign-extends it and prints negative values as -0x<hex>. tools/disasm_rdna2.py masked the field to 21 bits and printed it unsigned, so an encoded -1 appeared as 0x1fffff (+2 MiB). The SMEM branch now sign-extends after masking and prints negative values as -0x<hex> in both the plain form and the offset: form used with an SGPR soffset. Positive output is byte-identical.

Verification

Environment: Windows 11, Python 3.14.5, current origin/main.

  • python -B tools/disasm_rdna2.py --hex "000000f4ffff1ffa": before s_load_dword s0, s[0:1], 0x1fffff, after s_load_dword s0, s[0:1], -0x1.
  • python -B tests/rdna2_tools_check.py: after the fix Ran 152 tests ... OK (skipped=19).
  • Negative control: the same test file against unmodified origin/main tools/disasm_rdna2.py fails in test_golden_vectors: 's_load_dword s0, s[0:1], 0x1fffff' != 's_load_dword s0, s[0:1], -0x1'.
  • New golden vectors (next to the existing SMEM ones): -1, the most negative value (-0x100000), the largest positive value 0xfffff (unchanged), and the soffset form with a negative immediate (s0 offset:-0x1).

Consumers of the text: tools/scan_unsupported_shaders.py matches SMEM lines with 0x[0-9a-f]+, so a negative offset no longer matches and the line is treated as unsupported, which is the conservative outcome (previously it was silently accepted as a huge positive offset). tools/startup/gfx2hlsl.py parses the plain operand with int(token, 0), which accepts -0x1.

Not run: the LLVM comparison in test_llvm_comparison (needs LLVM_LIB, not installed). The offset:-0x1 spelling for the soffset form is kept consistent with the plain form; I could not confirm it against LLVM output here.

Evidence and follow-up

Rebased on current main. No open PR touches tools/disasm_rdna2.py. The sibling PRs for the CLI input errors and VOPC DPP change other parts of the same two files; the three merge in any order.

AI-assisted.

**@⁠RenzoWit35** on GitHub · 2026-11-24 22:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1984) `RenzoWit35:tooling/disasm-smem-signed-offset` → `main` · +21 −9 · 5 files · 2 commits · merged 2026-11-24 23:15 UTC ## Change On GFX9+ and RDNA 2 the SMEM OFFSET[20:0] field is a signed 21-bit byte offset, and LLVM's AMDGPU disassembler sign-extends it and prints negative values as `-0x<hex>`. `tools/disasm_rdna2.py` masked the field to 21 bits and printed it unsigned, so an encoded -1 appeared as `0x1fffff` (+2 MiB). The SMEM branch now sign-extends after masking and prints negative values as `-0x<hex>` in both the plain form and the ` offset:` form used with an SGPR soffset. Positive output is byte-identical. ## Verification Environment: Windows 11, Python 3.14.5, current `origin/main`. - `python -B tools/disasm_rdna2.py --hex "000000f4ffff1ffa"`: before `s_load_dword s0, s[0:1], 0x1fffff`, after `s_load_dword s0, s[0:1], -0x1`. - `python -B tests/rdna2_tools_check.py`: after the fix `Ran 152 tests ... OK (skipped=19)`. - Negative control: the same test file against unmodified `origin/main` `tools/disasm_rdna2.py` fails in `test_golden_vectors`: `'s_load_dword s0, s[0:1], 0x1fffff' != 's_load_dword s0, s[0:1], -0x1'`. - New golden vectors (next to the existing SMEM ones): -1, the most negative value (-0x100000), the largest positive value 0xfffff (unchanged), and the soffset form with a negative immediate (`s0 offset:-0x1`). Consumers of the text: `tools/scan_unsupported_shaders.py` matches SMEM lines with `0x[0-9a-f]+`, so a negative offset no longer matches and the line is treated as unsupported, which is the conservative outcome (previously it was silently accepted as a huge positive offset). `tools/startup/gfx2hlsl.py` parses the plain operand with `int(token, 0)`, which accepts `-0x1`. Not run: the LLVM comparison in `test_llvm_comparison` (needs LLVM_LIB, not installed). The `offset:-0x1` spelling for the soffset form is kept consistent with the plain form; I could not confirm it against LLVM output here. ## Evidence and follow-up Rebased on current `main`. No open PR touches `tools/disasm_rdna2.py`. The sibling PRs for the CLI input errors and VOPC DPP change other parts of the same two files; the three merge in any order. AI-assisted.
On GFX9+ and RDNA 2 the SMEM OFFSET[20:0] field is a signed 21-bit byte
offset, and LLVM prints negative values as -0x<hex>. The disassembler
masked the field to 21 bits and printed it unsigned, so an encoded -1
appeared as +0x1fffff. Sign-extend after masking and print negative
values as -0x<hex> in both the plain and the soffset + offset: forms.
Positive output is unchanged.

Regression vectors cover -1, the most negative value, the largest
positive value and the soffset form with a negative offset.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:47:39 +00:00
github manually merged commit ed7d09a466 into gh-pr/1984/base 2026-11-26 23:47:40 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 23:11 UTC · original

Both Linux jobs had stopped at SMEM modifier offset:-0x100000. Accept the new spelling in the existing validator while refusing the address with the same specific diagnostic. Explicit signed hex, signed decimal and older positive field spellings all refuse. Local SMEM controls, translator checks, decoder suite and Markdown links passed.

**@⁠R0Y00** on GitHub · 2026-11-24 23:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1984#issuecomment-7147114664) Both Linux jobs had stopped at `SMEM modifier offset:-0x100000`. Accept the new spelling in the existing validator while refusing the address with the same specific diagnostic. Explicit signed hex, signed decimal and older positive field spellings all refuse. Local SMEM controls, translator checks, decoder suite and Markdown links passed.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 22:39 UTC · original · reviewed

Review of head 83bb752d2d.

P1 (blocking): this change breaks an existing check, and the Linux CI job fails.

python3 -B tests/startup_smem_address_check.py passes on current main. With this head it fails:

AssertionError: expected 'SMEM immediate offset' in 'SMEM modifier offset:-0x100000'
  must_refuse_bytes(encode_smem(SMEM_BUFFER_LOAD_DWORDX4, 24, 16, soffset=8, imm=neg_imm), 'SMEM immediate offset')

Cause: the startup translator reads the disassembler text. Once the offset prints as a negative value, a negative immediate is no longer refused with the SMEM immediate offset reason. It is now reported as an SMEM modifier offset:-0x... message instead. The disassembler change needs either a matching update in the consumer (so a negative immediate is still refused with the same reason) or an updated check that states the new intended behavior. Please also say which one is intended.

The fix itself looks right: for the new vectors (-0x1, -0x100000, 0xfffff, offset:-0x1) the decode matches the signed 21-bit rule.

Commands run locally:

  • python3 tests/rdna2_tools_check.py: OK, 152 tests (19 skipped)
  • python3 tests/docs_links_check.py: pass
  • python3 tests/bidi_controls_check.py: pass
  • git diff --check origin/main...HEAD: clean
  • git merge-tree --write-tree --name-only origin/main HEAD: no conflicts
  • python3 -B tests/startup_smem_address_check.py: FAIL on this head, pass with tools/disasm_rdna2.py from origin/main
  • gh pr checks 1984: Linux Python checks FAIL; Windows jobs were still pending

Not run: Win2025 and mutation checks, because the P1 above already blocks merge.

Counts: P1 = 1, P2 = 0. No merge. Please push a fixed head and it will be re-checked.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 22:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1984#pullrequestreview-6048517903) · **reviewed** Review of head 83bb752d2d92e7bd0eb348dc49a7ea903b9fa86d. **P1 (blocking): this change breaks an existing check, and the Linux CI job fails.** `python3 -B tests/startup_smem_address_check.py` passes on current main. With this head it fails: ``` AssertionError: expected 'SMEM immediate offset' in 'SMEM modifier offset:-0x100000' must_refuse_bytes(encode_smem(SMEM_BUFFER_LOAD_DWORDX4, 24, 16, soffset=8, imm=neg_imm), 'SMEM immediate offset') ``` Cause: the startup translator reads the disassembler text. Once the offset prints as a negative value, a negative immediate is no longer refused with the `SMEM immediate offset` reason. It is now reported as an `SMEM modifier offset:-0x...` message instead. The disassembler change needs either a matching update in the consumer (so a negative immediate is still refused with the same reason) or an updated check that states the new intended behavior. Please also say which one is intended. The fix itself looks right: for the new vectors (`-0x1`, `-0x100000`, `0xfffff`, `offset:-0x1`) the decode matches the signed 21-bit rule. Commands run locally: - `python3 tests/rdna2_tools_check.py`: OK, 152 tests (19 skipped) - `python3 tests/docs_links_check.py`: pass - `python3 tests/bidi_controls_check.py`: pass - `git diff --check origin/main...HEAD`: clean - `git merge-tree --write-tree --name-only origin/main HEAD`: no conflicts - `python3 -B tests/startup_smem_address_check.py`: FAIL on this head, pass with `tools/disasm_rdna2.py` from origin/main - `gh pr checks 1984`: Linux Python checks FAIL; Windows jobs were still pending Not run: Win2025 and mutation checks, because the P1 above already blocks merge. Counts: P1 = 1, P2 = 0. No merge. Please push a fixed head and it will be re-checked. AI-assisted; commands listed were executed locally.
This discussion has been locked. Commenting is limited to contributors.
No description provided.