fix: f64/f32 points from the review of #139 (v_cvt_f64_f32 abs/neg in HLSL, v_fract NaN and bound, 1/(2*pi), sign of zero) #209
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!209
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/209/head"
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 15:14 UTC · original
KainanP:fix/f64-cvt-modifiers-fract-nan→main· +199 −20 · 7 files · 5 commits · merged 2026-11-25 15:41 UTCChange
Fixes the two blocking points and the four non-blocking notes of @Exorion1er's review of #139 (#139), which were merged into
mainwith the RDNA 2 stack before they could be fixed there.Linked issue: Refs #139
Four commits, one per point:
v_cvt_f64_f32applies abs/neg in HLSL (blocking point 1). The f32 source went throughsource()without its VOP3 modifiers while the interpreter applies them:v_cvt_f64_f32_e64 v[0:1], -v2with v2 = 1.0 gave -1.0 in the interpreter and +1.0 on the GPU. The conversion is now done with integers: abs/neg on bit 31, then the exact f32 → f64 conversion (ISA: 0 ULP, denormals kept), NaN made quiet with its sign and payload, like the interpreter. Measured while writing the test:(double)asfloat(x)returns0x7FFFFFFFE0000000for every NaN on the RTX 4060 (sign and payload lost), so keeping the old double cast with modifiers added would still have diverged. Side effect: the translation needs no doubles any more, so the parity test also runs on Intel UHD (no FP64).v_fract_f64on NaN and ±infinity (blocking point 2)._fractcalledmath.floor(nan)(PythonValueError). Now: NaN in → the same NaN, made quiet (sign and payload kept); ±infinity → NaN. Following the review's note, the result is also bounded by the largest double below 1.0 (0x3FEFFFFFFFFFFFFF): the ISA formula isS0 + -floor(S0), and LLVM models the instruction with that bound (ConstantFolding.cpp,amdgcn_fract: "prevent fract(-small) from returning 1.0"). Read in LLVM, not measured on hardware. In the same commit:trunc/ceil/floor/rndne_f64keep the sign of zero (trunc(-0.5) = -0.0, IEEE 754 roundToIntegral), and the module docstring says that the ISA givesv_rcp_f64,v_rsq_f64andv_sqrt_f64to 2^29 ULP while the interpreter returns the correctly rounded value (none of them is translated to HLSL).0x3FC45F306DC9C882. The RDNA 2 ISA (November 2020, §6.2 "Operands", p. 41) gives the exact value used: half0x3118, single0x3e22f983, double0x3fc45f306dc9c882; LLVM uses the same double (AMDGPUBaseInfo.cpp,isInlinableLiteral64). Fixed in both places the review named:rdna2_exec_cmp64(interpreter, f64 compares and f64 operations) andrdna2_hlsl_wide. The f32 value was already right.mainbefore #139). Measured on the three adapters:trunc/ceil/rndne(-0.5)andfloor(-0.0)return -0.0 on RTX 4060, WARP and Intel UHD, the interpreter gave +0.0;frac(-1e-20)returns0x3F7FFFFFon WARP and Intel UHD but 1.0 on the RTX 4060. The interpreter now keeps the sign of zero and boundsv_fract_f32below 1.0; the HLSL boundsfracwith a compare (notmin, so a NaN goes through unchanged). Left out on purpose: NaN results,fract(±inf)and denormal inputs, whose NaN pattern and flushing differ between the three adapters (measured: NaN0x7FFFFFFFon RTX, input payload or0xFFC00000on WARP/Intel; f32 denormals flushed on all three). That is a separate question.Verification
Windows 11 26200, Python 3.12, runtime built from this branch (VS 2022 Build Tools, CMake), on top of
mainat488a71c:README: the test count stays
1100+(each commit checked: README count = collected tests rounded down, RDNA 2 coverage numbers =rdna2_exec.coverage()).Oracle and test data
v_cvt_f64_f32; 16 sources ×v_fract/trunc/ceil/rndne/floor_f32.v_fract_f64and the f64 roundings have no HLSL translation (HLSL has no doublefloor): the recompiler names them (Untranslatable), now tested forv_fract_f64too.mainand the tests of this branch, 20 tests fail on each of RTX 4060, WARP and Intel UHD.Checklist
E_NOTIMPL), never a fake success.Made with AI assistance (Claude Code, Claude Opus 5.5); tests run on the three adapters above.
🤖 Generated with Claude Code
@KainanP on GitHub · 2026-11-25 18:59 UTC · original
Hardware measurement requested: https://github.com/akimfomin/PortBridge/issues/82
AI use: Claude Code (Claude Opus 5.5).