Skip to content

startup: refuse NEG on an inline-integer or literal VOP3 source in gfx2hlsl - #2529

Merged
tedin7 merged 3 commits into
R0Y00:mainfrom
Makto94:startup/gfx2hlsl-refuse-neg-integer-operand
Nov 25, 2026
Merged

tedin7 merged 3 commits into
R0Y00:mainfrom
Makto94:startup/gfx2hlsl-refuse-neg-integer-operand

Conversation

@Makto94

@Makto94 Makto94 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Refs #1723

Problem

tools/startup/gfx2hlsl.py translates 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 same 0xffffffff. A literal 5 with NEG reads 0xfffffffb. Float operations are affected too: v_cmp_lt_f32_e64 with inline 1 and NEG translates to F(0xffffffffu).

check_encoding already notes this ("The printed -1 is ambiguous"). The only NEG model for an integer source in the repository is v_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_encoding reads 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.
  • The two data sources (slots 0 and 1) of v_cndmask_b32_e64 are excepted. They keep their sign-bit model.
  • The rule does not test word 0 ABS bits: on the VOP3b forms they are SDST.
  • The existing NEG/ABS guards (16-bit compares, v_sad_*) keep their own refusal text. A few other refusals, for example op_sel on a VOP3b form with sdst s105/s106, now report the new message because this rule fires first. They stay refusals.
  • Inline floats, negative inlines, registers and VOP3b with sdst s4/s105/s106 are unchanged. Unused source slots that carry NEG are also refused (conservative).
  • docs/experiments.md gets one paragraph in the section "Startup translator: 16-bit integer compares". It records the refusal, the v_cndmask_b32_e64 exception and that the hardware behavior is not measured.

Tests

tests/startup_gfx2hlsl_refusals_check.py, new check_neg_integer_sources:

  • A loop over every accepted VOP3 opcode and every source slot: inline 1 with NEG must be refused, except the v_cndmask_b32_e64 data 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).
  • Named cases: v_mad_u32_u24 in 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_u32 and v_lshlrev_b64.
  • Negative controls: plain inline -1 still reads 0xffffffff; inline -1 with NEG, inline floats 240..248 with NEG, and v_add_co_u32 with sdst s4 are not refused by this rule; v_cndmask_b32_e64 slots 0 and 1 with inline 1 and NEG still give 0x80000001u; its mask slot (slot 2) is refused.

Before: on base c133432a with 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 onto d6830702 applied without changes, and the three checks and the full Python list were rerun on d6830702). Each mutant was applied in a temporary copy. All were killed.

Mutant Killed by
NEG tested on bit 29 only startup_gfx2hlsl_refusals_check.py (6 controls)
Literal (255) removed from the rule startup_gfx2hlsl_refusals_check.py (2 controls)
Range 128..191 instead of 128..192 startup_gfx2hlsl_refusals_check.py (1 control)
v_cndmask_b32_e64 exception extended to slot 2 startup_gfx2hlsl_refusals_check.py (3 controls)
Exception added for v_add_f32_e64 startup_gfx2hlsl_refusals_check.py (3 controls)
Exception added for v_mul_i32_i24_e64 startup_gfx2hlsl_refusals_check.py (2 controls)
Exception added for v_mad_i32_i24 startup_gfx2hlsl_refusals_check.py (2 controls)
New message changed to <op> with neg/abs startup_gfx2hlsl_refusals_check.py (12 controls)
Slot in the message always 0 startup_gfx2hlsl_refusals_check.py (6 controls)
Rule placed before the 16-bit compare guard startup_gfx2hlsl_cmp16_check.py

Independent 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}, sdst in {4, 105, 106}.

  • 3019 words change from accepted to refused. All are NEG on an inline integer 128..192 or a literal (255) outside the v_cndmask_b32_e64 data slots.
  • 86643 words were already refused. Only the message changes, because the new rule fires first (for example op_sel on a VOP3b form with sdst s105/s106).
  • 0 words change from refused to accepted.
  • v_sad_* is unchanged. v_mul_i32_i24_e64 and v_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 test bd66f8fb (code and test) and 38b5464e (docs). Windows 11 build 26300, Python from out/pe-env.

python -B tests/startup_gfx2hlsl_refusals_check.py
python -B tests/startup_gfx2hlsl_cmp16_check.py
python -B tests/startup_gfx2hlsl_sad_check.py
  • The three checks: exit 0.
  • The full Python list of the CI job (150 scripts at d6830702, via tools/run_checks_parallel.py): no FAILED. The only non-ok results are startup_run_sh_check.py and startup_build_rev_check.py, which return 77 (capability skip) on the base as well. A skip is not a pass.

