shader: lower v_div_fixup_f64 in the direct compute path (#3518) #3879

Open
github-bot wants to merge 1 commit from github-bot/gh-3877 into main AGit
Owner

@⁠Ammmae0x on GitHub · 2026-12-02 17:34 UTC · original
Ammmae0x:shader/direct-div-fixup-f64 → main · +845 −0 · 6 files · 1 commits · draft

Refs #3520, #2935

Lowers v_div_fixup_f64 (VOP3 0x160, RDNA 2 ISA section 12.12, opcode 352) in the direct C++ compute path only (#3673 covers pixel_aot; this PR does not touch it).

What landed — single commit on shader/direct-div-fixup-f64, off origin/main b68e954c, pushed to the fork with no force-push. 6 files, +845/-0:

  • src/gfx1013_direct_compute.inl — pure 32-bit integer (uint2 lo/hi words; no DXIL double, no i64, no fcmp, no DoublePrecisionFloatShaderOps/Int64ShaderOps) lowering in precedence order: Quiet(S2), Quiet(S1), 0/0 and Inf/Inf -> 0xfff80000_00000000, S1 == 0 || S2 == Inf -> signed Inf, S1 == Inf || S2 == 0 -> signed 0, exponent(S2) - exponent(S1) < -1075 -> signed 0, else (sign(S1) ^ sign(S2)) | abs(S0). Guards: direct-compute VOP3 only (!pixel_stage && !graphics_input, !i.wide refused, !i.subword, !i.dpp_control, !permuted, !i.scale, (i.a & 0x7800) refused), default binary64 rounding/denormal MODE check like v_fract_f64/v_min_f64 (and the op is now in the half_binary MODE-tracking list), aligned 64-bit VGPR dst, aligned 64-bit VGPR/SGPR pair sources + inline 0 (128) and inline binary64 constants 240..247, abs/neg on bit 31 of hi, clamp handled like the f32 form (NaN or negative -> +0.0, above 1.0 -> 1.0). Everything outside the contract is refused with the exact messages the fixture pins.
  • src/gfx1013_compute_native.cpp — clear_vector_spills treats v_div_fixup_f64 as a 2-VGPR pair write.
  • tests/native_div_fixup_f64_check.py (model/ir/controls/hardware) + tests/cmake/native_div_fixup_f64.cmake + tests/checks/python-linux/native_div_fixup_f64.txt — 24 boundary triples (NaN quieting and S2-over-S1 priority, 0/0, Inf/Inf, signed Inf/zero rules, -0/+0, subnormals, exp(S2)-exp(S1) at -1075 vs -1076, abs/neg, SGPR + VGPR + inline constants) plus a seeded sweep of 120 triples, plain and clamped; 15 refusal controls (omod, op_sel, literal/inline-129/239/248 sources, odd SGPR pair, VCC/EXEC pair, v255 source/destination, flushing and conditional MODE, spills in v10/v11) and 6 self-mutation controls (sign XOR, invalid, NaN priority, underflow, clamp, quieting).
  • docs/experiments/native-direct-div-fixup-f64.md — semantics, fixture, and the exponent note below.

Exponent semantics (flagged explicitly): "exponent" is the stored biased exponent field, as in the in-repo v_div_fixup_f32 lowering (a subnormal reads 0, not its normalized exponent). The two readings agree for every normal operand and for a subnormal S1, and differ only for a subnormal S2 against an S1 whose stored field is 1076 (stored diff -1076, normalized diff -1075). No case pins that one pair, so a hardware reading can arbitrate it; the fixture covers subnormal S2 at stored diffs -1023 and -2046 (both readings agree) and the normal-operand boundary at -1075 (pass-through) versus -1076 (underflow). There is no pixel_aot implementation of this op in-tree to cross-check against yet (#3673 is the separate task).

Linux verification (this host cannot run Windows CTest, DXC, or D3D12):

  • python -B tests/native_div_fixup_f64_check.py model — PASS: 144 triples x plain/clamp matched the independent frexp-based reference on 262 non-subnormal checks (26 subnormal checks use the stored-field rule); 6 self-mutations killed.
  • C++ lowering transcribed to Python agrees with the reference on 5144 triples x plain/clamp, 0 mismatches (including inline cases).
  • All fixture word streams decode with tools/disasm_rdna2.py as v_div_fixup_f64 v[10:11], v[2:3], v[4:5], v[6:7] (SGPR/inline/abs/neg/clamp forms in the e64 chunk decode as intended); all 15 refusal encodings decode as intended.
  • python -B tests/form_coverage_check.py — PASS (with the repo venv; system Python lacks iced_x86); python -B tests/docs_links_check.py — PASS (251 files, 954 links); python -B tests/bidi_controls_check.py — PASS (2996 files); tests/run_checks_parallel_check.py — ok; the model command is registered exactly once in the Linux CI list.
  • git diff --check clean; git merge-tree --write-tree origin/main HEAD exits 0.

ir, controls, and hardware modes need the Windows DXIL toolchain and are not verified on Linux.

WIN-VERIFY: pending | sha=9d8ff7156f8cb2347785a2202f4ed8dda5ffa23b | targets=native_compute_ir_dump compile_dxil native_store_replay | ctest=^native_div_fixup_f64_(ir|controls|hardware)$ | release=true

**@⁠Ammmae0x** on GitHub · 2026-12-02 17:34 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3877) `Ammmae0x:shader/direct-div-fixup-f64` → `main` · +845 −0 · 6 files · 1 commits · draft Refs #3520, #2935 Lowers `v_div_fixup_f64` (VOP3 `0x160`, RDNA 2 ISA section 12.12, opcode 352) in the direct C++ compute path only (`#3673` covers `pixel_aot`; this PR does not touch it). **What landed** — single commit on `shader/direct-div-fixup-f64`, off `origin/main` `b68e954c`, pushed to the fork with no force-push. 6 files, +845/-0: - `src/gfx1013_direct_compute.inl` — pure 32-bit integer (`uint2` lo/hi words; no DXIL `double`, no `i64`, no `fcmp`, no `DoublePrecisionFloatShaderOps`/`Int64ShaderOps`) lowering in precedence order: `Quiet(S2)`, `Quiet(S1)`, `0/0` and `Inf/Inf` -> `0xfff80000_00000000`, `S1 == 0 || S2 == Inf` -> signed Inf, `S1 == Inf || S2 == 0` -> signed 0, `exponent(S2) - exponent(S1) < -1075` -> signed 0, else `(sign(S1) ^ sign(S2)) | abs(S0)`. Guards: direct-compute VOP3 only (`!pixel_stage && !graphics_input`, `!i.wide` refused, `!i.subword`, `!i.dpp_control`, `!permuted`, `!i.scale`, `(i.a & 0x7800)` refused), default binary64 rounding/denormal MODE check like `v_fract_f64`/`v_min_f64` (and the op is now in the `half_binary` MODE-tracking list), aligned 64-bit VGPR dst, aligned 64-bit VGPR/SGPR pair sources + inline `0` (`128`) and inline binary64 constants `240..247`, `abs`/`neg` on bit 31 of `hi`, `clamp` handled like the f32 form (NaN or negative -> `+0.0`, above `1.0` -> `1.0`). Everything outside the contract is refused with the exact messages the fixture pins. - `src/gfx1013_compute_native.cpp` — `clear_vector_spills` treats `v_div_fixup_f64` as a 2-VGPR pair write. - `tests/native_div_fixup_f64_check.py` (`model`/`ir`/`controls`/`hardware`) + `tests/cmake/native_div_fixup_f64.cmake` + `tests/checks/python-linux/native_div_fixup_f64.txt` — 24 boundary triples (NaN quieting and S2-over-S1 priority, `0/0`, `Inf/Inf`, signed Inf/zero rules, `-0`/`+0`, subnormals, `exp(S2)-exp(S1)` at `-1075` vs `-1076`, abs/neg, SGPR + VGPR + inline constants) plus a seeded sweep of 120 triples, plain and clamped; 15 refusal controls (omod, op_sel, literal/inline-129/239/248 sources, odd SGPR pair, VCC/EXEC pair, v255 source/destination, flushing and conditional MODE, spills in v10/v11) and 6 self-mutation controls (sign XOR, invalid, NaN priority, underflow, clamp, quieting). - `docs/experiments/native-direct-div-fixup-f64.md` — semantics, fixture, and the exponent note below. **Exponent semantics (flagged explicitly):** "exponent" is the stored biased exponent field, as in the in-repo `v_div_fixup_f32` lowering (a subnormal reads 0, not its normalized exponent). The two readings agree for every normal operand and for a subnormal `S1`, and differ only for a subnormal `S2` against an `S1` whose stored field is 1076 (stored diff `-1076`, normalized diff `-1075`). No case pins that one pair, so a hardware reading can arbitrate it; the fixture covers subnormal `S2` at stored diffs `-1023` and `-2046` (both readings agree) and the normal-operand boundary at `-1075` (pass-through) versus `-1076` (underflow). There is no `pixel_aot` implementation of this op in-tree to cross-check against yet (`#3673` is the separate task). **Linux verification (this host cannot run Windows CTest, DXC, or D3D12):** - `python -B tests/native_div_fixup_f64_check.py model` — PASS: 144 triples x plain/clamp matched the independent `frexp`-based reference on 262 non-subnormal checks (26 subnormal checks use the stored-field rule); 6 self-mutations killed. - C++ lowering transcribed to Python agrees with the reference on 5144 triples x plain/clamp, 0 mismatches (including inline cases). - All fixture word streams decode with `tools/disasm_rdna2.py` as `v_div_fixup_f64 v[10:11], v[2:3], v[4:5], v[6:7]` (SGPR/inline/abs/neg/clamp forms in the e64 chunk decode as intended); all 15 refusal encodings decode as intended. - `python -B tests/form_coverage_check.py` — PASS (with the repo venv; system Python lacks `iced_x86`); `python -B tests/docs_links_check.py` — PASS (251 files, 954 links); `python -B tests/bidi_controls_check.py` — PASS (2996 files); `tests/run_checks_parallel_check.py` — ok; the model command is registered exactly once in the Linux CI list. - `git diff --check` clean; `git merge-tree --write-tree origin/main HEAD` exits 0. `ir`, `controls`, and `hardware` modes need the Windows DXIL toolchain and are not verified on Linux. WIN-VERIFY: pending | sha=9d8ff7156f8cb2347785a2202f4ed8dda5ffa23b | targets=native_compute_ir_dump compile_dxil native_store_replay | ctest=^native_div_fixup_f64_(ir|controls|hardware)$ | release=true
Pure 32-bit integer V_DIV_FIXUP_F64 (RDNA 2 ISA section 12.12,
opcode 352): Quiet(S2) over Quiet(S1), 0/0 and Inf/Inf give
0xfff80000_00000000, signed Inf/zero rules, stored-exponent
underflow at exponent(S2)-exponent(S1) < -1075, else
(sign(S1)^sign(S2)) | abs(S0), with clamp to [0, 1]. No DXIL
double, i64, fcmp, DoublePrecisionFloatShaderOps or
Int64ShaderOps. Refs #3518, #2935.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 19:11:25 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3879/head:github-bot/gh-3877'
git switch 'github-bot/gh-3877'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3877'
git switch 'github-bot/gh-3877'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3877'
git switch 'github-bot/gh-3877'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3877'
git switch 'main'
git merge --squash 'github-bot/gh-3877'
git switch 'main'
git merge --ff-only 'github-bot/gh-3877'
git switch 'main'
git merge 'github-bot/gh-3877'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.