tooling: print neg on a VOPC SDWA inline constant as neg(c) #1022

Merged
MasterDomino merged 2 commits from upstream-pr/1029 into main 2026-11-23 22:41:29 +00:00
MasterDomino commented 2026-11-23 22:09:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-23T22:09:43Z.


Refs #938

Summary

For a float VOPC SDWA source with neg and without abs on an inline constant (scalar codes 128-208 and 240-248), the decoder printed -c, or --c for a negative constant. For an integer constant this text names a different operand. f924027c81009606 sets the sign bit of the inline constant 1 (0x80000001), but it printed v_cmp_lt_f32_sdwa vcc_lo, -1, v18 .... That is the same text as the inline constant -1 (f924027cc1008606, 0xffffffff), and pixel_aot.lower accepted it as -1.

This change prints these operands as neg(c), as LLVM 15 does: neg(0), neg(1), neg(64), neg(-1), neg(-16), neg(0.5), neg(-0.5), neg(1.0), neg(0.15915494) and so on. pixel_aot.lower refuses a neg(...) operand (Unsupported arithmetic operand neg(1)), so it no longer lowers the encoding as a different constant.

I checked every affected spelling against the #938 sweep data rather than guessing. LLVM prints neg(c) in exactly the 90 codes x {f32, f16} groups where neg is set without abs on an inline constant. These forms already matched LLVM and do not change:

  • abs: |c|
  • abs+neg: -|c|, -|-1|
  • the constants themselves: -1, -0.5
  • neg on registers and named special operands: -s1, -src_shared_base, -src_vccz

The LLVM-specific float-constant spelling on i16/u16 compares is left unchanged, as agreed on #938.

Files: tools/disasm_rdna2.py (+14/-2), tests/rdna2_tools_check.py (+90).

Tests

New tests are in tests/rdna2_tools_check.py, which is already registered in CMake and both CI jobs:

  • test_vopc_sdwa_neg_on_inline_constant decodes 23 records, each followed by v_mov_b32_e32 v3, v4 (0403067e). The bytes come from llvm-mc 15.0.7 (-triple=amdgcn--amdpal -mcpu=gfx1013 -mattr=+wavefrontsize32) for the expected text. They cover integer constants 0, 1, 7, 64, -1 and -16 and float constants 0.5, -0.5, 1.0, 2.0, -4.0 and 0.15915494, as src0 and src1, on f32, f16, class and VOPCX compares, plus 7 unchanged spellings. The test checks (offset, length, opcode, text) for each record and for the v_mov at offset 8. It also checks two refused records: neg on the integer compare's src0 (f904887d81869606) and on the class compare's src1 (f902117d01860696). Each must be vopc_sdwa at offset 0 with length 8, with v_mov_b32_e32 v3, v4 at offset 8.

    The same test checks that f924027c81009606 and f924027cc1008606 now decode to different texts, neg(1) and -1. In the program used by the #938 translator check, pixel_aot.lower accepts the -1 compare (asfloat(4294967295u) < alu20) and refuses the decoder text for neg(1) and neg(0.5) with Unsupported arithmetic operand neg(.

  • test_vopc_sdwa_neg_on_inline_constant_matches_llvm runs only when LLVM_LIB is set. LLVM 15 must print the same text and next offset for all 23 records, and must refuse both refused records at byte 0.

# LLVM_LIB="C:\Program Files\LLVM\bin\LLVM-C.dll", LLVM_MC / LLVM_OBJCOPY = LLVM 15.0.7 llvm-mc / llvm-objcopy
python -B tests/rdna2_tools_check.py      -> Ran 92 tests ... OK
python -B tests/rdna2_tools_check.py      (no LLVM env) -> Ran 92 tests ... OK (skipped=6)
python -B tests/shader_census_check.py    -> exit 0
python -B tests/shader_probe_check.py     -> exit 0
python -B tests/form_coverage_check.py    -> exit 0 ("form coverage checks passed")
python -B tests/docs_links_check.py       -> exit 0 ("Checked 13 Markdown files and 221 links.")

