shader: lower v_ceil_f64, v_floor_f64, v_trunc_f64 and v_rndne_f64 in direct compute #3630

Merged
Ammmae0x merged 5 commits from upstream-pr/3630 into main 2026-12-01 03:12:00 +00:00
Ammmae0x commented 2026-11-30 17:47:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-30T17:47:26Z.


Refs #2935, #3518

Lowers the four binary64 rounding instructions (_e32 and _e64) in the direct C++ compute path with pure 32-bit integer arithmetic only, following the v_*_f16 rounding shape and the v_cmp_*_f64 pair rules.

What changed

  • src/gfx1013_direct_compute.inl (+132): new lowering block after the f16 rounding block. Modifier gate (pixel_stage, graphics_input, i.subword, i.dpp_control, permuted, i.clamp, i.scale, op_sel, modifiers on S1/S2), MODE gate (half_mode_known && !((mode_bits ^ 0xf0u) & 0x8000ccu)), destination must be a VGPR pair (256 <= dst < 511), S0 accepts VGPR pairs, aligned even SGPR pairs, integer 0 (128 -> +0.0) and inline binary64 constants 240..247 (lo = 0); abs then neg act on bit 63 before rounding. Result selected by biased exponent: exp >= 1075 passes the pair unchanged (NaN payload included); exp < 1023 rounds to a signed zero or one (the nonzero test looks at lo too, so a tiny subnormal is not mistaken for zero; rndne |x| == 0.5 rounds to even ±0.0, |x| > 0.5 rounds to ±1.0, including 0x3fe00000_00000001); in between, the fraction sits in lo (1044..1074, carry on wrap), straddles the word boundary (1043, half 0x80000000, evenness hi & 1, carry +1 to hi), or splits across hi and lo (1023..1042, half/sticky comparison across both words, evenness base_hi & unit_hi). All DXIL shift amounts stay in [0, 31] in every lane (clamped selects outside the range). No DXIL double, no i64 in @main(), no fcmp, neither DoublePrecisionFloatShaderOps nor Int64ShaderOps.
  • MODE loop: all four opcodes set half_binary = true, so a conditional denorm-mode write before them refuses.
  • src/gfx1013_compute_native.cpp: the four names join the pair condition in clear_vector_spills, so writing v[d:d+1] invalidates lane spills on both d and d+1.
  • tests/native_round_f64_check.py (model/ir/controls/hardware) + tests/cmake/native_round_f64.cmake + tests/checks/python-linux/native_round_f64.txt + docs/experiments/native-direct-round-f64.md.

Tests

Linux (this host cannot compile the translation unit or run Windows CTest; the C++ executions run in the WIN-VERIFY round):

/tmp/pe-env/bin/python -B tests/native_round_f64_check.py model
native_round_f64 model: 112 values x 4 ops x abs/neg matched math/Fraction; 18 self-mutations killed
/tmp/pe-env/bin/python -B tests/form_coverage_check.py
form coverage checks passed
/tmp/pe-env/bin/python -B tests/docs_links_check.py
Checked 189 Markdown files and 740 links.
/tmp/pe-env/bin/python -B tests/bidi_controls_check.py
Checked 2745 tracked source, script and build/CI files: no bidirectional controls.
/tmp/pe-env/bin/python -B tools/run_checks_parallel.py --from-dir tests/checks/python-linux
all 72 checks passed

git diff --check clean, git merge-tree --write-tree origin/main HEAD exits 0, zero personal paths in the diff.

Mutation audit

Every branch, guard and constant added is pinned by a test that kills its mutation: the modifier and MODE gates by the controls refusals (26 forms, exact substrings + non-zero exit); the half_binary MODE-loop addition by the conditional s_denorm_mode refusal; the destination/source pair acceptance by the controls refusals and the ir e64 chunk (SGPR pairs, inline 128/240..247, abs/neg, abs+neg); abs/neg by the ir modifier cases and the hardware e64 program; the 1075 passthrough, 1023 sub-one bound and the lo-aware nonzero test by the ir boundary values and the model big/small/nz_lo mutations; the lo-range unit, half, evenness and carry by the exp = 1044/1074 values and the model lo_unit/lo_half/lo_even/lo_carry mutations; the word-boundary half and evenness by the exp = 1043 ties and the model mid_half/mid_even mutations; the hi-range unit, half, sticky lo and evenness by the exp = 1023..1042 values and the model hi_unit/hi_half/hi_sticky/hi_even mutations; the sub-one ±1.0/±0.0 results and the sign by the ±0.5 ± 1ulp and subnormal values and the model rndne_half/trunc_sub/floor_sign/ceil_sign/sign_lose mutations. The clear_vector_spills addition joins the pair list for parity with v_cvt_f64_*; it is not what lets a pair write succeed over a symbolic lane spill. write() checks has_spill(r) on the state before clear_vector_spills runs, so any numeric vector write to a VGPR holding symbolic lanes intentionally refuses, and the controls spill refusals pin that both vector_write(i.dst) and vector_write(i.dst + 1) execute write(): a lane spilled into v10 refuses with write to a VGPR holding symbolic lanes: v10, and one spilled into v11 refuses with ...: v11, for each of the four ops.

