Recompiler: apply abs and neg bitwise for v_cmp_class_f32 #1308
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1318"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by mahfuzinam0045-spec on 2026-11-24T14:39:59Z.
Apply VOP3
absandnegmodifiers bitwise forv_cmp_class_f32, and take rawuintbit patterns directly infclassandfclass64.Fixes #1281
What is in it
crates/xcl/src/gpu/recomp/emit.rs:v_cmp_class_f32: applym.abs[0]as({a} & 0x7FFFFFFFu)andm.neg[0]as({a} ^ 0x80000000u)directly on the rawuintbits instead of callingSelf::fsrc(abs(asfloat(u))/(-asfloat(u))). This prevents denormal flushing and signaling NaN quieting.fclass(uint u): update HLSL preamble function to acceptuint udirectly, eliminating the redundantasuint(asfloat(u))round-trip.fclass64(uint l, uint h)&v_cmp_class_f64: pass low and high dwords directly intofclass64(lo_hi[0].0, hi)withoutasdouble/asuintconversion.crates/xcl/src/gpu/recomp/tests.rs:v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat: verify emitted HLSL applies bitwise mask/flip on the sign bit and avoidsasfloat.gpu_cmp_class_f32_preserves_snan_and_denormals: synthetic test asserting that sNaN, qNaN, -subnormal with ABS, and sNaN with NEG match their respective class bits without being quieted or flushed.Tested
link.exe/gcc.exe) are absent on this development environment. Full validation and regression suite run via GitHub Actions CI (PR checks).v_cmp_class_f32_emits_bitwise_modifiers_without_asfloatandgpu_cmp_class_f32_preserves_snan_and_denormals.Regression run
Regression testing requires Windows SDK and DXC toolchains. Relying on project CI.
Not tested
AI use
Antigravity (Gemini 3.8 Flash) was used to analyze the modifier lowering discrepancy in
crates/xcl/src/gpu/recomp/emit.rs, implement bitwise modifiers on rawuintbits, updatefclassandfclass64, and author the recompiler unit tests.Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T14:47:07Z.
Full-suite run, since this PR has no test report yet. Tested exact head
25c44a6(on its base930e8b4): two tests fail, both on the expected HLSL text rather than the emitter.Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: the xcl lib run ends with 2 failed (707 passed, 21 ignored), so cargo stops before the remaining test binaries. Reproduced 3 of 3 times withcargo test -p xcl --lib -- f64_class_compare_vopc_and_vop3 v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat.f64_class_compare_vopc_and_vop3(existing test,tests.rs:474) still expects(v12) >> fclass64(asdouble(v10, v11)). Withfclass64now taking(uint l, uint h), the emitted text is(v12) >> fclass64(v10, v11),fclass64(v10, (v11 & 0x7FFFFFFFu))andfclass64(v10, (v11 ^ 0x80000000u)), so the threecontainschecks need theasdouble(...)dropped.v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat(new,tests.rs:7180): the emitted compare is right (fclass(((v0 & 0x7FFFFFFFu) ^ 0x80000000u))), but!t.hlsl.contains("asfloat(")checks the whole shader, and the shared helper preamble always hasasfloat((e.g.fract_f). The check needs to look at the compare line only, or forfclass(asfloat(.XCL_ADAPTER=radeon): the same two failures.v_cmp_class_f32to the sign bit; #1308 and #1309 were opened about five minutes before this one, and both pass the full suite here.Not tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T15:34:08Z.
Test report — RTX 3060 Ti (Windows 11),
cargo test -p xcl --libon the PR head merged with currentmain:2 failures (707 passed, 2 failed, 21 ignored; single-threaded run — parallel runs also intermittently abort with 0xc0000005, same harness flake seen on unmodified
main):gpu::recomp::tests::f64_class_compare_vopc_and_vop3— pre-existing test still asserts the old helper signature: it expectsfclass64(asdouble(v10, v11)), but this PR changedfclass64to take(uint l, uint h). The test needs updating to the new call shape (e.g.fclass64(v10, v11)/fclass64(v10, (v11 & 0x7FFFFFFFu))).gpu::recomp::tests::v_cmp_class_f32_emits_bitwise_modifiers_without_asfloat(new in this PR) —assert!(!t.hlsl.contains("asfloat("))can never hold: the shared kernel prelude emitsasfloat(unconditionally (e.g.fract_f,f16tof32helpers), regardless of which instructions the program uses. The assertion needs to be scoped to the emitted compare expression rather than the wholet.hlsl.The GPU-side behaviour itself looks right —
gpu_cmp_class_f32_preserves_snan_and_denormalspasses on this card.Imported from ivall/xcl. Originally posted by mahfuzinam0045-spec on 2026-11-24T16:26:59Z.
Thanks @futurepro62 and @DavidM1911 for the test reports!
Pushed commit
c02943aresolving both test assertions:f64_class_compare_vopc_and_vop3to match thefclass64(uint l, uint h)argument shape (droppedasdouble(...)).asfloatcheck inv_cmp_class_f32_emits_bitwise_modifiers_without_asfloatto!t.hlsl.contains("fclass(asfloat(")so it doesn't match the preamble helpers.Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T16:51:49Z.
Retest of the new head
c02943a: both tests I reported now pass on both GPUs.XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 753 passed, 0 failed, 41 ignored.XCL_ADAPTER=radeon, same command: 753 passed, 0 failed, 41 ignored, nothing skipped.f64_class_compare_vopc_and_vop3andv_cmp_class_f32_emits_bitwise_modifiers_without_asfloatareokon both.AI use
Imported from ivall/xcl. Originally posted by ivall on 2026-11-24T20:50:02Z.
Closing this as a duplicate of #1306 (group D2 in #1607), which makes the same f32 change and was opened first. The f64 part here hands the two words to the helper instead of
asdoubleof them.mainalready applies abs / neg to the sign bit there, so no result changes.This says nothing about the quality of the code here. If this PR covers a case the other one does not, or #1306 is closed without being merged, say so and I'll reopen it.
Thank you for the work.
AI use: Claude Code (Claude Opus 5.5) read the diffs and the checks in #1607 and wrote this comment, on the maintainer's behalf.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T04:53:06Z.
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
Pull request closed