Recompiler: apply ABS / NEG on v_mov_b32, v_cndmask_b32 and two cvts #796
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/802"
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 upipibi on 2026-11-24T05:37:16Z.
The VOP3 (and SDWA / DPP16) forms of
v_mov_b32,v_cndmask_b32,v_cvt_f32_f16andv_cvt_f64_f32take the ABS / NEG source modifiers, and XCL dropped them on both backends: the four arms used the raw source, while every other float source goes throughfsrc/fh/f64v.v_cndmask_b32_e64 v5, -v1, |v2|, vccwith v1 = 1.0, v2 = -2.0 gave 1.0 / -2.0 where -1.0 / 2.0 is right.References: the RDNA 2 ISA says of
V_CNDMASK_B32andV_MOV_B32that floating-point modifiers are valid and the instruction "is suitable for negating or taking the absolute value of a floating-point value" (VOP2 opcode 1, VOP1 opcode 1, with the examplev_mov_b32 v0, -v1). LLVM foldsfneg/fabsof select operands intoV_CNDMASK_B32_e64(VOPSelectModsPat,SIInstructions.td), and its MC tests encodev_cndmask_b32_e64 v5, -v1, |v2|, vcc(gfx10_asm_vop2.s),v_cvt_f32_f16_e64 v5, -v1andv_cvt_f64_f32_e64 v[5:6], -v1(gfx10_asm_vop1.s). LLVM itself never puts modifiers onv_mov_b32(VOPProfile_MOVhas none); the ISA text is the only source for that one.The modifiers are applied on the sign bit, as
valu64already does for f64 sources (abs clears it, then neg flips it). The move and the select stay untyped, so a NaN keeps its payload and -0 and denormals pass bit-exact. Forv_cvt_f32_f16they act on bit 15 of the f16 input, forv_cvt_f64_f32on the f32 input.What is in it
crates/xcl/src/gpu/recomp/emit.rs: helpersign_mods, used by thev_mov_b32/v_mov_fed_b32,v_cndmask_b32andv_cvt_f32_f16arms ofvaluand thev_cvt_f64_f32arm ofvalu64.crates/xcl/src/gpu/dxil/lower_valu.rs,lower_wide.rs(second commit): the same on the direct translator.Lw::sign_modapplies abs / neg on the sign bit; it is used by thev_mov_b32/v_mov_fed_b32,v_cndmask_b32andv_cvt_f32_f16arms and byv_cvt_f64_f32invalu64.crates/xcl/src/gpu/recomp/tests.rs: GPU testgpu_abs_neg_on_move_select_and_conversions.v_cndmask_b32_e64 -v1, |v2|with VCC alternating per lane, on (1.0, -2.0), a quiet NaN with a payload against a negative signalling NaN, (-0, -0) and denormals;v_mov_b32_e64 -v1and-|v2|on the same inputs;v_cvt_f32_f16_e64 -vand|v|on 1.0, -0, -2.0, 0.5;v_cvt_f64_f32_e64 -vand|v|on 1.0, -0, -3.5, 0.25. All results compared as bits.CharlyRien's RTX 3090 comparison (https://github.com/xcl-dev/xcl/pull/802#issuecomment-7373902215), thanks: without this PR a pixel program on the direct path differed from HLSL on 9,748 and 790 of 16,384 pixels (seeds 0 and 1); with it all three seeds matched.
Tested
At the current head
47c53a7(rebased ontomaine99b0bdon 2026-12-03): NVIDIA GeForce RTX 3070, driver 621.40, Windows 11 Pro, rustc 1.100.0, debug.cargo test -p xcl --lib -- --test-threads=4(default, direct backend): 2864 passed, 0 failed, 37 ignoredgpu_abs_neg_on_move_select_and_conversions, 3 runs each withXCL_DIRECT_DXIL=0and=1: 1 passed, 0 failed every run; unset (default) withgpu_mullit_and_cvt_off_match_rdna2: 2 passed, 0 failed.Earlier, at
fed16e7:fed16e7, as-is: Radeon RX 7800 XT (RDNA3, native wave64, driver 32.0.31035.1003), Windows 11, debug, DXC 1.9.0.5512.gpu_abs_neg_on_move_select_and_conversionspasses withXCL_DIRECT_DXIL=0and=1.gpu_tests: 135 passed, 1 failed with=0; 134 passed, 2 failed with=1. Workspace (--test-threads=4): 1154 passed, 1 failed. The failures aren't this PR's.fuzz_validate_and_gpu_1(seed 722) is the known RDNA3 failure onmain.gpu_image_get_resinfo_1d_arrayon the direct path comes from this head's basecbc296a, which predates #2046's fix for it (5ebaf3eb).maincbc296a(one conflict:mainchangedv_rcp_f64torcp_d; kept that). Atfed16e7: the new test passes withXCL_DIRECT_DXIL=0and1;gpu_tests 135 passed withXCL_DIRECT_DXIL=0, 134 passed and 1 failed with1. The failure isgpu_image_get_resinfo_1d_array, which fails onmaintoo (#2046 fixes it).dxilunits: 151 passed.XCL_DIRECT_DXIL=1at its first assertion (lane 0v_cndmask_b32 -v1, |v2|gave0xC0000000, expected0x40000000).cargo test --workspace --no-fail-fast -- --test-threads=4on228f8e9: 705 passed, 0 failed, 41 ignoredgpu_geometry_wave32_prefix_count_over_a_mask(no wave64),gpu_wave32_program_in_wave64_hardware(no wave64)main(d5442d2) without theemit.rschange, at its first assertion: lane 0v_cndmask_b32 -v1, |v2|gave0xC0000000(-2.0), expected0x40000000(2.0). It passes with the change.Regression run
The pair below is for the earlier head
fed16e7, before the 2026-12-03 rebase; a pair on47c53a7is needed.Pair for the current head
fed16e7againstmain426a5a7, run by ThiagoAlexsander on the retail title (comment, thanks): RTX 5080 16 GB,scripts/smoke.ps1 -Seconds 60. Pasted as printed.Earlier pair, on the first version (
228f8e9, HLSL change only), run by eizispark on an AMD Radeon RX 9070 XT (thanks):main:
PR:
Not tested
v_mov_b32: the ISA says so, but no compiler I could check emits it.Modsand now the same path, but the test uses VOP3 only.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T05:38:02Z.
@eizispark, thanks again for the #761 pair. If you have time for more, these four of ours also only need the
xcl-smokepair (mainplus head, same title and duration); they're recompiler and disassembler changes:228f8e920d1c45bfbeea77a978aa41b7af19587ev_swaprel_b32destination index):4db1a2a4a3d03b3f5eb559670c1f584fbbdd055c// pc:comments):5a60d0dad6be82337d8a41fcafdd3f73c9f8be95ec0aa67f44ffb13fcf73db4e9f9d8548a972d2e2I'll copy the blocks into each Regression run with credit. No pressure if you're busy.
Imported from ivall/xcl. Originally posted by MesshM on 2026-11-24T05:46:10Z.
Test run of
228f8e920d1c45bfbeea77a978aa41b7af19587eon AMD RDNA4. I merged it onto currentmaine50836blocally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 705 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 664 passed, 0 failed, 21 ignoredSKIPPED;gpu_abs_neg_on_move_select_and_conversionspasses.Review: ABS / NEG are applied on the bits (clear / flip the sign bit at the operand's width), which keeps NaN payloads and matches how the hardware applies float modifiers to moves and selects. I found nothing to change.
Not tested: no retail title or regression run (I have no unpacked game), no
XCL_SAMPLE_*tests, release build; the PR's head on its old base was not run, only its merge ontomain.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
Imported from ivall/xcl. Originally posted by ethandepstein-del on 2026-11-24T05:57:37Z.
Independent native Windows NVIDIA RTX 5080 (wave32) + D3D12 debug layer build/test run and code review at head
228f8e920d1c45bfbeea77a978aa41b7af19587e.Code Review
sign_modshelper (absclears the sign bit first, thennegflips it, preserving NaN payloads,-0, and denormals) applied tov_mov_b32/v_mov_fed_b32,v_cndmask_b32,v_cvt_f32_f16(16-bit sign0x8000), andv_cvt_f64_f32. No issues found.Tested
617.42/32.0.16.1742), Windows 11 Pro 25H2 (26200.9974), D3D12 debug layer installed (d3d12SDKLayers.dll),rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC from Windows SDK10.0.26100.0, debug build.cargo build --workspace && cargo test --workspace -- --test-threads=4ok, executed on RTX 5080, not skipped):gpu::recomp::tests::gpu_abs_neg_on_move_select_and_conversionsgpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask(no wave64)gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware(no wave64)Not tested
AI use: Antigravity (Gemini 4 Neon reviewed the diff; Gemini 4 Hydrogen ran the RTX 5080 workspace tests) drafted this report.
Imported from ivall/xcl. Originally posted by eizispark on 2026-11-24T06:06:32Z.
Hardware check of
228f8e920d1c45bfbeea77a978aa41b7af19587e(verified clean merge withmainbeaa245): pass.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profilecargo test --workspace -- --test-threads=4:705 passed, 0 failed, 41 ignored(GPU tests skipped on this adapter:none)cargo test -p xcl --lib gpu_abs_neg_on_move_select_and_conversions:1 passed, 0 failedRegression run
main(f4ce27c):PR (
228f8e9):Not tested
AI use
scripts/smoke.ps1harness on this machine and formatted this report.Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T06:07:27Z.
Thanks @eizispark: both blocks are now in Regression run, credited.
Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-24T06:41:29Z.
2|
3|AMD/wave64 + release-build datapoint - the axes your row lists as not tested.
4|
5|Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Wine = Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust 1.100.0 cross
x86_64-pc-windows-gnu, release profile,XCL_NETWORK=0, native wave64. Same rig as my Linux rows in #42 / #718.6|
7|Merged state: head
228f8e9onto mainbeaa245, clean merge.8|
9|Full suite,
cargo test --workspace --release --no-fail-fast -- --test-threads=4: 704 passed, 10 failed, 41 ignored (17 suites). The 10 = this rig's 7 stable Wine-lane failures (my #42 row) + the #718 flaky trio firing that run (~2/5 rate, PR-independent). Nothing new fails. Your test passes bit-for-bit on RDNA3:gpu_abs_neg_on_move_select_and_conversionsok.10|
11|Not tested: retail titles (none here), Windows, RDNA4.
12|Counts only, no game data.
13|AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T10:58:33Z.
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!
Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T11:06:11Z.
Diff review on \ed16e7\ (\lower_valu.rs, \lower_wide.rs, \emit.rs, \ ests.rs) looks clean, and \Build and test\ is green. Two items remaining before merge: update Regression run in the PR body from \
228f8e9\ to \ed16e7\ (to pass \PR description), and add an AMD GPU verification run covering \ed16e7\ (with \XCL_DIRECT_DXIL=1\ and \Imported from ivall/xcl. Originally posted by upipibi on 2026-11-25T11:19:32Z.
@raylitebull The smoke pair in the body is a run of
228f8e9, so I can't just change the commit tofed16e7: the block has to name the head that was run. I've asked for a fresh pair atfed16e7and an AMD run in #1607 (request), and I'll paste them here when they come.Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-25T12:51:49Z.
Test report: AMD Radeon RX 7800 XT (RDNA3, native wave64) for head
fed16e7da66f8fbd563146123485168fd759fb96(requested on #1607).Setup: RX 7800 XT, driver 32.0.31035.1003, Windows 11 Pro 10.0.26200, rustc/cargo 1.100.0, debug build, DXC 1.9.0.5512 (
dxcon PATH). Detached checkout of the PR head; the merge base iscbc296a, so it does not includeea088a5, and I did not merge it with currentmain.Targeted (
cargo test -p xcl --lib -- gpu_abs_neg_on_move_select_and_conversions --nocapture --test-threads=1):XCL_DIRECT_DXIL=0: 1 passed, 0 failed, 0 ignoredXCL_DIRECT_DXIL=1: 1 passed, 0 failed, 0 ignoredAll
gpu_lib tests (cargo test -p xcl --lib -- gpu_ --test-threads=1):XCL_DIRECT_DXIL=0: 135 passed, 1 failed, 1 ignored. The failure isgpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1(seed 722,res[30] = 0x1vs CPU0x7fffffff), the known RDNA3 failure onmain. The PR does not touch it.XCL_DIRECT_DXIL=1: 134 passed, 2 failed, 1 ignored. Failures: the samefuzz_validate_and_gpu_1, andgpu_image_get_resinfo_1d_array(lane 0 resinfo[4, 1, 1], expected[4, 3, 1]). The PR does not touch image resinfo. I did not run this test onmainunderXCL_DIRECT_DXIL=1, so I can't say whether it also fails there.Full suite (
cargo test --workspace --no-fail-fast -- --test-threads=4, env unset): 1154 passed, 1 failed, 46 ignored.fuzz_validate_and_gpu_1, as above), 26 ignored.SKIPPEDlines, all inlower_dxil::tests(f16 / f32 conversion programs refused by the per-lane form). These are not coverage.Not tested: retail title or
scripts/smoke.ps1, NVIDIA, Intel, Wine/vkd3d, this PR merged with currentmain,gpu_image_get_resinfo_1d_arrayonmainunderXCL_DIRECT_DXIL=1.AI use: this report was run and written by Claude Code (Claude Sonnet 5.5). I read the diff but did not change any code.
Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-26T08:51:04Z.
NVIDIA and AMD full-suite run, to go with the reports above by oni-swr, since none of them covers NVIDIA. Tested exact head
fed16e7d(on its basecbc296a).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::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 1143 passed, 0 failed, 44 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_abs_neg_on_move_select_and_conversions.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 1154 passed, 0 failed, 46 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 mainb49be183too, 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,const_and_null_mask_operands_agree_with_hlsl_on_the_gpuandmask_ff0_and_flbit_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
Imported from ivall/xcl. Originally posted by throny on 2026-11-28T16:54:51Z.
merge-check claim
head:
fed16e7da6Imported from ivall/xcl. Originally posted by throny on 2026-11-28T17:10:43Z.
merge-check
base:
db3921dchead:
fed16e7da6merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2146 passed, 0 failed, 48 ignored (26 SKIPPED lines). Base alone at
db3921dc: 2145 passed, 0 failed, 48 ignored.review: no blocking finding; all hunks read. The sign handling is right, including the half-float input after the operand select; nothing is applied twice, and no other arm handles these instructions. It does not overlap #2058. The smoke pair and the AMD run asked for in the thread are in the description now.
performance: none unless a modifier is set. It changes a translator source: every tester re-translates all shaders once.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:09:31Z.
Triage (#1607) – head
fed16e7No open or merged PR applies ABS/NEG to
v_mov_b32,v_cndmask_b32,v_cvt_f32_f16orv_cvt_f64_f32. Main'semit.rsandlower_valu.rs/lower_wide.rsstill use the raw sources in those arms.No problems found in the diff. The sign-bit form keeps NaN payloads and denormals, and the GPU test compares bits on both VCC polarities.
The PR conflicts with main and needs a rebase.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by CharlyRien on 2026-12-03T09:35:20Z.
Tested on an RTX 3090 (driver 621.47, Windows 11 22631), with head
fed16e7donmain817eb1fcplus four local commits that add a test-only probe (not upstream). The probe translates one console program both ways (direct DXIL and HLSL + DXC), runs both on the GPU with the same synthetic inputs, and compares the outputs.gpu_abs_neg_on_move_select_and_conversionspasses on both paths (XCL_DIRECT_DXIL=0and=1), as do the other threeabs_negtests.Two notes:
main,runner::run_codesends kernels to the direct path whenXCL_DIRECT_DXILis unset (dxil/kernel.rs). So the new test checks only the direct path by default. Looping over both, asgpu_mullit_and_cvt_off_match_rdna2does (for direct in [false, true]), would cover HLSL too.main16c2fd08gives one textual conflict, intests.rsonly: the new test andMULLIT_RDNA2/gpu_mullit_and_cvt_off_match_rdna2are added at the same place. Keeping both resolves it. The code files apply cleanly.AI use: Claude Code (Claude Opus 5.5) ran the probe and the tests on the 3090 and wrote this; checked and posted by me.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.