Recompiler: use IEEE-754 equality for float compare-and-swap atomics #2011
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2011
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2011/head"
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?
@Decodere on GitHub · 2026-11-25 00:41 UTC · original
Decodere:fix-1489-fcmpswap-ieee-eq→main· +349 −29 · 4 files · 1 commits · merged 2026-11-25 01:12 UTCChanges RDNA2 float compare-and-swap atomics (
ds_cmpst[_rtn]_f32,{buffer,flat,global}_atomic_fcmpswap[_x2], andimage_atomic_fcmpswap) in both the HLSL emitter and Direct DXIL translator from raw bitwise compare-exchange to bounded CAS loops using IEEE-754 float equality (-0.0 == +0.0swaps and returns the pre-swap sign bits;qNaN == qNaNandsNaN == sNaNkeep without swapping). Part of #1489 (XCL-BT-042).Matches
AC-Storm-YT's RDNA2 (gfx1036) silicon verification on #1489 (#issuecomment-7142546620). Comparisons are expressed with pureuint/uint64_tbit operations (!is_nan(cur) && (cur == cmp || ((cur | cmp) & !SIGN) == 0)) so DXC fast-math cannot miscompile NaN or signed-zero checks, 64-bitfcmpswapneeds noDoubleExtensions, andPRELUDE_MEMstays untouched. Bitwise integercmpswap/cmpst_b32operations remain single compare-exchange instructions.What is in it
crates/xcl/src/gpu/recomp/emit.rs: split"fcmpswap"/"cmpst_f32"from bitwise"cmpswap"/"cmpst_b32"inrmw32and"fcmpswap"from"cmpswap"inrmw64, emitting bounded 4096-iteration IEEE-754 CAS loops starting from an atomicOr 0read (InterlockedOr/InterlockedOr64+InterlockedCompareExchange/InterlockedCompareExchange64, preventing 64-bit load tearing or non-atomic mismatch early-exits, compatible with multi-window accessors).crates/xcl/src/gpu/dxil/lower_mem.rs: addLw::feq_bits32,Lw::feq_bits64,Lw::fcas32, andLw::fcas64(initializinginitvia atomicOr 0), and use them for"fcmpswap"/"cmpst_f32"inrmw32and"fcmpswap"inatomic64.crates/xcl/src/gpu/dxil/lower_image.rs: addLw::texel_fcas(reusingLw::feq_bits32and atomicOr 0initial read) forimage_atomic_fcmpswapwhile keepingimage_atomic_cmpswapas a singleatomic_cmpxchg.crates/xcl/src/gpu/recomp/tests.rs:atomic_fcmpswap_x2_uses_ieee_64_bit_cas(verifying atomicInterlockedOr64initial load, 1/2-window HLSL DXC compile, and 1/2/heap-window Direct DXIL validation) andgpu_atomic_fcmpswap_x2(±0.0swaps,qNaNkeeps, contended shared cells).gpu_float_cas_uses_ieee_equalityverifying LDS (ds_cmpst_rtn_f32), 32-bit/64-bit buffer/global/flat (*_atomic_fcmpswap[_x2]), image UAV (image_atomic_fcmpswap), and bitwise integer controls across 8 edge cases (-0/+0,+0/-0,qNaN,sNaN, denormal vs+0, finite match/mismatch,-inf) on both HLSL and Direct DXIL.Tested
0ef1bc386), DXC 1.9.2609.5 (01b62ad4), release build.atomic_fcmpswap_x2_uses_ieee_64_bit_cas(CPU) andgpu_float_cas_uses_ieee_equality(RTX 4060 GPU:hlsl lane 0 case 0: ds_cmpst_rtn_f32kept0x80000000instead of swapping-0.0vs+0.0to1.0f) fail before the fix.cargo test --release -p xcl --lib gpu::recomp::tests::atomic_fcmpswap_x2_uses_ieee_64_bit_cas -- --nocapture: 1 passed, 0 failed, 0 ignored.cargo test --release -p xcl --lib gpu_float_cas_uses_ieee_equality -- --nocapture: 1 passed, 0 failed, 0 ignored (both HLSL and Direct DXIL executed on RTX 4060).gpu_atomic_fcmpswap_x2(default HLSL andXCL_DIRECT_DXIL=1) andgpu_images_sample_load_store_atomic(XCL_DIRECT_DXIL=1): all passed, 0 failed.cargo build --release --workspace+cargo test --release --workspace -- --test-threads=4: 991 passed, 0 failed, 45 ignored across 20 test binaries.SKIPPEDGPU/runtime tests on this adapter (24 lines):no wave64subcases acrossgpu::recomp::lower::tests(4),gpu::recomp::lower_dxil::tests(13), andgpu::recomp::tests(2)#1426refusals (V_MUL_F16,V_PK_MUL_F16,V_CVT_F16_F32) ingpu::recomp::lower_dxil::testsshaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required)heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windowsRegression run
scripts/smoke.ps1onmain(8e87fc7b62a87ea589ccb9ea6182f514016cf7db) and on this PR's head commit (990b9d4795ca4707ca5c71f2fd93aca5071e4a35):Not tested
MODE.FP_DENORM=0(f32 denormal-flushed mode, where RDNA2 flushes denormals to±0.0before comparing): XCL currently preserves denormals and does not tracks_denorm_modefor float atomics.ds_cmpst[_rtn]_f64(64-bit LDS atomics are not currently implemented in XCL).--release).AI use
emit.rs,lower_mem.rs, andlower_image.rs, implemented the fix, CPU/GPU regression tests, and PR description; every line of the diff, test run, and smoke check was verified on local RTX 4060 hardware.RDNA2 float compare-and-swap atomics (`ds_cmpst[_rtn]_f32`, `{buffer,flat,global}_atomic_fcmpswap[_x2]`, `image_atomic_fcmpswap`) compare using IEEE-754 float equality where `-0.0 == +0.0` swaps (returning the pre-swap sign bits) and `NaN == NaN` (both qNaN and sNaN) does not swap, as verified on RDNA2 silicon (`XCL-BT-042`, #1489). Previously both the HLSL emitter (`recomp/emit.rs`) and Direct DXIL translator (`dxil/lower_mem.rs`, `dxil/lower_image.rs`) lowered all float CAS atomics to raw bitwise compare-exchange. Replace those with bounded 4096-iteration CAS loops starting from an atomic `Or 0` read (preventing 64-bit load tearing or non-atomic early-exit reads on mismatch) and checking bitwise IEEE-754 ordered equality (`!is_nan(cur) && (cur == cmp || ((cur | cmp) & !SIGN) == 0)`) in pure `u32` / `u64` integer ops so DXC fast-math cannot miscompile NaN/zero checks, 64-bit `fcmpswap` needs no `DoubleExtensions`, and `PRELUDE_MEM` stays untouched. Integer `cmpswap` / `cmpst_b32` ops remain single bitwise compare-exchanges. Update `atomic_fcmpswap_x2_uses_ieee_64_bit_cas` and `gpu_atomic_fcmpswap_x2`, and add `gpu_float_cas_uses_ieee_equality` covering all 32-bit/64-bit float CAS families plus integer controls on both HLSL and Direct DXIL. Part of #1489 Assisted-by: Google Antigravity (Gemini 4 Neon)@oni-swr on GitHub · 2026-11-25 01:06 UTC · original
AMD RDNA3 (RX 7800 XT, native wave64) test report for #2011 at head
990b9d47merged withmain2e1c9562(clean merge).Tested
Windows Kits\10\bin\10.0.26100.0\x64), debug build,XCL_ADAPTER="RX 7800 XT".cargo test -p xcl --lib gpu::recomp::tests::atomic_fcmpswap_x2_uses_ieee_64_bit_cas -- --nocapture: 1 passed, 0 failed (0.09s)cargo test -p xcl --lib gpu_float_cas_uses_ieee_equality -- --nocapture: 1 passed, 0 failed (0.37s; both HLSL and Direct DXIL on RX 7800 XT)cargo test -p xcl --lib gpu_atomic_fcmpswap_x2 -- --nocapture: 1 passed, 0 failed (0.27s)XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu_atomic_fcmpswap_x2 -- --nocapture: 1 passed, 0 failed (0.22s)XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu_images_sample_load_store_atomic -- --nocapture: 1 passed, 0 failed (0.24s)cargo build --workspace+cargo test --workspace -- --test-threads=4 --nocapture, withe2everified aftercargo build --workspace): 1001 passed, 1 failed, 45 ignored across 20 test binaries.gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1(seed 722: res[30] = 0x1, CPU 0x7fffffff,sdiv i64inside aswitch). Verified directly onorigin/main2e1c9562on the same RX 7800 XT: it fails identically there (pre-existing onmain, unrelated to this PR).SKIPPEDlines (7): the 6 intentional#1426per-lane refusals ingpu::recomp::lower_dxil::tests(V_MUL_F16,V_PK_MUL_F16,V_CVT_F16_F32, wave32 and wave64) plusheap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows. Zerono wave64skips — all native wave64 GPU tests ran and passed.Not tested
scripts/smoke.ps1title run, or other AMD generations.AI use
@futurepro62 on GitHub · 2026-11-25 01:05 UTC · original · edited 2026-11-25 01:15 UTC
Full-suite run, since this PR has no test report yet. Tested exact head
990b9d4(on its base8e87fc7).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 980 passed, 0 failed, 43 ignored. SKIPPED (no wave64):a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu,a_per_lane_2d_or_3d_group_runs_on_the_gpu,coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu,cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu,gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware,the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.gpu_float_cas_uses_ieee_equality.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 990 passed, 0 failed, 45 ignored. SKIPPED:f16_programs_on_the_gpu(f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))),f32_programs_on_the_gpu(f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))),f32_programs_on_the_gpu(f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).--skipleaves out tests that fail on main7994cd1too, not because of this PR. On NVIDIA:heap_window_out_of_memory_falls_back_to_the_switch_form(#1651), the fourgpu::recomp::lower_dxil::tests::*_programs_on_the_gputests andconst_and_null_mask_operands_agree_with_hlsl_on_the_gpu(follow-up on #1651) fail becauserunner::skip_testturns their skips into failures underXCL_REQUIRE_GPU=mesh, andgpu::dxil::fuzz_testsseeds 70, 545, 1019 and 1507 failCreateComputePipelineStatewithE_OUTOFMEMORYon this card (drivers 616.64 and 621.40). On AMD:fuzz_validate_and_gpu_1fails on seed 540 (res[833]0x7 vs CPU 0x6). The AMD run does not setXCL_REQUIRE_GPU.Not tested
AI use
@JJAutoCompare on GitHub · 2026-11-25 01:17 UTC · original
Independent Intel Arc A770 verification of clean PR head
990b9d4795ca4707ca5c71f2fd93aca5071e4a35. The PR merged during the run. The tested commit is included in merge0cdc896fa3b63ab781a5ba0dc0c278b240e02976.Tested
32.0.101.9175, Ryzen 7 3800X (6 cores / 12 logical processors exposed), Windows 11 Enterprise Evaluation 25H2 x64 (26200.9974). Rust/Cargo 1.100.0 MSVC, debug test profile. Both logs confirmed DXC and DXIL 1.9.2609.5 viaXCL_DXC_DIR.TEMP/TMPonL:, withCARGO_BUILD_JOBS=2andCARGO_INCREMENTAL=0. Precompiled withcargo test -p xcl --lib --no-runoutside the shared Arc lock. SetXCL_ADAPTER=A770for GPU execution.Not tested
Full workspace suite, release build, retail-title smoke, heap-window GPU dispatch, or other GPU/driver combinations in this run.
AI use
Codex (
gpt-6.2-sol) ran the focused tests, checked the logs, and wrote this report.@DavidM1911 on GitHub · 2026-11-25 03:51 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!