Skip to content

shader: lower v_ldexp_f32 in the direct compute path - #3057

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
legacy-code-archaeologist:shader/direct-ldexp
Nov 27, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
legacy-code-archaeologist:shader/direct-ldexp

Conversation

@legacy-code-archaeologist

Copy link
Copy Markdown
Contributor

Change

src/gfx1013_direct_compute.inl lowers v_ldexp_f32 in the direct C++ compute path using integer bit operations only, matching tools/pixel_aot.py's ldexp32. Fixes #3013.

  • Semantics: exact binary32 scaling by 2^S1; zero, Inf and NaN (with payload) pass unchanged; denormal S0 normalized via five conditional shifts (16, 8, 4, 2, 1); S1 clamped to [-512, 512]; overflow to signed Inf; subnormal results rounded to nearest even; clamp saturates with integer comparisons (NaN / negative / -0 -> +0, >= 1.0 -> 1.0, denormals preserved).
  • Modifiers & refusals: abs/neg on S0 handled via bit operations; abs/neg on S1/S2, nonzero src2, omod, op_sel, SDWA and DPP are refused.
  • Fixture & docs: tests/native_ldexp_check.py, tests/cmake/native_ldexp.cmake, docs/experiments/native-direct-ldexp.md.

Verification

Commit 60c05adf on upstream/cpp-migration a0f67731, Windows 10.0.26100, dev preset:

  • cmake --build --preset dev --target compile_dxil native_store_replay: ok.
  • ctest --preset dev --no-tests=error -R '^native_ldexp_' -V: native_ldexp_controls passed (1.13 s); native_ldexp_hardware skipped (exit 77 — default adapter does not report shader model 6.6 with wave32, so readback is unmeasured).
  • python -B tests/docs_links_check.py: passed (66 Markdown files and 581 links).

AI-assisted.

R0Y00 commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thanks for adding the v_ldexp_f32 coverage. New shader-lowering PRs target main. Retargeting this branch as it stands would also bring in the cpp-migration copies of #3034 and #3042. I checked that the single 60c05adf commit applies cleanly on main 801f4c3b. Could you replay just that commit onto current main and let us know when the PR is ready to retarget? If either heap change is needed for this fixture, please point to the dependency so we can order the reviews.

Copy link
Copy Markdown
Contributor

I tested the single 60c05adf00d4d04fce727b486e8ecdfa87ff3992 patch cherry-picked onto main ff04a75e58b5fb63e8638fa8cbdae8d98b06f48a (local a9b053f317dd38b144033c8395b4df6709b3bf0a). The four-file change applied cleanly. Neither of the two migration-only heap commits was needed for these fixtures.

Windows 11 26300.10075, MSVC 19.52, SDK 10.0.26100, DXC 1.9.2602.17, GeForce RTX 4070 (32.0.16.2124, default adapter, SM 6.6 / wave32, debug layer off for native replay).

foreach ($preset in 'release', 'dev') {
    cmake --build --preset $preset --target compile_dxil native_store_replay
    ctest --preset $preset --no-tests=error -j 1 -R '^native_(ldexp|absdiff|perm_lerp|cvt_pk16)_(controls|hardware)$' -V
}

Both presets passed 8/8 without skips. native_ldexp_hardware matched all 2,064 words per preset. The integer DXIL and operand-refusal controls passed.

As an independent Release check, I replayed 192 input/exponent pairs across 24 dispatches and compared all 49,536 readback words against math.ldexp in binary64, rounded once with struct.pack('<f', ...). This scaling is exact in binary64 for finite binary32 inputs in the allowed exponent range. The sweep included signed zero, adjacent subnormal/normal values, underflow ties, overflow, infinities, NaN payloads and both INT32 exponent extremes. All matched. The local WARP adapter advertises 4-lane waves, so the native replay does not apply to it.

Exact binary32 scaling after pixel_aot.py's ldexp32 with integer bit
operations only: zero, Inf and NaN unchanged, denormal inputs
normalized, denormal results rounded to nearest even, S1 clamped to
[-512, 512] and an integer saturate for clamp. Modifiers on S1/S2, a
src2 field, omod, op_sel, SDWA and DPP are refused.

Fixes R0Y00#3013

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@legacy-code-archaeologist
legacy-code-archaeologist changed the base branch from cpp-migration to main November 27, 2026 13:45
@legacy-code-archaeologist

Copy link
Copy Markdown
Contributor Author

@R0Y00 Replayed just the single v_ldexp_f32 commit onto main (36d2cbeb -> 35b43fac, updating the base SHA in docs/experiments/native-direct-ldexp.md) and retargeted PR #3057 to main. Confirmed neither #3034 nor #3042 is needed for this change or its fixtures.

Thanks @RonLogic for the independent RTX 4070 and 192-case math.ldexp verification.

Re-verified locally on 35b43fac (dev preset):

  • cmake --build --preset dev --target compile_dxil native_store_replay: ok
  • ctest --preset dev --no-tests=error -R '^native_ldexp_' -V: native_ldexp_controls passed (1.03 s); native_ldexp_hardware skipped (77, Quadro M1000M does not support shader model 6.6 with wave32 — readback unmeasured locally)
  • python -B tests/docs_links_check.py: passed (75 Markdown files and 585 links)

AI-assisted.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 35b43fac integrated with main 2a4bbff5 (tree 2974b781d9a265c74a68df1d282c5053456a5b5d). The retargeted diff contains only the four v_ldexp_f32 files. The lowering bounds shifts even on discarded lanes, retains special values without clamp, and rounds subnormal results using the retained significand bit. Built compile_dxil native_store_replay and ran ctest --test-dir <build> --no-tests=error -j 1 -V -R '^native_(ldexp|absdiff|perm_lerp|cvt_pk16)_(controls|hardware)$' in Debug and Release /O2. Both passed 8/8 with zero skips, and v_ldexp_f32 matched all 2,064 words on RTX. The compile and incorrect-reference controls passed. Windows 11 build 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, SDK DXC 10.0.26100, native replay debug layer off. The native fixture requires wave32 and has no local WARP coverage.

@R0Y00
R0Y00 merged commit 020c7a8 into R0Y00:main Nov 27, 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.

cpp-migration: lower v_ldexp_f32 in the direct compute path

3 participants