feat: f16 integer and normalized conversions, pknorm/pack and min3/max3/med3 in the RDNA 2 interpreter and HLSL — 1,364/1,490 #275
No reviewers
Labels
No labels
accessibility
bloqué : binaire console
bug
chargeur
console-dll
cpu
documentation
duplicate
enhancement
good first issue
gpu
help wanted
invalid
performance
question
runtime-gdk
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LooperSalty--AnyXboxX!275
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-275"
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?
@KainanP on GitHub · 2026-11-25 23:54 UTC · original
KainanP:feat/f16-int-norm-pack→main· +871 −10 · 12 files · 3 commits · openChange
The reference interpreter and the HLSL recompiler now run 20 half-precision encodings that until now raised
Untranslated/Untranslatable: the 16-bit integer and normalized conversions, the pknorm/pack ops and the three-operand f16 min/max/median.v_cvt_f16_{u16,i16},v_cvt_{u16,i16}_f16(8)v_cvt_norm_{i16,u16}_f16(4)× 32767/× 65535v_cvt_pknorm_{i16,u16}_{f16,f32},v_pack_b32_f16(5)pknorm=cvt_normon each half / f32 word,{S1, S0};pack={S1.f16, S0.f16}v_min3_f16,v_max3_f16,v_med3_f16(3)min(min(S0, S1), S2)/max(max(…))built on main'sv_min/max_f16;med3as the ISA pseudocode (any NaN →min3)VOP3:
abs/negact on bit 15 of an f16 half (bit 31 of an f32 source);op_selis accepted where the ISA's table 21 allows it (v_cvt_pknorm_*_f16,v_pack_b32_f16: source halves;v_min3/max3/med3_f16: source halves, andop_sel[3]writesD[31:16]);clampsaturates an f16 result to [0, 1] (NaN → +0), as the f16 ops of #218 do. A float inline constant on the 16-bit integer source ofv_cvt_f16_{u16,i16}gives the low half of its f32 pattern, as #226 settled for 16-bit integer sources (LLVMSIInstrInfo::isInlineConstant). Everything unsourced is refused by name on both sides: SDWA/DPP forms,omod,op_selon the VOP1 opcodes, on f32 sources, on the destination of the 32-bit packs and on the high half of a constant,abs/negon integer sources, andclampon integer or packed results.How it sits with other work:
0x7E00), and the HLSL reuses hisF32ToF16/F16IsNan/F16Min/F16Max/F16Clamphelpers instead of redefining them.v_min3/max3/med3_f16call hishalf_min/half_max(interpreter) andF16Min/F16Max(HLSL), so their NaN and signed-zero rules are exactly main'sv_min/max_f16.v_floor/ceil/trunc/rndne_f16), #246 (v_cvt_pkrtz_f16_f32), #247 (v_fract_f16,v_frexp_mant_f16,v_frexp_exp_i16_f16) and #250 (f16 compares in HLSL) — none of their opcodes is here. The code is a separate module pair (emu/rdna2_exec_f16conv.py,emu/rdna2_hlsl_f16conv.py); the dispatchers get one import and one branch each, so the only textual overlap with those PRs is the README coverage line (and the HLSL helper list next to #250).v_min/max/min3/max3/med3NaN and ±0 rules): the f16 versions here already follow the same rules — a NaN operand gives the other operand, −0 is below +0,med3with a NaN source ismin3, somed3(NaN, 0, 1.0)= +0. The median compares as floats (+0 == −0) exactly like #269'smedian3.Coverage: interpreter 1,344 → 1,364 of 1,490 encodings on current
main(rdna2_exec.coverage()prints(1364, 1490); README 91%), in the 2 READMEs (English and French); the test count is 1900+ (1,940 collected).docs/images/*.svgare left as on main (they still show an older count and need a package for the imports bar).Linked issue: none.
Verification
Windows 11, Python 3.12, runtime built with CMake (run on
3e258c8; the rebase onto578098bonly brings #274's README lines).The two new files plus the neighbouring f16/graphics/wave64 GPU tests (
test_rdna2_exec_f16conv.py,test_rdna2_hlsl_f16conv.py,test_rdna2_hlsl_f16.py,test_rdna2_f16.py,test_rdna2_graphics.py,test_rdna2_hlsl_wave64.py) on the two other adapters:Oracle and test data
test_f16conv_ops_match_interpreter_on_gpu(wave32) and..._in_wave64: every one of the 20 encodings with its accepted VOP3 variants (neg/abs,clamp,op_sel), inline f16/integer constants and literals, under a partial EXEC (0x0F0FF0F3;0xF00F0FF0for the upper 32 lanes), on per-lane sources built from 36 f16 boundary halves (±0, denormals, 0.5 ties, 0.5 + 2^-11, 1 − 2^-11, 32768, 65504, ±inf, quiet/signalling/negative NaNs) under junk other halves and 25 f32 boundary words (denormals, near-ties of the norm products, ±inf, NaNs), one lane in eight random, each destination preset to a per-lane old value.test_parity_program_results_vary_by_laneguards that results vary per lane and that inactive lanes keep their old value.test_unary_ops_on_every_f16_input_match_interpreter_on_gpu: the 6 unary ops on all 65,536 16-bit inputs (a 2,048-step loop over 32 lanes), each 32-bit destination word folded into a per-lane, per-op checksum (rotl(sum, 5) + word), so one wrong word on any input changes the stored memory.test_helpers_compile_in_vertex_and_pixel_shaders: the helpers are present and compile invs_6_0/ps_6_x.pknorm_f32is held in two words), so results do not depend on a driver's denormal handling or float folding, and they run on Intel UHD without FP64.tests/test_rdna2_exec_f16conv.py, arithmetic in the comments): edges, ties, saturation ends,op_sel, constants, inactive lanes, the min3/max3/med3 NaN and ±0 cases, and every refused form (with the HLSL refusal).emu.rdna2_exec_f16convdoes not exist) and each of the 20 encodings raisesinstruction non traduite.Sources (labelled per
docs/research/rdna2-sources.md; printed page numbers of the archived PDF, SHA-25622aec03f…4795):V_CVT_U16_F16/V_CVT_I16_F16"Conversion is done with truncation", "supports … saturation";V_CVT_F16_U16/I16andV_CVT_NORM_*"0.5ULP accuracy".V_PACK_B32_F16D[31:16].f16 = S1.f16; D[15:0].f16 = S0.f16;V_CVT_PKNORM_*_F16D = {(snorm)S1.f16, (snorm)S0.f16},V_CVT_PKNORM_*_F32D.i16_lo = (snorm)S0.f32; D.i16_hi = (snorm)S1.f32;V_MIN3_F16:D.f16 = V_MIN_F16(V_MIN_F16(S0.f16, S1.f16), S2.f16),V_MAX3_F16alike (p. 181);V_MED3_F16(p. 182):if (isNan(S0.f16) || isNan(S1.f16) || isNan(S2.f16)) D.f16 = V_MIN3_F16(S0.f16, S1.f16, S2.f16); else if (V_MAX3_F16(S0.f16, S1.f16, S2.f16) == S0.f16) D.f16 = V_MAX_F16(S1.f16, S2.f16); else if (… == S1.f16) D.f16 = V_MAX_F16(S0.f16, S2.f16); else D.f16 = V_MAX_F16(S0.f16, S1.f16).V_MAX_F16/V_MIN_F16pseudocode —else if (S0.f16 == NaN) D.f16 = S1.f16; else if (S1.f16 == NaN) D.f16 = S0.f16; else if (S0.f16 == +0.0 && S1.f16 == -0.0) …(−0.0 below +0.0), the same rows #269 quotes for f32. Main'shalf_min/half_maxalready implement them, andmin3/max3/med3inherit them here. TheIEEE_MODE && sNaN → Quiet(…)rows are not modelled (as on main).V_CVT_PKNORM_{I16,U16}_F16,V_MIN3/MAX3/MED3_{F16,…},V_PACK_F16, and "not for VOP1, VOP2 or VOPC instructions using the VOP3 encoding".VOP1Instructions.td:fp_to_uint_sat/fp_to_sint_satare selected tov_cvt_u16_f16/v_cvt_i16_f16("These i16 conversions naturally saturate"; the LangRef'sllvm.fpto*i.satgives 0 for NaN).AMDGPUInstCombineIntrinsic.cpp,fmed3AMDGCN: constantllvm.amdgcn.fmed3(f32 and f16) is folded with the ISA's median rule — compare againstmaxnum(maxnum(S0, S1), S2)(an APFloat compare, so +0 == −0), thenmaxnumof the other two — and a NaN operand folds tominnumof the other two, i.e.min3.GCNSubtarget::zeroesHigh16BitsOfDest: "On gfx10, all 16-bit instructions preserve the high bits" (v_cvt_f16_{u16,i16}are listed).Assumptions left open (measurement requests)
These rest on no published measurement; each is a small hardware run (RDNA 2, wave32, default MODE):
v_cvt_pknorm_{i16,u16}_f32: one rounding of the exact product (asv_cvt_norm_*'s "0.5ULP accuracy"), or an f32 product rounded first? They differ only on near-ties, e.g.0x3EFFFFFF(0.5 − 2^-25) × 32767 = 16383.49999902 → 16383 here, 16384 with an f32 product.0.5 × 32767= 16383.5 → 16384,0.5 × 65535→ 32768), from the ISA's default round mode; D3D's description (+0.5 then truncate) allows ±1 tolerance._e32) forms keep the high half of the destination like the VOP3 ones (LLVM's gfx10 rule for 16-bit instructions);v_cvt_{u16,i16}_f16andv_cvt_norm_*are not in LLVM's list.abs/negon an f16 half or a packed half are bit operations on bit 15.v_min3/max3/med3_f16with every source NaN give0x7E00(main'sv_min/max_f16returns the canonical NaN; the pseudocode would pass S1 through, which #269 keeps for f32); withIEEE_MODEset, a signalling NaN source should come back quieted instead of being skipped — not modelled, as for main'sv_min/max_f16and #269.v_med3_f16(-0, +0, -1)= +0 from the ISA pseudocode and LLVM's fold (max3 = +0 "equals" S0 = −0, so the result ismax(S1, S2)); a sorted median would give −0.clamponv_cvt_{u16,i16}_f16(the ISA says the bit only gates the INEXACT exception there),v_cvt_norm_*,v_cvt_pknorm_*,v_pack_b32_f16;op_sel[3]on the 32-bit packs;omod(whether it applies to f16 destinations depends on MODE).Checklist
E_NOTIMPL), never a fake success. (Unsourced forms raiseUntranslated/Untranslatablenaming the instruction and the modifier.)test_readme_sync.pychecks it).Made with AI assistance: Claude Code with Claude Opus 5.5, for KainanP.
🤖 Generated with Claude Code
20 encodings that raised Untranslated / Untranslatable: v_cvt_f16_{u16,i16}, v_cvt_{u16,i16}_f16 and v_cvt_norm_{i16,u16}_f16 (VOP1 and VOP3), and the VOP3 v_cvt_pknorm_{i16,u16}_{f16,f32}, v_pack_b32_f16 and v_min3/max3/med3_f16. New modules emu/rdna2_exec_f16conv.py and emu/rdna2_hlsl_f16conv.py, built on IxMxAMAR's f16 modules (#218, #219): same half-register conventions, and min3/max3/med3 use half_min/half_max and F16Min/F16Max, so their NaN and signed zero rules are main's v_min/max_f16 (ISA V_MIN/MAX_F16 pseudocode). The HLSL helpers are integer-only (no FP64, no loop). Unsourced modifier forms are refused by name on both sides. Semantics from the AMD RDNA 2 ISA (November 2020), LLVM AMDGPU and Microsoft Learn data conversion rules; assumptions are listed in the module docstring. Co-Authored-By: Claude Opus 5.5 <[email protected]>f5cc86ec6bto6a72be899e@KainanP on GitHub · 2026-11-26 09:11 UTC · original
Rebased onto main
c4c93bdafter #230/#232/#235 merged (head6a72be8). README recounted fromrdna2_exec.coverage(): 1,305 of 1,490 RDNA 2 encodings (88%) in the 9 READMEs (main's 1,285 + this PR's 20), tests 1700+. The French and Russian READMEs had "1.285" with a dot on main; they now use the space their "1 490" uses.Code conflicts were in the dispatch and helper lists of
rdna2_exec_vop3.py,rdna2_hlsl.py,rdna2_hlsl_graphics.pyandrdna2_hlsl_wave64.py, where #232 (int16) and the f16 compare PRs added entries next to this PR's. I kept both sides. None of the 20 names is handled byrdna2_exec_f16,rdna2_exec_int16orrdna2_exec_cmpf16, and none is in the HLSL f16/int16 tables, so the order of the checks doesn't change anything.Tests: full suite on the RTX 4060: 1684 passed, 17 skipped. The f16conv HLSL parity and interpreter files: 36 passed on WARP and 36 passed on Intel UHD. Ruff clean.
AI use: Claude Code (Claude Opus 5.5).
@KainanP on GitHub · 2026-11-26 11:26 UTC · original
#302 made this PR conflict, so I merged
maininto the branch (merge commit6b06430, no rebase).Kept both sides in
rdna2_exec.py,rdna2_exec_vop3.py,rdna2_hlsl.py,rdna2_hlsl_graphics.pyandrdna2_hlsl_wave64.py: #302's VOP3P packed f16 andv_pk_fmac_f16(imports, dispatch, EXECUTABLE, HELPERS,coverage_names), plus this PR'srdna2_exec_f16conv/rdna2_hlsl_f16conv. The two sets of instruction names don't overlap, so the dispatch order doesn't change either side.README:
rdna2_exec.coverage()on the merged tree is 1,332 of 1,490 (89%), up from the 1,305 (88%) this PR claimed. I updated that in the 9 READMEs. The test count stays 1700+ (1,710 collected).Tests on the merged tree:
tests/test_rdna2_hlsl*98 passed. Full suite: 1695 passed, 15 skipped. The skips are Rust/TomBox builds that aren't present locally.test_rdna2_hlsl_f16conv.py,test_rdna2_exec_f16conv.pyandtest_rdna2_hlsl_pkf16.py40/40 passed on each.rdna2_opsverifier: 38,999 encodings, 0 wrong lengths.AI use: Claude Code (Claude Opus 5.5).
@KainanP on GitHub · 2026-11-26 12:48 UTC · original
Merged
main(#351) into the branch with a merge commit (eb7b150), no rebase.rdna2_exec.coverage()on the merged tree.crates/anyxboxx-report/data/rdna2-coverage.txtmust follow the Python measure, so7afa9f4regenerates it (python tests/test_rust_traduction_parity.py: VOP1 68 → 74, VOP3 404 → 418).pytest -n auto,ANYXBOXX_REQUIRE_RUNTIME=1) 1844 passed, 1 skipped;test_rdna2_hlsl_f16conv.py8 passed on WARP and on Intel UHD; ruff (W605,F,E9) clean;rdna2_mnemonics.py --verifieron the gfx10 LLVM tests OK (38,999 encodings). CI green.Note: #343 also regenerates that table (MIMG row), so whichever merges second will need a one-line merge there.
AI use: Claude Code (Claude Opus 5.5).
@LooperSalty on GitHub · 2026-11-26 15:27 UTC · original
This PR now conflicts with main in
crates/anyxboxx-report/data/rdna2-coverage.txt(the coverage counts moved after #310 and #353). Please rebase on main, regenerate the coverage file and the counts in the 9 READMEs with the repository tools instead of editing by hand, run the RDNA 2 tests and force-push your branch.🤖 Generated with Claude Code
7afa9f4c5ctoed48058e8f@KainanP on GitHub · 2026-11-26 15:50 UTC · original
Rebased on main
8473267(headed48058, three commits, no merge commits). The previous head is kept locally as tagpre-rebase2-275.crates/anyxboxx-report/data/rdna2-coverage.txt: took main's version, then regenerated it withpython tests/test_rust_traduction_parity.py. VOP1 75 → 81, VOP3 411 → 425 (the 20 encodings of this PR).rdna2_exec.coverage()on the rebased tree gives 1,346 of 1,490 (90%). I wrote that into the 9 READMEs from the function's output with a script, not by hand. Main still showed 1,285 (86%). The test count stays 1800+ (1,886 collected).rdna2_exec.py,rdna2_exec_vop3.py,rdna2_hlsl.py,rdna2_hlsl_graphics.pyandrdna2_hlsl_wave64.py: I kept both sides. None of the 14 names here (20 encodings) is inrdna2_exec_f16(#310's transcendentals included),rdna2_exec_int16,rdna2_exec_cmpf16,rdna2_exec_pkf16or the HLSL f16/int16/pkf16 tables. #353 only touches Rust MIMG code.Checks on the rebased tree:
ANYXBOXX_REQUIRE_RUNTIME=1 pytest -n auto): 1885 passed, 1 skipped (test_runtime_package.py:235, "Rust refusal differs from C++"). That includestest_readme_sync.pyandtest_built_in_gpu_table_is_up_to_date.test_rdna2_hlsl_f16conv.py: 8 passed on WARP, 8 passed on Intel UHD.rdna2_mnemonics.py --verifieron the gfx10 LLVM tests: 38,999 encodings, 0 wrong lengths.AI use: Claude Code (Claude Opus 5.5).
ed48058e8fto13325ca205@KainanP on GitHub · 2026-11-26 16:21 UTC · original
Rebased on main
ce0f90fafter #343 (head13325ca, three commits, no merge commits; previous head kept locally as tagpre-rebase3-275).HELPERSlines inrdna2_exec.py,rdna2_hlsl.py,rdna2_hlsl_graphics.pyandrdna2_hlsl_wave64.py, next to #343's gather lines: both kept.crates/anyxboxx-report/data/rdna2-coverage.txt: regenerated withpython tests/test_rust_traduction_parity.pyon the rebased tree (VOP1 75 → 81, VOP3 411 → 425; MIMG keeps main's 57).rdna2_exec.coverage()gives 1,364 of 1,490 (91%). Main's code is at 1,344 (its READMEs still read 1,330), this PR adds 20. Test count 1900+ (1,932 collected).ANYXBOXX_REQUIRE_RUNTIME=1,pytest -n auto) 1931 passed, 1 skipped;test_rdna2_hlsl_f16conv.py8 passed on WARP and on Intel UHD;rdna2_mnemonics.py --verifier38,999 encodings, 0 wrong lengths; ruff (W605,F,E9) clean.AI use: Claude Code (Claude Opus 5.5).
@LooperSalty on GitHub · 2026-11-26 17:26 UTC · original
The count does not match across the PR. The title says
1,228/1,490, the README rows say1,364 of the 1,490(the earlier comment said 1,305). Please set the title to the number printed byrdna2_exec.coverage()after the rebase, and use that same figure in the 9 READMEs, including the 91% row. The HLSL tests compare against the reference interpreter byte for byte, so the code side looks ready.🤖 Generated with Claude Code
feat: f16 integer and normalized conversions, pknorm/pack and min3/max3/med3 in the RDNA 2 interpreter and HLSL — 1,228/1,490to feat: f16 integer and normalized conversions, pknorm/pack and min3/max3/med3 in the RDNA 2 interpreter and HLSL — 1,364/1,490@KainanP on GitHub · 2026-11-26 17:43 UTC · original
Title fixed:
rdna2_exec.coverage()prints(1364, 1490)on this branch, and also on the branch merged with currentmain(merges cleanly). The 9 READMEs already use 1,364 of 1,490 and the 91% row; the 1,228 and 1,305 figures were from earlier bases.AI use: Claude Code (Claude Opus 5.5).
13325ca205to6ff62eb452@KainanP on GitHub · 2026-11-26 18:26 UTC · original
Rebased onto main
8e32daa(after #407), head6ff62eb, three commits (previous head kept locally as tagpre-rebase4-275).rdna2_exec.coverage()on the rebased tree prints (1364, 1490), the same as before. The title, the GPU bullet (91%) and "1,364 of the 1,490" in both READMEs all use this figure. Main's READMEs read 1,330 (89%).rdna2-coverage.txt: started from main's copy and regenerated withpython tests/test_rust_traduction_parity.py. The result is the same as this branch's (VOP1 81, VOP3 425). Test count stays 1900+ (1,940 collected).ANYXBOXX_REQUIRE_RUNTIME=1,pytest -n auto) 1939 passed, 1 skipped.test_rdna2_hlsl_f16conv.py8 passed on WARP and on Intel UHD.rdna2_mnemonics.py --verifier: 38,999 encodings, 0 wrong lengths. ruff (W605,F,E9) clean.AI use: Claude Code (Claude Opus 5.5).
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.