tests: pin cmp16 refusals for neg/abs, literals, 16-bit conditions #2418

Merged
Makto94 merged 1 commit from upstream-pr/2426 into main 2026-11-25 17:13:10 +00:00
Makto94 commented 2026-11-25 16:26:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-25T16:26:10Z.


Refs #1723

Problem

tests/startup_gfx2hlsl_cmp16_check.py (added in #2369, Part of #1723) fixes the accepted 16-bit VOPC compares well, but its "Refusals" section left three guards of the lowering unpinned:

  • The _e64 NEG/ABS guard in check_encoding(). The decoder prints NEG on inline 1 as -1, the same text as inline -1 (v_cmp_lt_i16_e64 s4, -1, v2 for both; ABS prints |1|). Only the raw word tells them apart, so the guard is the only protection against reading -1 for 1. The check exercised it for v_cmp_lt_i16_e64 only.
  • The literal limits of a 16-bit source (-16 <= value <= 0xffff). Only values inside the range were tried.
  • The conditions that exist at no 16-bit integer width (t, lg, nlg, nlt, nle, ngt, nge, neq, o, u). Only v_cmp_f_i16_e64 was checked.

Mutants of tools/startup/gfx2hlsl.py that break these guards passed the check on main (7092683a).

Change

Test-only; 20 added lines in the "Refusals" section of controls(). No file under tools/ changes.

  • NEG and ABS on inline 1 are refused with neg/abs for all 24 opcodes (v_cmp/v_cmpx x 6 relations x i16/u16, _e64): 48 cases.
  • Literal 0xffff is accepted and 0x10000 is refused (wider than 16 bits) for i16 and u16.
  • The 10 non-existent conditions are refused for i16/u16 and v_cmp/v_cmpx (_e64): 40 cases, each with the expected v_cmp[x]_<cond>_<type> reason.

The check is already in the Linux list of .github/workflows/windows.yml (job python-linux, line 259), so CI runs the new cases without a workflow change.

Mutants

Each mutant edits one expression in tools/startup/gfx2hlsl.py at 7092683a. "main check" is the unmodified check from main; "new check" is this PR.

# Input Reference Mutant main check Killed by (new check)
M4 literal 0xffff, i16/u16 accepted (widest 16-bit literal) upper bound 0xffff -> 0xfffe passes literal 0xffff {i16,u16} accepted
M5 literal 0x10000, i16/u16 refused, wider than 16 bits upper bound 0xffff -> 0x10000 passes literal 0x10000 {i16,u16}
M10 NEG/ABS on inline 1, v_cmpx_* refused (decoder prints -1 / |1|) guard regex drops x?, so v_cmpx is unguarded passes neg/absolute on inline 1 in v_cmpx_*
M11 NEG/ABS on inline 1, u16 refused guard regex only i16 passes neg/absolute on inline 1 in v_cmp[x]_*_u16
M12 NEG/ABS on inline 1, ne refused guard regex drops ne passes neg/absolute on inline 1 in v_cmp[x]_ne_*
M17 v_cmp[x]_t_{i16,u16}_e64 refused condition t allowed passes v_cmp_t_i16_e64, v_cmpx_t_i16_e64, and the u16 pair
M18 v_cmp[x]_lg_{i16,u16}_e64 refused condition lg allowed passes v_cmp_lg_i16_e64, v_cmpx_lg_i16_e64, and the u16 pair
M25 NEG/ABS on inline 1, all but v_cmp_lt_i16_e64 refused guard applies to lt_i16_e64 only passes neg/absolute on inline 1 in v_cmp[x]_* for every other opcode

Reference for M10 (decoder output, not the translator): v_cmp_lt_i16_e64 with inline 1 and NEG decodes (tools/disasm_rdna2.py, decode_instruction) to v_cmp_lt_i16_e64 s4, -1, v2, with ABS to v_cmp_lt_i16_e64 s4, |1|, v2, and with inline -1 to s4, -1, v2. The NEG and inline -1 texts are identical, so without the raw-word guard the translator would read -1 where the source holds 1.

Verification

Commit under test: fa464666 on 7092683a. Windows 11, Python 3.12, no GPU used.

out\pe-env\Scripts\python.exe -B tests\startup_gfx2hlsl_cmp16_check.py

Expected and observed: 163 refusals: ok ... PASS, exit 0 (unmodified main check: 71 refusals: ok, exit 0). With each mutant in the table applied, the main check still exits 0, and the new check exits 1 with 163 refusals: MISMATCH followed by the case names listed above.

Limits

  • Only the no-argument mode ran. The binary mode (LLVM 15 llvm-mc) and the draw cases were not run; the added cases do not use them.
  • No change under tools/.
  • Mutant M21 (low16_only switched off in the register source) cannot be told apart in Probe, so it is not covered here.
  • The table lists the 8 mutants (of 25 tried) that survived the main check and are killed by this PR; the other 17 were not re-run for this PR.
  • A second, separate mutation pass repeated the 8 mutants on this commit's earlier revision (same result) and tried 18 more; three of those (ge dropped from the guard, o/u allowed, upper bound < 0xffff) are also killed only by the new cases, and one (lg table entry) is equivalent because lg is refused first. It also confirmed against tools/disasm_rdna2.py and docs/coverage/gfx1013.tsv that i16/u16 compares exist only for lt/eq/le/gt/ne/ge.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6608873673 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2426). Originally posted by [Makto94](https://github.com/Makto94) on 2026-11-25T16:26:10Z. --- Refs #1723 ## Problem `tests/startup_gfx2hlsl_cmp16_check.py` (added in #2369, Part of #1723) fixes the accepted 16-bit VOPC compares well, but its "Refusals" section left three guards of the lowering unpinned: - The `_e64` NEG/ABS guard in `check_encoding()`. The decoder prints NEG on inline 1 as `-1`, the same text as inline -1 (`v_cmp_lt_i16_e64 s4, -1, v2` for both; ABS prints `|1|`). Only the raw word tells them apart, so the guard is the only protection against reading `-1` for `1`. The check exercised it for `v_cmp_lt_i16_e64` only. - The literal limits of a 16-bit source (`-16 <= value <= 0xffff`). Only values inside the range were tried. - The conditions that exist at no 16-bit integer width (`t`, `lg`, `nlg`, `nlt`, `nle`, `ngt`, `nge`, `neq`, `o`, `u`). Only `v_cmp_f_i16_e64` was checked. Mutants of `tools/startup/gfx2hlsl.py` that break these guards passed the check on `main` (`7092683a`). ## Change Test-only; 20 added lines in the "Refusals" section of `controls()`. No file under `tools/` changes. - NEG and ABS on inline 1 are refused with `neg/abs` for all 24 opcodes (`v_cmp`/`v_cmpx` x 6 relations x i16/u16, `_e64`): 48 cases. - Literal `0xffff` is accepted and `0x10000` is refused (`wider than 16 bits`) for i16 and u16. - The 10 non-existent conditions are refused for i16/u16 and `v_cmp`/`v_cmpx` (`_e64`): 40 cases, each with the expected `v_cmp[x]_<cond>_<type>` reason. The check is already in the Linux list of `.github/workflows/windows.yml` (job `python-linux`, line 259), so CI runs the new cases without a workflow change. ## Mutants Each mutant edits one expression in `tools/startup/gfx2hlsl.py` at `7092683a`. "main check" is the unmodified check from `main`; "new check" is this PR. | # | Input | Reference | Mutant | main check | Killed by (new check) | |---|---|---|---|---|---| | M4 | literal `0xffff`, i16/u16 | accepted (widest 16-bit literal) | upper bound `0xffff` -> `0xfffe` | passes | `literal 0xffff {i16,u16} accepted` | | M5 | literal `0x10000`, i16/u16 | refused, `wider than 16 bits` | upper bound `0xffff` -> `0x10000` | passes | `literal 0x10000 {i16,u16}` | | M10 | NEG/ABS on inline 1, `v_cmpx_*` | refused (decoder prints `-1` / `\|1\|`) | guard regex drops `x?`, so `v_cmpx` is unguarded | passes | `neg/absolute on inline 1 in v_cmpx_*` | | M11 | NEG/ABS on inline 1, u16 | refused | guard regex only `i16` | passes | `neg/absolute on inline 1 in v_cmp[x]_*_u16` | | M12 | NEG/ABS on inline 1, `ne` | refused | guard regex drops `ne` | passes | `neg/absolute on inline 1 in v_cmp[x]_ne_*` | | M17 | `v_cmp[x]_t_{i16,u16}_e64` | refused | condition `t` allowed | passes | `v_cmp_t_i16_e64`, `v_cmpx_t_i16_e64`, and the u16 pair | | M18 | `v_cmp[x]_lg_{i16,u16}_e64` | refused | condition `lg` allowed | passes | `v_cmp_lg_i16_e64`, `v_cmpx_lg_i16_e64`, and the u16 pair | | M25 | NEG/ABS on inline 1, all but `v_cmp_lt_i16_e64` | refused | guard applies to `lt_i16_e64` only | passes | `neg/absolute on inline 1 in v_cmp[x]_*` for every other opcode | Reference for M10 (decoder output, not the translator): `v_cmp_lt_i16_e64` with inline 1 and NEG decodes (`tools/disasm_rdna2.py`, `decode_instruction`) to `v_cmp_lt_i16_e64 s4, -1, v2`, with ABS to `v_cmp_lt_i16_e64 s4, |1|, v2`, and with inline -1 to `s4, -1, v2`. The NEG and inline -1 texts are identical, so without the raw-word guard the translator would read `-1` where the source holds `1`. ## Verification Commit under test: `fa464666` on `7092683a`. Windows 11, Python 3.12, no GPU used. ``` out\pe-env\Scripts\python.exe -B tests\startup_gfx2hlsl_cmp16_check.py ``` Expected and observed: `163 refusals: ok` ... `PASS`, exit 0 (unmodified `main` check: `71 refusals: ok`, exit 0). With each mutant in the table applied, the `main` check still exits 0, and the new check exits 1 with `163 refusals: MISMATCH` followed by the case names listed above. ## Limits - Only the no-argument mode ran. The `binary` mode (LLVM 15 `llvm-mc`) and the draw cases were not run; the added cases do not use them. - No change under `tools/`. - Mutant M21 (`low16_only` switched off in the register source) cannot be told apart in `Probe`, so it is not covered here. - The table lists the 8 mutants (of 25 tried) that survived the `main` check and are killed by this PR; the other 17 were not re-run for this PR. - A second, separate mutation pass repeated the 8 mutants on this commit's earlier revision (same result) and tried 18 more; three of those (`ge` dropped from the guard, `o`/`u` allowed, upper bound `< 0xffff`) are also killed only by the new cases, and one (`lg` table entry) is equivalent because `lg` is refused first. It also confirmed against `tools/disasm_rdna2.py` and `docs/coverage/gfx1013.tsv` that i16/u16 compares exist only for lt/eq/le/gt/ne/ge.
upstream-sync closed this pull request 2026-11-25 18:01:04 +00:00
MasterDomino commented 2026-11-25 18:01:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-25T17:13:06Z.

Review: APPROVED


Approved at head fa464666. The change is test-only: 20 lines in the "Refusals" section of tests/startup_gfx2hlsl_cmp16_check.py.

Commands executed (Windows 11 build 26300, Python 3.13; no GPU needed)

python -B tests/startup_gfx2hlsl_cmp16_check.py
  • At fa464666: 163 refusals: ok, then PASS.
  • Merged with current main 38468ab8: same result, and the merge is clean.

Negative control

I applied five of the listed mutants, one at a time, to tools/startup/gfx2hlsl.py, then reverted each. Each ran against this PR's check and against main's check:

Mutant main check This PR's check
M10: guard regex v_cmpx? changed to v_cmp exit 0 (survives) exit 1, 163 refusals: MISMATCH
M11: guard regex [iu]16 changed to i16 exit 0 exit 1
M5: literal bound <= 0x10000 exit 0 exit 1
M4: literal bound <= 0xfffe exit 0 exit 1
M17: condition t allowed exit 0 exit 1

This matches the table in the description. I also checked that the three guards the new cases target exist in gfx2hlsl.py as described: the NEG/ABS raw-word guard, the -16..0xffff source bound, and the six-relation filter.

Merge checks: CI passed at this head ("Build and test on Windows" and both Linux jobs). The /O2 and coverage skips come from explicit workflow conditions. There are no review threads.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6061850292 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2426#pullrequestreview-6061850292). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-25T17:13:06Z. **Review:** APPROVED --- Approved at head `fa464666`. The change is test-only: 20 lines in the "Refusals" section of `tests/startup_gfx2hlsl_cmp16_check.py`. ### Commands executed (Windows 11 build 26300, Python 3.13; no GPU needed) ```powershell python -B tests/startup_gfx2hlsl_cmp16_check.py ``` - At `fa464666`: `163 refusals: ok`, then `PASS`. - Merged with current `main` `38468ab8`: same result, and the merge is clean. ### Negative control I applied five of the listed mutants, one at a time, to `tools/startup/gfx2hlsl.py`, then reverted each. Each ran against this PR's check and against `main`'s check: | Mutant | `main` check | This PR's check | |---|---|---| | M10: guard regex `v_cmpx?` changed to `v_cmp` | exit 0 (survives) | exit 1, `163 refusals: MISMATCH` | | M11: guard regex `[iu]16` changed to `i16` | exit 0 | exit 1 | | M5: literal bound `<= 0x10000` | exit 0 | exit 1 | | M4: literal bound `<= 0xfffe` | exit 0 | exit 1 | | M17: condition `t` allowed | exit 0 | exit 1 | This matches the table in the description. I also checked that the three guards the new cases target exist in `gfx2hlsl.py` as described: the NEG/ABS raw-word guard, the `-16..0xffff` source bound, and the six-relation filter. Merge checks: CI passed at this head ("Build and test on Windows" and both Linux jobs). The `/O2` and coverage skips come from explicit workflow conditions. There are no review threads. AI-assisted; commands listed were executed locally.
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!2418
No description provided.