shader: lower v_frexp_mant_f16 and v_frexp_exp_i16_f16 in the direct compute path #3120

Merged
R0D4X merged 2 commits from upstream-pr/3120 into main 2026-11-27 17:48:43 +00:00
R0D4X commented 2026-11-27 16:04:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-27T16:04:32Z.


Fixes #3118. Refs #2935.

What this changes

  • Lowers v_frexp_mant_f16 (VOP1 0x59 / VOP3A 0x1d9) and v_frexp_exp_i16_f16 (VOP1 0x5a / VOP3A 0x1da) in src/gfx1013_direct_compute.inl using exact 32-bit integer IEEE-754 binary16 manipulation while preserving D[31:16].
  • Normalizes denormal inputs without flushing, preserves ±0.0h, ±Inf, and NaN, supports VOP3A abs/neg on src0 and clamp on v_frexp_mant_f16, and refuses unsupported modifier combinations (clamp on v_frexp_exp_i16_f16, omod, op_sel, unused VOP3 sources).

Tests & docs added

  • tests/native_frexp_f16_check.py & tests/cmake/native_frexp_f16.cmake:
    • native_frexp_f16_controls: validates emitted integer DXIL (shl i32 / lshr i32), refuses invalid modifiers, and verifies that the flush_denormals, no_clamp, and zero_high negative controls each differ.
    • native_frexp_f16_hardware: dispatches 8 binary16 edge cases (±0.0h, normals, smallest normal, largest/smallest subnormals, +Inf) across VOP1 and VOP3A (neg, abs + clamp) with pre-seeded D[31:16], matching 2048 result words and 16 sentinel guards.
  • docs/experiments/native-frexp-f16.md: experiment note and reproduction commands.

Verification

  • Commit: ebeb373d
  • Environment: Windows 11 x64 (10.0.26300.9974), MSVC 19.44.35230, Windows SDK / DXC 10.0.26100.0, NVIDIA GeForce RTX 5080 (10de:2c02, driver 32.0.16.2124).
  • ctest --preset dev --no-tests=error -R '^native_frexp_f16_|^native_ldexp_' -V: 4/4 passed (0 skipped).
  • ctest --preset release --no-tests=error -R '^native_frexp_f16_|^native_ldexp_': 4/4 passed (0 skipped).
  • tests/docs_links_check.py & tests/bidi_controls_check.py: passed.

