Repository navigation
startup: refuse NEG on an inline-integer or literal VOP3 source in gfx2hlsl - #2529
Conversation
The decoder prints inline 1 with NEG as -1, the text of inline -1, so the two encodings translated to the same 0xffffffff, and a literal 5 with NEG became 0xfffffffb. Refuse NEG (w1[31:29]) on an inline 0..64 or literal source of any VOP3 instruction except the v_cndmask_b32_e64 data sources, which model NEG as the sign bit flipped. Inline floats, registers and negative inlines are unchanged; ABS is not tested because it is SDST on the VOP3b forms.
tedin7
left a comment
There was a problem hiding this comment.
Review of head 38b5464 (comment only).
Scope: refusal-only guard in check_encoding (tools/startup/gfx2hlsl.py), a new test in tests/startup_gfx2hlsl_refusals_check.py, one docs paragraph. No new lowering, no executable-path change, no startup claim to verify on the game.
Checked:
- The guard reads VOP3 word 1 NEG bits 31:29 and refuses on source fields 128..192 and 255. This matches the ambiguity the existing comment in
check_encodingalready names (printed-1for inline 1 with NEG vs. plain inline -1). - The
v_cndmask_b32_e64data slots (0 and 1) keep their sign-bit model from #1710. Slot 2 is still refused. - ABS is correctly left out: on VOP3b forms word 0 bits 10:8 are SDST.
- Sibling guards (#2369 16-bit compares, #2450
v_sad_*) still win with their own text where they fire first. The test accepts either message. - No other open or merged PR covers this slice (searched NEG / VOP3 / inline / gfx2hlsl).
Commands run locally (worktree on the exact head, 1 commit behind main):
python3 tests/startup_gfx2hlsl_refusals_check.py: PASSpython3 tests/docs_links_check.py: PASSpython3 tests/bidi_controls_check.py: PASSgit diff --check origin/main...HEAD: clean- Mutation 1: upper bound 192 -> 191 (inline 64 no longer refused): the test fails (exit 1).
- Mutation 2: remove the
v_cndmask_b32_e64exception: the test fails (exit 1).
Result: no blocking findings. Win2025 WARP and the CI run on this head are still pending; merge stays gated on those.
AI-assisted; commands listed were executed locally.
|
Win2025 WARP receipt for head d239d8e after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
AI-assisted; commands listed were executed locally. |
…rce (follow-up to #2529) (#2563) * startup: translate VOP3 NEG on an inline-integer or literal float source The refusal added for NEG on an inline-integer or literal VOP3 source (Part of #1723) covered every slot. For a float-typed source slot of the f32 ALU table (VEC_F) and of v_cmp(x)_*_f32 (src0 only for the class compares), translate NEG with the model LLVM's assembler uses when it folds neg into an immediate: bit 31 of the 32-bit source word flipped (inline 1 -> 0x80000001, literal 0x5 -> 0x80000005, inline 0 -> 0x80000000). The word is taken from the encoding, not from the printed text, and emitted as an exact bit pattern. RDNA hardware behaviour for these sources is not measured; the WARP and NVIDIA readback only checks the HLSL against this model. Integer-typed slots, the class mask slot, NEG with ABS on the same source, and everything refused for another reason stay refused. Tests: startup_gfx2hlsl_neg_check.py checks the emitted words for v_fma_f32, v_mul_f32 and v_med3_f32 with NEG on inline 0, 1 and 64 and a literal, and in dispatch mode reads them back on WARP and hardware against a CPU reference (the two subnormal v_mul results may flush to signed zero). startup_gfx2hlsl_refusals_check.py now expects float slots to translate and integer slots, the class mask slot and NEG with ABS to refuse. AI-assisted. # Conflicts: # CMakeLists.txt # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # interactive rebase in progress; onto 9bef64e # Last command done (1 command done): # pick 19a8c3aa # startup: translate VOP3 NEG on an inline-integer or literal float source # No commands remaining. # You are currently rebasing branch 'vop3-neg-inline' on '9bef64ee'. # # Changes to be committed: # modified: .github/workflows/windows.yml # modified: AGENTS.md # modified: CMakeLists.txt # modified: docs/experiments.md # new file: tests/startup_gfx2hlsl_neg_check.py # modified: tests/startup_gfx2hlsl_refusals_check.py # modified: tools/startup/gfx2hlsl.py # * build: restore the endforeach of the v_fma_mix dispatch tests Resolving the rebase onto main dropped the endforeach() that closes the startup_gfx2hlsl_fma_mix_dispatch loop, so the CMake configure failed. The neg tests now follow the closed loop. AI-assisted.
Refs #1723
Problem
tools/startup/gfx2hlsl.pytranslates the text printed by the disassembler. For a VOP3 source, the disassembler prints inline integer 1 with the NEG bit set as-1. This is the same text as the plain inline -1 (operand 193). The two encodings therefore translate to the same0xffffffff. A literal 5 with NEG reads0xfffffffb. Float operations are affected too:v_cmp_lt_f32_e64with inline 1 and NEG translates toF(0xffffffffu).check_encodingalready notes this ("The printed -1 is ambiguous"). The only NEG model for an integer source in the repository isv_cndmask_b32(sign bit flipped). The hardware behavior of NEG on integer sources was not measured. Related guards: #2369 (raw-word check of NEG/ABS for the 16-bit compares), #2426 and #2450 (v_sad_*).Change
check_encodingreads word 1 of every VOP3 instruction. It refuses NEG (bits 31:29, one bit per source) on a source field in 128..192 (inline 0..64) or 255 (literal). The refusal names the opcode and the source slot.v_cndmask_b32_e64are excepted. They keep their sign-bit model.v_sad_*) keep their own refusal text. A few other refusals, for exampleop_selon a VOP3b form withsdsts105/s106, now report the new message because this rule fires first. They stay refusals.sdsts4/s105/s106 are unchanged. Unused source slots that carry NEG are also refused (conservative).docs/experiments.mdgets one paragraph in the section "Startup translator: 16-bit integer compares". It records the refusal, thev_cndmask_b32_e64exception and that the hardware behavior is not measured.Tests
tests/startup_gfx2hlsl_refusals_check.py, newcheck_neg_integer_sources:v_cndmask_b32_e64data slots. The test accepts as a valid refusal either the new message or an earlier NEG/ABS refusal of an existing guard (16-bit compares,v_sad_*from startup: lower v_sad_u8, v_sad_u16, and v_sad_u32 in gfx2hlsl #2450).v_mad_u32_u24in all three slots (with NEG refused, without NEG translated), inline 0 and 64, a literal with and without NEG,v_add_f32_e64, a compare, a compare with a literal in slot 1,v_add_co_u32andv_lshlrev_b64.0xffffffff; inline -1 with NEG, inline floats 240..248 with NEG, andv_add_co_u32withsdsts4 are not refused by this rule;v_cndmask_b32_e64slots 0 and 1 with inline 1 and NEG still give0x80000001u; its mask slot (slot 2) is refused.Before: on base
c133432awith only the new test, the check fails (rc=1, 12 controls failed). After: with this change it passes (rc=0, 82 controls ok).Mutation checks
Independent falsification (on the same two commits at base
c133432a; the rebase ontod6830702applied without changes, and the three checks and the full Python list were rerun ond6830702). Each mutant was applied in a temporary copy. All were killed.startup_gfx2hlsl_refusals_check.py(6 controls)startup_gfx2hlsl_refusals_check.py(2 controls)startup_gfx2hlsl_refusals_check.py(1 control)v_cndmask_b32_e64exception extended to slot 2startup_gfx2hlsl_refusals_check.py(3 controls)v_add_f32_e64startup_gfx2hlsl_refusals_check.py(3 controls)v_mul_i32_i24_e64startup_gfx2hlsl_refusals_check.py(2 controls)v_mad_i32_i24startup_gfx2hlsl_refusals_check.py(2 controls)<op> with neg/absstartup_gfx2hlsl_refusals_check.py(12 controls)startup_gfx2hlsl_refusals_check.py(6 controls)startup_gfx2hlsl_cmp16_check.pyIndependent falsification also ran a differential of
main(c133432a) against this change over 608256 VOP3 words: opcode 0..0x3ff, 3 source slots, 22 source values, NEG in {0, slot bit, 7},sdstin {4, 105, 106}.v_cndmask_b32_e64data slots.op_selon a VOP3b form withsdsts105/s106).v_sad_*is unchanged.v_mul_i32_i24_e64andv_mad_i32_i24(startup: lower v_mul_i32_i24 and v_mad_i32_i24 in gfx2hlsl #2410) are covered without a list of names.Verification
Base
d6830702; commits under testbd66f8fb(code and test) and38b5464e(docs). Windows 11 build 26300, Python fromout/pe-env.d6830702, viatools/run_checks_parallel.py): no FAILED. The only non-ok results arestartup_run_sh_check.pyandstartup_build_rev_check.py, which return 77 (capability skip) on the base as well. A skip is not a pass.Limits
check_encodingoru_srcforv_cndmask_b32, and startup: lower v_pack_b32_f16 with op_sel and neg/abs in gfx2hlsl #2475 touchestools/startup/gfx2hlsl.py; a rebase may be needed.