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

Merged
Leyukaka merged 2 commits from upstream-pr/2563 into main 2026-11-25 21:23:21 +00:00
Leyukaka commented 2026-11-25 21:08:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-25T21:08:28Z.


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 #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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6613790754 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2563). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-25T21:08:28Z. --- Follow-up to #2529 ([claim](https://github.com/R0Y00/Xbox2Windows/issues/1723#issuecomment-7174262692)). 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 #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.
upstream-sync closed this pull request 2026-11-25 22:02:06 +00:00
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!2555
No description provided.