Environment: Windows 11, Python 3.13.1, LLVM 15.0.7 (LLVM-C.dll, llvm-mc, llvm-objcopy), commit c4b5bef on upstream/main 64ecc87 (measured at 50919ec on cd87907; tools/disasm_rdna2.py and its tests are unchanged between the two bases, and rdna2_tools_check, shader_census_check, form_coverage_check and docs_links_check were rerun after the rebase).

Lowerer before and after

These are the decoder texts for each encoding and the pixel_aot.lower verdicts in the #938 translator program:

encoding upstream/main text lower this branch text lower
f924027c81009606 (neg(1)) -1 accepted as 0xffffffff neg(1) refused
f924027cc1009606 (neg(-1)) --1 accepted neg(-1) refused
f924027cf0009606 (neg(0.5)) -0.5 accepted neg(0.5) refused
f924027cc1008606 (inline -1) -1 accepted -1 accepted

Sweep before and after

I ran the independent #938 sweep script (sweep_980.py: 869,888 VOPC SDWA records, all compared against LLVM 15.0.7) on this commit. Each record is compared with the original #938 run:

category before after
text_mismatch: neg on an inline constant 12,131 0
text_mismatch: i16/u16 float-constant spelling (unchanged on purpose) 875 875
both_decode_match 200,243 212,374
llvm_refuses_disasm_decodes (codes 209-234; separate change) 20,129 20,129
both_refuse 636,138 636,138
llvm_fault (LLVM 15 selector-7 crash) 372 372
total deltas 33,135 21,004

All 12,131 records moved from text_mismatch to both_decode_match. All 875 remaining text mismatches are i16/u16 compares with no neg( on either side. No record entered a new delta category. Thirteen records that LLVM refuses changed decoder text, for example s230, -5 became s230, neg(5). They stay in llvm_refuses_disasm_decodes because of their 209-234 scalar code, which the companion branch refuses. Truncated-tail checks: 0 unexpected. Scanner mismatches: 0. Translator verdicts on the canonical records: unchanged (96 accepted and supported, 716 refused and unsupported). The sweep's in-memory negative controls still report their injected defects with 0 deltas outside the expected scope.

Negative control

I reverted tools/disasm_rdna2.py to upstream/main and kept the new tests. test_vopc_sdwa_neg_on_inline_constant then fails:

AssertionError: Lists differ: ...
-   'v_cmp_lt_f32_sdwa vcc_lo, -1, v2 src0_sel:DWORD src1_sel:DWORD'),
+   'v_cmp_lt_f32_sdwa vcc_lo, neg(1), v2 src0_sel:DWORD src1_sel:DWORD'),

With the change restored, both tests pass.

Limits

  • Float compares whose source is neg(<float constant>), such as neg(0.5), were lowered correctly before as -0.5f. The lowerer now refuses them, which is a deliberate loss of coverage: one rule refuses every neg-on-inline-constant encoding. The scanner's per-line check (is_instruction_supported) still calls neg(c) lines supported. As before, the lowerer is the authority.
  • Only the VOPC SDWA path changes. VOP3 has the same spelling: llvm-mc's v_add_f32_e64 v0, neg(1), v1 (000003d581020220) decodes as v_add_f32_e64 v0, -1, v1. That is out of scope here and was not checked against the lowerer.
  • The existing tests needed no changes. No README or docs/ text describes this spelling. The branch merges cleanly with the companion 209-234 branch (git merge-tree).

