Repository navigation
rdna2spirv: v_cndmask_b32's abs/neg source modifiers are sign-bit moves - #4103
Exopus-0x65f7ad0 wants to merge 2 commits into
Conversation
v_cndmask_b32 read its sources with src_u, whose modify() applies VOP3 abs/neg through SPIR-V FAbs/OpFNegate. Those may quiet a signalling NaN (the mini interpreter does: -v1 of 0x7F800001 came out 0xFFC00001) or flush a denormal, which a bit move never does. The sources now go through src_u_sign_mods: abs clears bit 31 and neg flips it on the raw bits, as the translator already does for v_cmp_class_f32, whose input modifiers are measured as sign-bit moves on gfx1036. tests/semantic/test_cndmask_sign_mods.py: 15 words (signalling/quiet NaNs, denormals, zeros, infinities, normals) x v, -v, |v|, -|v| x both operands through the interpreter, no FAbs/OpFNegate in the module, and spirv-val when it is on PATH. docs/design.md: the contract row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 1edc31b8 on Windows 11: python tests/semantic/test_cndmask_sign_mods.py -> 4 tests, OK; compileall and git diff --check clean.
The test distinguishes bit moves from float ops on signallings NaNs and denormals for both abs and neg on either source, and the ordinary select cases still match. Implementing the modifiers as sign-bit operations is the correct semantics for a bitwise select. No blocking issue.
|
Windows x86-64 check of
AI-assisted (Claude). No game files, no GPU. |
|
Automated test:
Same machine and setup as my earlier manual reports. AI-assisted (Claude Code). |
|
Tested at the head on Windows 11 / Python 3.13.0: 4 tests / 120 subtests OK; reverting gives 21 failures, as claimed; The change is right: One gap: the condition operand is not covered. Approve. AI-assisted review, no game files, no GPU. |
…enormal bits Signalling NaNs and a denormal through -v, |v| and -|v| on src0 and src1. On an RTX 5060 Ti (driver 621.14) the old FAbs path gave 0x7fffffff for |0xff800001| (the driver's canonical NaN); with the sign-bit moves all 4096 pixels are exact. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Added a GPU test, Run on an NVIDIA GeForce RTX 5060 Ti, driver 621.14, Windows 11, with
So the quieting isn't just the mini interpreter's: NVIDIA's |
|
Targeted Vulkan readback on an RTX 3070: I translated the same synthetic wave32 All 30 differences at base were modified NaNs: five input patterns × three modifiers × two source slots. Every one returned Windows 11 build 26200, NVIDIA driver 617.14, subgroup size 32, CPython 3.14.10, LLVM 23.1.5, SPIRV-Tools v2026.4. Synthetic inputs only. AI-assisted with Codex. |
|
On an RTX 3070 with driver 617.14, the official The baseline difference was confined to the second channel of every pixel. Absolute value of the negative signaling NaN produced Windows 11, CPython 3.14.10, LLVM 23.1.5, SPIRV-Tools v2026.4. Both runs used the same |
Claim: #3918 (comment) (new SHADER item)
Problem
v_cndmask_b32(Genintools/rdna2spirv.py) read both sources withsrc_u, whosemodify()applies a VOP3abs/negthrough SPIR-VOpExtInst FAbs/OpFNegate.v_cndmaskonly moves bits, so on hardware those modifiers are sign-bit moves; SPIR-V's float ops may quiet a signalling NaN and, under a flushing float mode, flush a denormal. The translator already handles exactly this forv_cmp_class_f32(whose input modifiers are measured as sign-bit moves on gfx1036, all four MODE settings) andv_pack_b32_f16, but not forv_cndmask.Through
tests/semantic/spirv_mini_interp.py, onmain:v1-v1|v1|-|v1|0x7F800001(sNaN)0xFFC00001(want0xFF800001)0x7FC00001(want0x7F800001)0xFFC00001(want0xFF800001)0xFF800001(sNaN)0x7FC00001(want0x7F800001)0x7FC00001(want0x7F800001)0xFFC00001(want0xFF800001)Change
Gen.src_u_sign_mods(a): the source read without itsabs/neg, thenOpBitwiseAnd 0x7FFFFFFFforabsandOpBitwiseXor 0x80000000forneg(abs first), the same sequencecmp_classemits.v_cndmask_b32reads src0 and src1 through it. Nothing else changes (SDWA selection still happens insrc_u, before the modifiers).docs/design.md: a contract row, "v_cndmask_b32source modifiers", with how it's backed (below).How the rule is confirmed
v_cndmaskitself (I have no RDNA2 GPU).v_cmp_class_f32are hardware-measured as raw sign-bit moves on gfx1036 (672/672, all four IEEE/denorm modes; the "Floating-point class compare" row).fneg/fabsthrough a select intov_cndmask_b32_e64's source modifiers (AMDGPUTargetLowering::foldFreeOpFromSelect), which is only exact if they are sign-bit moves (LLVM'sfneg/fabsnever quiet).A GPU readback on an AMD card would be welcome.
Tests
tests/semantic/test_cndmask_sign_mods.py(new, hand-written assembly, no game files): 15 words (signalling and quiet NaNs of both signs, denormals, ±0, ±inf, normals) xv1,-v1,|v1|,-|v1|x the modified operand as src0 and as src1; the unselected modified operand doesn't leak; noFAbs/OpFNegatein the module; andspirv-as+spirv-val --target-env vulkan1.3on each module when they're on PATH (they were, from Vulkan SDK 1.4.363.0).test_cndmask_sign_mods.pymain's translator (LEONIDA_TOOLS_DIR)Full
python -m unittest discover -s tests/semantic(Windows 11, Python 3.12): 7,460 tests, the same 9 failures/errors asmainaa2988cc(7,456 tests there):test_divergent_loop_wave64_emulate_and_native_cs(3),test_rejected_forms(2),test_each_mutation_is_caught,test_anchors_match_crlf_translator_copies,test_nested_divergent_loops_emulate,test_bug4b_loop_carried_split_sgpr_pair_ballot, all red onmainand taken (TEST-857, #3995, ...).tests/test_design_contract_rows.py,test_docs_design_rows.py,test_docs_table_rows.py,test_docs_repo_paths.py: OK.Limitations
v_cndmaskwithabs/negis unknown.v_pack_b32_f16; for a non-arithmetic op likev_cndmaskthev_cmp_class_f32measurement suggests none.AI-assisted (Claude Code). CPU and spirv-val only; not run on a GPU.