Limits

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 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_encoding already names (printed -1 for inline 1 with NEG vs. plain inline -1).
  • The v_cndmask_b32_e64 data 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: PASS
  • python3 tests/docs_links_check.py: PASS
  • python3 tests/bidi_controls_check.py: PASS
  • git 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_e64 exception: 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.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

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 d239d8e492c9ca89153a3ac5c8a5ac94f0ebb5d6:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2): 32.16s (configure 2.08s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2): 58.26s (configure 2.08s)
  • Windows Python checks: tests/mesh_heap_sampler_check.py ok (0.7s), tests/startup_buffer_address_check.py ok (0.5s), tests/startup_buffer_format_word3_table_check.py ok (0.1s), tests/startup_compute_request_offline_check.py ok (0.5s), tests/startup_compute_translate_check.py ok (0.2s), tests/startup_flat_param_check.py ok (0.1s), tests/startup_gfx2hlsl_add_sub_co_check.py ok (0.1s), tests/startup_gfx2hlsl_add_sub_co_ci_check.py ok (0.2s), tests/startup_gfx2hlsl_bit_alu_check.py ok (0.7s), tests/startup_gfx2hlsl_capture_check.py ok (1.0s), tests/startup_gfx2hlsl_cmp16_check.py ok (0.3s), tests/startup_gfx2hlsl_compare_dst_check.py ok (0.1s), tests/startup_gfx2hlsl_compute_check.py ok (0.4s), tests/startup_gfx2hlsl_cselect_mask_check.py ok (0.1s), tests/startup_gfx2hlsl_cvt_alu_check.py ok (0.1s), tests/startup_gfx2hlsl_f32_lg_check.py ok (1.2s), tests/startup_gfx2hlsl_f32_nan_check.py ok (5.1s), tests/startup_gfx2hlsl_getpc_refusal_check.py ok (0.1s), tests/startup_gfx2hlsl_handler_arity_check.py ok (0.1s), tests/startup_gfx2hlsl_image_arity_check.py ok (0.1s), tests/startup_gfx2hlsl_image_get_lod_check.py ok (0.1s), tests/startup_gfx2hlsl_int_med3_check.py ok (0.1s), tests/startup_gfx2hlsl_join_symbols_check.py ok (0.2s), tests/startup_gfx2hlsl_loop_constants_check.py ok (0.1s), tests/startup_gfx2hlsl_mask_overwrite_check.py ok (0.1s), tests/startup_gfx2hlsl_operand_count_check.py ok (0.3s), tests/startup_gfx2hlsl_pack_absdiff_check.py ok (2.6s), tests/startup_gfx2hlsl_readfirstlane_recompute_check.py ok (0.1s), tests/startup_gfx2hlsl_readfirstlane_uniform_check.py ok (0.1s), tests/startup_gfx2hlsl_refusals_check.py ok (0.5s), tests/startup_gfx2hlsl_root_check.py ok (0.7s), tests/startup_gfx2hlsl_sad_check.py ok (0.3s), tests/startup_gfx2hlsl_saveexec_same_reg_check.py ok (0.1s), tests/startup_gfx2hlsl_scalar_arity_check.py ok (0.2s), tests/startup_gfx2hlsl_scalar_brev_fold_check.py ok (0.1s), tests/startup_gfx2hlsl_scalar_m0_check.py ok (0.1s), tests/startup_gfx2hlsl_scalar_table_arity_check.py ok (0.3s), tests/startup_gfx2hlsl_sdwa_cvt_check.py ok (0.3s), tests/startup_gfx2hlsl_sgpr_spill_check.py ok (0.1s), tests/startup_gfx2hlsl_shift64_check.py ok (0.1s), tests/startup_gfx2hlsl_smem_offset_check.py ok (0.1s), tests/startup_gfx2hlsl_sop2_complement_check.py ok (5.3s), tests/startup_gfx2hlsl_sopk_accum_check.py ok (0.8s), tests/startup_gfx2hlsl_sopk_signext_check.py ok (0.1s), tests/startup_gfx2hlsl_swap_check.py ok (0.3s), tests/startup_gfx2hlsl_vopc_sdwa_check.py ok (4.0s), tests/startup_gfx2hlsl_waitcnt_depctr_check.py ok (0.1s), tests/startup_gfx2hlsl_watch_check.py ok (2.4s), tests/startup_image_2d_array_check.py ok (0.2s), tests/startup_image_3d_check.py ok (0.1s), tests/startup_image_gather_lz_check.py ok (0.7s), tests/startup_image_load_d16_check.py ok (0.8s), tests/startup_image_sample_a16_check.py ok (0.1s), tests/startup_image_sample_b_check.py ok (0.1s), tests/startup_image_sample_c_check.py ok (0.2s), tests/startup_image_sample_l_check.py ok (0.2s), tests/startup_image_sample_lod_check.py ok (0.6s), tests/startup_inline_sampler_check.py ok (0.1s), tests/startup_mesh57_skeleton_check.py ok (0.1s), tests/startup_run_ps1_check.py ok (9.3s), tests/startup_run_sh_check.py skipped (0.1s), tests/startup_sampler_heap_check.py ok (0.1s), tests/startup_shader_cache_rekey_check.py ok (1.7s), tests/startup_smem_address_check.py ok (0.1s), tests/startup_stream_fetch_check.py ok (0.2s), tests/startup_stream_interface_check.py ok (0.2s), tests/startup_translator_check.py ok (0.4s)
  • sccache: -734/-2529 hits; wall 148.7s

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit ce53084 into R0Y00:main Nov 25, 2026
5 checks passed
R0Y00 pushed a commit that referenced this pull request Nov 25, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants