mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:45:54 +01:00
[PR #1585] rdna2spirv: emit OpBitFieldUExtract for the VOP3 16-bit result mask (NVIDIA And-&-0xFFFF miscompile) #1604
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1604
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1585
Author: @whoalin1
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:nc-i16-clamp-nv📝 Commits (3)
526b434rdna2spirv: emit OpBitFieldUExtract for the VOP3 16-bit result mask (NVIDIA And-&-0xFFFF miscompile)b816a5erdna2spirv: extend the BitFieldUExtract workaround to cvt_i16/snorm and d16 saturate69b363ddocs: escape the preserved-half merge pipe in the design table📊 Changes
4 files changed (+25 additions, -9 deletions)
View changed files
📝
docs/design.md(+1 -1)📝
tests/semantic/test_alu_add_sub_i16.py(+4 -1)📝
tests/semantic/test_valu_int16.py(+3 -1)📝
tools/rdna2spirv.py(+17 -6)📄 Description
Finding from the overnight fuzz campaign (coordination issue #14 — the issue's comment thread is currently at its cap, so context lives here): on NVIDIA'''s shader compiler,
OpBitwiseAnd %uint X, 0xFFFFmiscompiles whenXis a value that passed through%int-typed ops and the result feeds a preserve-high-half merge(old & 0xFFFF0000) | lo— the kept high half comes out corrupted while the low half is fine. Measured on an RTX 4070 SUPER (Windows, wave32):v_add_nc_i16 v14, v3, v12 op_sel:[1,1,0] clampwrote0x1113AAA8for the correct0x0002AAA8.OpBitFieldUExtract %uint X, 0, 16is spec-identical (zero-extended low 16) and does not trigger the miscompile. This PR emits it at every site where an int-derived value is masked for a preserved-16-bit-half merge:v_add/sub_{nc_,}{i16,u16}, the_rev/shift forms,v_mul_lo_u16,v_{min,max}_{u16,i16},v_mad_{u16,i16},v_{min,max,med}3_{u16,i16})v_cvt_i16_f16/v_cvt_norm_i16_f16conversions (aBitcastof an%intOpConvertFToS)saturate_int16feeding d16 image/buffer stores (aBitcastof an%intSClamp)The unsigned/unorm siblings, the
v_pk_*packed paths, and the f16put_f16_bitsidiom were audited and deliberately left: they either produce%uint-only values or build a packed dword rather than a preserve merge.Scope note (thanks @ecox982745): because the signed and unsigned conversions share the result-mask helper, the emitted SPIR-V for
v_cvt_u16_f16andv_cvt_norm_u16_f16also gains oneOpBitFieldUExtracteach (like their signed siblings), andv_cvt_pk_i16_i32gains two through the signed saturation helper, one per packed operand. These are the same spec-identical zero-extended-low-16 rewrite at zero cost; ecox982745's independent RTX 4090 sweep of all 65,536 binary16 encodings for each ofv_cvt_{i16,u16}_f16/v_cvt_norm_{i16,u16}_f16plus 65,536v_cvt_pk_i16_i32input pairs found 0 mismatches in 327,680 outputs per revision, with all GPU buffers byte-identical between revisions.Verification
0x0002AAA8;v_sub_nc_i16 … clamp0x0002AAAC; 160 randomizedv_add/sub_nc_i16programs across allop_sel/clampcombos — 0 mismatches vs a Python reference.v_cvt_i16_f16/v_cvt_norm_i16_f16spot checks produce correct results on both old and new SPIR-V (the miscompile did not reproduce on that shape, but the extract removes the risky pattern at zero cost).--pc-tail-ubo,LEONIDA_PC_TAIL_UBO=1): repro, sub-clamp, mad_i16, min3 cases all match NVIDIA/reference — no AMD regression (the op is spec-identical).python -I scripts/run_semantic_tests.py tests/semantic— 487 files / 6,279 tests, 0 failures. Two tests that pinned theOpBitwiseAnd … 0xFFFFshape were updated to the extract form with their negative controls intact.compileallclean; the changed ops all passspirv-val.docs/design.mdcontract-table row forv_add_nc_i16/v_sub_nc_i16documents the workaround, the trigger shape, and the confirmation method.Independent review: initial pass found three missed sites of the same idiom (now covered); re-review confirmed the six-site coverage is exhaustive against a full census of
And … 0xFFFFemit sites.AI-assisted (Devin).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.