Notes

  • An SDWA-encoded form refuses in the decoder, which has no SDWA profile for these ops.
  • Hardware readbacks compare NaN results by class, in case hardware quiets sNaNs.
  • The ir mode splits the wave32 program into dumps of at most 1024 stores each, since F.store masks offsets to 12 bits.

Windows Verification (ca0f1c09182b4ea25bdea32950956752a449f593)

Commit: ca0f1c09182b4ea25bdea32950956752a449f593 (merge-tree upstream/main HEAD -> 7512efd3, exit 0; git diff --check clean)
Adapter: NVIDIA GeForce RTX 4050 Laptop GPU (vendor=10de device=28e1, driver=32.0.15.9186, XBOX2WINDOWS_ADAPTER=NVIDIA)
dev: cmake --build --preset dev --target compile_dxil native_compute_ir_dump native_store_replay && ctest --preset dev --no-tests=error -R '^native_(round|fract)_f64_' --output-on-failure -> 6/6 passed (8.24s; round: ir 1.19s, controls 1.57s, hardware 1.30s; fract: ir 0.99s, controls 1.55s, hardware 1.51s)
release: cmake --build --preset release --target compile_dxil native_compute_ir_dump native_store_replay && ctest --preset release --no-tests=error -R '^native_round_f64_' --output-on-failure -> 3/3 passed (3.52s; ir 0.66s, controls 1.35s, hardware 1.38s)
Checks: native_round_f64_check.py model (112x4x4 matched, 18 mutations killed), form_coverage_check.py, docs_links_check.py (199 files, 765 links), bidi_controls_check.py (2793 files) -> passed

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5570639527 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3630). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-30T17:47:26Z. --- Refs #2935, #3518 Lowers the four binary64 rounding instructions (`_e32` and `_e64`) in the direct C++ compute path with pure 32-bit integer arithmetic only, following the `v_*_f16` rounding shape and the `v_cmp_*_f64` pair rules. ## What changed - `src/gfx1013_direct_compute.inl` (+132): new lowering block after the f16 rounding block. Modifier gate (`pixel_stage`, `graphics_input`, `i.subword`, `i.dpp_control`, `permuted`, `i.clamp`, `i.scale`, `op_sel`, modifiers on S1/S2), MODE gate (`half_mode_known && !((mode_bits ^ 0xf0u) & 0x8000ccu)`), destination must be a VGPR pair (`256 <= dst < 511`), S0 accepts VGPR pairs, aligned even SGPR pairs, integer `0` (`128` -> `+0.0`) and inline binary64 constants `240..247` (`lo = 0`); abs then neg act on bit 63 before rounding. Result selected by biased exponent: `exp >= 1075` passes the pair unchanged (NaN payload included); `exp < 1023` rounds to a signed zero or one (the nonzero test looks at `lo` too, so a tiny subnormal is not mistaken for zero; `rndne` `|x| == 0.5` rounds to even `±0.0`, `|x| > 0.5` rounds to `±1.0`, including `0x3fe00000_00000001`); in between, the fraction sits in `lo` (`1044..1074`, carry on wrap), straddles the word boundary (`1043`, half `0x80000000`, evenness `hi & 1`, carry `+1` to `hi`), or splits across `hi` and `lo` (`1023..1042`, half/sticky comparison across both words, evenness `base_hi & unit_hi`). All DXIL shift amounts stay in `[0, 31]` in every lane (clamped selects outside the range). No DXIL `double`, no `i64` in `@main()`, no `fcmp`, neither `DoublePrecisionFloatShaderOps` nor `Int64ShaderOps`. - MODE loop: all four opcodes set `half_binary = true`, so a conditional denorm-mode write before them refuses. - `src/gfx1013_compute_native.cpp`: the four names join the `pair` condition in `clear_vector_spills`, so writing `v[d:d+1]` invalidates lane spills on both `d` and `d+1`. - `tests/native_round_f64_check.py` (model/ir/controls/hardware) + `tests/cmake/native_round_f64.cmake` + `tests/checks/python-linux/native_round_f64.txt` + `docs/experiments/native-direct-round-f64.md`. ## Tests Linux (this host cannot compile the translation unit or run Windows CTest; the C++ executions run in the WIN-VERIFY round): ``` /tmp/pe-env/bin/python -B tests/native_round_f64_check.py model native_round_f64 model: 112 values x 4 ops x abs/neg matched math/Fraction; 18 self-mutations killed /tmp/pe-env/bin/python -B tests/form_coverage_check.py form coverage checks passed /tmp/pe-env/bin/python -B tests/docs_links_check.py Checked 189 Markdown files and 740 links. /tmp/pe-env/bin/python -B tests/bidi_controls_check.py Checked 2745 tracked source, script and build/CI files: no bidirectional controls. /tmp/pe-env/bin/python -B tools/run_checks_parallel.py --from-dir tests/checks/python-linux all 72 checks passed ``` `git diff --check` clean, `git merge-tree --write-tree origin/main HEAD` exits 0, zero personal paths in the diff. ## Mutation audit Every branch, guard and constant added is pinned by a test that kills its mutation: the modifier and MODE gates by the `controls` refusals (26 forms, exact substrings + non-zero exit); the `half_binary` MODE-loop addition by the conditional `s_denorm_mode` refusal; the destination/source pair acceptance by the `controls` refusals and the `ir` e64 chunk (SGPR pairs, inline `128`/`240..247`, abs/neg, abs+neg); `abs`/`neg` by the `ir` modifier cases and the `hardware` e64 program; the `1075` passthrough, `1023` sub-one bound and the `lo`-aware nonzero test by the `ir` boundary values and the model `big`/`small`/`nz_lo` mutations; the lo-range unit, half, evenness and carry by the `exp = 1044`/`1074` values and the model `lo_unit`/`lo_half`/`lo_even`/`lo_carry` mutations; the word-boundary half and evenness by the `exp = 1043` ties and the model `mid_half`/`mid_even` mutations; the hi-range unit, half, sticky `lo` and evenness by the `exp = 1023..1042` values and the model `hi_unit`/`hi_half`/`hi_sticky`/`hi_even` mutations; the sub-one `±1.0`/`±0.0` results and the sign by the `±0.5 ± 1ulp` and subnormal values and the model `rndne_half`/`trunc_sub`/`floor_sign`/`ceil_sign`/`sign_lose` mutations. The `clear_vector_spills` addition joins the pair list for parity with `v_cvt_f64_*`; it is not what lets a pair write succeed over a symbolic lane spill. `write()` checks `has_spill(r)` on the state before `clear_vector_spills` runs, so any numeric vector write to a VGPR holding symbolic lanes intentionally refuses, and the `controls` spill refusals pin that both `vector_write(i.dst)` and `vector_write(i.dst + 1)` execute `write()`: a lane spilled into `v10` refuses with `write to a VGPR holding symbolic lanes: v10`, and one spilled into `v11` refuses with `...: v11`, for each of the four ops. ## Notes - An SDWA-encoded form refuses in the decoder, which has no SDWA profile for these ops. - Hardware readbacks compare NaN results by class, in case hardware quiets sNaNs. - The `ir` mode splits the wave32 program into dumps of at most 1024 stores each, since `F.store` masks offsets to 12 bits. ### Windows Verification (`ca0f1c09182b4ea25bdea32950956752a449f593`) ```text Commit: ca0f1c09182b4ea25bdea32950956752a449f593 (merge-tree upstream/main HEAD -> 7512efd3, exit 0; git diff --check clean) Adapter: NVIDIA GeForce RTX 4050 Laptop GPU (vendor=10de device=28e1, driver=32.0.15.9186, XBOX2WINDOWS_ADAPTER=NVIDIA) dev: cmake --build --preset dev --target compile_dxil native_compute_ir_dump native_store_replay && ctest --preset dev --no-tests=error -R '^native_(round|fract)_f64_' --output-on-failure -> 6/6 passed (8.24s; round: ir 1.19s, controls 1.57s, hardware 1.30s; fract: ir 0.99s, controls 1.55s, hardware 1.51s) release: cmake --build --preset release --target compile_dxil native_compute_ir_dump native_store_replay && ctest --preset release --no-tests=error -R '^native_round_f64_' --output-on-failure -> 3/3 passed (3.52s; ir 0.66s, controls 1.35s, hardware 1.38s) Checks: native_round_f64_check.py model (112x4x4 matched, 18 mutations killed), form_coverage_check.py, docs_links_check.py (199 files, 765 links), bidi_controls_check.py (2793 files) -> passed ``` AI-assisted. <!-- WIN-VERIFY: passed | sha=ca0f1c09182b4ea25bdea32950956752a449f593 | targets=compile_dxil native_compute_ir_dump native_store_replay | ctest=^native_round_f64_ | release=true -->
lukaslw-lab commented 2026-11-30 20:23:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T20:23:28Z.