Scope: covers synthetic direct-DXIL compute fixtures for v_frexp_mant_f16 and v_frexp_exp_i16_f16 only; does not establish full-game execution.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5529611406 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3120). Originally posted by [R0D4X](https://github.com/R0D4X) on 2026-11-27T16:04:32Z. --- Fixes #3118. Refs #2935. ## What this changes - Lowers `v_frexp_mant_f16` (VOP1 `0x59` / VOP3A `0x1d9`) and `v_frexp_exp_i16_f16` (VOP1 `0x5a` / VOP3A `0x1da`) in `src/gfx1013_direct_compute.inl` using exact 32-bit integer IEEE-754 binary16 manipulation while preserving `D[31:16]`. - Normalizes denormal inputs without flushing, preserves `±0.0h`, `±Inf`, and `NaN`, supports VOP3A `abs`/`neg` on `src0` and `clamp` on `v_frexp_mant_f16`, and refuses unsupported modifier combinations (`clamp` on `v_frexp_exp_i16_f16`, `omod`, `op_sel`, unused VOP3 sources). ## Tests & docs added - `tests/native_frexp_f16_check.py` & `tests/cmake/native_frexp_f16.cmake`: - `native_frexp_f16_controls`: validates emitted integer DXIL (`shl i32` / `lshr i32`), refuses invalid modifiers, and verifies that the `flush_denormals`, `no_clamp`, and `zero_high` negative controls each differ. - `native_frexp_f16_hardware`: dispatches 8 binary16 edge cases (`±0.0h`, normals, smallest normal, largest/smallest subnormals, `+Inf`) across VOP1 and VOP3A (`neg`, `abs` + `clamp`) with pre-seeded `D[31:16]`, matching 2048 result words and 16 sentinel guards. - `docs/experiments/native-frexp-f16.md`: experiment note and reproduction commands. ## Verification - Commit: `ebeb373d` - Environment: Windows 11 x64 (`10.0.26300.9974`), MSVC `19.44.35230`, Windows SDK / DXC `10.0.26100.0`, NVIDIA GeForce RTX 5080 (`10de:2c02`, driver `32.0.16.2124`). - `ctest --preset dev --no-tests=error -R '^native_frexp_f16_|^native_ldexp_' -V`: **4/4 passed** (0 skipped). - `ctest --preset release --no-tests=error -R '^native_frexp_f16_|^native_ldexp_'`: **4/4 passed** (0 skipped). - `tests/docs_links_check.py` & `tests/bidi_controls_check.py`: **passed**. *Scope: covers synthetic direct-DXIL compute fixtures for `v_frexp_mant_f16` and `v_frexp_exp_i16_f16` only; does not establish full-game execution.*
tedin7 commented 2026-11-27 17:48:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T17:48:29Z.

Review: COMMENTED


Review of d6fdfce67e (the change from ebeb373d, updated with main; the PR's own diff is unchanged).

Code: same structure as the f32 frexp lowering, on the low 16 bits of src0. Zero, Inf and NaN keep the input (mantissa op) or give 0 (exponent op); normal inputs give sign | 0.5h | fraction and exponent - 14; denormals are normalized with a four-step shift count, which gives exponent p - 23 for a denormal with its top bit at position p, as frexp expects. The result goes to D[15:0] and D[31:16] is kept, the same convention the other 16-bit results in this file use; the test seeds the high half of the destination and checks it survives. Clamp is refused on the exponent op and clamps the mantissa to [0, 1.0h]; omod, op_sel, DPP/SDWA and unused sources are refused. The reference is computed independently. No other open PR covers these two opcodes in the direct compute path.

Windows results are in the comment below.

Commands: git diff origin/main...pull/3120/head -- src/ tests/ (read), plus the Windows commands listed in the comment.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6091726254 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3120#pullrequestreview-6091726254). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T17:48:29Z. **Review:** COMMENTED --- Review of d6fdfce67e940cba8b6e7900c11b3707d41949bd (the change from ebeb373d, updated with main; the PR's own diff is unchanged). Code: same structure as the f32 frexp lowering, on the low 16 bits of src0. Zero, Inf and NaN keep the input (mantissa op) or give 0 (exponent op); normal inputs give sign | 0.5h | fraction and exponent - 14; denormals are normalized with a four-step shift count, which gives exponent p - 23 for a denormal with its top bit at position p, as frexp expects. The result goes to D[15:0] and D[31:16] is kept, the same convention the other 16-bit results in this file use; the test seeds the high half of the destination and checks it survives. Clamp is refused on the exponent op and clamps the mantissa to [0, 1.0h]; omod, op_sel, DPP/SDWA and unused sources are refused. The reference is computed independently. No other open PR covers these two opcodes in the direct compute path. Windows results are in the comment below. Commands: `git diff origin/main...pull/3120/head -- src/ tests/` (read), plus the Windows commands listed in the comment. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-27 17:48:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T17:48:31Z.


Windows Server 2025 verification of d6fdfce67e940cba8b6e7900c11b3707d41949bd (D3D12 WARP, MSVC 14.44.35207):

  • dev: cmake --build --preset dev --target compile_dxil native_store_replay; ctest --preset dev -R <native sweep>: 100% tests passed out of 128 (74 passed, 54 hardware legs skipped)
  • release: cmake --build --preset release --target compile_dxil native_store_replay; ctest --preset release -R <native sweep>: 100% tests passed out of 128 (74 passed, 54 skipped)

<native sweep> = every native_* test except native_startup_request_cache_hardware, which fails on WARP-only hosts with or without this PR (wave lane count 32 requested, WARP offers 4; the test comes from #2955). native_frexp_f16_controls passed in both presets; the _hardware leg skips on WARP because it needs a physical wave32 adapter.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7224808034 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3120#issuecomment-7224808034). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T17:48:31Z. --- Windows Server 2025 verification of `d6fdfce67e940cba8b6e7900c11b3707d41949bd` (D3D12 WARP, MSVC 14.44.35207): - dev: `cmake --build --preset dev --target compile_dxil native_store_replay`; `ctest --preset dev -R <native sweep>`: 100% tests passed out of 128 (74 passed, 54 hardware legs skipped) - release: `cmake --build --preset release --target compile_dxil native_store_replay`; `ctest --preset release -R <native sweep>`: 100% tests passed out of 128 (74 passed, 54 skipped) `<native sweep>` = every `native_*` test except `native_startup_request_cache_hardware`, which fails on WARP-only hosts with or without this PR (wave lane count 32 requested, WARP offers 4; the test comes from #2955). `native_frexp_f16_controls` passed in both presets; the `_hardware` leg skips on WARP because it needs a physical wave32 adapter. AI-assisted; commands listed were executed locally.
chadhyatt commented 2026-11-27 19:39:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chadhyatt on 2026-11-27T19:39:21Z.


The private direct-compute intake found a concrete untested operand case at 429f11d5110: the f16 frexp lowering takes operand32(src0) & 0xffff. Inline float sources 240-248 are f32 patterns in operand32 (e.g. 1.0 = 0x3f800000, whose low half is zero), while the equivalent binary16 source is 0x3c00. The frexp mantissa/exp for inline 1.0 should be 0.5h/1, not zero/0. Reuse the existing half operand decode convention and include inline 0.5, -1, 1 and 0.159 cases, plus signed NaN/negative-clamp reference controls. The f16 implementation also needs a proven half MODE/denorm contract or a typed refusal for unsupported FTZ/RTZ modes; graphics direct-path admission should remain unclaimed until measured. This is a static source finding, not new hardware evidence.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7226741066 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3120#issuecomment-7226741066). Originally posted by [chadhyatt](https://github.com/chadhyatt) on 2026-11-27T19:39:21Z. --- The private direct-compute intake found a concrete untested operand case at `429f11d5110`: the f16 frexp lowering takes `operand32(src0) & 0xffff`. Inline float sources 240-248 are f32 patterns in `operand32` (e.g. 1.0 = `0x3f800000`, whose low half is zero), while the equivalent binary16 source is `0x3c00`. The frexp mantissa/exp for inline 1.0 should be 0.5h/1, not zero/0. Reuse the existing half operand decode convention and include inline 0.5, -1, 1 and 0.159 cases, plus signed NaN/negative-clamp reference controls. The f16 implementation also needs a proven half MODE/denorm contract or a typed refusal for unsupported FTZ/RTZ modes; graphics direct-path admission should remain unclaimed until measured. This is a static source finding, not new hardware evidence.
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!3120
No description provided.