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

Merged
RenzoWit35 merged 2 commits from upstream-pr/1984 into main 2026-11-24 23:15:09 +00:00
RenzoWit35 commented 2026-11-24 22:36:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T22:36:47Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6592798400 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1984). Originally posted by [RenzoWit35](https://github.com/RenzoWit35) on 2026-11-24T22:36:47Z. --- ## 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.
tedin7 commented 2026-11-24 23:03:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T22:39:09Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6048517903 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1984#pullrequestreview-6048517903). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T22:39:09Z. **Review:** COMMENTED --- 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.
upstream-sync closed this pull request 2026-11-25 00:04:47 +00:00
R0Y00 commented 2026-11-25 01:01:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T23:11:18Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7147114664 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1984#issuecomment-7147114664). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T23:11:18Z. --- 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.
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
R0Y00/Xbox2Windows!1977
No description provided.