Skip to content

startup: translate VOP3 NEG on an inline-integer or literal float source (follow-up to #2529) - #2563

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
Leyukaka:vop3-neg-inline
Nov 25, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
Leyukaka:vop3-neg-inline

Conversation

@Leyukaka

Copy link
Copy Markdown
Contributor

Follow-up to #2529 (claim). Part of #1723.

#2529 refuses NEG on an inline-integer (0..64) or literal source of any VOP3 instruction, because the printed text loses the distinction. This translates it for float-typed source slots instead:

  • Slots: sources of the f32 ALU table (VEC_F: v_fma_f32, v_mul_f32, v_med3_f32, v_add_f32, ...) and of v_cmp(x)_*_f32. For the class compares, only src0; the mask slot is excluded.
  • Model: NEG flips bit 31 of the 32-bit source word, as LLVM's assembler does when it folds neg into an immediate (AMDGPUAsmParser::applyInputFPModifiers); the RDNA 2 ISA lists VOP3 NEG as a float input modifier. Inline 1 gives 0x80000001, literal 0x5 gives 0x80000005, inline 0 gives 0x80000000. The word is read from the encoding, as startup: refuse NEG on an inline-integer or literal VOP3 source in gfx2hlsl #2529's check does, not from the printed text, and emitted as an exact bit pattern through F(). RDNA hardware behaviour of NEG on these immediate sources is not measured; the WARP and NVIDIA readback only checks the HLSL against this model.
  • Still refused: integer-typed slots, the class mask slot, NEG together with ABS on the same source, and anything refused for another reason. v_cndmask_b32_e64 keeps its own handling.

Tests (Windows 11, Python 3.14, DXC from the Windows SDK 10.0.26100), on main 9bef64e plus this commit:

  • python -B tests/startup_gfx2hlsl_neg_check.py (new): ok. The emitted word for v_fma_f32, v_mul_f32 and v_med3_f32 with NEG on inline 0, inline 1, inline 64 and a literal.
  • ... dispatch <dxc> <offscreen_check> warp and hardware: ok, on WARP (Microsoft Basic Render Driver) and an NVIDIA GeForce RTX 5080. Each form is compared with a CPU reference built from the encoded words. The two v_mul_f32 results that are subnormal may flush to signed zero; the others are compared bit-exactly, including -0.0 for inline 0.
  • tests/startup_gfx2hlsl_refusals_check.py: ok. Float slots now translate; integer slots, the class mask slot and NEG with ABS still refuse.
  • Also ok: startup_gfx2hlsl_bit_alu_check, startup_gfx2hlsl_mad_check, startup_gfx2hlsl_operand_count_check, startup_gfx2hlsl_handler_arity_check, startup_translator_check, startup_gfx2hlsl_f32_nan_check, startup_gfx2hlsl_f32_lg_check, startup_gfx2hlsl_cvt_alu_check, startup_gfx2hlsl_compute_check and startup_gfx2hlsl_int_med3_check.

Mutation checks, run by hand. Each one fails at least one of the checks above:

  • no sign flip (fails the new check, the refusals check and the WARP dispatch);
  • integer slots accepted;
  • the class mask slot accepted;
  • NEG with ABS accepted (each of the last three fails the refusals check).

Measured on a local capture (counts only, inputs private; requests re-keyed with shader_cache_rekey.py for the current revision): at main 9bef64e, 176 pipelines translate (85 graphics, 91 compute), and the #2529 refusal was the first refusal for about 1,400 requests. With this change none stop there, and 179 translate (87 graphics, 92 compute). The rest now stop at refusals that were already there behind it: src_scc in s_mov_b32 (818), an execz VCC definition (341), v_readfirstlane_b32 proofs (284) and |vN| on v_cndmask_b32_e64 (217).

AI-assisted.

The refusal added for NEG on an inline-integer or literal VOP3 source
(Part of R0Y00#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
#
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.
@R0Y00
R0Y00 merged commit 6c7a59a into R0Y00:main Nov 25, 2026
5 checks passed
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