Review: APPROVED


Reviewed 7503e733 by reading the diff; not built or run.

Verdict: approve. I traced each exponent range of the lowering and found no wrong result. No MUST.

  • NIT The hardware check compares NaNs by class, but the path has no float operation, so exp >= 1075 passes the pair bit-for-bit, sNaN payload included. An exact compare would pin that on a device too. (Same point as on #3634.)
  • Checked, no finding:
    • Below 1023 (src/gfx1013_direct_compute.inl:2162-2171): floor gives −1 and ceil +1 only for a nonzero input of the right sign; otherwise ±0 keeps its sign. rndne gives ±1 only above 0.5, and the nz test reads lo, so a lo-only subnormal is not taken for zero.
    • lo range 1044..1074 (odd = base_lo & unit_lo, wrapped carry into hi); word boundary 1043 (half 0x80000000, LSB hi & 1); hi range 1023..1042 (lo sticky; at 1023 the odd bit is the exponent LSB, right for [1, 2)). Out-of-range lanes shift by 1, so every shift stays in [0, 31].
    • Sources, MODE gate, half_binary and the spill pair entry match v_ldexp_f64. In-place pairs are safe.
    • The rules match the pixel lowering in #3643 (Inf/NaN and |x| ≥ 2^52 pass unchanged, ties to even, signed zeros kept), so the two paths agree.

Tests: model checks the model against Fraction round-to-nearest-even, with 18 self-mutations. ir runs the C++ lowering on rows at exponents 1042/1043/1044/1074 (every word-split branch), a sweep, and e64 forms. controls pins 26 refusals plus the spill refusals on v[d] and v[d+1]. CI ran only model (Linux checks); the native_round_f64_* CTest entries are not in the Windows pr preset filter. ir/controls/hardware have only the author's run at this head (RTX 4050, dev + release).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6119898036 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3630#pullrequestreview-6119898036). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-30T20:23:28Z. **Review:** APPROVED --- Reviewed `7503e733` by reading the diff; not built or run. **Verdict: approve.** I traced each exponent range of the lowering and found no wrong result. No MUST. - **NIT** The hardware check compares NaNs by class, but the path has no float operation, so `exp >= 1075` passes the pair bit-for-bit, sNaN payload included. An exact compare would pin that on a device too. (Same point as on #3634.) - Checked, no finding: - Below 1023 (`src/gfx1013_direct_compute.inl:2162-2171`): floor gives −1 and ceil +1 only for a nonzero input of the right sign; otherwise ±0 keeps its sign. rndne gives ±1 only above 0.5, and the `nz` test reads `lo`, so a lo-only subnormal is not taken for zero. - lo range 1044..1074 (odd = `base_lo & unit_lo`, wrapped carry into `hi`); word boundary 1043 (half `0x80000000`, LSB `hi & 1`); hi range 1023..1042 (`lo` sticky; at 1023 the odd bit is the exponent LSB, right for [1, 2)). Out-of-range lanes shift by 1, so every shift stays in [0, 31]. - Sources, MODE gate, `half_binary` and the spill pair entry match `v_ldexp_f64`. In-place pairs are safe. - The rules match the pixel lowering in #3643 (Inf/NaN and |x| ≥ 2^52 pass unchanged, ties to even, signed zeros kept), so the two paths agree. Tests: `model` checks the model against `Fraction` round-to-nearest-even, with 18 self-mutations. `ir` runs the C++ lowering on rows at exponents 1042/1043/1044/1074 (every word-split branch), a sweep, and e64 forms. `controls` pins 26 refusals plus the spill refusals on `v[d]` and `v[d+1]`. CI ran only `model` (Linux checks); the `native_round_f64_*` CTest entries are not in the Windows `pr` preset filter. `ir`/`controls`/`hardware` have only the author's run at this head (RTX 4050, dev + release).
R0Y00 commented 2026-12-01 03:10:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-01T03:10:59Z.

Review: APPROVED


Reviewed the direct C++ binary64 rounding family and the refusal guards for MODE and unsupported operands. ctest --test-dir <build> --no-tests=error -j1 -R '^native_round_f64_(ir|controls|hardware)$' --output-on-failure passed IR, refusal controls and the RTX 4060 Laptop readback.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6124496583 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3630#pullrequestreview-6124496583). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-01T03:10:59Z. **Review:** APPROVED --- Reviewed the direct C++ binary64 rounding family and the refusal guards for MODE and unsupported operands. `ctest --test-dir <build> --no-tests=error -j1 -R '^native_round_f64_(ir|controls|hardware)$' --output-on-failure` passed IR, refusal controls and the RTX 4060 Laptop readback.
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!3630
No description provided.