AI-assisted.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6569847054 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1029). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-23T22:09:43Z. --- Refs #938 ## Summary For a float VOPC SDWA source with neg and without abs on an inline constant (scalar codes 128-208 and 240-248), the decoder printed `-c`, or `--c` for a negative constant. For an integer constant this text names a different operand. `f924027c81009606` sets the sign bit of the inline constant 1 (0x80000001), but it printed `v_cmp_lt_f32_sdwa vcc_lo, -1, v18 ...`. That is the same text as the inline constant -1 (`f924027cc1008606`, 0xffffffff), and `pixel_aot.lower` accepted it as -1. This change prints these operands as `neg(c)`, as LLVM 15 does: `neg(0)`, `neg(1)`, `neg(64)`, `neg(-1)`, `neg(-16)`, `neg(0.5)`, `neg(-0.5)`, `neg(1.0)`, `neg(0.15915494)` and so on. `pixel_aot.lower` refuses a `neg(...)` operand (`Unsupported arithmetic operand neg(1)`), so it no longer lowers the encoding as a different constant. I checked every affected spelling against the #938 sweep data rather than guessing. LLVM prints `neg(c)` in exactly the 90 codes x {f32, f16} groups where neg is set without abs on an inline constant. These forms already matched LLVM and do not change: - abs: `|c|` - abs+neg: `-|c|`, `-|-1|` - the constants themselves: `-1`, `-0.5` - neg on registers and named special operands: `-s1`, `-src_shared_base`, `-src_vccz` The LLVM-specific float-constant spelling on i16/u16 compares is left unchanged, as agreed on #938. Files: `tools/disasm_rdna2.py` (+14/-2), `tests/rdna2_tools_check.py` (+90). ## Tests New tests are in `tests/rdna2_tools_check.py`, which is already registered in CMake and both CI jobs: - `test_vopc_sdwa_neg_on_inline_constant` decodes 23 records, each followed by `v_mov_b32_e32 v3, v4` (`0403067e`). The bytes come from llvm-mc 15.0.7 (`-triple=amdgcn--amdpal -mcpu=gfx1013 -mattr=+wavefrontsize32`) for the expected text. They cover integer constants 0, 1, 7, 64, -1 and -16 and float constants 0.5, -0.5, 1.0, 2.0, -4.0 and 0.15915494, as src0 and src1, on f32, f16, class and VOPCX compares, plus 7 unchanged spellings. The test checks `(offset, length, opcode, text)` for each record and for the `v_mov` at offset 8. It also checks two refused records: neg on the integer compare's src0 (`f904887d81869606`) and on the class compare's src1 (`f902117d01860696`). Each must be `vopc_sdwa` at offset 0 with length 8, with `v_mov_b32_e32 v3, v4` at offset 8. The same test checks that `f924027c81009606` and `f924027cc1008606` now decode to different texts, `neg(1)` and `-1`. In the program used by the #938 translator check, `pixel_aot.lower` accepts the `-1` compare (`asfloat(4294967295u) < alu20`) and refuses the decoder text for `neg(1)` and `neg(0.5)` with `Unsupported arithmetic operand neg(`. - `test_vopc_sdwa_neg_on_inline_constant_matches_llvm` runs only when `LLVM_LIB` is set. LLVM 15 must print the same text and next offset for all 23 records, and must refuse both refused records at byte 0. ``` # LLVM_LIB="C:\Program Files\LLVM\bin\LLVM-C.dll", LLVM_MC / LLVM_OBJCOPY = LLVM 15.0.7 llvm-mc / llvm-objcopy python -B tests/rdna2_tools_check.py -> Ran 92 tests ... OK python -B tests/rdna2_tools_check.py (no LLVM env) -> Ran 92 tests ... OK (skipped=6) python -B tests/shader_census_check.py -> exit 0 python -B tests/shader_probe_check.py -> exit 0 python -B tests/form_coverage_check.py -> exit 0 ("form coverage checks passed") python -B tests/docs_links_check.py -> exit 0 ("Checked 13 Markdown files and 221 links.") ``` Environment: Windows 11, Python 3.13.1, LLVM 15.0.7 (`LLVM-C.dll`, `llvm-mc`, `llvm-objcopy`), commit `c4b5bef` on upstream/main `64ecc87` (measured at `50919ec` on `cd87907`; `tools/disasm_rdna2.py` and its tests are unchanged between the two bases, and `rdna2_tools_check`, `shader_census_check`, `form_coverage_check` and `docs_links_check` were rerun after the rebase). ## Lowerer before and after These are the decoder texts for each encoding and the `pixel_aot.lower` verdicts in the #938 translator program: | encoding | upstream/main text | lower | this branch text | lower | |---|---|---|---|---| | `f924027c81009606` (neg(1)) | `-1` | accepted as 0xffffffff | `neg(1)` | refused | | `f924027cc1009606` (neg(-1)) | `--1` | accepted | `neg(-1)` | refused | | `f924027cf0009606` (neg(0.5)) | `-0.5` | accepted | `neg(0.5)` | refused | | `f924027cc1008606` (inline -1) | `-1` | accepted | `-1` | accepted | ## Sweep before and after I ran the independent #938 sweep script (`sweep_980.py`: 869,888 VOPC SDWA records, all compared against LLVM 15.0.7) on this commit. Each record is compared with the original #938 run: | category | before | after | |---|---:|---:| | text_mismatch: neg on an inline constant | 12,131 | **0** | | text_mismatch: i16/u16 float-constant spelling (unchanged on purpose) | 875 | 875 | | both_decode_match | 200,243 | 212,374 | | llvm_refuses_disasm_decodes (codes 209-234; separate change) | 20,129 | 20,129 | | both_refuse | 636,138 | 636,138 | | llvm_fault (LLVM 15 selector-7 crash) | 372 | 372 | | total deltas | 33,135 | 21,004 | All 12,131 records moved from `text_mismatch` to `both_decode_match`. All 875 remaining text mismatches are i16/u16 compares with no `neg(` on either side. No record entered a new delta category. Thirteen records that LLVM refuses changed decoder text, for example `s230, -5` became `s230, neg(5)`. They stay in `llvm_refuses_disasm_decodes` because of their 209-234 scalar code, which the companion branch refuses. Truncated-tail checks: 0 unexpected. Scanner mismatches: 0. Translator verdicts on the canonical records: unchanged (96 accepted and supported, 716 refused and unsupported). The sweep's in-memory negative controls still report their injected defects with 0 deltas outside the expected scope. ## Negative control I reverted `tools/disasm_rdna2.py` to upstream/main and kept the new tests. `test_vopc_sdwa_neg_on_inline_constant` then fails: ``` AssertionError: Lists differ: ... - 'v_cmp_lt_f32_sdwa vcc_lo, -1, v2 src0_sel:DWORD src1_sel:DWORD'), + 'v_cmp_lt_f32_sdwa vcc_lo, neg(1), v2 src0_sel:DWORD src1_sel:DWORD'), ``` With the change restored, both tests pass. ## Limits - Float compares whose source is `neg(<float constant>)`, such as `neg(0.5)`, were lowered correctly before as `-0.5f`. The lowerer now refuses them, which is a deliberate loss of coverage: one rule refuses every neg-on-inline-constant encoding. The scanner's per-line check (`is_instruction_supported`) still calls `neg(c)` lines supported. As before, the lowerer is the authority. - Only the VOPC SDWA path changes. VOP3 has the same spelling: llvm-mc's `v_add_f32_e64 v0, neg(1), v1` (`000003d581020220`) decodes as `v_add_f32_e64 v0, -1, v1`. That is out of scope here and was not checked against the lowerer. - The existing tests needed no changes. No README or `docs/` text describes this spelling. The branch merges cleanly with the companion 209-234 branch (`git merge-tree`). AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:45:55 +00:00
R0Y00 commented 2026-11-24 06:49:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T22:22:45Z.


In 750457f I kept the LLVM-compatible spelling and preserved the existing whole-dword f32 comparison for decimal negation. The decoder-to-lowerer controls require identical HLSL for neg(0.5) / -0.5 and neg(-0.5) / --0.5. The integer-bit case neg(1) still refuses and the scanner now agrees, while plain -1 keeps its old meaning. Local Python decoder suite: 92 cases, six LLVM-dependent skips; static pixel suite passed. Fresh CI will exercise LLVM 15.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7115677750 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1029#issuecomment-7115677750). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T22:22:45Z. --- In 750457f I kept the LLVM-compatible spelling and preserved the existing whole-dword f32 comparison for decimal negation. The decoder-to-lowerer controls require identical HLSL for `neg(0.5)` / `-0.5` and `neg(-0.5)` / `--0.5`. The integer-bit case `neg(1)` still refuses and the scanner now agrees, while plain `-1` keeps its old meaning. Local Python decoder suite: 92 cases, six LLVM-dependent skips; static pixel suite passed. Fresh CI will exercise LLVM 15.
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!1022
No description provided.