feat(rdna2): implement 16-bit float transcendentals (VOP1/VOP3) in interpreter and HLSL (1,299/1,490) #310
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!310
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-310"
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?
@Lewandox on GitHub · 2026-11-26 02:14 UTC · original
Lewandox:feat/rdna2-f16-transcendentals→main· +526 −2 · 4 files · 5 commits · merged 2026-11-26 15:26 UTCChange
Implement the 7 RDNA 2 16-bit float (
f16) transcendental instructions in both the reference interpreter (PrototypeScarlett/emu/rdna2_exec_f16.py) and the HLSL recompiler (PrototypeScarlett/emu/rdna2_hlsl_f16.py), covering both VOP1 and VOP3 encodings (+14 encodings, raising interpreter coverage from 1,285/1,490 to 1,299/1,490):v_rcp_f16(VOP1 opcode 84) —1.0 / S0.f16v_sqrt_f16(VOP1 opcode 85) —sqrt(S0.f16)v_rsq_f16(VOP1 opcode 86) —1.0 / sqrt(S0.f16)v_log_f16(VOP1 opcode 87) —log2(S0.f16)v_exp_f16(VOP1 opcode 88) —pow(2.0, S0.f16)v_sin_f16(VOP1 opcode 96) —sin(S0.f16 * 2 * pi)v_cos_f16(VOP1 opcode 97) —cos(S0.f16 * 2 * pi)Key details
22aec03f2706dba2e148ffde1f3a25d5cdd42c71a96f95240aeb48d995d44795), Section 12.8, VOP1 opcodes 84–88 and 96–97 (printed pages 147–149), cross-checked against GPUOpenamdgpu_isa_rdna2.xml.v_sin_f16/v_cos_f16: inputs are reduced modulo 1 turn (x - trunc(x)) and mapped to the first octant[0, 0.125]before multiplying by2 * pi, so large finite integers (+-65504), quarter-turns (+-0.25,0.5,0.75), and negative subnormals (-2^-24) match the ISA functional examples (V_SIN_F16(0xfbff) => 0x0000,V_COS_F16(0x3400) => 0x0000,V_SIN_F16(0x8000) => 0x8000) with zero f32/f64 rounding drift across all 65,536 binary16 inputs.op_sel,abs,neg, andclampin VOP3, preserves high/low halves and inactive EXEC lanes, refuses unsourcedomodand SDWA/DPP forms in both interpreter and HLSL, and works in compute (wave32 & wave64) and graphics shaders without touching any other module.emu/rdna2_exec_f16.pyandemu/rdna2_hlsl_f16.py(0x7E00).Verification
@gpu) were skipped locally becausedxc/anyxboxx_gpu_run.exeare not installed on this machine; CI runs the Windows WARP GPU parity suite (both wave32 and wave64 tests are included intests/test_rdna2_f16_transcendentals.py).rcp,sqrt,rsq,log2,sin, andcos(and 1 tie-boundary difference at0x11c5forexp2, well within the ISA's 0.51 ULP specification).Oracle and test data
tests/test_rdna2_f16_transcendentals.py(GPL-3.0-or-later, same as repository).tests/test_rdna2_f16_transcendentals.pyfail withUntranslated/Untranslatablewithout this change and pass with it.Checklist
E_NOTIMPL), never a fake success.test_readme_sync.pychecks it).Made with AI assistance.
@LooperSalty on GitHub · 2026-11-26 10:38 UTC · original
Review (rule 4, oracle): the description says the f64 interpreter formula and the f32 HLSL helper differ on one binary16 input for
v_exp_f16(0x11c5, a tie boundary). Rule 4 asks for byte-for-byte parity between the HLSL and the reference interpreter, and the tests deliberately avoid ties ("no 0.5 ULP ties"), so this known divergence is not covered by any test.Please:
half_exp2andF16Expround the same way (same intermediate precision and same tie rule), so0x11c5matches, or refuse the input by name if it cannot be made exact.v_rcp/sqrt/rsq/log/exp/sin/cos_f16, so the claimed exhaustive check lives in the suite and not only in the PR text.The rest (VOP1/VOP3, op_sel/abs/neg/clamp, refusals of omod/SDWA/DPP, synthetic encodings, sources cited) looks good.
🤖 Generated with Claude Code
@Lewandox on GitHub · 2026-11-26 14:52 UTC · original
Thanks for the thorough review! Addressed all three points in the latest commit:
0x11c5(and all 65,536 binary16 inputs): replaced the hardwareexp2(x)call inF16Exp(PrototypeScarlett/emu/rdna2_hlsl_f16.py) with range reduction (2^x = 2^n \cdot 2^f,f \in [-0.5, 0.5]), a split-\ln(2)precise floatpolynomial (f \cdot \text{LN2\_HI}is exact in f32 for all 11-bit f16 significands), and TwoSum + round-to-odd (same pattern asF16Fma) before scaling by2^nandF32ToF16. This eliminates double rounding soF16Exp(0x11c5) == 0x3c01 == half_exp2(0x11c5). Also replaced hardwarelog2/sin/cosinF16LogandF16Trigwith deterministicprecise floatrange-reduced polynomials so GPU SFU ULP differences cannot flip ties across vendors/WARP.test_f16_transcendentals_exhaustive_parity_on_gpuintests/test_rdna2_f16_transcendentals.py, parameterized over all 7 instructions (v_rcp/sqrt/rsq/log/exp/sin/cos_f16), running a Wave32 loop over every binary16 encoding (0x0000..0xFFFF) in both the reference interpreter (rdna2_exec.run) and translated HLSL on GPU/WARP (rdna2_gpu.run), plus0x11C5 -> 0x3C01inISA_CASESandGPU_INPUTS.ISA_CASESinterpreter oracle tests intact.